diff options
author | Seppia <nonso@insicuri.net> | 2016-06-15 16:12:22 +0200 |
---|---|---|
committer | Seppia <nonso@insicuri.net> | 2016-06-15 16:12:22 +0200 |
commit | 7207ab32cdb629d77cbf1fcc7786e4519cd1ba60 (patch) | |
tree | e925c762885d262ab5a2484afb5e92ec3d929d89 /old_code/keygen.c | |
parent | 3fc67dfb100be0dfc55c2f52be4678a57b095cdc (diff) | |
download | onetimebluh-7207ab32cdb629d77cbf1fcc7786e4519cd1ba60.tar.gz onetimebluh-7207ab32cdb629d77cbf1fcc7786e4519cd1ba60.tar.bz2 onetimebluh-7207ab32cdb629d77cbf1fcc7786e4519cd1ba60.zip |
moved sources to appropriate directories
Diffstat (limited to 'old_code/keygen.c')
-rw-r--r-- | old_code/keygen.c | 60 |
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); +} |