Skip to content

Commit e63a531

Browse files
committed
Merge pull request #228 from hanumantmk/fips
Avoid use of SHA1 for scram for FIPS
2 parents 6515183 + 2d739fe commit e63a531

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/mongoc/mongoc-scram.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,33 @@ _mongoc_scram_salt_password (mongoc_scram_t *scram,
303303
}
304304

305305

306+
static bool
307+
_mongoc_scram_sha1 (const unsigned char *input,
308+
const size_t input_len,
309+
unsigned char *output)
310+
{
311+
EVP_MD_CTX digest_ctx;
312+
bool rval = false;
313+
314+
EVP_MD_CTX_init (&digest_ctx);
315+
316+
if (1 != EVP_DigestInit_ex (&digest_ctx, EVP_sha1 (), NULL)) {
317+
goto cleanup;
318+
}
319+
320+
if (1 != EVP_DigestUpdate (&digest_ctx, input, input_len)) {
321+
goto cleanup;
322+
}
323+
324+
rval = (1 == EVP_DigestFinal_ex (&digest_ctx, output, NULL));
325+
326+
cleanup:
327+
EVP_MD_CTX_cleanup (&digest_ctx);
328+
329+
return rval;
330+
}
331+
332+
306333
static bool
307334
_mongoc_scram_generate_client_proof (mongoc_scram_t *scram,
308335
uint8_t *outbuf,
@@ -327,7 +354,7 @@ _mongoc_scram_generate_client_proof (mongoc_scram_t *scram,
327354
&hash_len);
328355

329356
/* StoredKey := H(client_key) */
330-
SHA1 (client_key, MONGOC_SCRAM_HASH_SIZE, stored_key);
357+
_mongoc_scram_sha1 (client_key, MONGOC_SCRAM_HASH_SIZE, stored_key);
331358

332359
/* ClientSignature := HMAC(StoredKey, AuthMessage) */
333360
HMAC (EVP_sha1 (),

0 commit comments

Comments
 (0)