Skip to content

Commit 554ddf3

Browse files
committed
refactor: cleanup prf header
1 parent 5f93441 commit 554ddf3

File tree

6 files changed

+40
-38
lines changed

6 files changed

+40
-38
lines changed

tests/unit/s2n_ssl_prf_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#include "testlib/s2n_testlib.h"
2323
#include "tls/s2n_prf.h"
2424

25-
/*
25+
int s2n_tls_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
2626

27+
/*
2728
* Grabbed from gnutls-cli --insecure -d 9 www.example.com --ciphers AES --macs SHA --protocols SSLv3
2829
*
2930
* |<9>| INT: PREMASTER SECRET[48]: 03009e8e006a7f1451d32164088a8cba5077d1b819160662a97e90a765cec244b5f8f98fd50cfe8e4fba97994a7a4843

tests/unit/s2n_tls_hybrid_prf_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
106106

107107
EXPECT_MEMCPY_SUCCESS(conn->kex_params.client_key_exchange_message.data, client_key_exchange_message, client_key_exchange_message_length);
108108

109-
EXPECT_SUCCESS(s2n_hybrid_prf_master_secret(conn, &combined_pms));
109+
EXPECT_SUCCESS(s2n_prf_hybrid_master_secret(conn, &combined_pms));
110110
EXPECT_BYTEARRAY_EQUAL(expected_master_secret, conn->secrets.version.tls12.master_secret, S2N_TLS_SECRET_LEN);
111111
EXPECT_SUCCESS(s2n_free(&conn->kex_params.client_key_exchange_message));
112112
EXPECT_SUCCESS(s2n_connection_free(conn));

tests/unit/s2n_tls_prf_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626

2727
#define TEST_BLOB_SIZE 64
2828

29+
bool s2n_libcrypto_supports_tls_prf();
30+
int s2n_prf(struct s2n_connection *conn, struct s2n_blob *secret,
31+
struct s2n_blob *label, struct s2n_blob *seed_a,
32+
struct s2n_blob *seed_b, struct s2n_blob *seed_c, struct s2n_blob *out);
33+
S2N_RESULT s2n_prf_get_digest_for_ems(struct s2n_connection *conn,
34+
struct s2n_blob *message, s2n_hash_algorithm hash_alg, struct s2n_blob *output);
35+
S2N_RESULT s2n_tls_prf_extended_master_secret(struct s2n_connection *conn,
36+
struct s2n_blob *premaster_secret, struct s2n_blob *session_hash, struct s2n_blob *sha1_hash);
37+
int s2n_tls_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
38+
2939
/*
3040
* Grabbed from gnutls-cli --insecure -d 9 www.example.com --ciphers AES --macs SHA --protocols TLS1.0
3141
*

tls/s2n_kex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ const struct s2n_kex s2n_hybrid_ecdhe_kem = {
245245
.server_key_send = &s2n_hybrid_server_key_send,
246246
.client_key_recv = &s2n_hybrid_client_key_recv,
247247
.client_key_send = &s2n_hybrid_client_key_send,
248-
.prf = &s2n_hybrid_prf_master_secret,
248+
.prf = &s2n_prf_hybrid_master_secret,
249249
};
250250

251251
/* TLS1.3 key exchange is implemented differently from previous versions and does

tls/s2n_prf.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@
3434
#include "utils/s2n_mem.h"
3535
#include "utils/s2n_safety.h"
3636

37+
#if defined(OPENSSL_IS_AWSLC)
38+
#define S2N_LIBCRYPTO_SUPPORTS_TLS_PRF 1
39+
#else
40+
#define S2N_LIBCRYPTO_SUPPORTS_TLS_PRF 0
41+
#endif
42+
43+
/* The s2n p_hash implementation is abstracted to allow for separate implementations, using
44+
* either s2n's formally verified HMAC or OpenSSL's EVP HMAC, for use by the TLS PRF. */
45+
struct s2n_p_hash_hmac {
46+
int (*alloc)(struct s2n_prf_working_space *ws);
47+
int (*init)(struct s2n_prf_working_space *ws, s2n_hmac_algorithm alg, struct s2n_blob *secret);
48+
int (*update)(struct s2n_prf_working_space *ws, const void *data, uint32_t size);
49+
int (*final)(struct s2n_prf_working_space *ws, void *digest, uint32_t size);
50+
int (*reset)(struct s2n_prf_working_space *ws);
51+
int (*cleanup)(struct s2n_prf_working_space *ws);
52+
int (*free)(struct s2n_prf_working_space *ws);
53+
};
54+
55+
S2N_RESULT s2n_prf_get_digest_for_ems(struct s2n_connection *conn, struct s2n_blob *message,
56+
s2n_hash_algorithm hash_alg, struct s2n_blob *output);
57+
S2N_RESULT s2n_tls_prf_extended_master_secret(struct s2n_connection *conn,
58+
struct s2n_blob *premaster_secret, struct s2n_blob *session_hash, struct s2n_blob *sha1_hash);
59+
3760
S2N_RESULT s2n_key_material_init(struct s2n_key_material *key_material, struct s2n_connection *conn)
3861
{
3962
RESULT_ENSURE_REF(key_material);
@@ -659,7 +682,7 @@ int s2n_tls_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *prem
659682
return s2n_prf(conn, premaster_secret, &label, &client_random, &server_random, NULL, &master_secret);
660683
}
661684

