From 0ac833790de9a7f41a0de4d7766de6d7df119c5b Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 7 Mar 2018 16:55:24 -0700 Subject: [PATCH] check q in wc_CheckPubKey_ex() if available in DhKey --- wolfcrypt/src/dh.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/dh.c b/wolfcrypt/src/dh.c index e51b96190..5bb56c11f 100644 --- a/wolfcrypt/src/dh.c +++ b/wolfcrypt/src/dh.c @@ -908,6 +908,11 @@ int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz, if (ret == 0 && prime != NULL) { if (mp_read_unsigned_bin(&q, prime, primeSz) != MP_OKAY) ret = MP_READ_E; + + } else if (mp_iszero(&key->q) == MP_NO) { + /* use q available in DhKey */ + if (mp_copy(&key->q, &q) != MP_OKAY) + ret = MP_INIT_E; } /* pub (y) should not be 0 or 1 */ @@ -926,7 +931,7 @@ int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz, ret = MP_CMP_E; } - if (ret == 0 && prime != NULL) { + if (ret == 0 && (prime != NULL || (mp_iszero(&key->q) == MP_NO) )) { /* restore key->p into p */ if (mp_copy(&key->p, &p) != MP_OKAY)