mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
GMAC working
This commit is contained in:
parent
f128dd6426
commit
d689f9e029
8 changed files with 218 additions and 28 deletions
|
@ -81,7 +81,7 @@ static MunitResult test_key_stream(const MunitParameter params[], void *user)
|
|||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_key), gkcrypt.key, gkcrypt_key);
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_key), gkcrypt.key_base, gkcrypt_key);
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_iv), gkcrypt.iv, gkcrypt_iv);
|
||||
|
||||
uint8_t key_stream_result[0x20];
|
||||
|
@ -115,7 +115,7 @@ static MunitResult test_endecrypt(const MunitParameter params[], void *user)
|
|||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_key), gkcrypt.key, gkcrypt_key);
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_key), gkcrypt.key_base, gkcrypt_key);
|
||||
munit_assert_memory_equal(sizeof(gkcrypt_iv), gkcrypt.iv, gkcrypt_iv);
|
||||
|
||||
uint8_t key_stream_result[0x20];
|
||||
|
@ -150,6 +150,72 @@ static MunitResult test_endecrypt(const MunitParameter params[], void *user)
|
|||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static MunitResult test_gmac(const MunitParameter params[], void *user)
|
||||
{
|
||||
static const uint8_t gkcrypt_key[] = { 0xb6, 0x4b, 0x1e, 0x65, 0x3f, 0xbb, 0xa7, 0xab, 0x80, 0xb3, 0x1e, 0x5a, 0x32, 0x4d, 0xec, 0xc0 };
|
||||
static const uint8_t gkcrypt_iv[] = { 0x7c, 0xc8, 0xd0, 0x19, 0x9e, 0xdf, 0xd8, 0xc3, 0xb5, 0x0f, 0x32, 0xee, 0x36, 0x33, 0x6a, 0x5a };
|
||||
|
||||
static const uint8_t buf[] = { 0x03, 0x00, 0x18, 0x00, 0x19, 0x00, 0x02, 0x50, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x69, 0xa0, 0x00, 0xf9, 0xf8, 0x98, 0x24, 0xda, 0x56, 0x0b, 0x74, 0xec, 0x68, 0x15, 0xd3, 0x1f,
|
||||
0x85, 0x43, 0xaa, 0xd3, 0xcd, 0xb8, 0x50, 0x2e, 0x90, 0xa4, 0xb0, 0x85, 0xf3, 0xbe, 0x9a, 0x47,
|
||||
0x97, 0xc1, 0xab, 0x5f, 0xa5, 0xfd, 0x62, 0x5c, 0x26, 0x1a, 0x54, 0x36, 0x72, 0x30, 0xc3, 0x2b,
|
||||
0xe0, 0x2c, 0x5a, 0x86, 0x07, 0xf5, 0xdc, 0x12, 0x55, 0xb4, 0x8e, 0x17, 0x5b, 0xe4, 0x7f, 0x96,
|
||||
0x55, 0x86, 0xf0, 0xfb, 0x45, 0xe2, 0xf8, 0xe8, 0x7d, 0x5f, 0x3a, 0x8b, 0xb0, 0x64, 0x6c, 0x54,
|
||||
0xf6, 0x8c, 0x4e, 0xa4, 0x12, 0xa3, 0x26, 0x7f, 0x22, 0x5b, 0x19, 0x98, 0xba, 0xd4, 0xad, 0x9f,
|
||||
0x5f, 0x63, 0xaf, 0x1f, 0x97, 0x8c, 0x17, 0x49, 0xa3, 0x30, 0x71, 0xd2, 0xb0, 0x49, 0x2c, 0x75,
|
||||
0xa2, 0x89, 0xda, 0x50, 0xfd, 0x9b, 0x08, 0x41, 0x98, 0x2d, 0x8c, 0x0b, 0x92, 0x79, 0xae, 0x60,
|
||||
0x23, 0x83, 0xef, 0x5c, 0xda, 0xce, 0x71, 0x08, 0x2d, 0x0b, 0x17, 0x62, 0x56, 0x48, 0xc5, 0xe2,
|
||||
0x0f, 0x22, 0x1d, 0xdc, 0xcc, 0xc2, 0x82, 0xa6, 0x8e, 0xec, 0x1e, 0x04, 0x0c, 0x08, 0xaa, 0xa2,
|
||||
0x80, 0x6c, 0x4f, 0xd3, 0x6f, 0xc1, 0x9b, 0x76, 0x9a, 0x58, 0xaa, 0x25, 0x56, 0xef, 0xf2, 0xfd,
|
||||
0x77, 0xf0, 0x32, 0x4e, 0x83, 0xe2, 0x30, 0x25, 0xa5, 0x5a, 0xf1, 0xdf, 0xc8, 0x75, 0xa2, 0xb6,
|
||||
0x2b, 0xfd, 0xac, 0xbc, 0x63, 0x09, 0xa1, 0xcc, 0x2b, 0xf5, 0x46, 0xef, 0x49, 0x83, 0x8f, 0x0b,
|
||||
0xc1, 0x47, 0xac, 0x5a, 0x00, 0x2e, 0xec, 0x1c, 0xd0, 0x0a, 0x66, 0xb5, 0xee, 0x9e, 0xad, 0xc9,
|
||||
0x64, 0x2d, 0xcb, 0x98, 0x0f, 0x43, 0xa6, 0xe1, 0x4c, 0xe7, 0x9f, 0x2d, 0xab, 0x94, 0x01, 0xd7,
|
||||
0x52, 0x84, 0x19 };
|
||||
|
||||
static const size_t key_pos = 0x69a0;
|
||||
|
||||
static const uint8_t gmac_expected[] = { 0x6f, 0x81, 0x10, 0x97 };
|
||||
|
||||
ChiakiGKCrypt gkcrypt;
|
||||
memset(&gkcrypt, 0, sizeof(gkcrypt));
|
||||
|
||||
memcpy(gkcrypt.key_gmac_current, gkcrypt_key, sizeof(gkcrypt.key_gmac_current));
|
||||
memcpy(gkcrypt.iv, gkcrypt_iv, sizeof(gkcrypt.iv));
|
||||
gkcrypt.key_buf = NULL;
|
||||
gkcrypt.key_buf_size = 0;
|
||||
gkcrypt.key_gmac_index_next = 1;
|
||||
|
||||
uint8_t gmac[CHIAKI_GKCRYPT_GMAC_SIZE];
|
||||
ChiakiErrorCode err = chiaki_gkcrypt_gmac(&gkcrypt, key_pos, buf, sizeof(buf), gmac);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
|
||||
munit_assert_memory_equal(sizeof(gmac), gmac, gmac_expected);
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static MunitResult test_gen_gmac_key(const MunitParameter params[], void *user)
|
||||
{
|
||||
static const uint8_t key_initial[] = { 0xbe, 0xeb, 0xa0, 0xf0, 0x3d, 0x05, 0x70, 0x7d, 0x3a, 0xc7, 0x3c, 0xd7, 0x32, 0xb9, 0x48, 0x01 };
|
||||
static const uint8_t iv[] = { 0xe8, 0x71, 0x87, 0xe7, 0x63, 0xe0, 0xdf, 0x46, 0x3d, 0xc2, 0x02, 0x4a, 0x2c, 0xd2, 0x9c, 0x45 };
|
||||
static const uint8_t key_result[] = { 0xe3, 0xdb, 0x92, 0xd9, 0xdd, 0xd3, 0x68, 0x99, 0xae, 0xfd, 0x9b, 0x15, 0xe1, 0xa6, 0x87, 0x8b };
|
||||
|
||||
ChiakiGKCrypt gkcrypt;
|
||||
memset(&gkcrypt, 0, sizeof(gkcrypt));
|
||||
memcpy(gkcrypt.key_gmac_base, key_initial, sizeof(gkcrypt.key_gmac_base));
|
||||
memcpy(gkcrypt.iv, iv, sizeof(gkcrypt.iv));
|
||||
|
||||
uint8_t key_out[CHIAKI_GKCRYPT_BLOCK_SIZE];
|
||||
chiaki_gkcrypt_gen_gmac_key(1, key_initial, iv, key_out);
|
||||
|
||||
munit_assert_memory_equal(sizeof(key_out), key_out, key_result);
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MunitTest tests_gkcrypt[] = {
|
||||
{
|
||||
|
@ -170,7 +236,23 @@ MunitTest tests_gkcrypt[] = {
|
|||
},
|
||||
{
|
||||
"/en_decrypt",
|
||||
test_key_stream,
|
||||
test_endecrypt,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"/gmac",
|
||||
test_gmac,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"/gen_gmac_key",
|
||||
test_gen_gmac_key,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue