diff options
-rw-r--r-- | crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs index 36d91a62d..98003004d 100644 --- a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs +++ b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using System.IO; using NUnit.Framework; - +using Org.BouncyCastle.Asn1; +using Org.BouncyCastle.Asn1.BC; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium; @@ -38,16 +39,21 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests RunTestVectorFile(testVectorFile); } - /* [Test] public void TestKeyEncodingDilithium2() { - byte[] altEncKey = Base64.Decode("oED4ZvqhK4kChPclP5VhOPvvnwof3QeTFq/zR5UtSr6SYicBkpe1TkafnSk5whDHgEp8imVwfeP2LbSopHb5KQuUFstGqsdII9o8Zf+50yempJ1+C5G64KfQlqkI8/Y6cShWWNgeWm/5OGyxhF0hYVGIwaTTs6AN3QaPjSutLPNdZ82Vd4BSNB5dzZMaoYV619rNO7HGlfwrWkyCoDVQftpgw4NjiAnJ0BPcDJTzPVD3cq3Dw5f14AwNsUijLZ4CuRzzCBBx0B+SbIruEnGbDNhfzp3FdDg2sy/hRqD6/0gzOBExzLT8ofBE6D9VcmiPT+KgLbiObhZt+mjzGGE3wnXgmklX5Qr/d7kyamm4tq3xiKm58/VdkB3ASt+ULo1jXQtuoXVkn7vfT/1LAVbJ6QIqvxcQknDj2j2oUSWYLz48qfgNWtbM/EOZ8WBaV9UxO7Sd5wF+/wiVUxrMC+3BdrJnWSP00s7AJBH4NdQfU7E6uK1BhJEDLZaiRshi1lnu7PfKLdKSIyRL73VsmjQhONXtyBy1gG876DSa846d3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J5fJOl/+PA7tkhAumHjDK11EfCcz95BFVCy2gcVyTLSLpp7HnAJ3aMQBnYcWPqyQjz0opnPp2r5aA2d8Tvfp6opnjrr5ygGRsa+2olrfoeMS/h9WZDvzZTHVoWyHsqISYbWdqWr/Fw2SwGyZjTRiR/P+EYxt07AOaxKKorpZ04LVjY+zzoiE5j6x6BvnfPAAeSWpUWZtTJup0nSh/elNnTdK2VoD/qnOsZfP0Z+ozJzmPXT06VavSK0wIqngSI+b6QJ9GOKF7ghJ94YxXg8b3EqmwBQBPE3/hgAR0EVQWqcNLS9yVuBik/dgZSpg86lbu10CLkyeMD7tVkPeQ2xsyBq4eOcdFG1NYfUtcVnCSwstUZ6CJqHL7yN09CaQobmb0pk4TWrld3YaDqI4edtl9/Lsbl34Je84kJlCD0f2CPQlCJu5igfXpfB5YEmt+R2WllkRropOnHhDfbNGZFjTpURLYfhQw+yaComYfHoYHyv9bEDP9nP/H7MsrBnha5kgJKfY8BiiL3fn3iZ3qFIMWYNpszJlY2TOCer47HjlMqcynm9c0czQsOlABeiyTQ3Ac5pWJNIIzIm6HyP1GlmjxJ18omhRBX1pWDxbw3Hf3oT5u37fbaS2J28ehE1vBTB7526103TXmZVPVFjuTaUlvlmxkynG1PGSQRAjePR2AYr9DgR1oxmI/IW/9YoNOZuP7sq+szhvEqPOwg0fBX2TJPt2Dn9oZm+S83UbJHDAAQznTXis/AZ3NLiLnPDKrRlrRoD4g6Z4/EddtzDt9AaWLoKUIS2ZucI1/ouGTJI9g6wWNUwJaNSUkdC057KUeCAOHk="); - - AsymmetricKeyParameter altPubDec = PqcPublicKeyFactory.CreateKey(SubjectPublicKeyInfo.GetInstance(altSubPubEnc)); - Assert.AreEqual(altEncKey, ((DilithiumPublicKeyParameters)altPubDec).GetEncoded()); - + /* + * TODO: Update to new algorithm + byte[] altEncKey = Base64.Decode("oED4ZvqhK4kChPclP5VhOPvvnwof3QeTFq/zR5UtSr6SYicBkpe1TkafnSk5whDHgEp8imVwfeP2LbS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jxJ18omhRBX1pWDxbw3Hf3oT5u37fbaS2J28ehE1vBTB7526103TXmZVPVFjuTaUlvlmxkynG1PGSQRAjePR2AYr9DgR1oxmI/IW/9YoNOZuP7sq+szhvEqPOwg0fBX2TJPt2Dn9oZm+S83UbJHDAAQznTXis/AZ3NLiLnPDKrRlrRoD4g6Z4/EddtzDt9AaWLoKUIS2ZucI1/ouGTJI9g6wWNUwJaNSUkdC057KUeCAOHk="); + + SubjectPublicKeyInfo seq1 = SubjectPublicKeyInfo.GetInstance(altEncKey); + SubjectPublicKeyInfo seq2 = SubjectPublicKeyInfo.GetInstance(altSubPubEnc); + altEncKey = new SubjectPublicKeyInfo(new AlgorithmIdentifier(BCObjectIdentifiers.dilithium2), seq1.PublicKey).GetDerEncoded(); + altSubPubEnc = new SubjectPublicKeyInfo(new AlgorithmIdentifier(BCObjectIdentifiers.dilithium2), seq2.PublicKey).GetDerEncoded(); + AsymmetricKeyParameter altPubDec = PqcPublicKeyFactory.CreateKey(SubjectPublicKeyInfo.GetInstance(altSubPubEnc)); + Assert.AreEqual(altEncKey, ((DilithiumPublicKeyParameters)altPubDec).GetEncoded()); + */ Security.SecureRandom random = new Security.SecureRandom(); DilithiumKeyGenerationParameters kparam = new DilithiumKeyGenerationParameters(random, DilithiumParameters.Dilithium2); DilithiumKeyPairGenerator kpg = new DilithiumKeyPairGenerator(); @@ -65,7 +71,6 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests Assert.AreEqual(((DilithiumPublicKeyParameters)pub).GetEncoded(), ((DilithiumPublicKeyParameters)pubDec).GetEncoded()); Assert.AreEqual(((DilithiumPrivateKeyParameters)priv).GetEncoded(), ((DilithiumPrivateKeyParameters)privDec).GetEncoded()); } - */ private static void RunTestVector(string name, IDictionary<string, string> buf) { |