void bench_rabbit(void) { Rabbit enc; double start, total, persec; int i; RabbitSetKey(&enc, key, iv); start = current_time(); for(i = 0; i < megs; i++) RabbitProcess(&enc, cipher, plain, sizeof(plain)); total = current_time() - start; persec = 1 / total * megs; printf("RABBIT %d megs took %5.3f seconds, %6.2f MB/s\n", megs, total, persec); }
void bench_rabbit(void) { Rabbit enc; double start, total, persec; int i; RabbitSetKey(&enc, key, iv); start = current_time(1); for(i = 0; i < numBlocks; i++) RabbitProcess(&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("RABBIT %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec); }
int rabbit_test() { byte cipher[16]; byte plain[16]; const char* keys[] = { "\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", "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B\xFE\x36\x3D\x2E\x29\x13\x28\x91" }; const char* ivs[] = { "\x00\x00\x00\x00\x00\x00\x00\x00", "\x59\x7E\x26\xC1\x75\xF5\x73\xC3", 0 }; testVector a, b, c; testVector test_rabbit[3]; int times = sizeof(test_rabbit) / sizeof(testVector), i; a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; a.output = "\xED\xB7\x05\x67\x37\x5D\xCD\x7C"; a.inLen = strlen(a.input); a.outLen = strlen(a.output); b.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; b.output = "\x6D\x7D\x01\x22\x92\xCC\xDC\xE0"; b.inLen = strlen(b.input); b.outLen = strlen(b.output); c.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; c.output = "\x9C\x51\xE2\x87\x84\xC3\x7F\xE9"; c.inLen = strlen(c.input); c.outLen = strlen(c.output); test_rabbit[0] = a; test_rabbit[1] = b; test_rabbit[2] = c; for (i = 0; i < times; ++i) { Rabbit enc; Rabbit dec; RabbitSetKey(&enc, (byte*)keys[i], (byte*)ivs[i]); RabbitSetKey(&dec, (byte*)keys[i], (byte*)ivs[i]); RabbitProcess(&enc, cipher, (byte*)test_rabbit[i].input, (word32)test_rabbit[i].outLen); RabbitProcess(&dec, plain, cipher, (word32)test_rabbit[i].outLen); if (memcmp(plain, test_rabbit[i].input, test_rabbit[i].outLen)) return -130 - i; if (memcmp(cipher, test_rabbit[i].output, test_rabbit[i].outLen)) return -130 - 5 - i; } return 0; }
/********************* Defination of rabbit_test() ***************************/ int rabbit_test(void) { byte cipher[16]; byte plain[16]; const char* keys[] = { /* each keys[i] must be 128 bits��16 bytes��*/ "\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", "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B\xFE\x36\x3D\x2E\x29\x13\x28\x91", }; const char* ivs[] = { /* each iv[i] must be 64 bits��8 bytes��*/ "\x00\x00\x00\x00\x00\x00\x00\x00", "\x59\x7E\x26\xC1\x75\xF5\x73\xC3", }; testVector a, b, c; testVector test_rabbit[3]; int times = sizeof(test_rabbit) / sizeof(testVector); a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"; a.output = "\xED\xB7\x05\x67\x37\x5D\xCD\x7C"; a.inLen = 8;/* must be the right number of bytes of input*/ a.outLen = 8;/* must be the right number of bytes of output*/ b.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00"; b.output = "\x6D\x7D\x01\x22\x92\xCC\xDC\xE0\xE2"; b.inLen = 9; b.outLen = 9; c.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; c.output = "\x04\xCE\xCA\x7A\x1A\x86\x6E\x77\xFC\xCA"; c.inLen = 10; c.outLen = 10; test_rabbit[0] = a; test_rabbit[1] = b; test_rabbit[2] = c; for (int i = 0; i < times; ++i) { Rabbit enc; Rabbit dec; byte* iv; /* align keys/ivs in plain/cipher buffers */ memcpy(plain, keys[i],16); /* get 64 bits iv */ if (ivs[i]) { memcpy(cipher, ivs[i],8); iv = cipher; } else iv = NULL; RabbitSetKey(&enc, plain, iv); RabbitSetKey(&dec, plain, iv); /* align input */ memcpy(plain, test_rabbit[i].input, test_rabbit[i].outLen); /* Rabbit Encryption process */ RabbitProcess(&enc, cipher, plain, (word32)test_rabbit[i].outLen); /*Print the cipher text */ printf("The %d's Cipher Text is��",i+1); for(int j=0;j<test_rabbit[i].outLen;j++) { printf("-%x",cipher[j]); } printf("\r\n"); printf("\r\n"); /* Rabbit Decryption process */ RabbitProcess(&dec, plain, cipher, (word32)test_rabbit[i].outLen); /*Print the plain text */ printf("The %d's Plain Text is��",i+1); for(int j=0;j<test_rabbit[i].outLen;j++) { printf("-%x",plain[j]); } printf("\r\n"); printf("\r\n"); /* Compare plain text��generated from decryption, with test_rabbit[i].input defined */ if (memcmp(plain, test_rabbit[i].input, test_rabbit[i].outLen)) return i+1; /* Compare cipher text, generated from encryption, with vtest_rabbit[i].output predefined */ if (memcmp(cipher, test_rabbit[i].output, test_rabbit[i].outLen)) return -(i+1); } return 0; }