diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-08-04 14:26:45 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-08-04 14:26:45 +0700 |
commit | f948a496ea7905d2282e8f4a0be41c4ca93f2d0b (patch) | |
tree | 31bbdeb8ebce99f8009ce8174e52d582e9d6aed8 /crypto/test | |
parent | Replace some locks with singleton init (diff) | |
download | BouncyCastle.NET-ed25519-f948a496ea7905d2282e8f4a0be41c4ca93f2d0b.tar.xz |
Added handling of L=1 in GenerateLmsContext()
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/pqc/crypto/test/HSSTest.cs | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/crypto/test/src/pqc/crypto/test/HSSTest.cs b/crypto/test/src/pqc/crypto/test/HSSTest.cs index 29b5e1f5a..45cabb906 100644 --- a/crypto/test/src/pqc/crypto/test/HSSTest.cs +++ b/crypto/test/src/pqc/crypto/test/HSSTest.cs @@ -13,16 +13,46 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests public class HSSTest { [Test] + public void TestOneLevelKeyGenAndSign() + { + byte[] msg = Strings.ToByteArray("Hello, world!"); + IAsymmetricCipherKeyPairGenerator kpGen = new HssKeyPairGenerator(); + + var lmsParameters = new LmsParameters[] + { + new LmsParameters(LMSigParameters.lms_sha256_n32_h5, LMOtsParameters.sha256_n32_w4) + }; + kpGen.Init(new HssKeyGenerationParameters(lmsParameters, new SecureRandom())); + + AsymmetricCipherKeyPair kp = kpGen.GenerateKeyPair(); + + HssSigner signer = new HssSigner(); + + signer.Init(true, kp.Private); + + byte[] sig = signer.GenerateSignature(msg); + + signer.Init(false, kp.Public); + + Assert.True(signer.VerifySignature(msg, sig)); + + HssPublicKeyParameters hssPubKey = (HssPublicKeyParameters)kp.Public; + + hssPubKey.GenerateLmsContext(sig); + } + + [Test] public void TestKeyGenAndSign() { byte[] msg = Strings.ToByteArray("Hello, world!"); IAsymmetricCipherKeyPairGenerator kpGen = new HssKeyPairGenerator(); - kpGen.Init(new HssKeyGenerationParameters( - new LmsParameters[]{ - new LmsParameters(LMSigParameters.lms_sha256_n32_h5, LMOtsParameters.sha256_n32_w4), - new LmsParameters(LMSigParameters.lms_sha256_n32_h5, LMOtsParameters.sha256_n32_w4) - }, new SecureRandom())); + var lmsParameters = new LmsParameters[] + { + new LmsParameters(LMSigParameters.lms_sha256_n32_h5, LMOtsParameters.sha256_n32_w4), + new LmsParameters(LMSigParameters.lms_sha256_n32_h5, LMOtsParameters.sha256_n32_w4) + }; + kpGen.Init(new HssKeyGenerationParameters(lmsParameters, new SecureRandom())); AsymmetricCipherKeyPair kp = kpGen.GenerateKeyPair(); |