Skip to content

Commit

Permalink
Merge pull request #104 from cconlon/sha224
Browse files Browse the repository at this point in the history
Add SHA-224 support to `MessageDigest`, `Mac`, `Signature`, `KeyGenerator`
  • Loading branch information
JacobBarthelmeh authored Mar 5, 2025
2 parents 7134511 + aa49b15 commit 613e4f4
Show file tree
Hide file tree
Showing 20 changed files with 1,612 additions and 29 deletions.
5 changes: 5 additions & 0 deletions README_JCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The JCE provider currently supports the following algorithms:
MessageDigest Class
MD5
SHA-1
SHA-224
SHA-256
SHA-384
SHA-512
Expand All @@ -107,17 +108,20 @@ The JCE provider currently supports the following algorithms:
Mac Class
HmacMD5
HmacSHA1
HmacSHA224
HmacSHA256
HmacSHA384
HmacSHA512

Signature Class
MD5withRSA
SHA1withRSA
SHA224withRSA
SHA256withRSA
SHA384withRSA
SHA512withRSA
SHA1withECDSA
SHA224withECDSA
SHA256withECDSA
SHA384withECDSA
SHA512withECDSA
Expand All @@ -130,6 +134,7 @@ The JCE provider currently supports the following algorithms:
KeyGenerator
AES
HmacSHA1
HmacSHA224
HmacSHA256
HmacSHA384
HmacSHA512
Expand Down
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.

75 changes: 75 additions & 0 deletions jni/include/com_wolfssl_wolfcrypt_Sha224.h

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

33 changes: 25 additions & 8 deletions jni/jni_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#ifndef NO_SHA
#define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
#endif
#ifdef WOLFSSL_SHA224
#define SHA224_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
#endif
#ifndef NO_SHA256
#define SHA256_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
#endif
Expand All @@ -61,44 +64,44 @@
/* copy from cyassl/hmac.c */
static WC_INLINE int GetHashSizeByType(int type)
{
if (!(type == WC_MD5 || type == WC_SHA || type == WC_SHA256
|| type == WC_SHA384 || type == WC_SHA512))
if (!(type == WC_MD5 || type == WC_SHA || type == WC_SHA224
|| type == WC_SHA256 || type == WC_SHA384 || type == WC_SHA512)) {
return BAD_FUNC_ARG;
}

switch (type) {
#ifndef NO_MD5
case WC_MD5:
return MD5_DIGEST_SIZE;
break;
#endif

#ifndef NO_SHA
case WC_SHA:
return SHA_DIGEST_SIZE;
break;
#endif

#ifdef WOLFSSL_SHA224
case WC_SHA224:
return SHA224_DIGEST_SIZE;
#endif

#ifndef NO_SHA256
case WC_SHA256:
return SHA256_DIGEST_SIZE;
break;
#endif

#if defined(CYASSL_SHA384) || defined(WOLFSSL_SHA384)
case WC_SHA384:
return SHA384_DIGEST_SIZE;
break;
#endif

#if defined(CYASSL_SHA512) || defined(WOLFSSL_SHA512)
case WC_SHA512:
return SHA512_DIGEST_SIZE;
break;
#endif

default:
return BAD_FUNC_ARG;
break;
}
}

Expand Down Expand Up @@ -355,6 +358,20 @@ Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha(
#endif
}

JNIEXPORT jint JNICALL
Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha224(
JNIEnv* env, jobject this)
{
#ifdef WOLFSSL_SHA224
jint result = WC_SHA224;
LogStr("WC_SHA224 = %d\n", result);
return result;
#else
/* not compiled in */
return (jint) -1;
#endif
}

JNIEXPORT jint JNICALL
Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha256(
JNIEnv* env, jobject this)
Expand Down
Loading

0 comments on commit 613e4f4

Please sign in to comment.