Debian Codegraph @

crt/s2n/crypto/s2n_hmac.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 /* this file is patched by sidetrail, clang-format invalidates patches */
16 /* clang-format off */
17
18 #pragma once
19
20 #include <stdint.h>
21
22 #include "crypto/s2n_hash.h"
23
24 typedef enum {
25 S2N_HMAC_NONE,
26 S2N_HMAC_MD5,
27 S2N_HMAC_SHA1,
28 S2N_HMAC_SHA224,
29 S2N_HMAC_SHA256,
30 S2N_HMAC_SHA384,
31 S2N_HMAC_SHA512,
32 S2N_HMAC_SSLv3_MD5,
33 S2N_HMAC_SSLv3_SHA1
34 } s2n_hmac_algorithm;
35
36 struct s2n_hmac_state {
37 s2n_hmac_algorithm alg;
38
39 uint16_t hash_block_size;
40 uint32_t currently_in_hash_block;
41 uint16_t xor_pad_size;
42 uint8_t digest_size;
43
44 struct s2n_hash_state inner;
45 struct s2n_hash_state inner_just_key;
46 struct s2n_hash_state outer;
47 struct s2n_hash_state outer_just_key;
48
49 /* key needs to be as large as the biggest block size */
50 uint8_t xor_pad[128];
51
52 /* For storing the inner digest */
53 uint8_t digest_pad[SHA512_DIGEST_LENGTH];
54 };
55
56 struct s2n_hmac_evp_backup {
57 struct s2n_hash_evp_digest inner;
58 struct s2n_hash_evp_digest inner_just_key;
59 struct s2n_hash_evp_digest outer;
60 struct s2n_hash_evp_digest outer_just_key;
61 };
62
63 int s2n_hmac_digest_size(s2n_hmac_algorithm alg, uint8_t *out);
64 int s2n_hmac_hash_alg(s2n_hmac_algorithm hmac_alg, s2n_hash_algorithm *out);
65 int s2n_hash_hmac_alg(s2n_hash_algorithm hash_alg, s2n_hmac_algorithm *out);
66
67 int s2n_hmac_new(struct s2n_hmac_state *state);
68 S2N_RESULT s2n_hmac_state_validate(struct s2n_hmac_state *state);
69 int s2n_hmac_init(struct s2n_hmac_state *state, s2n_hmac_algorithm alg, const void *key, uint32_t klen);
70 int s2n_hmac_update(struct s2n_hmac_state *state, const void *in, uint32_t size);
71 int s2n_hmac_digest(struct s2n_hmac_state *state, void *out, uint32_t size);
72 int s2n_hmac_digest_two_compression_rounds(struct s2n_hmac_state *state, void *out, uint32_t size);
73 int s2n_hmac_digest_verify(const void *a, const void *b, uint32_t len);
74 int s2n_hmac_free(struct s2n_hmac_state *state);
75 int s2n_hmac_reset(struct s2n_hmac_state *state);
76 int s2n_hmac_copy(struct s2n_hmac_state *to, struct s2n_hmac_state *from);
77 int s2n_hmac_save_evp_hash_state(struct s2n_hmac_evp_backup* backup, struct s2n_hmac_state* hmac);
78 int s2n_hmac_restore_evp_hash_state(struct s2n_hmac_evp_backup* backup, struct s2n_hmac_state* hmac);
79
80 S2N_RESULT s2n_hmac_md_from_alg(s2n_hmac_algorithm alg, const EVP_MD **md);