@@ -12670,8 +12670,20 @@ int SendKexDhReply(WOLFSSH* ssh)
1267012670 * add it to the hash and then add K. */
1267112671 if (ret == WS_SUCCESS) {
1267212672 sigBlockSz = (LENGTH_SZ * 2) + sigKeyBlock_ptr->pubKeyNameSz + sigSz;
12673- payloadSz = MSG_ID_SZ + (LENGTH_SZ * 3) +
12674- sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12673+ #ifdef WOLFSSH_CERTS
12674+ if (sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_SSH_RSA
12675+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP256
12676+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP384
12677+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP521) {
12678+ payloadSz = MSG_ID_SZ + (LENGTH_SZ * 2) +
12679+ sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12680+ }
12681+ else
12682+ #endif
12683+ {
12684+ payloadSz = MSG_ID_SZ + (LENGTH_SZ * 3) +
12685+ sigKeyBlock_ptr->sz + fSz + fPad + sigBlockSz;
12686+ }
1267512687 ret = PreparePacket(ssh, payloadSz);
1267612688 }
1267712689
@@ -12681,15 +12693,28 @@ int SendKexDhReply(WOLFSSH* ssh)
1268112693
1268212694 output[idx++] = msgId;
1268312695
12684- /* Copy the key block size into the buffer */
12685- c32toa(sigKeyBlock_ptr->sz, output + idx);
12686- idx += LENGTH_SZ;
12696+ #ifdef WOLFSSH_CERTS
12697+ if (sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_SSH_RSA
12698+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP256
12699+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP384
12700+ || sigKeyBlock_ptr->pubKeyFmtId == ID_X509V3_ECDSA_SHA2_NISTP521) {
12701+ /* BuildRFC6187Info writes the complete K_S including
12702+ * the outer length and key type name. Skip common header. */
12703+ }
12704+ else
12705+ #endif
12706+ {
12707+ /* Copy the key block size into the buffer */
12708+ c32toa(sigKeyBlock_ptr->sz, output + idx);
12709+ idx += LENGTH_SZ;
1268712710
12688- /* Copy the key name into the buffer */
12689- c32toa(sigKeyBlock_ptr->pubKeyFmtNameSz, output + idx);
12690- idx += LENGTH_SZ;
12691- WMEMCPY(output + idx, sigKeyBlock_ptr->pubKeyFmtName, sigKeyBlock_ptr->pubKeyFmtNameSz);
12692- idx += sigKeyBlock_ptr->pubKeyFmtNameSz;
12711+ /* Copy the key name into the buffer */
12712+ c32toa(sigKeyBlock_ptr->pubKeyFmtNameSz, output + idx);
12713+ idx += LENGTH_SZ;
12714+ WMEMCPY(output + idx, sigKeyBlock_ptr->pubKeyFmtName,
12715+ sigKeyBlock_ptr->pubKeyFmtNameSz);
12716+ idx += sigKeyBlock_ptr->pubKeyFmtNameSz;
12717+ }
1269312718
1269412719 /* add host public key */
1269512720 switch (sigKeyBlock_ptr->pubKeyFmtId) {
0 commit comments