Skip to content

Commit 62680d4

Browse files
committed
added sha256 test vector
1 parent 9b75148 commit 62680d4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crypto/test/src/crypto/test/OAEPTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Org.BouncyCastle.Crypto.Parameters;
1313
using Org.BouncyCastle.Math;
1414
using Org.BouncyCastle.Security;
15+
using Org.BouncyCastle.Utilities;
1516
using Org.BouncyCastle.Utilities.Encoders;
1617
using Org.BouncyCastle.Utilities.Test;
1718
using Org.BouncyCastle.X509;
@@ -823,6 +824,28 @@ public override void PerformTest()
823824
Fail("mixed digest failed decoding");
824825
}
825826
}
827+
828+
// 2048 bit SHA-256 known answer test
829+
byte[] encPub2048 = Base64.Decode("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvF6kzNRPSUM3klXHq6R7O6TfI9XOe6oK5Mm/wYLMY5tqnVXItOG2fQagKhULQSi7ihUTYBbiffG72LCQVUd4/m+FSJmFdbfQgIjtEanBCC4oE4G5/uKuGh1SGQSsppMQiaJ4g1q12RAruOYp6L94JMnSy5pq3czVtbMfiEskO/FfD+nVAnpQNlrRShn268FB4+6FUiR68nwEdQXTEs20/i9V2BwoHuMmIQyjPoHo3ArEyBEDxACH02nsezb8Kes/rLwW0unjHEyWpw9EnxqaXxDg9z8CNO2IDUYtesNXBdFB/ggz+IdbsEJf0MbsjGz9R2xl2+lSOALsf6FZQOphgQIDAQAB");
830+
byte[] encPri2048 = Base64.Decode("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC8XqTM1E9JQzeSVcerpHs7pN8j1c57qgrkyb/Bgsxjm2qdVci04bZ9BqAqFQtBKLuKFRNgFuJ98bvYsJBVR3j+b4VImYV1t9CAiO0RqcEILigTgbn+4q4aHVIZBKymkxCJoniDWrXZECu45inov3gkydLLmmrdzNW1sx+ISyQ78V8P6dU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EokzhlxXdHdlXr+2UbyHPQZTkFp4Q3AV159nS1gQDhDseNcqO3f7fsPRNCYP0r0rdeikbEQ3FvgthbY4BIQafjJxENhrQqjrgdMShRrAswmniBaRMFrIWP56RnqUsgbDgFSXL7OwvpExyIQhwSy4kTAoGBAN3x9T7UkwdHSAtpETC+9bGmdcbytHr6JElQKH8jM5sS3FKHR7NSGCGIBmYtbwU3GqU/4JUkDH+ASvsgT2KBLW9kj/zQRV6kW9g0O/2LY3RZ6bOvCs8p4LfPRBm6Zy1bm6h51Em62oXHoViYrI3TSmOfCK9nSeErsxt20sUfsLVW");
831+
832+
AsymmetricKeyParameter pub2048 = PublicKeyFactory.CreateKey(encPub2048);
833+
AsymmetricKeyParameter pri2048 = PrivateKeyFactory.CreateKey(encPri2048);
834+
835+
input = Strings.ToByteArray("OAEP SHA-256 Test");
836+
cipher = new OaepEncoding(new RsaEngine(), new Sha256Digest());
837+
838+
cipher.Init(true, new ParametersWithRandom(pub2048, new TestRandomData(encPub2048)));
839+
840+
output = cipher.ProcessBlock(input, 0, input.Length);
841+
842+
Assert.IsTrue(Arrays.AreEqual(Hex.Decode("8314e8dc39bfe75dcf1ecf770233593fd2f564c8bd2d4a4a66da238f8b3b476cbe4ccf40b2f3efdc74fd1fd015da1b7dd41802d9e61199b59d95714ac54b5479dd639d284038865d5a68790901093a6dac7afc086d26d4855b967eb262394eab9f15c3658ba62f90921d6354ce8d59095df761877b3e5e3278be84bae813f632a95042530eac0e28fa84f2a0202dd76529783ee3826c394476f381978dbabe7c08e76de5944b59aec0145ac6b2b75e1d153411ff8dceb18c14263eec5d9c6fc6cdbbd47006bcc0c905aaaf62d3f6b760dce5eb178635bb3fe02eb5772baa30eaa2cc00282830a9adc813611914e96ac1e3fc5c6319233ac65ff2a3c4468bac99"), output));
843+
844+
cipher.Init(false, pri2048);
845+
846+
output = cipher.ProcessBlock(output, 0, output.Length);
847+
848+
Assert.IsTrue(Arrays.AreEqual(input, output));
826849
}
827850

828851
private void TestForHighByteError(string label, int keySizeBits)

0 commit comments

Comments
 (0)