diff options
author | Jack Lloyd <[email protected]> | 2018-09-13 18:20:39 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-09-13 18:20:39 -0400 |
commit | c15720d3296edbcb9bdc14527ba71e60e3ec7a73 (patch) | |
tree | e37265e1decc7e1f053530e50a16f2a25670c9f6 /src/lib/ffi | |
parent | 175ddee5719138a0a3cdb5ba7fae6ce8e28f69b7 (diff) |
In FFI pwdhash functions, let len == 0 mean "call strlen"
Diffstat (limited to 'src/lib/ffi')
-rw-r--r-- | src/lib/ffi/ffi.h | 4 | ||||
-rw-r--r-- | src/lib/ffi/ffi_kdf.cpp | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h index ff7086488..fbc396d12 100644 --- a/src/lib/ffi/ffi.h +++ b/src/lib/ffi/ffi.h @@ -559,6 +559,8 @@ BOTAN_PUBLIC_API(2,0) int botan_pbkdf_timed(const char* pbkdf_algo, * @param out buffer to store the derived key, must be of out_len bytes * @param out_len the desired length of the key to produce * @param passphrase the password to derive the key from +* @param passphrase_len if > 0, specifies length of password. If len == 0, then +* strlen will be called on passphrase to compute the length. * @param salt a randomly chosen salt * @param salt_len length of salt in bytes * @return 0 on success, a negative value on failure @@ -585,6 +587,8 @@ int BOTAN_PUBLIC_API(2,8) botan_pwdhash( * @param out buffer to store the derived key, must be of out_len bytes * @param out_len the desired length of the key to produce * @param passphrase the password to derive the key from +* @param passphrase_len if > 0, specifies length of password. If len == 0, then +* strlen will be called on passphrase to compute the length. * @param salt a randomly chosen salt * @param salt_len length of salt in bytes * @return 0 on success, a negative value on failure diff --git a/src/lib/ffi/ffi_kdf.cpp b/src/lib/ffi/ffi_kdf.cpp index b72fe935e..639d25b1f 100644 --- a/src/lib/ffi/ffi_kdf.cpp +++ b/src/lib/ffi/ffi_kdf.cpp @@ -31,7 +31,7 @@ int botan_pbkdf(const char* algo, uint8_t out[], size_t out_len, 0, 0, out, out_len, - pass, std::strlen(pass), + pass, 0, salt, salt_len); } @@ -48,7 +48,7 @@ int botan_pbkdf_timed(const char* algo, nullptr, nullptr, out, out_len, - password, std::strlen(password), + password, 0, salt, salt_len); } @@ -64,6 +64,12 @@ int botan_pwdhash( const uint8_t salt[], size_t salt_len) { + if(algo == nullptr || password == nullptr) + return BOTAN_FFI_ERROR_NULL_POINTER; + + if(password_len == 0) + password_len = std::strlen(password); + return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int { auto pwdhash_fam = Botan::PasswordHashFamily::create(algo); @@ -93,6 +99,12 @@ int botan_pwdhash_timed( const uint8_t salt[], size_t salt_len) { + if(algo == nullptr || password == nullptr) + return BOTAN_FFI_ERROR_NULL_POINTER; + + if(password_len == 0) + password_len = std::strlen(password); + return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int { auto pwdhash_fam = Botan::PasswordHashFamily::create(algo); |