summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-02-11 17:16:58 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-02-11 17:16:58 +0700
commit829d9ef49246bc1d007b718f9227d135450ec4f4 (patch)
tree43a0aa8b712c927ebe94fd43486973f755986246
parentEdDSA: Faster pub key validation (diff)
downloadBouncyCastle.NET-ed25519-829d9ef49246bc1d007b718f9227d135450ec4f4.tar.xz
Fix SHAKE 'digest' output size
-rw-r--r--crypto/src/crypto/digests/ShakeDigest.cs5
-rw-r--r--crypto/src/security/DigestUtilities.cs16
-rw-r--r--crypto/test/src/test/DigestTest.cs12
3 files changed, 20 insertions, 13 deletions
diff --git a/crypto/src/crypto/digests/ShakeDigest.cs b/crypto/src/crypto/digests/ShakeDigest.cs
index b38e29dc3..8d7a7d6e3 100644
--- a/crypto/src/crypto/digests/ShakeDigest.cs
+++ b/crypto/src/crypto/digests/ShakeDigest.cs
@@ -46,6 +46,11 @@ namespace Org.BouncyCastle.Crypto.Digests
             get { return "SHAKE" + fixedOutputLength; }
         }
 
+        public override int GetDigestSize()
+        {
+            return fixedOutputLength >> 2;
+        }
+
         public override int DoFinal(byte[] output, int outOff)
         {
             return DoFinal(output, outOff, GetDigestSize());
diff --git a/crypto/src/security/DigestUtilities.cs b/crypto/src/security/DigestUtilities.cs
index 927ab9341..c67dd8b72 100644
--- a/crypto/src/security/DigestUtilities.cs
+++ b/crypto/src/security/DigestUtilities.cs
@@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Security
             SHA_1, SHA_224, SHA_256, SHA_384, SHA_512,
             SHA_512_224, SHA_512_256,
             SHA3_224, SHA3_256, SHA3_384, SHA3_512,
-            SHAKE128, SHAKE256,
+            SHAKE128_256, SHAKE256_512,
             SM3,
             TIGER,
             WHIRLPOOL,
@@ -109,8 +109,10 @@ namespace Org.BouncyCastle.Security
             algorithms[NistObjectIdentifiers.IdHMacWithSha3_384.Id] = "SHA3-384";
             algorithms[NistObjectIdentifiers.IdSha3_512.Id] = "SHA3-512";
             algorithms[NistObjectIdentifiers.IdHMacWithSha3_512.Id] = "SHA3-512";
-            algorithms[NistObjectIdentifiers.IdShake128.Id] = "SHAKE128";
-            algorithms[NistObjectIdentifiers.IdShake256.Id] = "SHAKE256";
+            algorithms["SHAKE128"] = "SHAKE128-256";
+            algorithms[NistObjectIdentifiers.IdShake128.Id] = "SHAKE128-256";
+            algorithms["SHAKE256"] = "SHAKE256-512";
+            algorithms[NistObjectIdentifiers.IdShake256.Id] = "SHAKE256-512";
 
             algorithms[GMObjectIdentifiers.sm3.Id] = "SM3";
 
@@ -144,8 +146,8 @@ namespace Org.BouncyCastle.Security
             oids["SHA3-256"] = NistObjectIdentifiers.IdSha3_256;
             oids["SHA3-384"] = NistObjectIdentifiers.IdSha3_384;
             oids["SHA3-512"] = NistObjectIdentifiers.IdSha3_512;
-            oids["SHAKE128"] = NistObjectIdentifiers.IdShake128;
-            oids["SHAKE256"] = NistObjectIdentifiers.IdShake256;
+            oids["SHAKE128-256"] = NistObjectIdentifiers.IdShake128;
+            oids["SHAKE256-512"] = NistObjectIdentifiers.IdShake256;
             oids["RIPEMD128"] = TeleTrusTObjectIdentifiers.RipeMD128;
             oids["RIPEMD160"] = TeleTrusTObjectIdentifiers.RipeMD160;
             oids["RIPEMD256"] = TeleTrusTObjectIdentifiers.RipeMD256;
@@ -254,8 +256,8 @@ namespace Org.BouncyCastle.Security
                     case DigestAlgorithm.SHA3_256: return new Sha3Digest(256);
                     case DigestAlgorithm.SHA3_384: return new Sha3Digest(384);
                     case DigestAlgorithm.SHA3_512: return new Sha3Digest(512);
-                    case DigestAlgorithm.SHAKE128: return new ShakeDigest(128);
-                    case DigestAlgorithm.SHAKE256: return new ShakeDigest(256);
+                    case DigestAlgorithm.SHAKE128_256: return new ShakeDigest(128);
+                    case DigestAlgorithm.SHAKE256_512: return new ShakeDigest(256);
                     case DigestAlgorithm.SM3: return new SM3Digest();
                     case DigestAlgorithm.TIGER: return new TigerDigest();
                     case DigestAlgorithm.WHIRLPOOL: return new WhirlpoolDigest();
diff --git a/crypto/test/src/test/DigestTest.cs b/crypto/test/src/test/DigestTest.cs
index f8a7a8194..30834acb6 100644
--- a/crypto/test/src/test/DigestTest.cs
+++ b/crypto/test/src/test/DigestTest.cs
@@ -61,12 +61,12 @@ namespace Org.BouncyCastle.Tests
             { NistObjectIdentifiers.IdSha3_384.Id, "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25" },
             { "SHA3-512", "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0" },
             { NistObjectIdentifiers.IdSha3_512.Id, "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0" },
-            //{ "SHAKE128", "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
-            //{ "SHAKE128-256", "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
-            //{ NistObjectIdentifiers.IdShake128.Id, "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
-            //{ "SHAKE256", "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
-            //{ "SHAKE256-512", "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
-            //{ NistObjectIdentifiers.IdShake256.Id, "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
+            { "SHAKE128", "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
+            { "SHAKE128-256", "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
+            { NistObjectIdentifiers.IdShake128.Id, "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" },
+            { "SHAKE256", "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
+            { "SHAKE256-512", "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
+            { NistObjectIdentifiers.IdShake256.Id, "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e4" },
             { "KECCAK224", "c30411768506ebe1c2871b1ee2e87d38df342317300a9b97a95ec6a8" },
             { "KECCAK-224", "c30411768506ebe1c2871b1ee2e87d38df342317300a9b97a95ec6a8" },
             { "KECCAK256", "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45" },