Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Whittington <bc@whittington.net.nz>2014-02-23 23:25:33 +0400
committerTim Whittington <bc@whittington.net.nz>2014-03-10 23:12:29 +0400
commit353b88e018048ac2dfc088e145f78a9af1916624 (patch)
tree49a10e8a0e95ebeda6c2fd7afc656f8a48c533ec /prov/src/test
parente8bf2f6f808f257c6887fa980b324219ece9acd0 (diff)
Add KeyGenerator registrations for SipHash in JCE API and add JCE SipHash algorithms to specs.
Also made Mac.SipHash-2-4 the primary algorithm with Mac.SipHash as an alias, as per usage in "SipHash: a fast short-input PRF" where SipHash is the family name.
Diffstat (limited to 'prov/src/test')
-rw-r--r--prov/src/test/java/org/bouncycastle/jce/provider/test/SipHashTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/prov/src/test/java/org/bouncycastle/jce/provider/test/SipHashTest.java b/prov/src/test/java/org/bouncycastle/jce/provider/test/SipHashTest.java
index 9120e88b..59861410 100644
--- a/prov/src/test/java/org/bouncycastle/jce/provider/test/SipHashTest.java
+++ b/prov/src/test/java/org/bouncycastle/jce/provider/test/SipHashTest.java
@@ -1,8 +1,13 @@
package org.bouncycastle.jce.provider.test;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
import java.security.Security;
+import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
+import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -16,6 +21,42 @@ public class SipHashTest
public void performTest()
throws Exception
{
+ testMac();
+ testKeyGenerator();
+ }
+
+ private void testKeyGenerator()
+ throws NoSuchAlgorithmException,
+ NoSuchProviderException
+ {
+ testKeyGen("SipHash");
+ testKeyGen("SipHash-2-4");
+ testKeyGen("SipHash-4-8");
+ }
+
+ private void testKeyGen(String algorithm)
+ throws NoSuchAlgorithmException,
+ NoSuchProviderException
+ {
+ KeyGenerator kg = KeyGenerator.getInstance(algorithm, "BC");
+
+ SecretKey key = kg.generateKey();
+
+ if (!key.getAlgorithm().equalsIgnoreCase("SipHash"))
+ {
+ fail("Unexpected algorithm name in key", "SipHash", key.getAlgorithm());
+ }
+ if (key.getEncoded().length != 16)
+ {
+ fail("Expected 128 bit key");
+ }
+ }
+
+ private void testMac()
+ throws NoSuchAlgorithmException,
+ NoSuchProviderException,
+ InvalidKeyException
+ {
byte[] key = Hex.decode("000102030405060708090a0b0c0d0e0f");
byte[] input = Hex.decode("000102030405060708090a0b0c0d0e");