From f9af463db1508c9542ab172b3efad2a1cd499fe2 Mon Sep 17 00:00:00 2001 From: Colton Willey Date: Wed, 4 Sep 2024 10:13:40 -0700 Subject: [PATCH] Update RSA verify documentation to specify that the output should be compared with the original plaintext --- doc/dox_comments/header_files/rsa.h | 32 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/doc/dox_comments/header_files/rsa.h b/doc/dox_comments/header_files/rsa.h index 9f099c1ed..ec001449e 100644 --- a/doc/dox_comments/header_files/rsa.h +++ b/doc/dox_comments/header_files/rsa.h @@ -23,7 +23,7 @@ int ret; ret = wc_InitRsaKey(&enc, NULL); // not using heap hint. No custom memory if ( ret != 0 ) { - // error initializing RSA key + // error initializing RSA key } \endcode @@ -166,7 +166,7 @@ int wc_FreeRsaKey(RsaKey* key); ret = wc_RsaDirect(in, (word32)sizeof(in), out, &outSz, &key, RSA_PRIVATE_ENCRYPT, &rng); if (ret < 0) { - //handle error + //handle error } \endcode @@ -240,7 +240,7 @@ int wc_RsaDirect(byte* in, word32 inLen, byte* out, word32* outSz, // initialize with received public key parameters ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, sizeof(out), &pub, &rng); if ( ret != 0 ) { - // error encrypting message + // error encrypting message } \endcode @@ -403,6 +403,12 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, if (ret < 0) { return -1; } + if (ret != inLen) { + return -1; + } + if (XMEMCMP(in, plain, ret) != 0) { + return -1; + } \endcode \sa wc_RsaSSL_Sign @@ -1037,7 +1043,7 @@ int wc_RsaEncryptSize(RsaKey* key); wc_InitRsaKey(&enc, NULL); // not using heap hint. No custom memory ret = wc_RsaPrivateKeyDecode(der, &idx, &enc, sizeof(der)); if( ret != 0 ) { - // error parsing private key + // error parsing private key } \endcode @@ -1087,7 +1093,7 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, wc_InitRsaKey(&pub, NULL); // not using heap hint. No custom memory ret = wc_RsaPublicKeyDecode(der, &idx, &pub, sizeof(der)); if( ret != 0 ) { - // error parsing public key + // error parsing public key } \endcode @@ -1132,7 +1138,7 @@ int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, wc_InitRsaKey(&pub, NULL); // not using heap hint. No custom memory ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), &pub); if( ret != 0 ) { - // error parsing public key elements + // error parsing public key elements } \endcode @@ -1215,7 +1221,7 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen); ret = wc_RsaPublicEncrypt_ex(in, sizeof(in), out, sizeof(out), &key, &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); if (ret < 0) { - //handle error + //handle error } \endcode @@ -1262,14 +1268,14 @@ int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out, ret = wc_RsaPublicEncrypt_ex(in, sizeof(in), out, sizeof(out), &key, &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); if (ret < 0) { - //handle error + //handle error } … ret = wc_RsaPrivateDecrypt_ex(out, ret, plain, sizeof(plain), &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); if (ret < 0) { - //handle error + //handle error } \endcode @@ -1320,14 +1326,14 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); if (ret < 0) { - //handle error + //handle error } … ret = wc_RsaPrivateDecryptInline_ex(out, ret, &plain, &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); if (ret < 0) { - //handle error + //handle error } \endcode @@ -1370,7 +1376,7 @@ int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen, ... ret = wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz); if (ret != 0) { - // Failure case. + // Failure case. } \endcode @@ -1516,7 +1522,7 @@ int wc_RsaKeyToPublicDer_ex(RsaKey* key, byte* output, word32 inLen, // generate 2048 bit long private key ret = wc_MakeRsaKey(&priv, 2048, e, &rng); if( ret != 0 ) { - // error generating private key + // error generating private key } \endcode