Skip to content

Instantly share code, notes, and snippets.

@KevinWMatthews
Last active March 24, 2018 05:26
Show Gist options
  • Save KevinWMatthews/9e57aa78e6f706c12071e533e42ca8c4 to your computer and use it in GitHub Desktop.
Save KevinWMatthews/9e57aa78e6f706c12071e533e42ca8c4 to your computer and use it in GitHub Desktop.
Overview and example of mocking an AES encryption library
// Bird's-eye view of overall production code
Cmac_Calculate()
{
aes_handle = Aes128_Create(key, iv)
// Perform several technical operations (CmacOps) per the CMAC spec.
CmacOps_GenerateSubkeys(aes_handle, *subkey1, *subkey2)
//...
CmacOps_ApplyCbcMac(aes_handle, <relevant_parameters>)
//...
}
// The individual steps are internally complex - test each.
// Test an individual operation; high level view
TEST(generate_subkeys)
{
// Setup
aes_handle = Aes128_Create(key, iv)
// Test
CmacOps_GenerateSubkeys(aes_handle, *subkey1, *subkey2)
// Verify
CHECK(expected, subkey1)
CHECK(expected, subkey2)
// Teardown
Aes128_Destroy(aes_handle)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment