Skip to content

Commit 4967e89

Browse files
authored
Merge pull request #206 from cconlon/fenrir323
Fenrir fixes
2 parents 46ff5a4 + 426a8a1 commit 4967e89

23 files changed

Lines changed: 307 additions & 157 deletions

IDE/Android/app/src/main/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ if ("${WOLFSSL_PKG_TYPE}" MATCHES "normal")
279279
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/evp.c)
280280
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/evp_pk.c)
281281
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/misc.c)
282+
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/asn_orig.c)
282283

283284
elseif("${WOLFSSL_PKG_TYPE}" MATCHES "fipsready")
284285
# FIPS Ready needs to explicitly order files for in-core integrity check to work properly.

IDE/WIN/wolfcryptjni.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_debug.h" />
7272
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_error.h" />
7373
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_NativeStruct.h" />
74+
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_util.h" />
7475
</ItemGroup>
7576
<ItemGroup>
7677
<ClCompile Include="..\..\jni\jni_aes.c" />

IDE/WIN/wolfcryptjni.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_NativeStruct.h">
121121
<Filter>Header Files</Filter>
122122
</ClInclude>
123+
<ClInclude Include="..\..\jni\include\wolfcrypt_jni_util.h">
124+
<Filter>Header Files</Filter>
125+
</ClInclude>
123126
</ItemGroup>
124127
<ItemGroup>
125128
<ClCompile Include="..\..\jni\jni_aes.c">

jni/include/com_wolfssl_wolfcrypt_Rsa.h

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jni/include/wolfcrypt_jni_util.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* wolfcrypt_jni_util.h
2+
*
3+
* Copyright (C) 2006-2026 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
#ifndef _Included_wolfcrypt_jni_util
23+
#define _Included_wolfcrypt_jni_util
24+
25+
#include <wolfssl/wolfcrypt/types.h>
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
/* check all length bytes for equality, return 0 on success */
32+
static WC_INLINE int JNIConstantCompare(const byte* a, const byte* b,
33+
int length)
34+
{
35+
int i;
36+
int compareSum = 0;
37+
38+
for (i = 0; i < length; i++) {
39+
compareSum |= a[i] ^ b[i];
40+
}
41+
42+
return compareSum;
43+
}
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
#endif

