From 829d9ef49246bc1d007b718f9227d135450ec4f4 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 11 Feb 2021 17:16:58 +0700 Subject: Fix SHAKE 'digest' output size --- crypto/src/crypto/digests/ShakeDigest.cs | 5 +++++ crypto/src/security/DigestUtilities.cs | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'crypto/src') 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(); -- cgit 1.4.1