| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <openssl/md5.h> |
| 19 |
#include <openssl/sha.h> |
| 20 |
#include <stdbool.h> |
| 21 |
#include <stdint.h> |
| 22 |
|
| 23 |
#include "crypto/s2n_evp.h" |
| 24 |
|
| 25 |
#define S2N_MAX_DIGEST_LEN SHA512_DIGEST_LENGTH |
| 26 |
|
| 27 |
typedef enum { |
| 28 |
S2N_HASH_NONE = 0, |
| 29 |
S2N_HASH_MD5, |
| 30 |
S2N_HASH_SHA1, |
| 31 |
S2N_HASH_SHA224, |
| 32 |
S2N_HASH_SHA256, |
| 33 |
S2N_HASH_SHA384, |
| 34 |
S2N_HASH_SHA512, |
| 35 |
S2N_HASH_MD5_SHA1, |
| 36 |
S2N_HASH_SHAKE256_64, |
| 37 |
|
| 38 |
S2N_HASH_ALGS_COUNT |
| 39 |
} s2n_hash_algorithm; |
| 40 |
|
| 41 |
|
| 42 |
struct s2n_hash_evp_digest { |
| 43 |
struct s2n_evp_digest evp; |
| 44 |
|
| 45 |
struct s2n_evp_digest evp_md5_secondary; |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
struct s2n_hash_state { |
| 52 |
const struct s2n_hash *hash_impl; |
| 53 |
s2n_hash_algorithm alg; |
| 54 |
uint8_t is_ready_for_input; |
| 55 |
uint64_t currently_in_hash; |
| 56 |
union { |
| 57 |
struct s2n_hash_evp_digest high_level; |
| 58 |
} digest; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
struct s2n_hash { |
| 65 |
int (*alloc)(struct s2n_hash_state *state); |
| 66 |
int (*init)(struct s2n_hash_state *state, s2n_hash_algorithm alg); |
| 67 |
int (*update)(struct s2n_hash_state *state, const void *data, uint32_t size); |
| 68 |
int (*digest)(struct s2n_hash_state *state, void *out, uint32_t size); |
| 69 |
int (*copy)(struct s2n_hash_state *to, struct s2n_hash_state *from); |
| 70 |
int (*reset)(struct s2n_hash_state *state); |
| 71 |
int (*free)(struct s2n_hash_state *state); |
| 72 |
}; |
| 73 |
|
| 74 |
S2N_RESULT s2n_hash_algorithms_init(); |
| 75 |
S2N_RESULT s2n_hash_algorithms_cleanup(); |
| 76 |
bool s2n_hash_use_custom_md5_sha1(); |
| 77 |
bool s2n_hash_supports_shake(); |
| 78 |
const EVP_MD *s2n_hash_alg_to_evp_md(s2n_hash_algorithm alg); |
| 79 |
int s2n_hash_digest_size(s2n_hash_algorithm alg, uint8_t *out); |
| 80 |
bool s2n_hash_is_available(s2n_hash_algorithm alg); |
| 81 |
int s2n_hash_is_ready_for_input(struct s2n_hash_state *state); |
| 82 |
int s2n_hash_new(struct s2n_hash_state *state); |
| 83 |
S2N_RESULT s2n_hash_state_validate(struct s2n_hash_state *state); |
| 84 |
int s2n_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg); |
| 85 |
int s2n_hash_update(struct s2n_hash_state *state, const void *data, uint32_t size); |
| 86 |
int s2n_hash_digest(struct s2n_hash_state *state, void *out, uint32_t size); |
| 87 |
int s2n_hash_copy(struct s2n_hash_state *to, struct s2n_hash_state *from); |
| 88 |
int s2n_hash_reset(struct s2n_hash_state *state); |
| 89 |
int s2n_hash_free(struct s2n_hash_state *state); |
| 90 |
int s2n_hash_get_currently_in_hash_total(struct s2n_hash_state *state, uint64_t *out); |