Skip to content

Commit 613e4f4

Browse files
Merge pull request #104 from cconlon/sha224
Add SHA-224 support to `MessageDigest`, `Mac`, `Signature`, `KeyGenerator`
2 parents 7134511 + aa49b15 commit 613e4f4

20 files changed

+1612
-29
lines changed

README_JCE.md

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The JCE provider currently supports the following algorithms:
8888
MessageDigest Class
8989
MD5
9090
SHA-1
91+
SHA-224
9192
SHA-256
9293
SHA-384
9394
SHA-512
@@ -107,17 +108,20 @@ The JCE provider currently supports the following algorithms:
107108
Mac Class
108109
HmacMD5
109110
HmacSHA1
111+
HmacSHA224
110112
HmacSHA256
111113
HmacSHA384
112114
HmacSHA512
113115

114116
Signature Class
115117
MD5withRSA
116118
SHA1withRSA
119+
SHA224withRSA
117120
SHA256withRSA
118121
SHA384withRSA
119122
SHA512withRSA
120123
SHA1withECDSA
124+
SHA224withECDSA
121125
SHA256withECDSA
122126
SHA384withECDSA
123127
SHA512withECDSA
@@ -130,6 +134,7 @@ The JCE provider currently supports the following algorithms:
130134
KeyGenerator
131135
AES
132136
HmacSHA1
137+
HmacSHA224
133138
HmacSHA256
134139
HmacSHA384
135140
HmacSHA512

jni/include/com_wolfssl_wolfcrypt_Hmac.h

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jni/include/com_wolfssl_wolfcrypt_Sha224.h

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jni/jni_hmac.c

+25-8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#ifndef NO_SHA
4747
#define SHA_DIGEST_SIZE WC_SHA_DIGEST_SIZE
4848
#endif
49+
#ifdef WOLFSSL_SHA224
50+
#define SHA224_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
51+
#endif
4952
#ifndef NO_SHA256
5053
#define SHA256_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
5154
#endif
@@ -61,44 +64,44 @@
6164
/* copy from cyassl/hmac.c */
6265
static WC_INLINE int GetHashSizeByType(int type)
6366
{
64-
if (!(type == WC_MD5 || type == WC_SHA || type == WC_SHA256
65-
|| type == WC_SHA384 || type == WC_SHA512))
67+
if (!(type == WC_MD5 || type == WC_SHA || type == WC_SHA224
68+
|| type == WC_SHA256 || type == WC_SHA384 || type == WC_SHA512)) {
6669
return BAD_FUNC_ARG;
70+
}
6771

6872
switch (type) {
6973
#ifndef NO_MD5
7074
case WC_MD5:
7175
return MD5_DIGEST_SIZE;
72-
break;
7376
#endif
7477

7578
#ifndef NO_SHA
7679
case WC_SHA:
7780
return SHA_DIGEST_SIZE;
78-
break;
81+
#endif
82+
83+
#ifdef WOLFSSL_SHA224
84+
case WC_SHA224:
85+
return SHA224_DIGEST_SIZE;
7986
#endif
8087

8188
#ifndef NO_SHA256
8289
case WC_SHA256:
8390
return SHA256_DIGEST_SIZE;
84-
break;
8591
#endif
8692

8793
#if defined(CYASSL_SHA384) || defined(WOLFSSL_SHA384)
8894
case WC_SHA384:
8995
return SHA384_DIGEST_SIZE;
90-
break;
9196
#endif
9297

9398
#if defined(CYASSL_SHA512) || defined(WOLFSSL_SHA512)
9499
case WC_SHA512:
95100
return SHA512_DIGEST_SIZE;
96-
break;
97101
#endif
98102

99103
default:
100104
return BAD_FUNC_ARG;
101-
break;
102105
}
103106
}
104107

@@ -355,6 +358,20 @@ Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha(
355358
#endif
356359
}
357360

361+
JNIEXPORT jint JNICALL
362+
Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha224(
363+
JNIEnv* env, jobject this)
364+
{
365+
#ifdef WOLFSSL_SHA224
366+
jint result = WC_SHA224;
367+
LogStr("WC_SHA224 = %d\n", result);
368+
return result;
369+
#else
370+
/* not compiled in */
371+
return (jint) -1;
372+
#endif
373+
}
374+
358375
JNIEXPORT jint JNICALL
359376
Java_com_wolfssl_wolfcrypt_Hmac_getCodeSha256(
360377
JNIEnv* env, jobject this)

0 commit comments

Comments
 (0)