@@ -5696,12 +5696,20 @@ static int KeyAgreeEcdhMlKem_client(WOLFSSH* ssh, byte hashId,
56965696 /* Replace the concatenated shared secrets with the hash. That
56975697 * will become the new shared secret. */
56985698 if (ret == 0) {
5699- sharedSecretHashSz = wc_HashGetDigestSize((enum wc_HashType)hashId);
5700- sharedSecretHash = (byte *)WMALLOC(sharedSecretHashSz,
5701- ssh->ctx->heap,
5702- DYNTYPE_PRIVKEY);
5703- if (sharedSecretHash == NULL) {
5704- ret = WS_MEMORY_E;
5699+ int digestSz;
5700+
5701+ digestSz = wc_HashGetDigestSize((enum wc_HashType)hashId);
5702+ if (digestSz <= 0) {
5703+ ret = WS_INVALID_ALGO_ID;
5704+ }
5705+ else {
5706+ sharedSecretHashSz = (byte)digestSz;
5707+ sharedSecretHash = (byte *)WMALLOC(sharedSecretHashSz,
5708+ ssh->ctx->heap,
5709+ DYNTYPE_PRIVKEY);
5710+ if (sharedSecretHash == NULL) {
5711+ ret = WS_MEMORY_E;
5712+ }
57055713 }
57065714 }
57075715
@@ -12370,11 +12378,19 @@ static int KeyAgreeEcdhMlKem_server(WOLFSSH* ssh, byte hashId,
1237012378 /* Replace the concatenated shared secrets with the hash. That
1237112379 * will become the new shared secret.*/
1237212380 if (ret == 0) {
12373- sharedSecretHashSz = wc_HashGetDigestSize((enum wc_HashType)hashId);
12374- sharedSecretHash = (byte *)WMALLOC(sharedSecretHashSz,
12375- ssh->ctx->heap, DYNTYPE_PRIVKEY);
12376- if (sharedSecretHash == NULL) {
12377- ret = WS_MEMORY_E;
12381+ int digestSz;
12382+
12383+ digestSz = wc_HashGetDigestSize((enum wc_HashType)hashId);
12384+ if (digestSz <= 0) {
12385+ ret = WS_INVALID_ALGO_ID;
12386+ }
12387+ else {
12388+ sharedSecretHashSz = (byte)digestSz;
12389+ sharedSecretHash = (byte *)WMALLOC(sharedSecretHashSz,
12390+ ssh->ctx->heap, DYNTYPE_PRIVKEY);
12391+ if (sharedSecretHash == NULL) {
12392+ ret = WS_MEMORY_E;
12393+ }
1237812394 }
1237912395 }
1238012396 if (ret == 0) {
@@ -13557,12 +13573,11 @@ int SendKexDhInit(WOLFSSH* ssh)
1355713573#if !defined(WOLFSSH_NO_NISTP256_MLKEM768_SHA256) || \
1355813574 !defined(WOLFSSH_NO_NISTP384_MLKEM1024_SHA384) || \
1355913575 !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
13560- if (ssh->handshake->useEccMlKem) {
13576+ if (ret == WS_SUCCESS && ssh->handshake->useEccMlKem) {
1356113577 MlKemKey kem;
1356213578 word32 length_publickey = 0;
1356313579 word32 length_privatekey = 0;
1356413580 int mlKemType = WC_ML_KEM_768;
13565- ret = 0;
1356613581
1356713582 WMEMSET(&kem, 0, sizeof(kem));
1356813583
0 commit comments