From 45deb2802f509a0dca03694f5be93ecefd82d78f Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Fri, 5 Apr 2024 10:04:29 -0600 Subject: [PATCH] JCE: add support for SecureRandom.getInstance("DEFAULT"), maps to HashDRBG --- README_JCE.md | 1 + .../java/com/wolfssl/provider/jce/WolfCryptProvider.java | 2 ++ .../wolfssl/provider/jce/test/WolfCryptRandomTest.java | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README_JCE.md b/README_JCE.md index 9bfde157..49cf3582 100644 --- a/README_JCE.md +++ b/README_JCE.md @@ -34,6 +34,7 @@ The JCE provider currently supports the following algorithms: SHA-512 SecureRandom Class + DEFAULT (maps to HashDRBG) HashDRBG Cipher Class diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java index 0d502c0f..c38f9cad 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java @@ -65,6 +65,8 @@ public WolfCryptProvider() { /* SecureRandom */ /* TODO: May need to add "SHA1PRNG" alias, other JCA consumemrs may * explicitly request it? Needs more testing. */ + put("SecureRandom.DEFAULT", + "com.wolfssl.provider.jce.WolfCryptRandom"); put("SecureRandom.HashDRBG", "com.wolfssl.provider.jce.WolfCryptRandom"); diff --git a/src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java b/src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java index fd93f4fb..b209a5e2 100644 --- a/src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java +++ b/src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java @@ -57,7 +57,13 @@ public static void testProviderInstallationAtRuntime() { public void testGetRandomFromProvider() throws NoSuchProviderException, NoSuchAlgorithmException { - SecureRandom rand = SecureRandom.getInstance("HashDRBG", "wolfJCE"); + SecureRandom rand = null; + + /* HashDRBG */ + rand = SecureRandom.getInstance("HashDRBG", "wolfJCE"); + + /* DEFAULT */ + rand = SecureRandom.getInstance("DEFAULT", "wolfJCE"); } @Test