F-5225: validate ChaCha IV length before native SetIV read
parent
b8392ced50
commit
39974a4f62
|
|
@ -72,6 +72,7 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Chacha_wc_1Chacha_1setIV
|
|||
int ret = 0;
|
||||
ChaCha* chacha = NULL;
|
||||
byte* iv = NULL;
|
||||
word32 ivSz = 0;
|
||||
|
||||
chacha = (ChaCha*)(uintptr_t)getNativeStruct(env, this);
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
|
|
@ -79,8 +80,9 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Chacha_wc_1Chacha_1setIV
|
|||
return;
|
||||
}
|
||||
iv = getByteArray(env, iv_object);
|
||||
ivSz = getByteArrayLength(env, iv_object);
|
||||
|
||||
if (chacha == NULL || iv == NULL) {
|
||||
if (chacha == NULL || iv == NULL || ivSz != CHACHA_IV_BYTES) {
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,22 @@ public class ChachaTest {
|
|||
/* test must throw */
|
||||
}
|
||||
|
||||
/* IV shorter than 12 bytes should be rejected */
|
||||
try {
|
||||
chacha.setIV(new byte[4]);
|
||||
fail("IV shorter than 12 bytes should be rejected.");
|
||||
} catch (WolfCryptException e) {
|
||||
/* test must throw */
|
||||
}
|
||||
|
||||
/* An IV longer than 12 bytes is not a valid ChaCha nonce */
|
||||
try {
|
||||
chacha.setIV(new byte[16]);
|
||||
fail("IV longer than 12 bytes should be rejected.");
|
||||
} catch (WolfCryptException e) {
|
||||
/* test must throw */
|
||||
}
|
||||
|
||||
chacha.setIV(IV);
|
||||
chacha.releaseNativeStruct();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue