summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/onetimebluh.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/onetimebluh.c b/src/onetimebluh.c
index e8da841..d657904 100644
--- a/src/onetimebluh.c
+++ b/src/onetimebluh.c
@@ -8,7 +8,7 @@
#include <error.h>
void xor (int ed, char* mess, char* keyf, char* outp); /* operates the bitwise XOR between mess and keyf and puts the output to outp */
-void keyrand (int nb, char* outp); /* generates random numbers using RAND_bytes from openssl and puts them into outp */
+void keyrand (long int nb, char* outp); /* generates random numbers using RAND_bytes from openssl and puts them into outp */
void bluh (int c, char* mess, char* outp, char* ch); /* performs the binary dump of the input file and prints that to outp */
void help (char* av[]); /* prints the help message */
@@ -22,7 +22,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)
+ long int nbytes = -1; // must be resolved temporary workaround (ho sonno)
+ char* sip = NULL;
/* The following while cycle parses the argv vector to find commands, options and relative arguments
using the function getopt_long */
@@ -91,7 +92,19 @@ int main (int argc, char* argv[]) {
}
break;
case 'n':
- nbytes = atoi (argv[optind-1]);
+ nbytes = strtol (argv[optind-1], &sip, 10);
+ if (sip[0] == 'K') {
+ nbytes = nbytes*1024;
+ } else if (sip[0] == 'M') {
+ nbytes = nbytes*1024*1024;
+ } else if (sip[0] == 'G') {
+ nbytes = nbytes*1024*1024*1024;
+ } else if (sip[0] == 'T') {
+ nbytes = nbytes*1024*1024*1024*1024;
+ } else if (sip[0] != '\0') {
+ printf ("You must specify the size in KiB, MiB, GiB or TiB, respectively using K, M, G or T, or nothing for single bytes.");
+ exit (EXIT_FAILURE);
+ }
break;
case 'o':
output = argv[optind-1];
@@ -217,7 +230,7 @@ void xor (int ed, char* mess, char* keyf, char* outp) {
return;
}
-void keyrand (int nb, char* outp) {
+void keyrand (long int nb, char* outp) {
char* defoutp = "default.key";
@@ -250,7 +263,7 @@ void keyrand (int nb, char* outp) {
fwrite (key, sizeof(char), nb, file);
fclose (file);
free (key);
- printf ("Created key file %s of %d bytes \n", outp, nb);
+ printf ("Created key file %s of %ld bytes \n", outp, nb);
} else {
printf ("Byte number specified is 0. \n");
printf ("Doing nothing! \n");
@@ -350,7 +363,7 @@ void help (char* av[]) {
"Options:\n\n"
" -c, --char=CAHRS reads two cahracters as argument and uses them to bluh your message\n"
" -k, --key-file=KEY_FILE use key (input)\n"
- " -n, --nbytes=NUM number of bytes\n"
+ " -n, --nbytes=NUM{K,M,G,T} number of bytes, you can specify K for KiB, M for MiB, etc... \n"
" -o, --output=FILE output name\n"
" -t, --tear-page deletes from the pad file the bytes used to encrypt/decrypt\n\n"
"Onetimebluh project repository at https://git.eigenlab.org/seppia/onetimebluh\n", av[0]);