diff options
author | Roy Basmacier <roy.basmacier@keyfactor.com> | 2022-07-11 14:24:48 -0400 |
---|---|---|
committer | Roy Basmacier <roy.basmacier@keyfactor.com> | 2022-07-11 14:24:48 -0400 |
commit | 141cf71f4b6ea7dbf709559b0a5fbf371856b86b (patch) | |
tree | 7ed004ac03fb4e722ca79da49bf998986f101632 | |
parent | Added SIKE to PrivateKeyFactory.cs and changed SikeVectorTest.cs (diff) | |
download | BouncyCastle.NET-ed25519-141cf71f4b6ea7dbf709559b0a5fbf371856b86b.tar.xz |
Detached picnic signature
-rw-r--r-- | crypto/src/pqc/crypto/picnic/PicnicSigner.cs | 2 | ||||
-rw-r--r-- | crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/crypto/src/pqc/crypto/picnic/PicnicSigner.cs b/crypto/src/pqc/crypto/picnic/PicnicSigner.cs index 302d144b3..7b631b3cb 100644 --- a/crypto/src/pqc/crypto/picnic/PicnicSigner.cs +++ b/crypto/src/pqc/crypto/picnic/PicnicSigner.cs @@ -38,7 +38,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Picnic byte[] sig = new byte[engine.GetSignatureSize(message.Length)]; engine.crypto_sign(sig, message, privKey.GetEncoded()); - return Arrays.CopyOfRange(sig, 0, message.Length + engine.GetTrueSignatureSize()); + return Arrays.CopyOfRange(sig, message.Length + 4, engine.GetTrueSignatureSize() + message.Length); } public bool VerifySignature(byte[] message, byte[] signature) diff --git a/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs b/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs index 550a94c68..e8ca6b4fb 100644 --- a/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/PicnicVectorTest.cs @@ -103,11 +103,23 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests signer.Init(true, privParams); byte[] sigGenerated = signer.GenerateSignature(msg); - Assert.True(smlen == sigGenerated.Length, name + " " + count + ": signature length"); + byte[] attachedSig = Arrays.ConcatenateAll(UInt32_To_LE((uint)sigGenerated.Length), msg, sigGenerated); + + Assert.True(smlen == attachedSig.Length, name + " " + count + ": signature length"); signer.Init(false, pubParams); - Assert.True(signer.VerifySignature(msg, sigGenerated), (name + " " + count + ": signature verify")); - Assert.True(Arrays.AreEqual(sigExpected, sigGenerated), name + " " + count + ": signature gen match"); + Assert.True(signer.VerifySignature(msg, attachedSig), (name + " " + count + ": signature verify")); + Assert.True(Arrays.AreEqual(sigExpected, attachedSig), name + " " + count + ": signature gen match"); + } + + private static byte[] UInt32_To_LE(uint n) + { + byte[] bs = new byte[4]; + bs[0] = (byte)(n); + bs[1] = (byte)(n >> 8); + bs[2] = (byte)(n >> 16); + bs[3] = (byte)(n >> 24); + return bs; } private static void RunTestVectorFile(string name) |