|
23 | 23 | int ret; |
24 | 24 | ret = wc_InitRsaKey(&enc, NULL); // not using heap hint. No custom memory |
25 | 25 | if ( ret != 0 ) { |
26 | | - // error initializing RSA key |
| 26 | + // error initializing RSA key |
27 | 27 | } |
28 | 28 | \endcode |
29 | 29 |
|
@@ -166,7 +166,7 @@ int wc_FreeRsaKey(RsaKey* key); |
166 | 166 | ret = wc_RsaDirect(in, (word32)sizeof(in), out, &outSz, &key, |
167 | 167 | RSA_PRIVATE_ENCRYPT, &rng); |
168 | 168 | if (ret < 0) { |
169 | | - //handle error |
| 169 | + //handle error |
170 | 170 | } |
171 | 171 | \endcode |
172 | 172 |
|
@@ -240,7 +240,7 @@ int wc_RsaDirect(byte* in, word32 inLen, byte* out, word32* outSz, |
240 | 240 | // initialize with received public key parameters |
241 | 241 | ret = wc_RsaPublicEncrypt(msg, sizeof(msg), out, sizeof(out), &pub, &rng); |
242 | 242 | if ( ret != 0 ) { |
243 | | - // error encrypting message |
| 243 | + // error encrypting message |
244 | 244 | } |
245 | 245 | \endcode |
246 | 246 |
|
@@ -333,6 +333,12 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, |
333 | 333 | if (ret < 0) { |
334 | 334 | return -1; |
335 | 335 | } |
| 336 | + if (ret != inLen) { |
| 337 | + return -1; |
| 338 | + } |
| 339 | + if (XMEMCMP(in, plain, ret) != 0) { |
| 340 | + return -1; |
| 341 | + } |
336 | 342 | \endcode |
337 | 343 |
|
338 | 344 | \sa wc_RsaPad |
@@ -1043,7 +1049,7 @@ int wc_RsaEncryptSize(RsaKey* key); |
1043 | 1049 | wc_InitRsaKey(&enc, NULL); // not using heap hint. No custom memory |
1044 | 1050 | ret = wc_RsaPrivateKeyDecode(der, &idx, &enc, sizeof(der)); |
1045 | 1051 | if( ret != 0 ) { |
1046 | | - // error parsing private key |
| 1052 | + // error parsing private key |
1047 | 1053 | } |
1048 | 1054 | \endcode |
1049 | 1055 |
|
@@ -1093,7 +1099,7 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, |
1093 | 1099 | wc_InitRsaKey(&pub, NULL); // not using heap hint. No custom memory |
1094 | 1100 | ret = wc_RsaPublicKeyDecode(der, &idx, &pub, sizeof(der)); |
1095 | 1101 | if( ret != 0 ) { |
1096 | | - // error parsing public key |
| 1102 | + // error parsing public key |
1097 | 1103 | } |
1098 | 1104 | \endcode |
1099 | 1105 |
|
@@ -1138,7 +1144,7 @@ int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, |
1138 | 1144 | wc_InitRsaKey(&pub, NULL); // not using heap hint. No custom memory |
1139 | 1145 | ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), &pub); |
1140 | 1146 | if( ret != 0 ) { |
1141 | | - // error parsing public key elements |
| 1147 | + // error parsing public key elements |
1142 | 1148 | } |
1143 | 1149 | \endcode |
1144 | 1150 |
|
@@ -1221,7 +1227,7 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen); |
1221 | 1227 | ret = wc_RsaPublicEncrypt_ex(in, sizeof(in), out, sizeof(out), &key, &rng, |
1222 | 1228 | WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); |
1223 | 1229 | if (ret < 0) { |
1224 | | - //handle error |
| 1230 | + //handle error |
1225 | 1231 | } |
1226 | 1232 | \endcode |
1227 | 1233 |
|
@@ -1268,14 +1274,14 @@ int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out, |
1268 | 1274 | ret = wc_RsaPublicEncrypt_ex(in, sizeof(in), out, sizeof(out), &key, |
1269 | 1275 | &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); |
1270 | 1276 | if (ret < 0) { |
1271 | | - //handle error |
| 1277 | + //handle error |
1272 | 1278 | } |
1273 | 1279 | … |
1274 | 1280 | ret = wc_RsaPrivateDecrypt_ex(out, ret, plain, sizeof(plain), &key, |
1275 | 1281 | WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); |
1276 | 1282 |
|
1277 | 1283 | if (ret < 0) { |
1278 | | - //handle error |
| 1284 | + //handle error |
1279 | 1285 | } |
1280 | 1286 | \endcode |
1281 | 1287 |
|
@@ -1326,14 +1332,14 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, |
1326 | 1332 | &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); |
1327 | 1333 |
|
1328 | 1334 | if (ret < 0) { |
1329 | | - //handle error |
| 1335 | + //handle error |
1330 | 1336 | } |
1331 | 1337 | … |
1332 | 1338 | ret = wc_RsaPrivateDecryptInline_ex(out, ret, &plain, &key, |
1333 | 1339 | WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); |
1334 | 1340 |
|
1335 | 1341 | if (ret < 0) { |
1336 | | - //handle error |
| 1342 | + //handle error |
1337 | 1343 | } |
1338 | 1344 | \endcode |
1339 | 1345 |
|
@@ -1376,7 +1382,7 @@ int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen, |
1376 | 1382 | ... |
1377 | 1383 | ret = wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz); |
1378 | 1384 | if (ret != 0) { |
1379 | | - // Failure case. |
| 1385 | + // Failure case. |
1380 | 1386 | } |
1381 | 1387 | \endcode |
1382 | 1388 |
|
@@ -1522,7 +1528,7 @@ int wc_RsaKeyToPublicDer_ex(RsaKey* key, byte* output, word32 inLen, |
1522 | 1528 | // generate 2048 bit long private key |
1523 | 1529 | ret = wc_MakeRsaKey(&priv, 2048, e, &rng); |
1524 | 1530 | if( ret != 0 ) { |
1525 | | - // error generating private key |
| 1531 | + // error generating private key |
1526 | 1532 | } |
1527 | 1533 | \endcode |
1528 | 1534 |
|
|
0 commit comments