@@ -1623,9 +1623,42 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
16231623 goto end ;
16241624
16251625 if (ssl -> options .dtls ) {
1626+ w64wrapper epochNumber ;
16261627 ret = Dtls13DeriveSnKeys (ssl , provision );
16271628 if (ret != 0 )
1628- return ret ;
1629+ goto end ;
1630+
1631+ switch (secret ) {
1632+ case early_data_key :
1633+ epochNumber = w64From32 (0 , DTLS13_EPOCH_EARLYDATA );
1634+ break ;
1635+ case handshake_key :
1636+ epochNumber = w64From32 (0 , DTLS13_EPOCH_HANDSHAKE );
1637+ break ;
1638+ case traffic_key :
1639+ case no_key :
1640+ epochNumber = w64From32 (0 , DTLS13_EPOCH_TRAFFIC0 );
1641+ break ;
1642+ case update_traffic_key :
1643+ if (side == ENCRYPT_SIDE_ONLY ) {
1644+ epochNumber = ssl -> dtls13Epoch ;
1645+ }
1646+ else if (side == DECRYPT_SIDE_ONLY ) {
1647+ epochNumber = ssl -> dtls13PeerEpoch ;
1648+ }
1649+ else {
1650+ ret = BAD_STATE_E ;
1651+ goto end ;
1652+ }
1653+ w64Increment (& epochNumber );
1654+ break ;
1655+ default :
1656+ ret = BAD_STATE_E ;
1657+ goto end ;
1658+ }
1659+ ret = Dtls13NewEpoch (ssl , epochNumber , side );
1660+ if (ret != 0 )
1661+ goto end ;
16291662 }
16301663
16311664#endif /* WOLFSSL_DTLS13 */
@@ -4083,15 +4116,6 @@ static int WritePSKBinders(WOLFSSL* ssl, byte* output, word32 idx)
40834116 if ((ret = SetKeysSide (ssl , ENCRYPT_SIDE_ONLY )) != 0 )
40844117 return ret ;
40854118
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-
40954119 }
40964120 #endif
40974121
@@ -6296,17 +6320,6 @@ static int CheckPreSharedKeys(WOLFSSL* ssl, const byte* input, word32 helloSz,
62966320 return ret ;
62976321
62986322 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-
63106323 ssl -> earlyData = process_early_data ;
63116324 }
63126325 else
@@ -7604,11 +7617,6 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
76047617 w64wrapper epochHandshake = w64From32 (0 , DTLS13_EPOCH_HANDSHAKE );
76057618 ssl -> dtls13Epoch = epochHandshake ;
76067619
7607- ret = Dtls13NewEpoch (
7608- ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
7609- if (ret != 0 )
7610- return ret ;
7611-
76127620 ret = Dtls13SetEpochKeys (
76137621 ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
76147622 if (ret != 0 )
@@ -11194,11 +11202,6 @@ static int SendTls13Finished(WOLFSSL* ssl)
1119411202 ssl -> dtls13Epoch = epochTraffic0 ;
1119511203 ssl -> dtls13PeerEpoch = epochTraffic0 ;
1119611204
11197- ret = Dtls13NewEpoch (
11198- ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
11199- if (ret != 0 )
11200- return ret ;
11201-
1120211205 ret = Dtls13SetEpochKeys (
1120311206 ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
1120411207 if (ret != 0 )
@@ -11236,11 +11239,6 @@ static int SendTls13Finished(WOLFSSL* ssl)
1123611239 ssl -> dtls13Epoch = epochTraffic0 ;
1123711240 ssl -> dtls13PeerEpoch = epochTraffic0 ;
1123811241
11239- ret = Dtls13NewEpoch (
11240- ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
11241- if (ret != 0 )
11242- return ret ;
11243-
1124411242 ret = Dtls13SetEpochKeys (
1124511243 ssl , epochTraffic0 , ENCRYPT_AND_DECRYPT_SIDE );
1124611244 if (ret != 0 )
@@ -11440,10 +11438,6 @@ static int DoTls13KeyUpdate(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
1144011438 if (ssl -> options .dtls ) {
1144111439 w64Increment (& ssl -> dtls13PeerEpoch );
1144211440
11443- ret = Dtls13NewEpoch (ssl , ssl -> dtls13PeerEpoch , DECRYPT_SIDE_ONLY );
11444- if (ret != 0 )
11445- return ret ;
11446-
1144711441 ret = Dtls13SetEpochKeys (ssl , ssl -> dtls13PeerEpoch , DECRYPT_SIDE_ONLY );
1144811442 if (ret != 0 )
1144911443 return ret ;
@@ -12859,11 +12853,6 @@ int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1285912853 ssl -> dtls13Epoch = epochHandshake ;
1286012854 ssl -> dtls13PeerEpoch = epochHandshake ;
1286112855
12862- ret = Dtls13NewEpoch (
12863- ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
12864- if (ret != 0 )
12865- return ret ;
12866-
1286712856 ret = Dtls13SetEpochKeys (
1286812857 ssl , epochHandshake , ENCRYPT_AND_DECRYPT_SIDE );
1286912858 if (ret != 0 )
0 commit comments