2727#include <CryptoInterface.h>
2828
2929#include <m-dict.h>
30+ #include <m-string.h>
3031#include <openssl/err.h>
3132#include <openssl/rand.h>
3233
@@ -53,7 +54,7 @@ static int BSLB_CryptoKey_Deinit(BSLB_CryptoKey_t *key)
5354/// @cond Doxygen_Suppress
5455#define M_OPL_BSLB_CryptoKey_t () M_OPEXTEND(M_POD_OPLIST, CLEAR(API_2(BSLB_CryptoKey_Deinit)))
5556/// Stable dict of crypto keys (key: key ID | value: key)
56- DICT_DEF2 (BSLB_CryptoKeyDict , uint64_t , M_BASIC_OPLIST , BSLB_CryptoKey_t , M_OPL_BSLB_CryptoKey_t ())
57+ DICT_DEF2 (BSLB_CryptoKeyDict , string_t , STRING_OPLIST , BSLB_CryptoKey_t , M_OPL_BSLB_CryptoKey_t ())
5758/// @endcond
5859
5960/// Crypto key registry
@@ -71,7 +72,7 @@ void BSL_CryptoDeinit(void)
7172 BSLB_CryptoKeyDict_clear (StaticKeyRegistry );
7273}
7374
74- int BSL_Crypto_UnwrapKey (BSL_Data_t * unwrapped_key_output , BSL_Data_t wrapped_key_plaintext , size_t key_id ,
75+ int BSL_Crypto_UnwrapKey (BSL_Data_t * unwrapped_key_output , BSL_Data_t wrapped_key_plaintext , const char * key_id ,
7576 size_t aes_variant )
7677{
7778 const EVP_CIPHER * cipher = (aes_variant == BSL_CRYPTO_AES_128 ) ? EVP_aes_128_wrap () : EVP_aes_256_wrap ();
@@ -117,7 +118,7 @@ int BSL_Crypto_UnwrapKey(BSL_Data_t *unwrapped_key_output, BSL_Data_t wrapped_ke
117118 return 0 ;
118119}
119120
120- int BSL_Crypto_WrapKey (BSL_Data_t * wrapped_key , BSL_Data_t cek , size_t content_key_id , size_t aes_variant )
121+ int BSL_Crypto_WrapKey (BSL_Data_t * wrapped_key , BSL_Data_t cek , const char * content_key_id , size_t aes_variant )
121122{
122123 const EVP_CIPHER * cipher = (aes_variant == BSL_CRYPTO_AES_128 ) ? EVP_aes_128_wrap () : EVP_aes_256_wrap ();
123124 EVP_CIPHER_CTX * ctx = EVP_CIPHER_CTX_new ();
@@ -166,7 +167,7 @@ int BSL_Crypto_WrapKey(BSL_Data_t *wrapped_key, BSL_Data_t cek, size_t content_k
166167 return 0 ;
167168}
168169
169- int BSL_AuthCtx_Init (BSL_AuthCtx_t * hmac_ctx , uint64_t keyid , BSL_CryptoCipherSHAVariant_e sha_var )
170+ int BSL_AuthCtx_Init (BSL_AuthCtx_t * hmac_ctx , const char * keyid , BSL_CryptoCipherSHAVariant_e sha_var )
170171{
171172 CHK_ARG_NONNULL (hmac_ctx );
172173
@@ -192,8 +193,11 @@ int BSL_AuthCtx_Init(BSL_AuthCtx_t *hmac_ctx, uint64_t keyid, BSL_CryptoCipherSH
192193 return BSL_ERR_FAILURE ;
193194 }
194195
196+ string_t keyid_str ;
197+ string_init_set_str (keyid_str , keyid );
198+
195199 pthread_mutex_lock (& StaticCryptoMutex );
196- const BSLB_CryptoKey_t * key_info = BSLB_CryptoKeyDict_cget (StaticKeyRegistry , keyid );
200+ const BSLB_CryptoKey_t * key_info = BSLB_CryptoKeyDict_cget (StaticKeyRegistry , keyid_str );
197201 if (key_info == NULL )
198202 {
199203 // Special case which should not happen
@@ -430,7 +434,7 @@ int BSL_Crypto_GenIV(void *buf, int size)
430434 return 0 ;
431435}
432436
433- int BSL_Crypto_AddRegistryKey (uint64_t keyid , const uint8_t * secret , size_t secret_len )
437+ int BSL_Crypto_AddRegistryKey (const char * keyid , const uint8_t * secret , size_t secret_len )
434438{
435439 CHK_ARG_NONNULL (secret );
436440 CHK_ARG_EXPR (secret_len > 0 );
@@ -452,20 +456,26 @@ int BSL_Crypto_AddRegistryKey(uint64_t keyid, const uint8_t *secret, size_t secr
452456 return ecode ;
453457 }
454458
459+ string_t keyid_str ;
460+ string_init_set_str (keyid_str , keyid );
461+
455462 pthread_mutex_lock (& StaticCryptoMutex );
456- BSLB_CryptoKeyDict_set_at (StaticKeyRegistry , keyid , key );
463+ BSLB_CryptoKeyDict_set_at (StaticKeyRegistry , keyid_str , key );
457464 pthread_mutex_unlock (& StaticCryptoMutex );
458465
459466 return 0 ;
460467}
461468
462- int BSLB_Crypto_GetRegistryKey (uint64_t keyid , const uint8_t * * secret , size_t * secret_len )
469+ int BSLB_Crypto_GetRegistryKey (const char * keyid , const uint8_t * * secret , size_t * secret_len )
463470{
464471 CHK_ARG_NONNULL (secret );
465472 // CHK_ARG_NONNULL(secret_len); // Note: secret_len CAN be NULL - this maybe should be fixed.
466473
474+ string_t keyid_str ;
475+ string_init_set_str (keyid_str , keyid );
476+
467477 pthread_mutex_lock (& StaticCryptoMutex );
468- const BSLB_CryptoKey_t * found = BSLB_CryptoKeyDict_cget (StaticKeyRegistry , keyid );
478+ const BSLB_CryptoKey_t * found = BSLB_CryptoKeyDict_cget (StaticKeyRegistry , keyid_str );
469479
470480 if (!found )
471481 {
0 commit comments