mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 03:07:29 +02:00
Merge pull request #3113 from guidovranken/scrypt-return-memory-e
Return MEMORY_E from wc_scrypt if allocation fails
This commit is contained in:
@ -501,6 +501,8 @@ int wc_PKCS12_PBKDF_ex(byte* output, const byte* passwd, int passLen,
|
|||||||
if (ret < 0) break;
|
if (ret < 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret < 0) break;
|
||||||
|
|
||||||
currentLen = min(kLen, (int)u);
|
currentLen = min(kLen, (int)u);
|
||||||
XMEMCPY(output, Ai, currentLen);
|
XMEMCPY(output, Ai, currentLen);
|
||||||
output += currentLen;
|
output += currentLen;
|
||||||
@ -721,16 +723,22 @@ int wc_scrypt(byte* output, const byte* passwd, int passLen,
|
|||||||
bSz = 128 * blockSize;
|
bSz = 128 * blockSize;
|
||||||
blocksSz = bSz * parallel;
|
blocksSz = bSz * parallel;
|
||||||
blocks = (byte*)XMALLOC(blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
blocks = (byte*)XMALLOC(blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (blocks == NULL)
|
if (blocks == NULL) {
|
||||||
|
ret = MEMORY_E;
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
/* Temporary for scryptROMix. */
|
/* Temporary for scryptROMix. */
|
||||||
v = (byte*)XMALLOC((1 << cost) * bSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
v = (byte*)XMALLOC((1 << cost) * bSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (v == NULL)
|
if (v == NULL) {
|
||||||
|
ret = MEMORY_E;
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
/* Temporary for scryptBlockMix. */
|
/* Temporary for scryptBlockMix. */
|
||||||
y = (byte*)XMALLOC(blockSize * 128, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
y = (byte*)XMALLOC(blockSize * 128, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (y == NULL)
|
if (y == NULL) {
|
||||||
|
ret = MEMORY_E;
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
/* Step 1. */
|
/* Step 1. */
|
||||||
ret = wc_PBKDF2(blocks, passwd, passLen, salt, saltLen, 1, blocksSz,
|
ret = wc_PBKDF2(blocks, passwd, passLen, salt, saltLen, 1, blocksSz,
|
||||||
|
Reference in New Issue
Block a user