#include #include #include int main(int argc, char* argv[]) { int opt; int nbytes = 256; 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 = "default.key"; 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); }