662-
int s2n_hybrid_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret)
685+
int s2n_prf_hybrid_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret)
663686
{
664687
POSIX_ENSURE_REF(conn);
665688

tls/s2n_prf.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@
1717

1818
#include <stdint.h>
1919

20-
#include "crypto/s2n_hash.h"
2120
#include "crypto/s2n_hmac.h"
21+
#include "tls/s2n_connection.h"
2222
#include "utils/s2n_blob.h"
2323

2424
/* Enough to support TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, 2*SHA384_DIGEST_LEN + 2*AES256_KEY_SIZE */
2525
#define S2N_MAX_KEY_BLOCK_LEN 160
2626

27-
#if defined(OPENSSL_IS_AWSLC)
28-
#define S2N_LIBCRYPTO_SUPPORTS_TLS_PRF 1
29-
#else
30-
#define S2N_LIBCRYPTO_SUPPORTS_TLS_PRF 0
31-
#endif
32-
3327
union p_hash_state {
3428
struct s2n_hmac_state s2n_hmac;
3529
struct s2n_evp_hmac_state evp_hmac;
@@ -41,18 +35,6 @@ struct s2n_prf_working_space {
4135
uint8_t digest1[S2N_MAX_DIGEST_LEN];
4236
};
4337

44-
/* The s2n p_hash implementation is abstracted to allow for separate implementations, using
45-
* either s2n's formally verified HMAC or OpenSSL's EVP HMAC, for use by the TLS PRF. */
46-
struct s2n_p_hash_hmac {
47-
int (*alloc)(struct s2n_prf_working_space *ws);
48-
int (*init)(struct s2n_prf_working_space *ws, s2n_hmac_algorithm alg, struct s2n_blob *secret);
49-
int (*update)(struct s2n_prf_working_space *ws, const void *data, uint32_t size);
50-
int (*final)(struct s2n_prf_working_space *ws, void *digest, uint32_t size);
51-
int (*reset)(struct s2n_prf_working_space *ws);
52-
int (*cleanup)(struct s2n_prf_working_space *ws);
53-
int (*free)(struct s2n_prf_working_space *ws);
54-
};
55-
5638
/* TLS key expansion results in an array of contiguous data which is then
5739
* interpreted as the MAC, KEY and IV for the client and server.
5840
*
@@ -75,27 +57,13 @@ struct s2n_key_material {
7557

7658
S2N_RESULT s2n_key_material_init(struct s2n_key_material *key_material, struct s2n_connection *conn);
7759

78-
#include "tls/s2n_connection.h"
79-
8060
S2N_RESULT s2n_prf_new(struct s2n_connection *conn);
8161
S2N_RESULT s2n_prf_wipe(struct s2n_connection *conn);
8262
S2N_RESULT s2n_prf_free(struct s2n_connection *conn);
8363

84-
int s2n_prf(struct s2n_connection *conn, struct s2n_blob *secret, struct s2n_blob *label, struct s2n_blob *seed_a,
85-
struct s2n_blob *seed_b, struct s2n_blob *seed_c, struct s2n_blob *out);
8664
int s2n_prf_calculate_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
87-
int s2n_tls_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
88-
int s2n_hybrid_prf_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
89-
S2N_RESULT s2n_tls_prf_extended_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret, struct s2n_blob *session_hash, struct s2n_blob *sha1_hash);
90-
S2N_RESULT s2n_prf_get_digest_for_ems(struct s2n_connection *conn, struct s2n_blob *message, s2n_hash_algorithm hash_alg, struct s2n_blob *output);
65+
int s2n_prf_hybrid_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret);
9166
S2N_RESULT s2n_prf_generate_key_material(struct s2n_connection *conn, struct s2n_key_material *key_material);
9267
int s2n_prf_key_expansion(struct s2n_connection *conn);
9368
int s2n_prf_server_finished(struct s2n_connection *conn);
9469
int s2n_prf_client_finished(struct s2n_connection *conn);
95-
96-
bool s2n_libcrypto_supports_tls_prf();
97-
98-
S2N_RESULT s2n_custom_prf(struct s2n_connection *conn, struct s2n_blob *secret, struct s2n_blob *label,
99-
struct s2n_blob *seed_a, struct s2n_blob *seed_b, struct s2n_blob *seed_c, struct s2n_blob *out);
100-
S2N_RESULT s2n_libcrypto_prf(struct s2n_connection *conn, struct s2n_blob *secret, struct s2n_blob *label,
101-
struct s2n_blob *seed_a, struct s2n_blob *seed_b, struct s2n_blob *seed_c, struct s2n_blob *out);

0 commit comments

Comments
 (0)