Skip to content

Commit eca2835

Browse files
committed
Dually define _bcrypt_derive_key_pbkdf2
1 parent f0c5ba0 commit eca2835

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ _crypto_hash_size (mongoc_crypto_t *crypto)
155155
}
156156
}
157157

158-
/* Wrapper for BCryptDeriveKeyPBKDF2 */
159158
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
159+
/* Wrapper for BCryptDeriveKeyPBKDF2 */
160160
static bool
161161
_bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
162162
const char *password,
@@ -189,16 +189,17 @@ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
189189
}
190190
return true;
191191
}
192-
#endif
193192

193+
#else
194194
/* Compute the SCRAM step Hi() as defined in RFC5802 */
195195
static bool
196-
mongoc_crypto_cng_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
196+
_bcrypt_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
197197
const char *password,
198198
size_t password_len,
199199
const uint8_t *salt,
200200
size_t salt_len,
201201
uint32_t iterations,
202+
size_t output_len,
202203
unsigned char *output)
203204
{
204205
uint8_t intermediate_digest[MONGOC_SCRAM_HASH_MAX_SIZE];
@@ -223,6 +224,7 @@ mongoc_crypto_cng_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
223224
}
224225
return true;
225226
}
227+
#endif
226228

227229
bool
228230
mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
@@ -234,12 +236,8 @@ mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
234236
size_t output_len,
235237
unsigned char *output)
236238
{
237-
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
238239
return _bcrypt_derive_key_pbkdf2 (
239-
_sha1_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output)
240-
#else
241-
return mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
242-
#endif
240+
_sha1_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output);
243241
}
244242

245243
void
@@ -283,12 +281,8 @@ mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
283281
size_t output_len,
284282
unsigned char *output)
285283
{
286-
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
287284
return _bcrypt_derive_key_pbkdf2 (
288-
_sha256_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output)
289-
#else
290-
return mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
291-
#endif
285+
_sha256_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output);
292286
}
293287

294288
void

0 commit comments

Comments
 (0)