summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeppia <nonso@insicuri.net>2016-06-12 06:40:34 +0200
committerSeppia <nonso@insicuri.net>2016-06-12 06:40:34 +0200
commitfa813ece17a99fb0a0a177ad5a0bf4f11d9629d7 (patch)
treeab30bd0e1e3807770a7aa54c8b2d28c7ee1c8c33
parent6fb039da2b18c278817dfcdb240e3e5032902e0a (diff)
downloadonetimebluh-fa813ece17a99fb0a0a177ad5a0bf4f11d9629d7.tar.gz
onetimebluh-fa813ece17a99fb0a0a177ad5a0bf4f11d9629d7.tar.bz2
onetimebluh-fa813ece17a99fb0a0a177ad5a0bf4f11d9629d7.zip
merged keygen.c to onetimbluh.c
-rw-r--r--onetimebluh.c45
1 files 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<stdio.h>
#include<stdlib.h>
#include<getopt.h>
+#include<openssl/rand.h>
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]);