Skip to content

Commit b79264f

Browse files
committed
Fix cbmc
1 parent 2820954 commit b79264f

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

crypto/s2n_hash.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include "utils/s2n_safety.h"
2222

2323
#if S2N_LIBCRYPTO_SUPPORTS_PROVIDERS
24-
static EVP_MD *evp_mds[S2N_HASH_ALGS_COUNT] = { 0 };
24+
static EVP_MD *s2n_evp_mds[S2N_HASH_ALGS_COUNT] = { 0 };
2525
#else
26-
static const EVP_MD *evp_mds[S2N_HASH_ALGS_COUNT] = { 0 };
26+
static const EVP_MD *s2n_evp_mds[S2N_HASH_ALGS_COUNT] = { 0 };
2727
#endif
2828

2929
static bool s2n_use_custom_md5_sha1()
@@ -58,26 +58,26 @@ S2N_RESULT s2n_hash_algorithms_init()
5858
* the default query string of "fips=yes" will need to be overridden for
5959
* legacy algorithms.
6060
*/
61-
evp_mds[S2N_HASH_MD5] = EVP_MD_fetch(NULL, "MD5", "-fips");
62-
evp_mds[S2N_HASH_MD5_SHA1] = EVP_MD_fetch(NULL, "MD5-SHA1", "-fips");
63-
evp_mds[S2N_HASH_SHA1] = EVP_MD_fetch(NULL, "SHA1", NULL);
64-
evp_mds[S2N_HASH_SHA224] = EVP_MD_fetch(NULL, "SHA224", NULL);
65-
evp_mds[S2N_HASH_SHA256] = EVP_MD_fetch(NULL, "SHA256", NULL);
66-
evp_mds[S2N_HASH_SHA384] = EVP_MD_fetch(NULL, "SHA384", NULL);
67-
evp_mds[S2N_HASH_SHA512] = EVP_MD_fetch(NULL, "SHA512", NULL);
61+
s2n_evp_mds[S2N_HASH_MD5] = EVP_MD_fetch(NULL, "MD5", "-fips");
62+
s2n_evp_mds[S2N_HASH_MD5_SHA1] = EVP_MD_fetch(NULL, "MD5-SHA1", "-fips");
63+
s2n_evp_mds[S2N_HASH_SHA1] = EVP_MD_fetch(NULL, "SHA1", NULL);
64+
s2n_evp_mds[S2N_HASH_SHA224] = EVP_MD_fetch(NULL, "SHA224", NULL);
65+
s2n_evp_mds[S2N_HASH_SHA256] = EVP_MD_fetch(NULL, "SHA256", NULL);
66+
s2n_evp_mds[S2N_HASH_SHA384] = EVP_MD_fetch(NULL, "SHA384", NULL);
67+
s2n_evp_mds[S2N_HASH_SHA512] = EVP_MD_fetch(NULL, "SHA512", NULL);
6868
#else
69-
evp_mds[S2N_HASH_MD5] = EVP_md5();
70-
evp_mds[S2N_HASH_SHA1] = EVP_sha1();
71-
evp_mds[S2N_HASH_SHA224] = EVP_sha224();
72-
evp_mds[S2N_HASH_SHA256] = EVP_sha256();
73-
evp_mds[S2N_HASH_SHA384] = EVP_sha384();
74-
evp_mds[S2N_HASH_SHA512] = EVP_sha512();
69+
s2n_evp_mds[S2N_HASH_MD5] = EVP_md5();
70+
s2n_evp_mds[S2N_HASH_SHA1] = EVP_sha1();
71+
s2n_evp_mds[S2N_HASH_SHA224] = EVP_sha224();
72+
s2n_evp_mds[S2N_HASH_SHA256] = EVP_sha256();
73+
s2n_evp_mds[S2N_HASH_SHA384] = EVP_sha384();
74+
s2n_evp_mds[S2N_HASH_SHA512] = EVP_sha512();
7575
/* Very old libcryptos like openssl-1.0.2 do not support EVP_MD_md5_sha1().
7676
* We work around that by manually combining MD5 and SHA1, rather than
7777
* using the composite algorithm.
7878
*/
7979
#if defined(S2N_LIBCRYPTO_SUPPORTS_EVP_MD5_SHA1_HASH)
80-
evp_mds[S2N_HASH_MD5_SHA1] = EVP_md5_sha1();
80+
s2n_evp_mds[S2N_HASH_MD5_SHA1] = EVP_md5_sha1();
8181
#endif
8282
#endif
8383
return S2N_RESULT_OK;
@@ -92,8 +92,8 @@ S2N_RESULT s2n_hash_algorithms_cleanup()
9292
* > If the reference count drops to 0 then the structure is freed.
9393
* > If the argument is NULL, nothing is done.
9494
*/
95-
EVP_MD_free(evp_mds[i]);
96-
evp_mds[i] = NULL;
95+
EVP_MD_free(s2n_evp_mds[i]);
96+
s2n_evp_mds[i] = NULL;
9797
}
9898
#endif
9999
return S2N_RESULT_OK;
@@ -103,7 +103,7 @@ const EVP_MD *s2n_hash_alg_to_evp_md(s2n_hash_algorithm alg)
103103
{
104104
PTR_ENSURE_GTE(alg, 0);
105105
PTR_ENSURE_LT(alg, S2N_HASH_ALGS_COUNT);
106-
return evp_mds[alg];
106+
return s2n_evp_mds[alg];
107107
}
108108

109109
int s2n_hash_digest_size(s2n_hash_algorithm alg, uint8_t *out)

tests/cbmc/proofs/s2n_hash_init/s2n_hash_init_harness.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ void s2n_hash_init_harness()
2525
struct s2n_hash_state *state = cbmc_allocate_s2n_hash_state();
2626
s2n_hash_algorithm alg;
2727

28+
assert(s2n_result_is_ok(s2n_hash_algorithms_init()));
29+
2830
/* Operation under verification. */
2931
if (s2n_hash_init(state, alg) == S2N_SUCCESS) {
3032
/* Post-conditions. */

tests/cbmc/proofs/s2n_hash_reset/s2n_hash_reset_harness.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void s2n_hash_reset_harness()
2424
/* Non-deterministic inputs. */
2525
struct s2n_hash_state *state = cbmc_allocate_s2n_hash_state();
2626

27+
assert(s2n_result_is_ok(s2n_hash_algorithms_init()));
28+
2729
/* Operation under verification. */
2830
if (s2n_hash_reset(state) == S2N_SUCCESS)
2931
{

0 commit comments

Comments
 (0)