|
@@ -28,7 +28,7 @@
|
|
|
@param out [out] Destination of decoding
|
|
|
@param outlen [in/out] The max size and resulting size of the decoding
|
|
|
@param res [out] Result of decoding, 1==valid, 0==invalid
|
|
|
- @return CRYPT_OK if successful (even if invalid)
|
|
|
+ @return CRYPT_OK if successful
|
|
|
*/
|
|
|
int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
|
|
const unsigned char *lparam, unsigned long lparamlen,
|
|
@@ -38,7 +38,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
|
|
{
|
|
|
unsigned char *DB, *seed, *mask;
|
|
|
unsigned long hLen, x, y, modulus_len;
|
|
|
- int err;
|
|
|
+ int err, ret;
|
|
|
|
|
|
LTC_ARGCHK(msg != NULL);
|
|
|
LTC_ARGCHK(out != NULL);
|
|
@@ -85,10 +85,12 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
|
|
|
|
|
*/
|
|
|
|
|
|
+ err = CRYPT_OK;
|
|
|
+ ret = CRYPT_OK;
|
|
|
+
|
|
|
/* must have leading 0x00 byte */
|
|
|
if (msg[0] != 0x00) {
|
|
|
- err = CRYPT_OK;
|
|
|
- goto LBL_ERR;
|
|
|
+ ret = CRYPT_INVALID_PACKET;
|
|
|
}
|
|
|
|
|
|
/* now read the masked seed */
|
|
@@ -137,8 +139,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
|
|
|
|
|
/* compare the lhash'es */
|
|
|
if (mem_neq(seed, DB, hLen) != 0) {
|
|
|
- err = CRYPT_OK;
|
|
|
- goto LBL_ERR;
|
|
|
+ ret = CRYPT_INVALID_PACKET;
|
|
|
}
|
|
|
|
|
|
/* now zeroes before a 0x01 */
|
|
@@ -146,28 +147,27 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
|
|
/* step... */
|
|
|
}
|
|
|
|
|
|
- /* error out if wasn't 0x01 */
|
|
|
+ /* error if wasn't 0x01 */
|
|
|
if (x == (modulus_len - hLen - 1) || DB[x] != 0x01) {
|
|
|
- err = CRYPT_INVALID_PACKET;
|
|
|
- goto LBL_ERR;
|
|
|
+ ret = CRYPT_INVALID_PACKET;
|
|
|
}
|
|
|
|
|
|
/* rest is the message (and skip 0x01) */
|
|
|
if ((modulus_len - hLen - 1 - ++x) > *outlen) {
|
|
|
- *outlen = modulus_len - hLen - 1 - x;
|
|
|
- err = CRYPT_BUFFER_OVERFLOW;
|
|
|
- goto LBL_ERR;
|
|
|
+ ret = CRYPT_INVALID_PACKET;
|
|
|
}
|
|
|
|
|
|
- /* copy message */
|
|
|
- *outlen = modulus_len - hLen - 1 - x;
|
|
|
- XMEMCPY(out, DB + x, modulus_len - hLen - 1 - x);
|
|
|
- x += modulus_len - hLen - 1;
|
|
|
+ if (ret == CRYPT_OK) {
|
|
|
+ /* copy message */
|
|
|
+ *outlen = modulus_len - hLen - 1 - x;
|
|
|
+ XMEMCPY(out, DB + x, modulus_len - hLen - 1 - x);
|
|
|
+ x += modulus_len - hLen - 1;
|
|
|
|
|
|
- /* valid packet */
|
|
|
- *res = 1;
|
|
|
+ /* valid packet */
|
|
|
+ *res = 1;
|
|
|
+ }
|
|
|
+ err = ret;
|
|
|
|
|
|
- err = CRYPT_OK;
|
|
|
LBL_ERR:
|
|
|
#ifdef LTC_CLEAN_STACK
|
|
|
zeromem(DB, modulus_len);
|