diff options
author | mw <megan@cryptoworkshop.com> | 2020-10-29 10:22:06 +1100 |
---|---|---|
committer | mw <megan@cryptoworkshop.com> | 2020-10-29 10:22:06 +1100 |
commit | 6536ed9e332d54431d00913685c02a3cf6bb287f (patch) | |
tree | 744309bd6f1c09c2268714bcabf422bb41375f0d /crypto/test/src/asn1 | |
parent | Added CSHAKEDigest, KMac, removed unused import from NewTspTest (diff) | |
download | BouncyCastle.NET-ed25519-6536ed9e332d54431d00913685c02a3cf6bb287f.tar.xz |
Added KMAC Params and test
Diffstat (limited to 'crypto/test/src/asn1')
-rw-r--r-- | crypto/test/src/asn1/test/KMacParamsTest.cs | 84 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/RegressionTest.cs | 45 |
2 files changed, 107 insertions, 22 deletions
diff --git a/crypto/test/src/asn1/test/KMacParamsTest.cs b/crypto/test/src/asn1/test/KMacParamsTest.cs new file mode 100644 index 000000000..1c080f755 --- /dev/null +++ b/crypto/test/src/asn1/test/KMacParamsTest.cs @@ -0,0 +1,84 @@ +using NUnit.Framework; +using Org.BouncyCastle.Asn1.Nist; +using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Utilities.Test; + +namespace Org.BouncyCastle.Asn1.Tests +{ + [TestFixture] + public class KMacParamsTest :SimpleTest + { + public override string Name => "KMacParamsTest"; + + + public override void PerformTest() + { + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(256).GetEncoded(), new DerSequence().GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(512).GetEncoded(), new DerSequence().GetEncoded())); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(512).GetEncoded(), new DerSequence(new DerInteger(512)).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(256).GetEncoded(), new DerSequence(new DerInteger(256)).GetEncoded())); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(512).GetEncoded(), KMACwithSHAKE128_params.getInstance(new DerSequence(new DerInteger(512))).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(256).GetEncoded(), KMACwithSHAKE256_params.getInstance(new DerSequence(new DerInteger(256))).GetEncoded())); + + byte[] customizationString = Strings.ToByteArray("hello, world!"); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(512, customizationString).GetEncoded(), new DerSequence( + new Asn1Encodable[] { new DerInteger(512), new DerOctetString(customizationString) }).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(256, customizationString).GetEncoded(), new DerSequence( + new Asn1Encodable[] { new DerInteger(256), new DerOctetString(customizationString) }).GetEncoded())); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(512, customizationString).GetEncoded(), + KMACwithSHAKE128_params.getInstance( + new DerSequence(new Asn1Encodable[] { new DerInteger(512), new DerOctetString(customizationString) })).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(256, customizationString).GetEncoded(), + KMACwithSHAKE256_params.getInstance(new DerSequence( + new Asn1Encodable[] { new DerInteger(256), new DerOctetString(customizationString) })).GetEncoded())); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(256, customizationString).GetEncoded(), new DerSequence( + new Asn1Encodable[] { new DerOctetString(customizationString) }).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(512, customizationString).GetEncoded(), new DerSequence( + new Asn1Encodable[] { new DerOctetString(customizationString) }).GetEncoded())); + + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE128_params(256, customizationString).GetEncoded(), + KMACwithSHAKE128_params.getInstance( + new DerSequence(new Asn1Encodable[] { new DerOctetString(customizationString) })).GetEncoded())); + Assert.IsTrue(Arrays.AreEqual(new KMACwithSHAKE256_params(512, customizationString).GetEncoded(), + KMACwithSHAKE256_params.getInstance(new DerSequence( + new Asn1Encodable[] { new DerOctetString(customizationString) })).GetEncoded())); + + KMACwithSHAKE128_params p128 = new KMACwithSHAKE128_params(256, customizationString); + Assert.AreEqual(256, p128.OutputLength); + Assert.IsTrue(Arrays.AreEqual(customizationString, p128.CustomizationString)); + Assert.IsTrue(p128 == KMACwithSHAKE128_params.getInstance(p128)); + + KMACwithSHAKE256_params p256 = new KMACwithSHAKE256_params(512, customizationString); + Assert.AreEqual(512, p256.OutputLength); + Assert.IsTrue(Arrays.AreEqual(customizationString, p256.CustomizationString)); + Assert.IsTrue(p256 == KMACwithSHAKE256_params.getInstance(p256)); + + p128 = new KMACwithSHAKE128_params(512); + Assert.AreEqual(512, p128.OutputLength); + Assert.IsTrue(Arrays.AreEqual(new byte[0], p128.CustomizationString)); + + p256 = new KMACwithSHAKE256_params(256); + Assert.AreEqual(256, p256.OutputLength); + Assert.IsTrue(Arrays.AreEqual(new byte[0], p256.CustomizationString)); + } + + public static void Main( + string[] args) + { + RunTest(new KMacParamsTest()); + } + + [Test] + public void TestFunction() + { + string resultText = Perform().ToString(); + + Assert.AreEqual(resultText, Name + ": Okay", resultText); + } + } +} diff --git a/crypto/test/src/asn1/test/RegressionTest.cs b/crypto/test/src/asn1/test/RegressionTest.cs index 67860ccd7..cf10c6c3b 100644 --- a/crypto/test/src/asn1/test/RegressionTest.cs +++ b/crypto/test/src/asn1/test/RegressionTest.cs @@ -6,20 +6,20 @@ namespace Org.BouncyCastle.Asn1.Tests { public class RegressionTest { - public static readonly ITest[] tests = - { + public static readonly ITest[] tests = + { new AdditionalInformationSyntaxUnitTest(), new AdmissionSyntaxUnitTest(), new AdmissionsUnitTest(), - new Asn1IntegerTest(), + new Asn1IntegerTest(), new AttributeTableUnitTest(), - new BiometricDataUnitTest(), - new BitStringTest(), + new BiometricDataUnitTest(), + new BitStringTest(), new CertHashUnitTest(), new CertificateTest(), - new CmsTest(), - new CommitmentTypeIndicationUnitTest(), - new CommitmentTypeQualifierUnitTest(), + new CmsTest(), + new CommitmentTypeIndicationUnitTest(), + new CommitmentTypeQualifierUnitTest(), new ContentHintsUnitTest(), new CscaMasterListTest(), new DataGroupHashUnitTest(), @@ -27,33 +27,33 @@ namespace Org.BouncyCastle.Asn1.Tests new DerApplicationSpecificTest(), new DerUtf8StringTest(), new EncryptedPrivateKeyInfoTest(), - new EqualsAndHashCodeTest(), + new EqualsAndHashCodeTest(), new EssCertIDv2UnitTest(), - new GeneralizedTimeTest(), + new GeneralizedTimeTest(), new GeneralNameTest(), new GenerationTest(), new InputStreamTest(), - new Iso4217CurrencyCodeUnitTest(), + new Iso4217CurrencyCodeUnitTest(), new IssuingDistributionPointUnitTest(), new KeyUsageTest(), - new LDSSecurityObjectUnitTest(), - new LinkedCertificateTest(), - new MiscTest(), + new LDSSecurityObjectUnitTest(), + new LinkedCertificateTest(), + new MiscTest(), new MonetaryLimitUnitTest(), new MonetaryValueUnitTest(), new NameOrPseudonymUnitTest(), new NamingAuthorityUnitTest(), new NetscapeCertTypeTest(), - new OcspTest(), - new OidTest(), + new OcspTest(), + new OidTest(), new OtherCertIDUnitTest(), new OtherSigningCertificateUnitTest(), new ParsingTest(), new PersonalDataUnitTest(), new Pkcs10Test(), - new Pkcs12Test(), + new Pkcs12Test(), new PkiFailureInfoTest(), - new PrivateKeyInfoTest(), + new PrivateKeyInfoTest(), new ProcurationSyntaxUnitTest(), new ProfessionInfoUnitTest(), new QCStatementUnitTest(), @@ -61,9 +61,9 @@ namespace Org.BouncyCastle.Asn1.Tests new RequestedCertificateUnitTest(), new RestrictionUnitTest(), new SemanticsInformationUnitTest(), - new SetTest(), - new SignerLocationUnitTest(), - new SmimeTest(), + new SetTest(), + new SignerLocationUnitTest(), + new SmimeTest(), new StringTest(), new SubjectKeyIdentifierTest(), new TagTest(), @@ -72,7 +72,8 @@ namespace Org.BouncyCastle.Asn1.Tests new UtcTimeTest(), new X509ExtensionsTest(), new X509NameTest(), - new X9Test(), + new X9Test(), + new KMacParamsTest() }; public static void Main( |