aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/ffi/ffi.h16
-rw-r--r--src/lib/ffi/ffi_block.cpp8
-rw-r--r--src/lib/ffi/ffi_cipher.cpp15
-rw-r--r--src/lib/ffi/ffi_mac.cpp8
-rw-r--r--src/tests/test_ffi.cpp22
5 files changed, 48 insertions, 21 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h
index 83c84b3fa..080c71cef 100644
--- a/src/lib/ffi/ffi.h
+++ b/src/lib/ffi/ffi.h
@@ -403,7 +403,7 @@ BOTAN_PUBLIC_API(2,8) int botan_mac_name(botan_mac_t mac, char* name, size_t* na
* @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,
+BOTAN_PUBLIC_API(2,8) int botan_mac_get_keyspec(botan_mac_t mac,
size_t* out_minimum_keylength,
size_t* out_maximum_keylength,
size_t* out_keylength_modulo);
@@ -435,10 +435,16 @@ BOTAN_PUBLIC_API(2,0) int botan_cipher_get_tag_length(botan_cipher_t cipher, siz
BOTAN_PUBLIC_API(2,0) int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t* nl);
BOTAN_PUBLIC_API(2,0) int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t* ug);
+// Prefer botan_cipher_get_keyspec
BOTAN_PUBLIC_API(2,0) int botan_cipher_query_keylen(botan_cipher_t,
size_t* out_minimum_keylength,
size_t* out_maximum_keylength);
+BOTAN_PUBLIC_API(2,8) int botan_cipher_get_keyspec(botan_cipher_t,
+ size_t* min_keylen,
+ size_t* max_keylen,
+ size_t* mod_keylen);
+
BOTAN_PUBLIC_API(2,0) int botan_cipher_set_key(botan_cipher_t cipher,
const uint8_t* key, size_t key_len);
@@ -606,10 +612,10 @@ 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 cipher,
- size_t* out_minimum_keylength,
- size_t* out_maximum_keylength,
- size_t* out_keylength_modulo);
+BOTAN_PUBLIC_API(2,8) int botan_block_cipher_get_keyspec(botan_block_cipher_t cipher,
+ size_t* out_minimum_keylength,
+ size_t* out_maximum_keylength,
+ size_t* out_keylength_modulo);
/*
* Multiple precision integers
diff --git a/src/lib/ffi/ffi_block.cpp b/src/lib/ffi/ffi_block.cpp
index e19747d2b..8e45fd1cc 100644
--- a/src/lib/ffi/ffi_block.cpp
+++ b/src/lib/ffi/ffi_block.cpp
@@ -85,10 +85,10 @@ int botan_block_cipher_name(botan_block_cipher_t cipher, char* name, size_t* nam
return write_str_output(name, name_len, bc.name()); });
}
-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)
+int botan_block_cipher_get_keyspec(botan_block_cipher_t cipher,
+ size_t* out_minimum_keylength,
+ size_t* out_maximum_keylength,
+ size_t* out_keylength_modulo)
{
return BOTAN_FFI_DO(Botan::BlockCipher, cipher, bc, {
if(out_minimum_keylength)
diff --git a/src/lib/ffi/ffi_cipher.cpp b/src/lib/ffi/ffi_cipher.cpp
index 8dee35a81..e9adc8637 100644
--- a/src/lib/ffi/ffi_cipher.cpp
+++ b/src/lib/ffi/ffi_cipher.cpp
@@ -59,6 +59,21 @@ int botan_cipher_query_keylen(botan_cipher_t cipher,
});
}
+int botan_cipher_get_keyspec(botan_cipher_t cipher,
+ size_t* out_minimum_keylength,
+ size_t* out_maximum_keylength,
+ size_t* out_keylength_modulo)
+ {
+ return BOTAN_FFI_DO(Botan::Cipher_Mode, cipher, c, {
+ if(out_minimum_keylength)
+ *out_minimum_keylength = c.key_spec().minimum_keylength();
+ if(out_maximum_keylength)
+ *out_maximum_keylength = c.key_spec().maximum_keylength();
+ if(out_keylength_modulo)
+ *out_keylength_modulo = c.key_spec().keylength_multiple();
+ });
+ }
+
int botan_cipher_set_key(botan_cipher_t cipher,
const uint8_t* key, size_t key_len)
{
diff --git a/src/lib/ffi/ffi_mac.cpp b/src/lib/ffi/ffi_mac.cpp
index 4fbe171ec..b1b021720 100644
--- a/src/lib/ffi/ffi_mac.cpp
+++ b/src/lib/ffi/ffi_mac.cpp
@@ -67,10 +67,10 @@ 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)
+int botan_mac_get_keyspec(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)
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index f922f8e64..d6824afd1 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -548,6 +548,7 @@ class FFI_Unit_Tests final : public Test
{
size_t min_keylen = 0;
size_t max_keylen = 0;
+ size_t mod_keylen = 0;
size_t nonce_len = 0;
size_t tag_len = 0;
@@ -555,6 +556,11 @@ class FFI_Unit_Tests final : public Test
result.test_int_eq(min_keylen, 16, "Min key length");
result.test_int_eq(max_keylen, 16, "Max key length");
+ TEST_FFI_OK(botan_cipher_get_keyspec, (cipher_encrypt, &min_keylen, &max_keylen, &mod_keylen));
+ result.test_int_eq(min_keylen, 16, "Min key length");
+ result.test_int_eq(max_keylen, 16, "Max key length");
+ result.test_int_eq(mod_keylen, 1, "Mod key length");
+
TEST_FFI_OK(botan_cipher_get_default_nonce_length, (cipher_encrypt, &nonce_len));
result.test_int_eq(nonce_len, 12, "Expected default EAX nonce length");
@@ -772,10 +778,10 @@ class FFI_Unit_Tests final : public Test
}
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));
+ TEST_FFI_RC(0, botan_mac_get_keyspec, (mac, nullptr, nullptr, nullptr));
+ TEST_FFI_RC(0, botan_mac_get_keyspec, (mac, &min_keylen, nullptr, nullptr));
+ TEST_FFI_RC(0, botan_mac_get_keyspec, (mac, nullptr, &max_keylen, nullptr));
+ TEST_FFI_RC(0, botan_mac_get_keyspec, (mac, nullptr, nullptr, &mod_keylen));
result.test_eq("Expected min keylen", min_keylen, 0);
result.test_eq("Expected max keylen", max_keylen, 4096);
@@ -933,10 +939,10 @@ class FFI_Unit_Tests final : public Test
TEST_FFI_RC(16, botan_block_cipher_block_size, (cipher));
size_t min_keylen = 0, max_keylen = 0, mod_keylen = 0;
- TEST_FFI_RC(0, botan_block_cipher_query_keylen, (cipher, nullptr, nullptr, nullptr));
- TEST_FFI_RC(0, botan_block_cipher_query_keylen, (cipher, &min_keylen, nullptr, nullptr));
- TEST_FFI_RC(0, botan_block_cipher_query_keylen, (cipher, nullptr, &max_keylen, nullptr));
- TEST_FFI_RC(0, botan_block_cipher_query_keylen, (cipher, nullptr, nullptr, &mod_keylen));
+ TEST_FFI_RC(0, botan_block_cipher_get_keyspec, (cipher, nullptr, nullptr, nullptr));
+ TEST_FFI_RC(0, botan_block_cipher_get_keyspec, (cipher, &min_keylen, nullptr, nullptr));
+ TEST_FFI_RC(0, botan_block_cipher_get_keyspec, (cipher, nullptr, &max_keylen, nullptr));
+ TEST_FFI_RC(0, botan_block_cipher_get_keyspec, (cipher, nullptr, nullptr, &mod_keylen));
result.test_eq("Expected min keylen", min_keylen, 16);
result.test_eq("Expected max keylen", max_keylen, 16);