Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jni/include/com_wolfssl_wolfcrypt_Chacha.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions jni/include/com_wolfssl_wolfcrypt_Hmac.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions jni/jni_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ Java_com_wolfssl_wolfcrypt_Aes_native_1update_1internal__I_3BII_3BI(
LogStr("wc_AesCbcDecrypt(aes=%p, out, in, inSz) = %d\n", aes, ret);
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output, ret);
Expand Down Expand Up @@ -223,10 +225,12 @@ Java_com_wolfssl_wolfcrypt_Aes_native_1update_1internal__ILjava_nio_ByteBuffer_2
ret = length;
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}
#else
throwNotCompiledInException(env);
ret = NOT_COMPILED_IN;
Expand Down
18 changes: 14 additions & 4 deletions jni/jni_aesccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,17 @@ JNIEXPORT jbyteArray JNICALL Java_com_wolfssl_wolfcrypt_AesCcm_wc_1AesCcmEncrypt

/* Allocate new buffer to hold ciphertext */
if (ret == 0) {
out = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
word32 outSz = inLen;
if (outSz == 0) {
/* AAD-only case, allocate 1 byte to avoid XMALLOC(0) */
outSz = 1;
}
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (out == NULL) {
ret = MEMORY_E;
}
else {
XMEMSET(out, 0, inLen);
XMEMSET(out, 0, outSz);
}
}

Expand Down Expand Up @@ -336,12 +341,17 @@ JNIEXPORT jbyteArray JNICALL Java_com_wolfssl_wolfcrypt_AesCcm_wc_1AesCcmDecrypt
}

if (ret == 0) {
out = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
word32 outSz = inLen;
if (outSz == 0) {
/* AAD-only case, allocate 1 byte to avoid XMALLOC(0) */
outSz = 1;
}
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (out == NULL) {
ret = MEMORY_E;
}
else {
XMEMSET(out, 0, inLen);
XMEMSET(out, 0, outSz);
}
}

Expand Down
12 changes: 8 additions & 4 deletions jni/jni_aescmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCmac_wc_1CmacUpdate___3BII(
throwWolfCryptExceptionFromError(env, ret);

LogStr("wc_CmacUpdate(cmac=%p, data, length) = %d\n", cmac, ret);
LogStr("data[%u]: [%p]\n", (word32)length, data + offset);
LogHex((byte*) data, offset, length);
if (data != NULL) {
LogStr("data[%u]: [%p]\n", (word32)length, data + offset);
LogHex((byte*) data, offset, length);
}

releaseByteArray(env, data_object, data, JNI_ABORT);
#else
Expand Down Expand Up @@ -236,8 +238,10 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCmac_wc_1CmacUpdate__Ljava_
throwWolfCryptExceptionFromError(env, ret);

LogStr("wc_CmacUpdate(cmac=%p, data, length) = %d\n", cmac, ret);
LogStr("data[%u]: [%p]\n", (word32)length, data + offset);
LogHex((byte*) data, offset, length);
if (data != NULL) {
LogStr("data[%u]: [%p]\n", (word32)length, data + offset);
LogHex((byte*) data, offset, length);
}
#else
throwNotCompiledInException(env);
#endif
Expand Down
20 changes: 12 additions & 8 deletions jni/jni_aesctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ Java_com_wolfssl_wolfcrypt_AesCtr_native_1update_1internal___3BII_3BI(
LogStr("wc_AesCtrEncrypt(aes=%p, out, in, inSz) = %d\n", aes, ret);
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output, ret);
Expand Down Expand Up @@ -218,10 +220,12 @@ Java_com_wolfssl_wolfcrypt_AesCtr_native_1update_1internal__Ljava_nio_ByteBuffer
ret = length;
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output);
LogHex((byte*) output, 0, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}
#else
throwNotCompiledInException(env);
#endif
Expand Down
15 changes: 11 additions & 4 deletions jni/jni_aescts.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCts_native_1set_1key_1inter
byte* key = NULL;
byte* iv = NULL;
word32 keySz = 0;
word32 ivSz = 0;

