summaryrefslogtreecommitdiffstats
path: root/old_code/keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'old_code/keygen.c')
-rw-r--r--old_code/keygen.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/old_code/keygen.c b/old_code/keygen.c
new file mode 100644
index 0000000..b03b89c
--- /dev/null
+++ b/old_code/keygen.c
@@ -0,0 +1,60 @@
+#include<stdio.h>
+#include<openssl/rand.h>
+#include<unistd.h>
+
+int main(int argc, char* argv[]) {
+
+ int opt;
+ int nbytes = 256;
+ char* defname = "default.key";
+ char* output;
+ int defout = 0;
+ int defbyte = 0;
+ int noopts = 0;
+ while ((opt = getopt(argc, argv, "b:o:")) != -1) {
+ switch (opt) {
+ case 'b':
+ nbytes = atoi(optarg);
+ defbyte = 1;
+ break;
+ case 'o':
+ output = argv[(optind-1)];
+ defout = 1;
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [-b nbytes] [-o output] \n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ if (noopts == 0) {
+ noopts = 1;
+ }
+ }
+
+ if(noopts == 0) {
+ printf("WARNING no option specified usign default values... \n");
+ }
+ if (nbytes < 0) {
+ printf("Negative byte value inserted! \n");
+ printf("Exiting... \n");
+ exit(EXIT_FAILURE);
+ } else if (nbytes != 0) {
+ if (defbyte == 0) {
+ printf("No byte number specified... using default value: 256 \n");
+ }
+ unsigned char key[nbytes];
+ RAND_bytes(key, nbytes);
+ if (defout == 0) {
+ output = defname;
+ printf("No output name specified... using default value: default.key \n");
+ }
+ FILE* file = fopen(output, "w");
+ fwrite(key, nbytes, 1, file);
+ fclose(file);
+ printf("Created key file %s of %d bytes \n", output, nbytes);
+ } else {
+ printf("Byte number specified is 0. \n");
+ printf("Doing nothing! \n");
+ }
+
+ exit(EXIT_SUCCESS);
+}