diff options
author | Jack Lloyd <[email protected]> | 2018-07-24 15:40:01 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-07-24 15:40:01 -0400 |
commit | d24cca944011863f6afe0b5be8fb2678128947aa (patch) | |
tree | bb6294c73e5ab9ebce4134512b5ed32b0f351873 /src | |
parent | 5d89df3fd37f93f07e04111712f2a21d9f418b74 (diff) |
Add botan_mac_query_keylen
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ffi/ffi.h | 14 | ||||
-rw-r--r-- | src/lib/ffi/ffi_mac.cpp | 15 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 10 |
3 files changed, 38 insertions, 1 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h index 9deefffb5..5e27962d8 100644 --- a/src/lib/ffi/ffi.h +++ b/src/lib/ffi/ffi.h @@ -385,6 +385,18 @@ BOTAN_PUBLIC_API(2,0) int botan_mac_clear(botan_mac_t mac); BOTAN_PUBLIC_API(2,8) int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len); /** +* Get the key length limits of this auth code +* @param mac the object to read +* @param out_minimum_keylength if non-NULL, will be set to minimum keylength of MAC +* @param out_maximum_keylength if non-NULL, will be set to maximum keylength of MAC +* @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys +*/ +BOTAN_PUBLIC_API(2,8) int botan_mac_query_keylen(botan_mac_t mac, + size_t* out_minimum_keylength, + size_t* out_maximum_keylength, + size_t* out_keylength_modulo); + +/** * Frees all resources of the MAC object * @param mac mac object * @return always returns 0 @@ -572,7 +584,7 @@ BOTAN_PUBLIC_API(2,8) int botan_block_cipher_name(botan_block_cipher_t cipher, * @param out_maximum_keylength if non-NULL, will be set to maximum keylength of cipher * @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys */ -BOTAN_PUBLIC_API(2,8) int botan_block_cipher_query_keylen(botan_block_cipher_t, +BOTAN_PUBLIC_API(2,8) int botan_block_cipher_query_keylen(botan_block_cipher_t cipher, size_t* out_minimum_keylength, size_t* out_maximum_keylength, size_t* out_keylength_modulo); diff --git a/src/lib/ffi/ffi_mac.cpp b/src/lib/ffi/ffi_mac.cpp index 02ac7900c..4fbe171ec 100644 --- a/src/lib/ffi/ffi_mac.cpp +++ b/src/lib/ffi/ffi_mac.cpp @@ -67,4 +67,19 @@ int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len) return write_str_output(name, name_len, m.name()); }); } +int botan_mac_query_keylen(botan_mac_t mac, + size_t* out_minimum_keylength, + size_t* out_maximum_keylength, + size_t* out_keylength_modulo) + { + return BOTAN_FFI_DO(Botan::MessageAuthenticationCode, mac, m, { + if(out_minimum_keylength) + *out_minimum_keylength = m.minimum_keylength(); + if(out_maximum_keylength) + *out_maximum_keylength = m.maximum_keylength(); + if(out_keylength_modulo) + *out_keylength_modulo = m.key_spec().keylength_multiple(); + }); + } + } diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 5940a1009..de80f3e3b 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -736,6 +736,16 @@ class FFI_Unit_Tests final : public Test result.test_eq("name", std::string(namebuf), "HMAC(SHA-256)"); } + size_t min_keylen = 0, max_keylen = 0, mod_keylen = 0; + TEST_FFI_RC(0, botan_mac_query_keylen, (mac, nullptr, nullptr, nullptr)); + TEST_FFI_RC(0, botan_mac_query_keylen, (mac, &min_keylen, nullptr, nullptr)); + TEST_FFI_RC(0, botan_mac_query_keylen, (mac, nullptr, &max_keylen, nullptr)); + TEST_FFI_RC(0, botan_mac_query_keylen, (mac, nullptr, nullptr, &mod_keylen)); + + result.test_eq("Expected min keylen", min_keylen, 0); + result.test_eq("Expected max keylen", max_keylen, 4096); + result.test_eq("Expected mod keylen", mod_keylen, 1); + size_t output_len; if(TEST_FFI_OK(botan_mac_output_length, (mac, &output_len))) { |