static int do_rand_test(unsigned char *key, int keylen, AES_PRNG_TV *tv, int ntv) { unsigned char R[16]; int i; if (!FIPS_rand_set_key(key, keylen)) return 0; for (i = 0; i < ntv; i++) { FIPS_rand_seed(tv[i].V, 16); FIPS_rand_set_dt(tv[i].DT); FIPS_rand_bytes(R, 16); if (memcmp(R, tv[i].R, 16)) return 0; } return 1; }
static void vst() { unsigned char *key = NULL; unsigned char *v = NULL; unsigned char *dt = NULL; unsigned char ret[16]; char buf[1024]; char lbuf[1024]; char *keyword, *value; long i, keylen; keylen = 0; while (fgets(buf, sizeof buf, stdin) != NULL) { fputs(buf, stdout); if (!strncmp(buf, "[AES 128-Key]", 13)) keylen = 16; else if (!strncmp(buf, "[AES 192-Key]", 13)) keylen = 24; else if (!strncmp(buf, "[AES 256-Key]", 13)) keylen = 32; if (!parse_line(&keyword, &value, lbuf, buf)) continue; if (!strcmp(keyword, "Key")) { key = hex2bin_m(value, &i); if (i != keylen) { fprintf(stderr, "Invalid key length, expecting %ld\n", keylen); return; } } else if (!strcmp(keyword, "DT")) { dt = hex2bin_m(value, &i); if (i != 16) { fprintf(stderr, "Invalid DT length\n"); return; } } else if (!strcmp(keyword, "V")) { v = hex2bin_m(value, &i); if (i != 16) { fprintf(stderr, "Invalid V length\n"); return; } if (!key || !dt) { fprintf(stderr, "Missing key or DT\n"); return; } FIPS_rand_set_key(key, keylen); FIPS_rand_seed(v, 16); FIPS_rand_set_dt(dt); if (FIPS_rand_bytes(ret, 16) <= 0) { fprintf(stderr, "Error getting PRNG value\n"); return; } pv("R", ret, 16); OPENSSL_free(key); key = NULL; OPENSSL_free(dt); dt = NULL; OPENSSL_free(v); v = NULL; } } }