Skip to content

Commit ad80b4b

Browse files
authored
Merge pull request #23 from ejohnstown/wc-fix
wolfCrypt Fix
2 parents a612d6c + 6af24ba commit ad80b4b

1 file changed

Lines changed: 33 additions & 17 deletions

File tree

src/internal.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,30 +3424,46 @@ int SendKexDhReply(WOLFSSH* ssh)
34243424
wc_FreeDhKey(&dhKey);
34253425

34263426
/* Hash in the server's DH f-value. */
3427-
c32toa(fSz + fPad, scratchLen);
3428-
wc_ShaUpdate(&ssh->handshake->hash, scratchLen, LENGTH_SZ);
3429-
if (fPad) {
3430-
scratchLen[0] = 0;
3431-
wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1);
3427+
if (ret == 0) {
3428+
c32toa(fSz + fPad, scratchLen);
3429+
ret = wc_ShaUpdate(&ssh->handshake->hash,
3430+
scratchLen, LENGTH_SZ);
3431+
}
3432+
if (ret == 0) {
3433+
if (fPad) {
3434+
scratchLen[0] = 0;
3435+
ret = wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1);
3436+
}
34323437
}
3433-
wc_ShaUpdate(&ssh->handshake->hash, f, fSz);
3438+
if (ret == 0)
3439+
ret = wc_ShaUpdate(&ssh->handshake->hash, f, fSz);
34343440

34353441
/* Hash in the shared secret k. */
3436-
c32toa(ssh->kSz + kPad, scratchLen);
3437-
wc_ShaUpdate(&ssh->handshake->hash, scratchLen, LENGTH_SZ);
3438-
if (kPad) {
3439-
scratchLen[0] = 0;
3440-
wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1);
3442+
if (ret == 0) {
3443+
c32toa(ssh->kSz + kPad, scratchLen);
3444+
ret = wc_ShaUpdate(&ssh->handshake->hash,
3445+
scratchLen, LENGTH_SZ);
34413446
}
3442-
wc_ShaUpdate(&ssh->handshake->hash, ssh->k, ssh->kSz);
3447+
if (ret == 0) {
3448+
if (kPad) {
3449+
scratchLen[0] = 0;
3450+
ret = wc_ShaUpdate(&ssh->handshake->hash, scratchLen, 1);
3451+
}
3452+
}
3453+
if (ret == 0)
3454+
ret = wc_ShaUpdate(&ssh->handshake->hash, ssh->k, ssh->kSz);
34433455

34443456
/* Save the handshake hash value h, and session ID. */
3445-
wc_ShaFinal(&ssh->handshake->hash, ssh->h);
3446-
ssh->hSz = SHA_DIGEST_SIZE;
3447-
if (ssh->sessionIdSz == 0) {
3448-
WMEMCPY(ssh->sessionId, ssh->h, ssh->hSz);
3449-
ssh->sessionIdSz = ssh->hSz;
3457+
if (ret == 0)
3458+
ret = wc_ShaFinal(&ssh->handshake->hash, ssh->h);
3459+
if (ret == 0) {
3460+
ssh->hSz = SHA_DIGEST_SIZE;
3461+
if (ssh->sessionIdSz == 0) {
3462+
WMEMCPY(ssh->sessionId, ssh->h, ssh->hSz);
3463+
ssh->sessionIdSz = ssh->hSz;
3464+
}
34503465
}
3466+
34513467
if (ret != WS_SUCCESS)
34523468
ret = WS_CRYPTO_FAILED;
34533469
}

0 commit comments

Comments
 (0)