Skip to content

Commit fe0d0f1

Browse files
committed
Pass hash_size to manual bcrupt pbkdf
1 parent 58b1bdf commit fe0d0f1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libmongoc/src/mongoc/mongoc-crypto-cng.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,11 @@ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE algorithm,
199199
const uint8_t *salt,
200200
size_t salt_len,
201201
uint32_t iterations,
202-
size_t output_len,
202+
size_t hash_size,
203203
unsigned char *output)
204204
{
205205
uint8_t intermediate_digest[MONGOC_SCRAM_HASH_MAX_SIZE];
206206
uint8_t start_key[MONGOC_SCRAM_HASH_MAX_SIZE];
207-
const int hash_size = _crypto_hash_size (crypto);
208207

209208
memcpy (start_key, salt, salt_len);
210209
start_key[salt_len] = 0;
@@ -241,8 +240,13 @@ mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
241240
size_t output_len,
242241
unsigned char *output)
243242
{
243+
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
244244
return _bcrypt_derive_key_pbkdf2 (
245245
_sha1_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output);
246+
#else
247+
return _bcrypt_derive_key_pbkdf2 (
248+
_sha1_hmac_algo, password, password_len, salt, salt_len, iterations, _crypto_hash_size (crypto), output);
249+
#endif
246250
}
247251

248252
void
@@ -286,8 +290,13 @@ mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
286290
size_t output_len,
287291
unsigned char *output)
288292
{
293+
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
289294
return _bcrypt_derive_key_pbkdf2 (
290295
_sha256_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output);
296+
#else
297+
return _bcrypt_derive_key_pbkdf2 (
298+
_sha256_hmac_algo, password, password_len, salt, salt_len, iterations, _crypto_hash_size (crypto), output);
299+
#endif
291300
}
292301

293302
void

0 commit comments

Comments
 (0)