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_Aes.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_AesCtr.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_AesEcb.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_AesOfb.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_Des3.h

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

3 changes: 3 additions & 0 deletions jni/include/wolfcrypt_jni_NativeStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void setDirectBufferLimit(JNIEnv* env, jobject buffer, jint limit);
byte* getByteArray(JNIEnv* env, jbyteArray array);
void releaseByteArray(JNIEnv* env, jbyteArray array, byte* elements, jint abort);
word32 getByteArrayLength(JNIEnv* env, jbyteArray array);
byte* getSecretByteArray(JNIEnv* env, jbyteArray array, jboolean* isCopy);
void releaseSecretByteArray(JNIEnv* env, jbyteArray array, byte* elements,
word32 len, jboolean isCopy);
void initializeNativeStruct(JNIEnv* env, jobject obj);

#ifdef __cplusplus
Expand Down
28 changes: 28 additions & 0 deletions jni/jni_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_Aes_mallocNativeStruct_1inter
{
#ifndef NO_AES
Aes* aes = NULL;
int ret = 0;

aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL) {
throwOutOfMemoryException(env, "Failed to allocate Aes object");
}
else {
XMEMSET(aes, 0, sizeof(Aes));
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
aes = NULL;
throwWolfCryptExceptionFromError(env, ret);
}
}

