Skip to content

Commit f5902bd

Browse files
authored
Merge pull request #9862 from embhorn/zd21243
Fix DeriveTls13Keys with no_key
2 parents 2cb1781 + 84650b5 commit f5902bd

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/tls13.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,8 @@ static const byte writeIVLabel[WRITE_IV_LABEL_SZ+1] = "iv";
14531453
* traffic messages.
14541454
* update_traffic_key when deriving next keys and IVs for encrypting
14551455
* traffic messages.
1456+
* no_key when deriving keys and IVs from existing secrets without
1457+
* re-deriving the secrets. Used during early data transitions.
14561458
* side ENCRYPT_SIDE_ONLY when only encryption secret needs to be derived.
14571459
* DECRYPT_SIDE_ONLY when only decryption secret needs to be derived.
14581460
* ENCRYPT_AND_DECRYPT_SIDE when both secret needs to be derived.
@@ -1541,6 +1543,12 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
15411543
}
15421544
break;
15431545

1546+
case no_key:
1547+
/* Called with early data to derive keys from existing secrets
1548+
* without re-deriving the secrets themselves. */
1549+
ret = 0;
1550+
break;
1551+
15441552
default:
15451553
ret = BAD_FUNC_ARG;
15461554
break;

tests/api/test_tls13.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,3 +3317,38 @@ int test_tls13_cert_req_sigalgs(void)
33173317
return EXPECT_RESULT();
33183318
}
33193319

3320+
int test_tls13_derive_keys_no_key(void)
3321+
{
3322+
EXPECT_DECLS;
3323+
#if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
3324+
struct test_memio_ctx test_ctx;
3325+
WOLFSSL_CTX *ctx_c = NULL;
3326+
WOLFSSL_CTX *ctx_s = NULL;
3327+
WOLFSSL *ssl_c = NULL;
3328+
WOLFSSL *ssl_s = NULL;
3329+
3330+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
3331+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
3332+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
3333+
3334+
/* DeriveTls13Keys with no_key should succeed (skip secret derivation,
3335+
* only derive keys/IVs from existing secrets). This is used with early
3336+
* data to derive keys without re-deriving the secrets. */
3337+
ExpectIntEQ(DeriveTls13Keys(ssl_s, no_key, DECRYPT_SIDE_ONLY, 0), 0);
3338+
ExpectIntEQ(DeriveTls13Keys(ssl_s, no_key, ENCRYPT_SIDE_ONLY, 0), 0);
3339+
ExpectIntEQ(DeriveTls13Keys(ssl_c, no_key, ENCRYPT_AND_DECRYPT_SIDE, 0),
3340+
0);
3341+
3342+
/* Unknown secret type should return BAD_FUNC_ARG */
3343+
ExpectIntEQ(DeriveTls13Keys(ssl_c, -1, ENCRYPT_SIDE_ONLY, 0),
3344+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3345+
3346+
wolfSSL_free(ssl_c);
3347+
wolfSSL_free(ssl_s);
3348+
wolfSSL_CTX_free(ctx_c);
3349+
wolfSSL_CTX_free(ctx_s);
3350+
#endif
3351+
3352+
return EXPECT_RESULT();
3353+
}
3354+

tests/api/test_tls13.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int test_tls13_plaintext_alert(void);
4141
int test_tls13_warning_alert_is_fatal(void);
4242
int test_tls13_unknown_ext_rejected(void);
4343
int test_tls13_cert_req_sigalgs(void);
44+
int test_tls13_derive_keys_no_key(void);
4445

4546
#define TEST_TLS13_DECLS \
4647
TEST_DECL_GROUP("tls13", test_tls13_apis), \
@@ -59,6 +60,7 @@ int test_tls13_cert_req_sigalgs(void);
5960
TEST_DECL_GROUP("tls13", test_tls13_plaintext_alert), \
6061
TEST_DECL_GROUP("tls13", test_tls13_warning_alert_is_fatal), \
6162
TEST_DECL_GROUP("tls13", test_tls13_unknown_ext_rejected), \
62-
TEST_DECL_GROUP("tls13", test_tls13_cert_req_sigalgs)
63+
TEST_DECL_GROUP("tls13", test_tls13_cert_req_sigalgs), \
64+
TEST_DECL_GROUP("tls13", test_tls13_derive_keys_no_key)
6365

6466
#endif /* WOLFCRYPT_TEST_TLS13_H */

wolfssl/internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,10 @@ enum DeriveKeyType {
37593759

37603760
WOLFSSL_LOCAL int DeriveEarlySecret(WOLFSSL* ssl);
37613761
WOLFSSL_LOCAL int DeriveHandshakeSecret(WOLFSSL* ssl);
3762-
WOLFSSL_LOCAL int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store);
3762+
#ifdef WOLFSSL_API_PREFIX_MAP
3763+
#define DeriveTls13Keys wolfSSL_DeriveTls13Keys
3764+
#endif
3765+
WOLFSSL_TEST_VIS int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store);
37633766
WOLFSSL_LOCAL int DeriveMasterSecret(WOLFSSL* ssl);
37643767
WOLFSSL_LOCAL int DeriveResumptionPSK(WOLFSSL* ssl, byte* nonce, byte nonceLen, byte* secret);
37653768
WOLFSSL_LOCAL int DeriveResumptionSecret(WOLFSSL* ssl, byte* key);

0 commit comments

Comments
 (0)