| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
#include <openssl/sha.h> |
| 20 |
#include <openssl/md5.h> |
| 21 |
|
| 22 |
#include "crypto/s2n_evp.h" |
| 23 |
|
| 24 |
#define S2N_MAX_DIGEST_LEN SHA512_DIGEST_LENGTH |
| 25 |
|
| 26 |
typedef enum { |
| 27 |
S2N_HASH_NONE, |
| 28 |
S2N_HASH_MD5, |
| 29 |
S2N_HASH_SHA1, |
| 30 |
S2N_HASH_SHA224, |
| 31 |
S2N_HASH_SHA256, |
| 32 |
S2N_HASH_SHA384, |
| 33 |
S2N_HASH_SHA512, |
| 34 |
S2N_HASH_MD5_SHA1, |
| 35 |
|
| 36 |
S2N_HASH_ALGS_COUNT |
| 37 |
} s2n_hash_algorithm; |
| 38 |
|
| 39 |
struct s2n_hash_state { |
| 40 |
s2n_hash_algorithm alg; |
| 41 |
int currently_in_hash_block; |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
enum { |
| 54 |
PER_BLOCK_COST = 1000, |
| 55 |
PER_BYTE_COST = 1, |
| 56 |
BLOCK_SIZE = 64, |
| 57 |
LENGTH_FIELD_SIZE = 8, |
| 58 |
DIGEST_SIZE = 20 |
| 59 |
}; |
| 60 |
|
| 61 |
#define MAX_SIZE 1024 |
| 62 |
|
| 63 |
enum { |
| 64 |
SUCCESS = 0, |
| 65 |
FAILURE = -1 |
| 66 |
}; |
| 67 |
|
| 68 |
int s2n_hash_digest_size(s2n_hash_algorithm alg, uint8_t *out); |
| 69 |
int s2n_hash_new(struct s2n_hash_state *state); |
| 70 |
S2N_RESULT s2n_hash_state_validate(struct s2n_hash_state *state); |
| 71 |
int s2n_hash_init(struct s2n_hash_state *state, s2n_hash_algorithm alg); |
| 72 |
int s2n_hash_update(struct s2n_hash_state *state, const void *data, uint32_t size); |
| 73 |
int s2n_hash_digest(struct s2n_hash_state *state, void *out, uint32_t size); |
| 74 |
int s2n_hash_copy(struct s2n_hash_state *to, struct s2n_hash_state *from); |
| 75 |
int s2n_hash_reset(struct s2n_hash_state *state); |
| 76 |
int s2n_hash_free(struct s2n_hash_state *state); |
| 77 |
int s2n_hash_get_currently_in_hash_total(struct s2n_hash_state *state, uint64_t *out); |