9393 WOLFSSH_NO_HMAC_SHA2_256
9494 Set when HMAC or SHA2-256 are disabled. Set to disable HMAC-SHA2-256
9595 support.
96+ WOLFSSH_NO_HMAC_SHA2_512
97+ Set when HMAC or SHA2-512 are disabled. Set to disable HMAC-SHA2-512
98+ support.
9699 WOLFSSH_NO_DH_GROUP1_SHA1
97100 Set when DH or SHA1 are disabled. Set to disable use of DH (Oakley 1) and
98101 SHA1 support.
102105 WOLFSSH_NO_DH_GROUP14_SHA256
103106 Set when DH or SHA256 are disabled. Set to disable use of DH (Oakley 14)
104107 and SHA256 support.
108+ WOLFSSH_NO_DH_GROUP16_SHA512
109+ Set when DH or SHA512 are disabled. Set to disable use of DH (Oakley 16)
110+ and SHA512 support.
105111 WOLFSSH_NO_DH_GEX_SHA256
106112 Set when DH or SHA2-256 are disabled. Set to disable use of DH group
107113 exchange and SHA2-256 support.
@@ -691,6 +697,9 @@ static const char cannedKexAlgoNames[] =
691697#if !defined(WOLFSSH_NO_DH_GROUP14_SHA256 )
692698 "diffie-hellman-group14-sha256,"
693699#endif
700+ #if !defined(WOLFSSH_NO_DH_GROUP16_SHA512 )
701+ "diffie-hellman-group16-sha512,"
702+ #endif
694703#if !defined(WOLFSSH_NO_DH_GEX_SHA256 )
695704 "diffie-hellman-group-exchange-sha256,"
696705#endif
@@ -798,6 +807,9 @@ static const char cannedMacAlgoNames[] =
798807#if !defined (WOLFSSH_NO_HMAC_SHA2_256 )
799808 "hmac-sha2-256,"
800809#endif
810+ #if !defined(WOLFSSH_NO_HMAC_SHA2_512 )
811+ "hmac-sha2-512,"
812+ #endif
801813#if defined(WOLFSSH_NO_SHA1_SOFT_DISABLE )
802814 #if !defined(WOLFSSH_NO_HMAC_SHA1_96 )
803815 "hmac-sha1-96,"
@@ -2444,6 +2456,9 @@ static const NameIdPair NameIdMap[] = {
24442456#ifndef WOLFSSH_NO_HMAC_SHA2_256
24452457 { ID_HMAC_SHA2_256 , TYPE_MAC , "hmac-sha2-256" },
24462458#endif
2459+ #ifndef WOLFSSH_NO_HMAC_SHA2_512
2460+ { ID_HMAC_SHA2_512 , TYPE_MAC , "hmac-sha2-512" },
2461+ #endif
24472462
24482463 /* Key Exchange IDs */
24492464#ifndef WOLFSSH_NO_DH_GROUP1_SHA1
@@ -2455,6 +2470,9 @@ static const NameIdPair NameIdMap[] = {
24552470#ifndef WOLFSSH_NO_DH_GROUP14_SHA256
24562471 { ID_DH_GROUP14_SHA256 , TYPE_KEX , "diffie-hellman-group14-sha256" },
24572472#endif
2473+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
2474+ { ID_DH_GROUP16_SHA512 , TYPE_KEX , "diffie-hellman-group16-sha512" },
2475+ #endif
24582476#ifndef WOLFSSH_NO_DH_GEX_SHA256
24592477 { ID_DH_GEX_SHA256 , TYPE_KEX , "diffie-hellman-group-exchange-sha256" },
24602478#endif
@@ -3626,6 +3644,10 @@ static INLINE byte MacSzForId(byte id)
36263644#ifndef WOLFSSH_NO_HMAC_SHA2_256
36273645 case ID_HMAC_SHA2_256 :
36283646 return WC_SHA256_DIGEST_SIZE ;
3647+ #endif
3648+ #ifndef WOLFSSH_NO_HMAC_SHA2_512
3649+ case ID_HMAC_SHA2_512 :
3650+ return WC_SHA512_DIGEST_SIZE ;
36293651#endif
36303652 default :
36313653 return 0 ;
@@ -3648,6 +3670,10 @@ static INLINE byte KeySzForId(byte id)
36483670 case ID_HMAC_SHA2_256 :
36493671 return WC_SHA256_DIGEST_SIZE ;
36503672#endif
3673+ #ifndef WOLFSSH_NO_HMAC_SHA2_512
3674+ case ID_HMAC_SHA2_512 :
3675+ return WC_SHA512_DIGEST_SIZE ;
3676+ #endif
36513677#ifndef WOLFSSH_NO_AES_CBC
36523678 case ID_AES128_CBC :
36533679 return AES_128_KEY_SIZE ;
@@ -3760,6 +3786,10 @@ enum wc_HashType HashForId(byte id)
37603786 #endif
37613787 return WC_HASH_TYPE_SHA512 ;
37623788#endif
3789+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
3790+ case ID_DH_GROUP16_SHA512 :
3791+ return WC_HASH_TYPE_SHA512 ;
3792+ #endif
37633793#ifndef WOLFSSH_NO_RSA_SHA2_512
37643794 case ID_RSA_SHA2_512 :
37653795 return WC_HASH_TYPE_SHA512 ;
@@ -4350,6 +4380,76 @@ static const byte dhPrimeGroup14[] = {
43504380static const word32 dhPrimeGroup14Sz = (word32 )sizeof (dhPrimeGroup14 );
43514381#endif
43524382
4383+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
4384+ static const byte dhPrimeGroup16 [] = {
4385+ /* SSH DH Group 16 (Oakley Group 16, 4096-bit MODP Group, RFC 3526) */
4386+ 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
4387+ 0xC9 , 0x0F , 0xDA , 0xA2 , 0x21 , 0x68 , 0xC2 , 0x34 ,
4388+ 0xC4 , 0xC6 , 0x62 , 0x8B , 0x80 , 0xDC , 0x1C , 0xD1 ,
4389+ 0x29 , 0x02 , 0x4E , 0x08 , 0x8A , 0x67 , 0xCC , 0x74 ,
4390+ 0x02 , 0x0B , 0xBE , 0xA6 , 0x3B , 0x13 , 0x9B , 0x22 ,
4391+ 0x51 , 0x4A , 0x08 , 0x79 , 0x8E , 0x34 , 0x04 , 0xDD ,
4392+ 0xEF , 0x95 , 0x19 , 0xB3 , 0xCD , 0x3A , 0x43 , 0x1B ,
4393+ 0x30 , 0x2B , 0x0A , 0x6D , 0xF2 , 0x5F , 0x14 , 0x37 ,
4394+ 0x4F , 0xE1 , 0x35 , 0x6D , 0x6D , 0x51 , 0xC2 , 0x45 ,
4395+ 0xE4 , 0x85 , 0xB5 , 0x76 , 0x62 , 0x5E , 0x7E , 0xC6 ,
4396+ 0xF4 , 0x4C , 0x42 , 0xE9 , 0xA6 , 0x37 , 0xED , 0x6B ,
4397+ 0x0B , 0xFF , 0x5C , 0xB6 , 0xF4 , 0x06 , 0xB7 , 0xED ,
4398+ 0xEE , 0x38 , 0x6B , 0xFB , 0x5A , 0x89 , 0x9F , 0xA5 ,
4399+ 0xAE , 0x9F , 0x24 , 0x11 , 0x7C , 0x4B , 0x1F , 0xE6 ,
4400+ 0x49 , 0x28 , 0x66 , 0x51 , 0xEC , 0xE4 , 0x5B , 0x3D ,
4401+ 0xC2 , 0x00 , 0x7C , 0xB8 , 0xA1 , 0x63 , 0xBF , 0x05 ,
4402+ 0x98 , 0xDA , 0x48 , 0x36 , 0x1C , 0x55 , 0xD3 , 0x9A ,
4403+ 0x69 , 0x16 , 0x3F , 0xA8 , 0xFD , 0x24 , 0xCF , 0x5F ,
4404+ 0x83 , 0x65 , 0x5D , 0x23 , 0xDC , 0xA3 , 0xAD , 0x96 ,
4405+ 0x1C , 0x62 , 0xF3 , 0x56 , 0x20 , 0x85 , 0x52 , 0xBB ,
4406+ 0x9E , 0xD5 , 0x29 , 0x07 , 0x70 , 0x96 , 0x96 , 0x6D ,
4407+ 0x67 , 0x0C , 0x35 , 0x4E , 0x4A , 0xBC , 0x98 , 0x04 ,
4408+ 0xF1 , 0x74 , 0x6C , 0x08 , 0xCA , 0x18 , 0x21 , 0x7C ,
4409+ 0x32 , 0x90 , 0x5E , 0x46 , 0x2E , 0x36 , 0xCE , 0x3B ,
4410+ 0xE3 , 0x9E , 0x77 , 0x2C , 0x18 , 0x0E , 0x86 , 0x03 ,
4411+ 0x9B , 0x27 , 0x83 , 0xA2 , 0xEC , 0x07 , 0xA2 , 0x8F ,
4412+ 0xB5 , 0xC5 , 0x5D , 0xF0 , 0x6F , 0x4C , 0x52 , 0xC9 ,
4413+ 0xDE , 0x2B , 0xCB , 0xF6 , 0x95 , 0x58 , 0x17 , 0x18 ,
4414+ 0x39 , 0x95 , 0x49 , 0x7C , 0xEA , 0x95 , 0x6A , 0xE5 ,
4415+ 0x15 , 0xD2 , 0x26 , 0x18 , 0x98 , 0xFA , 0x05 , 0x10 ,
4416+ 0x15 , 0x72 , 0x8E , 0x5A , 0x8A , 0xAA , 0xC4 , 0x2D ,
4417+ 0xAD , 0x33 , 0x17 , 0x0D , 0x04 , 0x50 , 0x7A , 0x33 ,
4418+ 0xA8 , 0x55 , 0x21 , 0xAB , 0xDF , 0x1C , 0xBA , 0x64 ,
4419+ 0xEC , 0xFB , 0x85 , 0x04 , 0x58 , 0xDB , 0xEF , 0x0A ,
4420+ 0x8A , 0xEA , 0x71 , 0x57 , 0x5D , 0x06 , 0x0C , 0x7D ,
4421+ 0xB3 , 0x97 , 0x0F , 0x85 , 0xA6 , 0xE1 , 0xE4 , 0xC7 ,
4422+ 0xAB , 0xF5 , 0xAE , 0x8C , 0xDB , 0x09 , 0x33 , 0xD7 ,
4423+ 0x1E , 0x8C , 0x94 , 0xE0 , 0x4A , 0x25 , 0x61 , 0x9D ,
4424+ 0xCE , 0xE3 , 0xD2 , 0x26 , 0x1A , 0xD2 , 0xEE , 0x6B ,
4425+ 0xF1 , 0x2F , 0xFA , 0x06 , 0xD9 , 0x8A , 0x08 , 0x64 ,
4426+ 0xD8 , 0x76 , 0x02 , 0x73 , 0x3E , 0xC8 , 0x6A , 0x64 ,
4427+ 0x52 , 0x1F , 0x2B , 0x18 , 0x17 , 0x7B , 0x20 , 0x0C ,
4428+ 0xBB , 0xE1 , 0x17 , 0x57 , 0x7A , 0x61 , 0x5D , 0x6C ,
4429+ 0x77 , 0x09 , 0x88 , 0xC0 , 0xBA , 0xD9 , 0x46 , 0xE2 ,
4430+ 0x08 , 0xE2 , 0x4F , 0xA0 , 0x74 , 0xE5 , 0xAB , 0x31 ,
4431+ 0x43 , 0xDB , 0x5B , 0xFC , 0xE0 , 0xFD , 0x10 , 0x8E ,
4432+ 0x4B , 0x82 , 0xD1 , 0x20 , 0xA9 , 0x21 , 0x08 , 0x01 ,
4433+ 0x1A , 0x72 , 0x3C , 0x12 , 0xA7 , 0x87 , 0xE6 , 0xD7 ,
4434+ 0x88 , 0x71 , 0x9A , 0x10 , 0xBD , 0xBA , 0x5B , 0x26 ,
4435+ 0x99 , 0xC3 , 0x27 , 0x18 , 0x6A , 0xF4 , 0xE2 , 0x3C ,
4436+ 0x1A , 0x94 , 0x68 , 0x34 , 0xB6 , 0x15 , 0x0B , 0xDA ,
4437+ 0x25 , 0x83 , 0xE9 , 0xCA , 0x2A , 0xD4 , 0x4C , 0xE8 ,
4438+ 0xDB , 0xBB , 0xC2 , 0xDB , 0x04 , 0xDE , 0x8E , 0xF9 ,
4439+ 0x2E , 0x8E , 0xFC , 0x14 , 0x1F , 0xBE , 0xCA , 0xA6 ,
4440+ 0x28 , 0x7C , 0x59 , 0x47 , 0x4E , 0x6B , 0xC0 , 0x5D ,
4441+ 0x99 , 0xB2 , 0x96 , 0x4F , 0xA0 , 0x90 , 0xC3 , 0xA2 ,
4442+ 0x23 , 0x3B , 0xA1 , 0x86 , 0x51 , 0x5B , 0xE7 , 0xED ,
4443+ 0x1F , 0x61 , 0x29 , 0x70 , 0xCE , 0xE2 , 0xD7 , 0xAF ,
4444+ 0xB8 , 0x1B , 0xDD , 0x76 , 0x21 , 0x70 , 0x48 , 0x1C ,
4445+ 0xD0 , 0x06 , 0x91 , 0x27 , 0xD5 , 0xB0 , 0x5A , 0xA9 ,
4446+ 0x93 , 0xB4 , 0xEA , 0x98 , 0x8D , 0x8F , 0xDD , 0xC1 ,
4447+ 0x86 , 0xFF , 0xB7 , 0xDC , 0x90 , 0xA6 , 0xC0 , 0x8F ,
4448+ 0x4D , 0xF4 , 0x35 , 0xC9 , 0x34 , 0x06 , 0x31 , 0x99 ,
4449+ 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF
4450+ };
4451+ static const word32 dhPrimeGroup16Sz = (word32 )sizeof (dhPrimeGroup16 );
4452+ #endif
43534453
43544454static int DoKexDhInit (WOLFSSH * ssh , byte * buf , word32 len , word32 * idx )
43554455{
@@ -9513,6 +9613,27 @@ static INLINE int CreateMac(WOLFSSH* ssh, const byte* in, word32 inSz,
95139613 }
95149614 break ;
95159615
9616+ #ifndef WOLFSSH_NO_HMAC_SHA2_512
9617+ case ID_HMAC_SHA2_512 :
9618+ {
9619+ Hmac hmac ;
9620+
9621+ ret = wc_HmacInit (& hmac , ssh -> ctx -> heap , INVALID_DEVID );
9622+ if (ret == WS_SUCCESS )
9623+ ret = wc_HmacSetKey (& hmac , WC_SHA512 ,
9624+ ssh -> keys .macKey ,
9625+ ssh -> keys .macKeySz );
9626+ if (ret == WS_SUCCESS )
9627+ ret = wc_HmacUpdate (& hmac , flatSeq , sizeof (flatSeq ));
9628+ if (ret == WS_SUCCESS )
9629+ ret = wc_HmacUpdate (& hmac , in , inSz );
9630+ if (ret == WS_SUCCESS )
9631+ ret = wc_HmacFinal (& hmac , mac );
9632+ wc_HmacFree (& hmac );
9633+ }
9634+ break ;
9635+ #endif
9636+
95169637 default :
95179638 WLOG (WS_LOG_DEBUG , "Invalid Mac ID" );
95189639 ret = WS_FATAL_ERROR ;
@@ -9575,6 +9696,19 @@ static INLINE int VerifyMac(WOLFSSH* ssh, const byte* in, word32 inSz,
95759696 ret = WS_VERIFY_MAC_E ;
95769697 break ;
95779698
9699+ case ID_HMAC_SHA2_512 :
9700+ ret = wc_HmacSetKey (& hmac , WC_SHA512 , ssh -> peerKeys .macKey ,
9701+ ssh -> peerKeys .macKeySz );
9702+ if (ret == WS_SUCCESS )
9703+ ret = wc_HmacUpdate (& hmac , flatSeq , sizeof (flatSeq ));
9704+ if (ret == WS_SUCCESS )
9705+ ret = wc_HmacUpdate (& hmac , in , inSz );
9706+ if (ret == WS_SUCCESS )
9707+ ret = wc_HmacFinal (& hmac , checkMac );
9708+ if (ConstantCompare (checkMac , mac , ssh -> peerMacSz ) != 0 )
9709+ ret = WS_VERIFY_MAC_E ;
9710+ break ;
9711+
95789712 default :
95799713 ret = WS_INVALID_ALGO_ID ;
95809714 }
@@ -9714,6 +9848,8 @@ int DoReceive(WOLFSSH* ssh)
97149848 /* Peek at the packet_length field. */
97159849 ato32 (ssh -> inputBuffer .buffer + ssh -> inputBuffer .idx , & ssh -> curSz );
97169850 if (ssh -> curSz > MAX_PACKET_SZ - (word32 )peerMacSz - UINT32_SZ ) {
9851+ WLOG (WS_LOG_DEBUG , "Packet length overflow: size = %u" ,
9852+ ssh -> curSz );
97179853 ssh -> error = WS_OVERFLOW_E ;
97189854 return WS_FATAL_ERROR ;
97199855 }
@@ -10341,6 +10477,8 @@ struct wolfSSH_sigKeyBlockFull {
1034110477 /* Size of Kyber public key (bigger than ciphertext) and some extra for the
1034210478 * ECC hybrid component. */
1034310479 #define KEX_F_SIZE 1024
10480+ #elif !defined(WOLFSSH_NO_DH_GROUP16_SHA512 )
10481+ #define KEX_F_SIZE (512 + 1)
1034410482#else
1034510483 #define KEX_F_SIZE (256 + 1)
1034610484#endif
@@ -10480,6 +10618,14 @@ static int GetDHPrimeGroup(int kexId, const byte** primeGroup,
1048010618 * generatorSz = dhGeneratorSz ;
1048110619 break ;
1048210620 #endif
10621+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
10622+ case ID_DH_GROUP16_SHA512 :
10623+ * primeGroup = dhPrimeGroup16 ;
10624+ * primeGroupSz = dhPrimeGroup16Sz ;
10625+ * generator = dhGenerator ;
10626+ * generatorSz = dhGeneratorSz ;
10627+ break ;
10628+ #endif
1048310629 #ifndef WOLFSSH_NO_DH_GEX_SHA256
1048410630 case ID_DH_GEX_SHA256 :
1048510631 * primeGroup = dhPrimeGroup14 ;
@@ -11764,6 +11910,12 @@ int SendKexDhReply(WOLFSSH* ssh)
1176411910 msgId = MSGID_KEXDH_REPLY ;
1176511911 break ;
1176611912#endif
11913+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
11914+ case ID_DH_GROUP16_SHA512 :
11915+ useDh = 1 ;
11916+ msgId = MSGID_KEXDH_REPLY ;
11917+ break ;
11918+ #endif
1176711919#ifndef WOLFSSH_NO_DH_GEX_SHA256
1176811920 case ID_DH_GEX_SHA256 :
1176911921 useDh = 1 ;
@@ -12333,6 +12485,15 @@ int SendKexDhInit(WOLFSSH* ssh)
1233312485 generatorSz = dhGeneratorSz ;
1233412486 break ;
1233512487#endif
12488+ #ifndef WOLFSSH_NO_DH_GROUP16_SHA512
12489+ case ID_DH_GROUP16_SHA512 :
12490+ ssh -> handshake -> useDh = 1 ;
12491+ primeGroup = dhPrimeGroup16 ;
12492+ primeGroupSz = dhPrimeGroup16Sz ;
12493+ generator = dhGenerator ;
12494+ generatorSz = dhGeneratorSz ;
12495+ break ;
12496+ #endif
1233612497#ifndef WOLFSSH_NO_DH_GEX_SHA256
1233712498 case ID_DH_GEX_SHA256 :
1233812499 ssh -> handshake -> useDh = 1 ;
0 commit comments