Fix GMAC for multiples of key refresh

This commit is contained in:
Florian Märkl 2019-04-12 23:44:31 +02:00
commit 0dac2bc4fb
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
2 changed files with 54 additions and 6 deletions

View file

@ -280,6 +280,50 @@ static MunitResult test_gmac_split(const MunitParameter params[], void *user)
return MUNIT_OK;
}
static MunitResult test_gmac_multiple_of_key_refresh(const MunitParameter params[], void *user)
{
static const uint8_t handshake_key[] = { 0x70, 0x58, 0x37, 0x50, 0x91, 0xea, 0xd1, 0x37, 0x71, 0x58, 0xec, 0xb3, 0xb, 0xea, 0x23, 0x87 };
static const uint8_t ecdh_secret[] = { 0x3c, 0x3a, 0xf0, 0xec, 0xd6, 0x33, 0x1b, 0xb1, 0x6d, 0x24, 0x4f, 0x48, 0x19, 0xde, 0x6, 0x3d,
0xc7, 0xe, 0xac, 0x95, 0x70, 0xac, 0x24, 0x92, 0x86, 0xa7, 0x24, 0xd0, 0x7a, 0x37, 0x55, 0x52 };
static const uint8_t data[] = { 0x3, 0x11, 0xa4, 0x11, 0xa5, 00, 0x2, 0x50, 0x21, 0x5, 00, 00, 00, 00, 00, 0x6b,
0x1d, 0xe0, 00, 0x83, 0xf1, 0xc4, 0x79, 0x71, 0xe4, 0x67, 0x7c, 0xcc, 0xb7, 0x92, 0x7, 0x8b,
0xba, 0x8a, 0x8, 0xd6, 0x62, 0xf5, 0x7, 0x5d, 0x4a, 0x20, 0x14, 0xb3, 0xe7, 0xe, 0x5c, 0x77,
0xfd, 0x6d, 0x60, 0xa3, 0xc5, 0x48, 0xa9, 0xc0, 0x61, 0xf9, 0x84, 0xf6, 0x37, 0x62, 0xac, 0xbc,
0x1f, 0x5d, 0xe4, 0x40, 0x90, 0x54, 0x71, 0x37, 0xab, 0x33, 0x7e, 0xaa, 0xa5, 0xf4, 0xc4, 0x9,
0x3, 0xf4, 0xb6, 0xa1, 0x2f, 0x2, 0x27, 0x53, 0xc6, 0xa5, 0xb1, 0x9c, 0x8f, 0xb4, 0x69, 0xd6,
0x5c, 0x7f, 0x79, 0x5f, 0x14, 0x47, 0xcc, 0xa8, 0x8b, 0x37, 0xf7, 0x77, 0x6d, 0x1, 0xf4, 0x5b,
0x59, 0xca, 0x96, 0x73, 0xa, 0x20, 0xf3, 0x7a, 0xd1, 0xd2, 0x7f, 0xfe, 0xb6, 0x66, 0xf4, 0xdb,
0x10, 0xaf, 0xf3, 0x7, 0xee, 0x49, 0x8a, 0xa1, 0xa5, 0x73, 0xd8, 0x23, 0x83, 0xe, 0xc, 0xc,
0x3a, 0x49, 0xdc, 0xd8, 0xc, 0xc8, 0xe4, 0xb6, 0xf2, 0x3c, 0x6d, 0x25, 0x6a, 0x7d, 0xa0, 0x1c,
0x3a, 0x8e, 0xf, 0x3f, 0x25, 0x47, 0x11, 0x89, 0x67, 0xc4, 0xf9, 0xac, 0xc7, 0xe2, 0x93, 0x74,
0xc6, 0xfb, 0xdd, 0x48, 0x57, 0xae, 0x53, 0xe2, 0xf4, 0x17, 0x80, 0x62, 0xf3, 0x9, 0xd8, 0xd4,
0x7a, 0x46, 0x6b, 0x8, 0x76, 0x9c, 0x29, 0x81, 0x91, 0x4e, 0x57, 0xaf, 0x70, 0xb6, 0x32, 0x78,
0x98, 0x9e, 0x85, 0xf2, 0xe3, 0x69, 0x15, 0xaf, 0xd4, 0x32, 0x54, 0xf, 0xd4, 0xa2, 0xfc, 0xf5,
0x36, 0xdc, 0x6, 0x45, 0xf4, 0x6, 0xa3, 0x38, 0x21, 0x2, 0xfd, 0xf0, 0x51, 0x75, 0xea, 0xb1,
0xf6, 0x8e, 0x39, 0x35, 0xfd, 0x75, 0x74, 0xad, 0xbc, 0x3e, 0xfb, 0xee, 0x7d, 0xf, 0x2d, 0x76,
0xbe, 0xfd, 0xee };
static const uint8_t crypt_index = 3;
static const size_t key_pos = 0x6b1de0; // % CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_KEY_POS == 0
static const uint8_t gmac_expected[] = { 0x20, 0xcc, 0xa5, 0xf1 };
ChiakiLog log;
ChiakiGKCrypt gkcrypt;
chiaki_gkcrypt_init(&gkcrypt, &log, 0, crypt_index, handshake_key, ecdh_secret);
uint8_t gmac[CHIAKI_GKCRYPT_GMAC_SIZE];
ChiakiErrorCode err = chiaki_gkcrypt_gmac(&gkcrypt, key_pos, data, sizeof(data), gmac);
if(err != CHIAKI_ERR_SUCCESS)
return MUNIT_ERROR;
munit_assert_memory_equal(sizeof(gmac), gmac, gmac_expected);
chiaki_gkcrypt_fini(&gkcrypt);
return MUNIT_OK;
}
MunitTest tests_gkcrypt[] = {
{
@ -330,5 +374,13 @@ MunitTest tests_gkcrypt[] = {
MUNIT_TEST_OPTION_NONE,
NULL
},
{
"/gmac_multiple_of_key_refresh",
test_gmac_multiple_of_key_refresh,
NULL,
NULL,
MUNIT_TEST_OPTION_NONE,
NULL
},
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};