From 4281ee4b4edeee6135de3b91430920f63944b5cf Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 3 Jun 2024 11:19:16 -0700 Subject: [PATCH] Sign H Casting 1. Fix the typecasting when signing H with RSA. 2. Assign the sign return value to ret, then assign it to *sigSz if successful. 3. Similar change for the encoded sign value. --- src/internal.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/internal.c b/src/internal.c index ca57e6579..0e5d73896 100644 --- a/src/internal.c +++ b/src/internal.c @@ -10944,24 +10944,32 @@ static int SignHRsa(WOLFSSH* ssh, byte* sig, word32* sigSz, } if (ret == WS_SUCCESS) { - encSigSz = wc_EncodeSignature(encSig, digest, digestSz, + ret = wc_EncodeSignature(encSig, digest, digestSz, wc_HashGetOID(hashId)); - if (encSigSz <= 0) { + if (ret <= 0) { WLOG(WS_LOG_DEBUG, "SignHRsa: Bad Encode Sig"); ret = WS_CRYPTO_FAILED; } + else { + encSigSz = (word32)ret; + ret = WS_SUCCESS; + } } if (ret == WS_SUCCESS) { WLOG(WS_LOG_INFO, "Signing hash with %s.", IdToName(ssh->handshake->pubKeyId)); - *sigSz = wc_RsaSSL_Sign(encSig, encSigSz, sig, + ret = wc_RsaSSL_Sign(encSig, encSigSz, sig, KEX_SIG_SIZE, &sigKey->sk.rsa.key, ssh->rng); - if (*sigSz <= 0) { + if (ret <= 0) { WLOG(WS_LOG_DEBUG, "SignHRsa: Bad RSA Sign"); ret = WS_RSA_E; } + else { + *sigSz = (word32)ret; + ret = WS_SUCCESS; + } } if (ret == WS_SUCCESS) {