jni/jni_aes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ Java_com_wolfssl_wolfcrypt_Aes_native_1update_1internal__I_3BII_3BI(
128128
}
129129
else if (length == 0) {
130130
ret = 0;
131-
} else if ((word32)(offset + length) >
131+
} else if (((jlong)offset + (jlong)length) >
132132
getByteArrayLength(env, input_object)) {
133133
ret = BUFFER_E; /* buffer overflow check */
134134
}
135-
else if ((word32)(outputOffset + length) >
135+
else if (((jlong)outputOffset + (jlong)length) >
136136
getByteArrayLength(env, output_object)) {
137137
ret = BUFFER_E; /* buffer overflow check */
138138
}
@@ -196,11 +196,11 @@ Java_com_wolfssl_wolfcrypt_Aes_native_1update_1internal__ILjava_nio_ByteBuffer_2
196196
else if (offset < 0 || length < 0) {
197197
ret = BAD_FUNC_ARG; /* signed sanizizers */
198198
}
199-
else if ((word32)(offset + length) >
199+
else if (((jlong)offset + (jlong)length) >
200200
getDirectBufferLimit(env, input_object)) {
201201
ret = BUFFER_E; /* buffer overflow check */
202202
}
203-
else if ((word32)(outputOffset + length) >
203+
else if (((jlong)outputOffset + (jlong)length) >
204204
getDirectBufferLimit(env, output_object)) {
205205
ret = BUFFER_E; /* buffer overflow check */
206206
}

jni/jni_aescmac.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCmac_wc_1CmacUpdate___3BII(
183183

184184
/* Validate bounds to prevent buffer overflow */
185185
if (!cmac || !data || offset < 0 || length < 0 ||
186-
(word32)(offset + length) > dataSz) {
186+
((jlong)offset + (jlong)length) > dataSz) {
187187
ret = BAD_FUNC_ARG;
188188
} else {
189189
ret = wc_CmacUpdate(cmac, data + offset, length);
@@ -222,7 +222,7 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCmac_wc_1CmacUpdate__Ljava_
222222

223223
/* Validate bounds to prevent buffer overflow */
224224
if (!cmac || !data || offset < 0 || length < 0 ||
225-
(word32)(offset + length) > bufferLimit) {
225+
((jlong)offset + (jlong)length) > bufferLimit) {
226226
ret = BAD_FUNC_ARG;
227227
} else {
228228
ret = wc_CmacUpdate(cmac, data + offset, length);

jni/jni_aesctr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ Java_com_wolfssl_wolfcrypt_AesCtr_native_1update_1internal___3BII_3BI(
133133
else if (length == 0) {
134134
ret = 0;
135135
}
136-
else if ((word32)(offset + length) >
136+
else if (((jlong)offset + (jlong)length) >
137137
getByteArrayLength(env, input_object)) {
138138
ret = BUFFER_E; /* buffer overflow check */
139139
}
140-
else if ((word32)(outputOffset + length) >
140+
else if (((jlong)outputOffset + (jlong)length) >
141141
getByteArrayLength(env, output_object)) {
142142
ret = BUFFER_E; /* buffer overflow check */
143143
}
@@ -196,11 +196,11 @@ Java_com_wolfssl_wolfcrypt_AesCtr_native_1update_1internal__Ljava_nio_ByteBuffer
196196
else if (offset < 0 || length < 0) {
197197
ret = BAD_FUNC_ARG;
198198
}
199-
else if ((word32)(offset + length) >
199+
else if (((jlong)offset + (jlong)length) >
200200
getDirectBufferLimit(env, input_object)) {
201201
ret = BUFFER_E; /* buffer overflow check */
202202
}
203-
else if ((word32)(outputOffset + length) >
203+
else if (((jlong)outputOffset + (jlong)length) >
204204
getDirectBufferLimit(env, output_object)) {
205205
ret = BUFFER_E; /* buffer overflow check */
206206
}

jni/jni_aescts.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_AesCts_native_1update_1interna
161161
/* CTS requires at least one block of input */
162162
ret = BUFFER_E;
163163
}
164-
else if ((word32)(offset + length) >
164+
else if (((jlong)offset + (jlong)length) >
165165
getByteArrayLength(env, input_object)) {
166166
ret = BUFFER_E; /* buffer overflow check */
167167
}
168-
else if ((word32)(outputOffset + length) >
168+
else if (((jlong)outputOffset + (jlong)length) >
169169
getByteArrayLength(env, output_object)) {
170170
ret = BUFFER_E; /* buffer overflow check */
171171
}
@@ -273,11 +273,11 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_AesCts_native_1update_1interna
273273
/* CTS requires at least one block of input */
274274
ret = BUFFER_E;
275275
}
276-
else if ((word32)(offset + length) >
276+
else if (((jlong)offset + (jlong)length) >
277277
getDirectBufferLimit(env, input_object)) {
278278
ret = BUFFER_E;
279279
}
280-
else if ((word32)(outputOffset + length) >
280+
else if (((jlong)outputOffset + (jlong)length) >
281281
getDirectBufferLimit(env, output_object)) {
282282
ret = BUFFER_E;
283283
}

jni/jni_aesecb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ Java_com_wolfssl_wolfcrypt_AesEcb_native_1update_1internal__I_3BII_3BI(
134134
else if ((length % AES_BLOCK_SIZE) != 0) {
135135
ret = BAD_FUNC_ARG; /* ECB requires block-aligned data */
136136
}
137-
else if ((word32)(offset + length) >
137+
else if (((jlong)offset + (jlong)length) >
138138
getByteArrayLength(env, input_object)) {
139139
ret = BUFFER_E; /* buffer overflow check */
140140
}
141-
else if ((word32)(outputOffset + length) >
141+
else if (((jlong)outputOffset + (jlong)length) >
142142
getByteArrayLength(env, output_object)) {
143143
ret = BUFFER_E; /* buffer overflow check */
144144
}
@@ -205,11 +205,11 @@ Java_com_wolfssl_wolfcrypt_AesEcb_native_1update_1internal__ILjava_nio_ByteBuffe
205205
else if ((length % AES_BLOCK_SIZE) != 0) {
206206
ret = BAD_FUNC_ARG; /* ECB requires block-aligned data */
207207
}
208-
else if ((word32)(offset + length) >
208+
else if (((jlong)offset + (jlong)length) >
209209
getDirectBufferLimit(env, input_object)) {
210210
ret = BUFFER_E; /* buffer overflow check */
211211
}
212-
else if ((word32)(outputOffset + length) >
212+
else if (((jlong)outputOffset + (jlong)length) >
213213
getDirectBufferLimit(env, output_object)) {
214214
ret = BUFFER_E; /* buffer overflow check */
215215
}

0 commit comments

Comments
 (0)