/* pkcs5-test.c * */ #include "crypto.h" /* FIXME: In which include file can getopt be found? Solaris man page * says stdlib.h, linux's says unistd.h. */ #include #include #include #include static void usage(void) { fprintf(stderr, "pkcs5-test [-i iterations] [-s salt] [-l key length] password"); exit(1); } static void print_hex(unsigned length, const char *data) { static const char digits[16] = "0123456789ABCDEF"; unsigned i; for (i = 0; i 10000000)) usage(); break; case 's': salt = optarg; break; case 'l': length = atoi(optarg); if ( (length < 1) || (length > 5000) ) usage(); break; case '?': usage(); default: abort(); } } if (optind != (argc - 1)) usage(); password = argv[optind]; key = alloca(length); pkcs5_derive_key(&crypto_hmac_sha1_algorithm, strlen(password), password, strlen(salt), salt, iterations, length, key); printf("Key:"); print_hex(length, key); printf("\n"); return 0; }