Skip to content

Commit df8ea92

Browse files
lrstewartjohubertj
authored andcommitted
refactor: remove openssl-1.0.2-fips 'allow md5' logic (aws#5048)
1 parent ca06538 commit df8ea92

26 files changed

+34
-451
lines changed

crypto/s2n_evp.c

+3-36
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,6 @@
1515

1616
#include "crypto/s2n_evp.h"
1717

18-
#include "crypto/s2n_fips.h"
19-
#include "error/s2n_errno.h"
20-
#include "utils/s2n_safety.h"
21-
22-
int s2n_digest_allow_md5_for_fips(struct s2n_evp_digest *evp_digest)
23-
{
24-
POSIX_ENSURE_REF(evp_digest);
25-
/* This is only to be used for EVP digests that will require MD5 to be used
26-
* to comply with the TLS 1.0 and 1.1 RFC's for the PRF. MD5 cannot be used
27-
* outside of the TLS 1.0 and 1.1 PRF when in FIPS mode.
28-
*/
29-
S2N_ERROR_IF(!s2n_is_in_fips_mode() || (evp_digest->ctx == NULL), S2N_ERR_ALLOW_MD5_FOR_FIPS_FAILED);
30-
31-
#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC)
32-
EVP_MD_CTX_set_flags(evp_digest->ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
33-
#endif
34-
return S2N_SUCCESS;
35-
}
36-
37-
S2N_RESULT s2n_digest_is_md5_allowed_for_fips(struct s2n_evp_digest *evp_digest, bool *out)
38-
{
39-
RESULT_ENSURE_REF(out);
40-
*out = false;
41-
#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC)
42-
if (s2n_is_in_fips_mode() && evp_digest && evp_digest->ctx && EVP_MD_CTX_test_flags(evp_digest->ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)) {
43-
/* s2n is in FIPS mode and the EVP digest allows MD5. */
44-
*out = true;
45-
}
46-
#else
47-
if (s2n_is_in_fips_mode()) {
48-
/* If s2n is in FIPS mode and built with AWS-LC or BoringSSL, there are no flags to check in the EVP digest to allow MD5. */
49-
*out = true;
50-
}
51-
#endif
52-
return S2N_RESULT_OK;
53-
}
18+
/*
19+
* TODO: update all CBMC proofs that depend on this file, then delete.
20+
*/

crypto/s2n_evp.h

-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,3 @@ struct s2n_evp_hmac_state {
5151
*/
5252
#define S2N_EVP_PKEY_CTX_set_signature_md(ctx, md) \
5353
EVP_PKEY_CTX_set_signature_md(ctx, (EVP_MD *) (uintptr_t) md)
54-
55-
int s2n_digest_allow_md5_for_fips(struct s2n_evp_digest *evp_digest);
56-
S2N_RESULT s2n_digest_is_md5_allowed_for_fips(struct s2n_evp_digest *evp_digest, bool *out);

crypto/s2n_hash.c

+1-55
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ bool s2n_hash_is_available(s2n_hash_algorithm alg)
113113
switch (alg) {
114114
case S2N_HASH_MD5:
115115
case S2N_HASH_MD5_SHA1:
116-
/* return false if in FIPS mode, as MD5 algs are not available in FIPS mode. */
117-
return !s2n_is_in_fips_mode();
118116
case S2N_HASH_NONE:
119117
case S2N_HASH_SHA1:
120118
case S2N_HASH_SHA224:
@@ -301,20 +299,6 @@ static int s2n_evp_hash_new(struct s2n_hash_state *state)
301299
return S2N_SUCCESS;
302300
}
303301

304-
static int s2n_evp_hash_allow_md5_for_fips(struct s2n_hash_state *state)
305-
{
306-
/* This is only to be used for s2n_hash_states that will require MD5 to be used
307-
* to comply with the TLS 1.0 and 1.1 RFC's for the PRF. MD5 cannot be used
308-
* outside of the TLS 1.0 and 1.1 PRF when in FIPS mode. When needed, this must
309-
* be called prior to s2n_hash_init().
310-
*/
311-
POSIX_GUARD(s2n_digest_allow_md5_for_fips(&state->digest.high_level.evp));
312-
if (s2n_use_custom_md5_sha1()) {
313-
POSIX_GUARD(s2n_digest_allow_md5_for_fips(&state->digest.high_level.evp_md5_secondary));
314-
}
315-
return S2N_SUCCESS;
316-
}
317-
318302
static int s2n_evp_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg)
319303
{
320304
POSIX_ENSURE_REF(state->digest.high_level.evp.ctx);
@@ -419,32 +403,16 @@ static int s2n_evp_hash_copy(struct s2n_hash_state *to, struct s2n_hash_state *f
419403
POSIX_GUARD_OSSL(EVP_MD_CTX_copy_ex(to->digest.high_level.evp_md5_secondary.ctx, from->digest.high_level.evp_md5_secondary.ctx), S2N_ERR_HASH_COPY_FAILED);
420404
}
421405

422-
bool is_md5_allowed_for_fips = false;
423-
POSIX_GUARD_RESULT(s2n_digest_is_md5_allowed_for_fips(&from->digest.high_level.evp, &is_md5_allowed_for_fips));
424-
if (is_md5_allowed_for_fips && (from->alg == S2N_HASH_MD5 || from->alg == S2N_HASH_MD5_SHA1)) {
425-
POSIX_GUARD(s2n_hash_allow_md5_for_fips(to));
426-
}
427406
return S2N_SUCCESS;
428407
}
429408

430409
static int s2n_evp_hash_reset(struct s2n_hash_state *state)
431410
{
432-
int reset_md5_for_fips = 0;
433-
bool is_md5_allowed_for_fips = false;
434-
POSIX_GUARD_RESULT(s2n_digest_is_md5_allowed_for_fips(&state->digest.high_level.evp, &is_md5_allowed_for_fips));
435-
if ((state->alg == S2N_HASH_MD5 || state->alg == S2N_HASH_MD5_SHA1) && is_md5_allowed_for_fips) {
436-
reset_md5_for_fips = 1;
437-
}
438-
439411
POSIX_GUARD_OSSL(S2N_EVP_MD_CTX_RESET(state->digest.high_level.evp.ctx), S2N_ERR_HASH_WIPE_FAILED);
440412
if (state->alg == S2N_HASH_MD5_SHA1 && s2n_use_custom_md5_sha1()) {
441413
POSIX_GUARD_OSSL(S2N_EVP_MD_CTX_RESET(state->digest.high_level.evp_md5_secondary.ctx), S2N_ERR_HASH_WIPE_FAILED);
442414
}
443415

444-
if (reset_md5_for_fips) {
445-
POSIX_GUARD(s2n_hash_allow_md5_for_fips(state));
446-
}
447-
448416
/* hash_init resets the ready_for_input and currently_in_hash fields. */
449417
return s2n_evp_hash_init(state, state->alg);
450418
}
@@ -465,7 +433,6 @@ static int s2n_evp_hash_free(struct s2n_hash_state *state)
465433

466434
static const struct s2n_hash s2n_low_level_hash = {
467435
.alloc = &s2n_low_level_hash_new,
468-
.allow_md5_for_fips = NULL,
469436
.init = &s2n_low_level_hash_init,
470437
.update = &s2n_low_level_hash_update,
471438
.digest = &s2n_low_level_hash_digest,
@@ -476,7 +443,6 @@ static const struct s2n_hash s2n_low_level_hash = {
476443

477444
static const struct s2n_hash s2n_evp_hash = {
478445
.alloc = &s2n_evp_hash_new,
479-
.allow_md5_for_fips = &s2n_evp_hash_allow_md5_for_fips,
480446
.init = &s2n_evp_hash_init,
481447
.update = &s2n_evp_hash_update,
482448
.digest = &s2n_evp_hash_digest,
@@ -514,19 +480,6 @@ S2N_RESULT s2n_hash_state_validate(struct s2n_hash_state *state)
514480
return S2N_RESULT_OK;
515481
}
516482

517-
int s2n_hash_allow_md5_for_fips(struct s2n_hash_state *state)
518-
{
519-
POSIX_ENSURE_REF(state);
520-
/* Ensure that hash_impl is set, as it may have been reset for s2n_hash_state on s2n_connection_wipe.
521-
* When in FIPS mode, the EVP API's must be used for hashes.
522-
*/
523-
POSIX_GUARD(s2n_hash_set_impl(state));
524-
525-
POSIX_ENSURE_REF(state->hash_impl->allow_md5_for_fips);
526-
527-
return state->hash_impl->allow_md5_for_fips(state);
528-
}
529-
530483
int s2n_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg)
531484
{
532485
POSIX_ENSURE_REF(state);
@@ -535,15 +488,8 @@ int s2n_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg)
535488
*/
536489
POSIX_GUARD(s2n_hash_set_impl(state));
537490

538-
bool is_md5_allowed_for_fips = false;
539-
POSIX_GUARD_RESULT(s2n_digest_is_md5_allowed_for_fips(&state->digest.high_level.evp, &is_md5_allowed_for_fips));
540-
541-
if (s2n_hash_is_available(alg) || ((alg == S2N_HASH_MD5 || alg == S2N_HASH_MD5_SHA1) && is_md5_allowed_for_fips)) {
542-
/* s2n will continue to initialize an "unavailable" hash when s2n is in FIPS mode and
543-
* FIPS is forcing the hash to be made available.
544-
*/
491+
if (s2n_hash_is_available(alg)) {
545492
POSIX_ENSURE_REF(state->hash_impl->init);
546-
547493
return state->hash_impl->init(state, alg);
548494
} else {
549495
POSIX_BAIL(S2N_ERR_HASH_INVALID_ALGORITHM);

crypto/s2n_hash.h

-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct s2n_hash_state {
7777
*/
7878
struct s2n_hash {
7979
int (*alloc)(struct s2n_hash_state *state);
80-
int (*allow_md5_for_fips)(struct s2n_hash_state *state);
8180
int (*init)(struct s2n_hash_state *state, s2n_hash_algorithm alg);
8281
int (*update)(struct s2n_hash_state *state, const void *data, uint32_t size);
8382
int (*digest)(struct s2n_hash_state *state, void *out, uint32_t size);
@@ -94,7 +93,6 @@ bool s2n_hash_is_available(s2n_hash_algorithm alg);
9493
int s2n_hash_is_ready_for_input(struct s2n_hash_state *state);
9594
int s2n_hash_new(struct s2n_hash_state *state);
9695
S2N_RESULT s2n_hash_state_validate(struct s2n_hash_state *state);
97-
int s2n_hash_allow_md5_for_fips(struct s2n_hash_state *state);
9896
int s2n_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg);
9997
int s2n_hash_update(struct s2n_hash_state *state, const void *data, uint32_t size);
10098
int s2n_hash_digest(struct s2n_hash_state *state, void *out, uint32_t size);

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips/Makefile

-32
This file was deleted.

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips/cbmc-proof.txt

-1
This file was deleted.

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips/s2n_digest_allow_md5_for_fips_harness.c

-40
This file was deleted.

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips_boringssl_awslc/Makefile

-35
This file was deleted.

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips_boringssl_awslc/cbmc-proof.txt

-1
This file was deleted.

tests/cbmc/proofs/s2n_digest_allow_md5_for_fips_boringssl_awslc/s2n_digest_allow_md5_for_fips_boringssl_awslc_harness.c

-40
This file was deleted.

tests/cbmc/proofs/s2n_digest_is_md5_allowed_for_fips/Makefile

-32
This file was deleted.

tests/cbmc/proofs/s2n_digest_is_md5_allowed_for_fips/cbmc-proof.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)