void bench_hc128(void) { HC128 enc; double start, total, persec; int i; Hc128_SetKey(&enc, key, iv); start = current_time(); for(i = 0; i < megs; i++) Hc128_Process(&enc, cipher, plain, sizeof(plain)); total = current_time() - start; persec = 1 / total * megs; printf("HC128 %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total, persec); }
void bench_hc128(void) { HC128 enc; double start, total, persec; int i; Hc128_SetKey(&enc, key, iv); start = current_time(1); for(i = 0; i < numBlocks; i++) Hc128_Process(&enc, cipher, plain, sizeof(plain)); total = current_time(0) - start; persec = 1 / total * numBlocks; #ifdef BENCH_EMBEDDED /* since using kB, convert to MB/s */ persec = persec / 1024; #endif printf("HC128 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec); }
int hc128_test() { byte cipher[16]; byte plain[16]; const char* keys[] = { "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD", "\x0F\x62\xB5\x08\x5B\xAE\x01\x54\xA7\xFA\x4D\xA0\xF3\x46\x99\xEC" }; const char* ivs[] = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", "\x0D\x74\xDB\x42\xA9\x10\x77\xDE\x45\xAC\x13\x7A\xE1\x48\xAF\x16", "\x28\x8F\xF6\x5D\xC4\x2B\x92\xF9\x60\xC7\x2E\x95\xFC\x63\xCA\x31" }; testVector a, b, c, d; testVector test_hc128[4]; int times = sizeof(test_hc128) / sizeof(testVector), i; a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; a.output = "\x37\x86\x02\xB9\x8F\x32\xA7\x48"; a.inLen = strlen(a.input); a.outLen = strlen(a.output); b.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; b.output = "\x33\x7F\x86\x11\xC6\xED\x61\x5F"; b.inLen = strlen(b.input); b.outLen = strlen(b.output); c.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; c.output = "\x2E\x1E\xD1\x2A\x85\x51\xC0\x5A"; c.inLen = strlen(c.input); c.outLen = strlen(c.output); d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; d.output = "\x1C\xD8\xAE\xDD\xFE\x52\xE2\x17\xE8\x35\xD0\xB7\xE8\x4E\x29"; d.inLen = strlen(d.input); d.outLen = strlen(d.output); test_hc128[0] = a; test_hc128[1] = b; test_hc128[2] = c; test_hc128[3] = d; for (i = 0; i < times; ++i) { HC128 enc; HC128 dec; Hc128_SetKey(&enc, (byte*)keys[i], (byte*)ivs[i]); Hc128_SetKey(&dec, (byte*)keys[i], (byte*)ivs[i]); Hc128_Process(&enc, cipher, (byte*)test_hc128[i].input, (word32)test_hc128[i].outLen); Hc128_Process(&dec, plain, cipher, (word32)test_hc128[i].outLen); if (memcmp(plain, test_hc128[i].input, test_hc128[i].outLen)) return -120 - i; if (memcmp(cipher, test_hc128[i].output, test_hc128[i].outLen)) return -120 - 5 - i; } return 0; }