@@ -1471,6 +1471,9 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
14711471 byte key_dig [MAX_PRF_DIG ];
14721472#endif
14731473 int provision ;
1474+ #ifdef WOLFSSL_DTLS13
1475+ w64wrapper epochNumber ;
1476+ #endif
14741477
14751478#if defined(WOLFSSL_RENESAS_TSIP_TLS )
14761479 ret = tsip_Tls13DeriveKeys (ssl , secret , side );
@@ -1626,6 +1629,34 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
16261629 ret = Dtls13DeriveSnKeys (ssl , provision );
16271630 if (ret != 0 )
16281631 return ret ;
1632+
1633+ switch (secret ) {
1634+ case early_data_key :
1635+ epochNumber = w64From32 (0 , DTLS13_EPOCH_EARLYDATA );
1636+ break ;
1637+ case handshake_key :
1638+ epochNumber = w64From32 (0 , DTLS13_EPOCH_HANDSHAKE );
1639+ break ;
1640+ case traffic_key :
1641+ case no_key :
1642+ epochNumber = w64From32 (0 , DTLS13_EPOCH_TRAFFIC0 );
1643+ break ;
1644+ case update_traffic_key :
1645+ if (side == ENCRYPT_SIDE_ONLY ) {
1646+ epochNumber = ssl -> dtls13Epoch ;
1647+ }
1648+ else if (side == DECRYPT_SIDE_ONLY ) {
1649+ epochNumber = ssl -> dtls13PeerEpoch ;
1650+ }
1651+ else {
1652+ return BAD_STATE_E ;
1653+ }
1654+ w64Increment (& epochNumber );
1655+ break ;
1656+ }
1657+ ret = Dtls13NewEpoch (ssl , epochNumber , side );
1658+ if (ret != 0 )
1659+ return ret ;
16291660 }
16301661
16311662#endif /* WOLFSSL_DTLS13 */
@@ -4083,15 +4114,6 @@ static int WritePSKBinders(WOLFSSL* ssl, byte* output, word32 idx)
40834114 if ((ret = SetKeysSide (ssl , ENCRYPT_SIDE_ONLY )) != 0 )
40844115 return ret ;
40854116
4086- #ifdef WOLFSSL_DTLS13
4087- if (ssl -> options .dtls ) {
4088- ret = Dtls13NewEpoch (
4089- ssl , w64From32 (0x0 , DTLS13_EPOCH_EARLYDATA ), ENCRYPT_SIDE_ONLY );
4090- if (ret != 0 )
4091- return ret ;
4092- }
4093- #endif /* WOLFSSL_DTLS13 */
4094-
40954117 }
40964118 #endif
40974119
@@ -6296,17 +6318,6 @@ static int CheckPreSharedKeys(WOLFSSL* ssl, const byte* input, word32 helloSz,
62966318 return ret ;
62976319
62986320 ssl -> keys .encryptionOn = 1 ;
6299-
6300- #ifdef WOLFSSL_DTLS13
6301- if (ssl -> options .dtls ) {
6302- ret = Dtls13NewEpoch (ssl ,
6303- w64From32 (0x0 , DTLS13_EPOCH_EARLYDATA ),
6304- DECRYPT_SIDE_ONLY );
6305- if (ret != 0 )
6306- return ret ;
6307- }
6308- #endif /* WOLFSSL_DTLS13 */
6309-
63106321 ssl -> earlyData = process_early_data ;
63116322 }
63126323 else
@@ -7604,11 +7615,6 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
76047615 w64wrapper epochHandshake = w64From32 (0 , DTLS13_EPOCH_HANDSHAKE );
76057616 ssl -> dtls13Epoch = epochHandshake ;
76067617
7607- ret = Dtls13NewEpoch (
7608- ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
7609- if (ret != 0 )
7610- return ret ;
7611-
76127618 ret = Dtls13SetEpochKeys (
76137619 ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
76147620 if (ret != 0 )
@@ -11194,11 +11200,6 @@ static int SendTls13Finished(WOLFSSL* ssl)
1119411200 ssl -> dtls13Epoch = epochTraffic0 ;
1119511201 ssl -> dtls13PeerEpoch = epochTraffic0 ;
1119611202
11197- ret = Dtls13NewEpoch (
11198- ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
11199- if (ret != 0 )
11200- return ret ;
11201-
1120211203 ret = Dtls13SetEpochKeys (
1120311204 ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
1120411205 if (ret != 0 )
@@ -11236,11 +11237,6 @@ static int SendTls13Finished(WOLFSSL* ssl)
1123611237 ssl -> dtls13Epoch = epochTraffic0 ;
1123711238 ssl -> dtls13PeerEpoch = epochTraffic0 ;
1123811239
11239- ret = Dtls13NewEpoch (
11240- ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
11241- if (ret != 0 )
11242- return ret ;
11243-
1124411240 ret = Dtls13SetEpochKeys (
1124511241 ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
1124611242 if (ret != 0 )
@@ -11440,10 +11436,6 @@ static int DoTls13KeyUpdate(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
1144011436 if (ssl -> options .dtls ) {
1144111437 w64Increment (& ssl -> dtls13PeerEpoch );
1144211438
11443- ret = Dtls13NewEpoch (ssl , ssl -> dtls13PeerEpoch , DECRYPT_SIDE_ONLY );
11444- if (ret != 0 )
11445- return ret ;
11446-
1144711439 ret = Dtls13SetEpochKeys (ssl , ssl -> dtls13PeerEpoch , DECRYPT_SIDE_ONLY );
1144811440 if (ret != 0 )
1144911441 return ret ;
@@ -12859,11 +12851,6 @@ int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1285912851 ssl -> dtls13Epoch = epochHandshake ;
1286012852 ssl -> dtls13PeerEpoch = epochHandshake ;
1286112853
12862- ret = Dtls13NewEpoch (
12863- ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
12864- if (ret != 0 )
12865- return ret ;
12866-
1286712854 ret = Dtls13SetEpochKeys (
1286812855 ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
1286912856 if (ret != 0 )
0 commit comments