MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / TestRijndael

Function TestRijndael

Libraries/unrar/rijndael.cpp:473–514  ·  view source on GitHub ↗

Test CBC encryption according to NIST 800-38A.

Source from the content-addressed store, hash-verified

471
472// Test CBC encryption according to NIST 800-38A.
473void TestRijndael()
474{
475 byte IV[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
476 byte PT[64]={
477 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
478 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
479 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
480 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10,
481 };
482
483 byte Key128[16]={0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};
484 byte Chk128[16]={0x3f,0xf1,0xca,0xa1,0x68,0x1f,0xac,0x09,0x12,0x0e,0xca,0x30,0x75,0x86,0xe1,0xa7};
485 byte Key192[24]={0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b};
486 byte Chk192[16]={0x08,0xb0,0xe2,0x79,0x88,0x59,0x88,0x81,0xd9,0x20,0xa9,0xe6,0x4f,0x56,0x15,0xcd};
487 byte Key256[32]={0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
488 byte Chk256[16]={0xb2,0xeb,0x05,0xe2,0xc3,0x9b,0xe9,0xfc,0xda,0x6c,0x19,0x07,0x8c,0x6a,0x9d,0x1b};
489 byte *Key[3]={Key128,Key192,Key256};
490 byte *Chk[3]={Chk128,Chk192,Chk256};
491
492 Rijndael rij; // Declare outside of loop to test re-initialization.
493 for (uint L=0;L<3;L++)
494 {
495 byte Out[16];
496 wchar Str[sizeof(Out)*2+1];
497
498 uint KeyLength=128+L*64;
499 rij.Init(true,Key[L],KeyLength,IV);
500 for (uint I=0;I<sizeof(PT);I+=16)
501 rij.blockEncrypt(PT+I,16,Out);
502 BinToHex(Chk[L],16,NULL,Str,ASIZE(Str));
503 mprintf(L"\nAES-%d expected: %s",KeyLength,Str);
504 BinToHex(Out,sizeof(Out),NULL,Str,ASIZE(Str));
505 mprintf(L"\nAES-%d result: %s",KeyLength,Str);
506 if (memcmp(Out,Chk[L],16)==0)
507 mprintf(L" OK");
508 else
509 {
510 mprintf(L" FAILED");
511 getchar();
512 }
513 }
514}
515#endif

Callers 1

TestRijMethod · 0.85

Calls 4

BinToHexFunction · 0.85
blockEncryptMethod · 0.80
mprintfFunction · 0.70
InitMethod · 0.45

Tested by

no test coverage detected