ctx = (AesCtsCtx*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
Expand All @@ -126,10 +127,14 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCts_native_1set_1key_1inter
key = getByteArray(env, key_object);
iv = getByteArray(env, iv_object);
keySz = getByteArrayLength(env, key_object);
ivSz = getByteArrayLength(env, iv_object);

if (ctx == NULL || key == NULL || iv == NULL) {
ret = BAD_FUNC_ARG;
}
else if (ivSz != AES_BLOCK_SIZE) {
ret = BAD_FUNC_ARG;
}

if (ret == 0) {
/* Initialize AES_KEY structure using OpenSSL-compatible functions.
Expand Down Expand Up @@ -254,10 +259,12 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_AesCts_native_1update_1interna
ctx, opmode, length, ret);
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output,
Expand Down
20 changes: 12 additions & 8 deletions jni/jni_aesecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ Java_com_wolfssl_wolfcrypt_AesEcb_native_1update_1internal__I_3BII_3BI(
LogStr("wc_AesEcbDecrypt(aes=%p, out, in, inSz) = %d\n", aes, ret);
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output, ret);
Expand Down Expand Up @@ -232,10 +234,12 @@ Java_com_wolfssl_wolfcrypt_AesEcb_native_1update_1internal__ILjava_nio_ByteBuffe
ret = length;
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}
#else
throwNotCompiledInException(env);
ret = NOT_COMPILED_IN;
Expand Down
18 changes: 14 additions & 4 deletions jni/jni_aesgcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,17 @@ JNIEXPORT jbyteArray JNICALL Java_com_wolfssl_wolfcrypt_AesGcm_wc_1AesGcmEncrypt

/* Allocate new buffer to hold ciphertext */
if (ret == 0) {
out = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
word32 outSz = inLen;
if (outSz == 0) {
/* AAD-only case, allocate 1 byte to avoid XMALLOC(0) */
outSz = 1;
}
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (out == NULL) {
ret = MEMORY_E;
}
else {
XMEMSET(out, 0, inLen);
XMEMSET(out, 0, outSz);
}
}

Expand Down Expand Up @@ -362,12 +367,17 @@ JNIEXPORT jbyteArray JNICALL Java_com_wolfssl_wolfcrypt_AesGcm_wc_1AesGcmDecrypt
}

if (ret == 0) {
out = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
word32 outSz = inLen;
if (outSz == 0) {
/* AAD-only case, allocate 1 byte to avoid XMALLOC(0) */
outSz = 1;
}
out = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (out == NULL) {
ret = MEMORY_E;
}
else {
XMEMSET(out, 0, inLen);
XMEMSET(out, 0, outSz);
}
}

Expand Down
20 changes: 12 additions & 8 deletions jni/jni_aesofb.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ Java_com_wolfssl_wolfcrypt_AesOfb_native_1update_1internal__I_3BII_3BI(
#endif
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output, ret);
Expand Down Expand Up @@ -246,10 +248,12 @@ Java_com_wolfssl_wolfcrypt_AesOfb_native_1update_1internal__ILjava_nio_ByteBuffe
ret = length;
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}
#else
throwNotCompiledInException(env);
ret = NOT_COMPILED_IN;
Expand Down
26 changes: 26 additions & 0 deletions jni/jni_chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ Java_com_wolfssl_wolfcrypt_Chacha_mallocNativeStruct(
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Chacha_native_1free
(JNIEnv* env, jobject this)
{
#ifdef HAVE_CHACHA
ChaCha* chacha = (ChaCha*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, prevent throwing another */
return;
}

LogStr("free ChaCha %p\n", chacha);

if (chacha) {
/* Zeroize ChaCha key/state, NativeStruct.xfree() frees memory */
#if (LIBWOLFSSL_VERSION_HEX >= 0x05008004) && \
!defined(WOLFSSL_NO_FORCE_ZERO)
wc_ForceZero(chacha, sizeof(ChaCha));
#else
XMEMSET(chacha, 0, sizeof(ChaCha));
#endif
}
#else
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Chacha_wc_1Chacha_1setIV
(JNIEnv* env, jobject this, jbyteArray iv_object)
{
Expand Down
20 changes: 12 additions & 8 deletions jni/jni_des3.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ Java_com_wolfssl_wolfcrypt_Des3_native_1update_1internal__I_3BII_3BI(
LogStr("wc_Des3CbcDecrypt(des=%p, out, in, inSz) = %d\n", des, ret);
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}

releaseByteArray(env, input_object, input, JNI_ABORT);
releaseByteArray(env, output_object, output, ret);
Expand Down Expand Up @@ -221,10 +223,12 @@ Java_com_wolfssl_wolfcrypt_Des3_native_1update_1internal__ILjava_nio_ByteBuffer_
ret = length;
}

LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
if (input != NULL && output != NULL) {
LogStr("input[%u]: [%p]\n", (word32)length, input + offset);
LogHex((byte*) input, offset, length);
LogStr("output[%u]: [%p]\n", (word32)length, output + outputOffset);
LogHex((byte*) output, outputOffset, length);
}
#else
throwNotCompiledInException(env);
#endif
Expand Down
Loading
Loading