From fa813ece17a99fb0a0a177ad5a0bf4f11d9629d7 Mon Sep 17 00:00:00 2001 From: Seppia Date: Sun, 12 Jun 2016 06:40:34 +0200 Subject: merged keygen.c to onetimbluh.c --- onetimebluh.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/onetimebluh.c b/onetimebluh.c index 98d0d3b..3516cd3 100644 --- a/onetimebluh.c +++ b/onetimebluh.c @@ -1,8 +1,10 @@ #include #include #include +#include void xor(char* mess, char* keyf, char* outp); +void keyrand(int nb, char* outp); void help(char* av[]); int main(int argc, char* argv[]) { @@ -12,6 +14,8 @@ int main(int argc, char* argv[]) { char* message = NULL; char* keyfile = NULL; char* output = NULL; + int nbytes = -1; // must be resolved temporary workaround (ho sonno) + while (opt) { int option_index = 0; static struct option options[] = { @@ -29,7 +33,7 @@ int main(int argc, char* argv[]) { switch (opt) { case 'b': - printf("Work in progress \n"); + nbytes = atoi(argv[optind-1]); break; case 'e': message = argv[optind-1]; @@ -37,7 +41,6 @@ int main(int argc, char* argv[]) { comm = 'e'; break; case 'g': - printf("Work in progress \n"); command++; comm = 'g'; break; @@ -77,6 +80,8 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } xor(message, keyfile, output); + } else if (comm == 'g') { + keyrand(nbytes, output); } exit(EXIT_SUCCESS); @@ -113,6 +118,42 @@ void xor(char* mess, char* keyf, char* outp) { return; } +void keyrand(int nb, char* outp) { + + char* defoutp = "default.key"; + + if((nb == -1) && (outp == NULL)) { + printf("WARNING no option specified usign default values... \n"); + nb = 256; + outp = defoutp; + } + if (nb < -1) { // orribile + printf("Negative byte value inserted! \n"); + printf("Exiting... \n"); + exit(EXIT_FAILURE); + } else if (nb != 0) { + if(nb == -1) { + printf("No byte number specified... using default value: 256 \n"); + nb = 256; + } + unsigned char key[nb]; + RAND_bytes(key, nb); + if (outp == NULL) { + outp = defoutp; + printf("No output name specified... using default value: default.key \n"); + } + FILE* file = fopen(outp, "w"); + fwrite(key, nb, 1, file); + fclose(file); + printf("Created key file %s of %d bytes \n", outp, nb); + } else { + printf("Byte number specified is 0. \n"); + printf("Doing nothing! \n"); + } + + return; +} + void help(char* av[]) { printf("ONETIMEBLUH USAGE: \n"); printf("%s [COMMAND] [OPTIONS] \n \n", av[0]); -- cgit v1.2.3