| 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 | |
| 16 | #pragma once |
| 17 | |
| 18 | #include "api/s2n.h" |
| 19 | #include "crypto/s2n_hash.h" |
| 20 | #include "crypto/s2n_tls13_keys.h" |
| 21 | |
| 22 | struct s2n_handshake_hashes { |
| 23 | struct s2n_hash_state md5; |
| 24 | struct s2n_hash_state sha1; |
| 25 | struct s2n_hash_state sha224; |
| 26 | struct s2n_hash_state sha256; |
| 27 | struct s2n_hash_state sha384; |
| 28 | struct s2n_hash_state sha512; |
| 29 | struct s2n_hash_state md5_sha1; |
| 30 | |
| 31 | /* TLS1.3 requires transcript hash digests to calculate secrets. |
| 32 | */ |
| 33 | uint8_t transcript_hash_digest[S2N_TLS13_SECRET_MAX_LEN]; |
| 34 | |
| 35 | /* To avoid allocating memory for hash objects, we reuse one temporary hash object. |
| 36 | * Do NOT rely on this hash state maintaining its value outside of the current context. |
| 37 | */ |
| 38 | struct s2n_hash_state hash_workspace; |
| 39 | }; |
| 40 | |
| 41 | S2N_RESULT s2n_handshake_hashes_new(struct s2n_handshake_hashes **hashes); |
| 42 | S2N_RESULT s2n_handshake_hashes_wipe(struct s2n_handshake_hashes *hashes); |
| 43 | S2N_CLEANUP_RESULT s2n_handshake_hashes_free(struct s2n_handshake_hashes **hashes); |