@@ -193,12 +193,13 @@ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
193
193
#else
194
194
/* Manually salts password if BCryptDeriveKeyPBKDF2 is unavailable */
195
195
static bool
196
- _bcrypt_derive_key_pbkdf2 (mongoc_crypto_t * crypto ,
196
+ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE algorithm ,
197
197
const char * password ,
198
198
size_t password_len ,
199
199
const uint8_t * salt ,
200
200
size_t salt_len ,
201
201
uint32_t iterations ,
202
+ size_t output_len ,
202
203
unsigned char * output )
203
204
{
204
205
uint8_t intermediate_digest [MONGOC_SCRAM_HASH_MAX_SIZE ];
@@ -211,11 +212,16 @@ _bcrypt_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
211
212
start_key [salt_len + 2 ] = 0 ;
212
213
start_key [salt_len + 3 ] = 1 ;
213
214
214
- crypto -> hmac (crypto , password , password_len , start_key , hash_size , output );
215
+ if (!_mongoc_crypto_cng_hmac_or_hash (algorithm , password , password_len , start_key , hash_size , output )) {
216
+ return false;
217
+ }
215
218
memcpy (intermediate_digest , output , hash_size );
216
219
217
220
for (uint32_t i = 2u ; i <= iterations ; i ++ ) {
218
- crypto -> hmac (crypto , password , password_len , intermediate_digest , hash_size , intermediate_digest );
221
+ if (!_mongoc_crypto_cng_hmac_or_hash (
222
+ algorithm , password , password_len , intermediate_digest , hash_size , output )) {
223
+ return false;
224
+ }
219
225
220
226
for (int k = 0 ; k < hash_size ; k ++ ) {
221
227
output [k ] ^= intermediate_digest [k ];
@@ -235,12 +241,8 @@ mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
235
241
size_t output_len ,
236
242
unsigned char * output )
237
243
{
238
- #if defined(MONGOC_HAVE_BCRYPT_PBKDF2 )
239
244
return _bcrypt_derive_key_pbkdf2 (
240
245
_sha1_hmac_algo , password , password_len , salt , salt_len , iterations , output_len , output );
241
- #else
242
- return _bcrypt_derive_key_pbkdf2 (crypto , password , password_len , salt , salt_len , iterations , output );
243
- #endif
244
246
}
245
247
246
248
void
@@ -284,12 +286,8 @@ mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
284
286
size_t output_len ,
285
287
unsigned char * output )
286
288
{
287
- #if defined(MONGOC_HAVE_BCRYPT_PBKDF2 )
288
289
return _bcrypt_derive_key_pbkdf2 (
289
290
_sha256_hmac_algo , password , password_len , salt , salt_len , iterations , output_len , output );
290
- #else
291
- return _bcrypt_derive_key_pbkdf2 (crypto , password , password_len , salt , salt_len , iterations , output );
292
- #endif
293
291
}
294
292
295
293
void
0 commit comments