LogStr("new Aes() = %p\n", aes);
Expand All @@ -60,6 +67,27 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_Aes_mallocNativeStruct_1inter
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Aes_wc_1AesFree
(JNIEnv* env, jobject this)
{
#ifndef NO_AES
Aes* aes = NULL;

aes = (Aes*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, if so stop and return */
return;
}

wc_AesFree(aes);

LogStr("wc_AesFree(aes=%p)\n", aes);
#else
(void)this;
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL
Java_com_wolfssl_wolfcrypt_Aes_native_1set_1key_1internal(
JNIEnv* env, jobject this, jbyteArray key_object, jbyteArray iv_object,
Expand Down
28 changes: 28 additions & 0 deletions jni/jni_aesctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesCtr_mallocNativeStruct_1in
{
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
Aes* aes = NULL;
int ret = 0;

aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL) {
throwOutOfMemoryException(env, "Failed to allocate AesCtr object");
}
else {
XMEMSET(aes, 0, sizeof(Aes));
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
aes = NULL;
throwWolfCryptExceptionFromError(env, ret);
}
}

LogStr("new AesCtr() = %p\n", aes);
Expand All @@ -60,6 +67,27 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesCtr_mallocNativeStruct_1in
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesCtr_wc_1AesFree
(JNIEnv* env, jobject this)
{
#if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
Aes* aes = NULL;

aes = (Aes*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, if so stop and return */
return;
}

wc_AesFree(aes);

LogStr("wc_AesFree(aes=%p)\n", aes);
#else
(void)this;
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL
Java_com_wolfssl_wolfcrypt_AesCtr_native_1set_1key_1internal(
JNIEnv* env, jobject this, jbyteArray key_object, jbyteArray iv_object)
Expand Down
28 changes: 28 additions & 0 deletions jni/jni_aesecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesEcb_mallocNativeStruct_1in
{
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
Aes* aes = NULL;
int ret = 0;

aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL) {
throwOutOfMemoryException(env, "Failed to allocate AesEcb object");
}
else {
XMEMSET(aes, 0, sizeof(Aes));
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
aes = NULL;
throwWolfCryptExceptionFromError(env, ret);
}
}

LogStr("new AesEcb() = %p\n", aes);
Expand All @@ -60,6 +67,27 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesEcb_mallocNativeStruct_1in
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesEcb_wc_1AesFree
(JNIEnv* env, jobject this)
{
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
Aes* aes = NULL;

aes = (Aes*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, if so stop and return */
return;
}

wc_AesFree(aes);

LogStr("wc_AesFree(aes=%p)\n", aes);
#else
(void)this;
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL
Java_com_wolfssl_wolfcrypt_AesEcb_native_1set_1key_1internal(
JNIEnv* env, jobject this, jbyteArray key_object, jbyteArray iv_object, jint opmode)
Expand Down
28 changes: 28 additions & 0 deletions jni/jni_aesofb.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesOfb_mallocNativeStruct_1in
{
#if !defined(NO_AES) && defined(WOLFSSL_AES_OFB)
Aes* aes = NULL;
int ret = 0;

aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL) {
throwOutOfMemoryException(env, "Failed to allocate AesOfb object");
}
else {
XMEMSET(aes, 0, sizeof(Aes));
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret != 0) {
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
aes = NULL;
throwWolfCryptExceptionFromError(env, ret);
}
}

LogStr("new AesOfb() = %p\n", aes);
Expand All @@ -60,6 +67,27 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_AesOfb_mallocNativeStruct_1in
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_AesOfb_wc_1AesFree
(JNIEnv* env, jobject this)
{
#if !defined(NO_AES) && defined(WOLFSSL_AES_OFB)
Aes* aes = NULL;

aes = (Aes*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, if so stop and return */
return;
}

wc_AesFree(aes);

LogStr("wc_AesFree(aes=%p)\n", aes);
#else
(void)this;
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL
Java_com_wolfssl_wolfcrypt_AesOfb_native_1set_1key_1internal(
JNIEnv* env, jobject this, jbyteArray key_object, jbyteArray iv_object,
Expand Down
28 changes: 28 additions & 0 deletions jni/jni_des3.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_Des3_mallocNativeStruct(
{
#ifndef NO_DES3
Des3* des = NULL;
int ret = 0;

des = (Des3*) XMALLOC(sizeof(Des3), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (des == NULL) {
throwOutOfMemoryException(env, "Failed to allocate Des3 object");
}
else {
XMEMSET(des, 0, sizeof(Des3));
ret = wc_Des3Init(des, NULL, INVALID_DEVID);
if (ret != 0) {
XFREE(des, NULL, DYNAMIC_TYPE_TMP_BUFFER);
des = NULL;
throwWolfCryptExceptionFromError(env, ret);
}
}

LogStr("new Des3() = %p\n", des);
Expand All @@ -59,6 +66,27 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_wolfcrypt_Des3_mallocNativeStruct(
#endif
}

JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Des3_wc_1Des3Free
(JNIEnv* env, jobject this)
{
#ifndef NO_DES3
Des3* des3 = NULL;

des3 = (Des3*) getNativeStruct(env, this);
if ((*env)->ExceptionOccurred(env)) {
/* getNativeStruct may throw exception, if so stop and return */
return;
}

wc_Des3Free(des3);

LogStr("wc_Des3Free(des3=%p)\n", des3);
#else
(void)this;
throwNotCompiledInException(env);
#endif
}

JNIEXPORT void JNICALL
Java_com_wolfssl_wolfcrypt_Des3_native_1set_1key_1internal(
JNIEnv* env, jobject this, jbyteArray key_object, jbyteArray iv_object,
Expand Down
28 changes: 23 additions & 5 deletions jni/jni_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1import_1private
if (ret == 0) {
if (curveName != NULL) {
name = (*env)->GetStringUTFChars(env, curveName, 0);
if (name == NULL) {
/* OutOfMemoryError pending, release arrays and return */
releaseByteArray(env, priv_object, priv, JNI_ABORT);
releaseByteArray(env, pub_object, pub, JNI_ABORT);
return;
}
ret = wc_ecc_get_curve_id_from_name(name);
(*env)->ReleaseStringUTFChars(env, curveName, name);

Expand Down Expand Up @@ -1018,8 +1024,14 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1get_1curve_1size_
ret = BAD_FUNC_ARG;
} else {
name = (*env)->GetStringUTFChars(env, curveName, 0);
ret = wc_ecc_get_curve_size_from_name(name);
(*env)->ReleaseStringUTFChars(env, curveName, name);
if (name == NULL) {
/* OutOfMemoryError pending */
ret = MEMORY_E;
}
else {
ret = wc_ecc_get_curve_size_from_name(name);
(*env)->ReleaseStringUTFChars(env, curveName, name);
}
}

#else
Expand Down Expand Up @@ -1120,7 +1132,9 @@ JNIEXPORT jbyteArray JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1private_1ke
if (ret == LENGTH_ONLY_E) {
ret = 0;
}
}

if (ret == 0) {
pkcs8 = (byte*)XMALLOC(pkcs8Sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (pkcs8 == NULL) {
ret = MEMORY_E;
Expand Down Expand Up @@ -1469,6 +1483,7 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1import_1public_1r
word32 ySz = 0;
const char* name = NULL;
int curveId = 0;
int curveSz = 0;
word32 expectedSz = 0;

ecc = (ecc_key*) getNativeStruct(env, this);
Expand Down Expand Up @@ -1496,15 +1511,18 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1import_1public_1r
if (ret == 0) {
curveId = wc_ecc_get_curve_id_from_name(name);
/* Get expected size for curve */
expectedSz = wc_ecc_get_curve_size_from_id(curveId);
curveSz = wc_ecc_get_curve_size_from_id(curveId);
(*env)->ReleaseStringUTFChars(env, curveName, name);

if (curveId < 0 || expectedSz <= 0) {
if (curveId < 0 || curveSz <= 0) {
ret = BAD_FUNC_ARG;
}
else {
expectedSz = (word32)curveSz;
}
}

if (xSz != expectedSz || ySz != expectedSz) {
if (ret == 0 && (xSz != expectedSz || ySz != expectedSz)) {
LogStr("ECC x or y size does not match expected size for curve\n");
ret = BAD_FUNC_ARG;
}
Expand Down
Loading
Loading