LibHac/tests/LibHac.Tests/CryptoTests/RsaTests.cs

130 lines
8.9 KiB
C#
Raw Permalink Normal View History

using System.Security.Cryptography;
using LibHac.Crypto;
using Xunit;
namespace LibHac.Tests.CryptoTests
{
public class RsaTests
{
[Fact]
public void RecoverRsaParameters_ReturnsCorrectParameters()
{
RSAParameters rsaParams = Rsa.RecoverParameters(Modulus, PublicExponent, PrivateExponent);
Assert.Equal(PrivateExponent, rsaParams.D);
Assert.Equal(ExpectedDp, rsaParams.DP);
Assert.Equal(ExpectedDq, rsaParams.DQ);
Assert.Equal(PublicExponent, rsaParams.Exponent);
Assert.Equal(ExpectedInverseQ, rsaParams.InverseQ);
Assert.Equal(Modulus, rsaParams.Modulus);
Assert.Equal(ExpectedP, rsaParams.P);
Assert.Equal(ExpectedQ, rsaParams.Q);
}
public readonly byte[] Modulus =
{
0xAD, 0x58, 0xEE, 0x97, 0xF9, 0x47, 0x90, 0x7D, 0xF9, 0x29, 0x5F, 0x1F, 0x39, 0x68, 0xEE, 0x49,
0x4C, 0x1E, 0x8D, 0x84, 0x91, 0x31, 0x5D, 0xE5, 0x96, 0x27, 0xB2, 0xB3, 0x59, 0x7B, 0xDE, 0xFD,
0xB7, 0xEB, 0x40, 0xA1, 0xE7, 0xEB, 0xDC, 0x60, 0xD0, 0x3D, 0xC5, 0x50, 0x92, 0xAD, 0x3D, 0xC4,
0x8C, 0x17, 0xD2, 0x37, 0x66, 0xE3, 0xF7, 0x14, 0x34, 0x38, 0x6B, 0xA7, 0x2B, 0x21, 0x10, 0x9B,
0x73, 0x49, 0x15, 0xD9, 0x2A, 0x90, 0x86, 0x76, 0x81, 0x6A, 0x10, 0xBD, 0x74, 0xC4, 0x20, 0x55,
0x25, 0xA8, 0x02, 0xC5, 0xA0, 0x34, 0x36, 0x7B, 0x66, 0x47, 0x2C, 0x7E, 0x47, 0x82, 0xA5, 0xD4,
0xA3, 0x42, 0x45, 0xE8, 0xFD, 0x65, 0x72, 0x48, 0xA1, 0xB0, 0x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CB, 0x2F, 0x2C, 0x90, 0xE6, 0x4B, 0x2D, 0x94, 0x62, 0xE8, 0xEC, 0x54, 0x7B, 0x94, 0xB7,
0xFB, 0x72, 0x05, 0xFB, 0xB3, 0x23, 0xCA, 0xF8, 0xD4, 0x5C, 0xF6, 0xAC, 0x7D, 0xEC, 0x47, 0xC6,
0xD3, 0x22, 0x5D, 0x7C, 0x15, 0xDD, 0x48, 0xE9, 0xBF, 0xA8, 0x99, 0x33, 0x02, 0x79, 0xD3, 0x65
};
public readonly byte[] PublicExponent =
{
0x01, 0x00, 0x01
};
public readonly byte[] ExpectedDp =
{
0x80, 0x1f, 0x3e, 0xe6, 0xed, 0xa2, 0xff, 0x60, 0x0e, 0xc3, 0xb7, 0xf3, 0xed, 0x73, 0x95, 0x05,
0x6d, 0x1f, 0x8a, 0xab, 0x14, 0x42, 0xa0, 0x21, 0x07, 0xe9, 0x92, 0xc7, 0x38, 0x26, 0x84, 0x60,
0xf9, 0xb3, 0x54, 0xad, 0x13, 0xf0, 0xc7, 0xd5, 0xfb, 0xac, 0xe2, 0x40, 0x68, 0x65, 0xf5, 0xb8,
0xc7, 0x4f, 0xd1, 0x58, 0xd6, 0xd2, 0x19, 0x26, 0x0a, 0xdb, 0x39, 0x2d, 0x23, 0xdd, 0x6f, 0x52,
0x48, 0xf2, 0x5d, 0x86, 0xa8, 0xe5, 0x38, 0x6c, 0x7e, 0xa4, 0x99, 0x1a, 0x40, 0xbf, 0x88, 0x11,
0x38, 0x08, 0x64, 0xff, 0xb7, 0xe9, 0x4c, 0x4d, 0xae, 0x2c, 0xfe, 0xb0, 0xe6, 0x66, 0x63, 0x14,
0x26, 0x85, 0x88, 0xe6, 0xc4, 0xe2, 0xe9, 0x15, 0xfa, 0xbb, 0xd1, 0x58, 0x70, 0x73, 0xe2, 0xbb,
0x3d, 0x4d, 0x28, 0x8b, 0xa9, 0x04, 0x7c, 0x16, 0xc6, 0xd1, 0x8e, 0x5b, 0x6b, 0xad, 0x4d, 0xdb
};
public readonly byte[] ExpectedDq =
{
0x84, 0x03, 0x42, 0x57, 0x72, 0xa5, 0x7a, 0x5a, 0x71, 0x1e, 0xb6, 0xba, 0x94, 0xd1, 0xfe, 0xea,
0x91, 0x2f, 0xce, 0x75, 0x22, 0xb3, 0x0a, 0xd1, 0x39, 0xce, 0xab, 0xe2, 0xee, 0x14, 0xa4, 0x24,
0xc2, 0x12, 0x74, 0xdd, 0xa8, 0x4d, 0xae, 0x2f, 0x99, 0xd7, 0x34, 0x2e, 0x5a, 0xe9, 0xfc, 0x5e,
0x69, 0xdf, 0xfb, 0xcb, 0x63, 0x91, 0x80, 0xbe, 0x00, 0x4d, 0x93, 0x8b, 0x24, 0x64, 0xd5, 0x24,
0x9a, 0x40, 0xea, 0xef, 0x25, 0x49, 0x14, 0xe6, 0xca, 0xb0, 0xae, 0xc4, 0xb4, 0x7d, 0x0e, 0x4f,
0xf4, 0x76, 0x00, 0xb6, 0x12, 0xc0, 0x7f, 0x86, 0x2b, 0xbb, 0xd8, 0x91, 0xcd, 0x49, 0x32, 0xad,
0x52, 0x11, 0x9c, 0x56, 0x7a, 0x28, 0xc6, 0x97, 0x80, 0x3e, 0xfa, 0xb1, 0x34, 0x9e, 0xb2, 0xb8,
0x1d, 0x16, 0xee, 0xa9, 0x22, 0xdc, 0x77, 0x5a, 0xde, 0x0b, 0xeb, 0xeb, 0x4e, 0xe8, 0x03, 0x41
};
public readonly byte[] ExpectedInverseQ =
{
0xb5, 0x71, 0x24, 0x42, 0xf4, 0x4c, 0xbd, 0xe2, 0x27, 0x6a, 0x22, 0x32, 0x9f, 0xe6, 0x88, 0x3e,
0xcf, 0xc8, 0x5d, 0x15, 0x04, 0x2c, 0x88, 0xac, 0x4f, 0xb9, 0xf1, 0x70, 0xef, 0x04, 0x07, 0xb4,
0x51, 0xd6, 0xab, 0x48, 0xa2, 0x70, 0x0b, 0xbc, 0xb9, 0xd9, 0xbc, 0xd8, 0x81, 0x29, 0x80, 0x6e,
0x0e, 0xab, 0xa0, 0x8a, 0x39, 0x62, 0x8f, 0x8e, 0x4b, 0xc3, 0xc9, 0x19, 0x64, 0x3b, 0x58, 0x9e,
0x94, 0x3c, 0xab, 0xfd, 0x53, 0xe1, 0xc0, 0xc6, 0x0f, 0x20, 0x30, 0x76, 0x16, 0xd1, 0xf0, 0xc6,
0x1d, 0x94, 0x58, 0xd3, 0x4b, 0xe8, 0x5e, 0x73, 0x02, 0x54, 0x88, 0x02, 0xc6, 0x8d, 0x62, 0xfd,
0xf1, 0x56, 0x35, 0x06, 0x81, 0x57, 0x79, 0x00, 0xc1, 0x7c, 0x9e, 0xd3, 0x61, 0x81, 0x65, 0xae,
0x70, 0x56, 0x24, 0x32, 0xfc, 0x92, 0x17, 0xc4, 0xed, 0x09, 0x27, 0xe3, 0x40, 0xc5, 0xfe, 0xe4
};
public readonly byte[] ExpectedP =
{
0xd2, 0x96, 0x44, 0xee, 0x2c, 0x8e, 0x97, 0x24, 0x83, 0x7c, 0xf0, 0x59, 0xeb, 0x8a, 0xa0, 0x24,
0xca, 0x2b, 0xd9, 0x92, 0x51, 0xf2, 0xa9, 0x33, 0x5b, 0x5f, 0x53, 0xf0, 0x53, 0xcf, 0x5c, 0xd0,
0xf5, 0x56, 0x73, 0xf1, 0x22, 0x64, 0xa1, 0xb5, 0x6e, 0x36, 0x22, 0xde, 0xf8, 0xa6, 0xa9, 0x3e,
0xff, 0x3d, 0x63, 0xb8, 0x1e, 0x52, 0xb5, 0x0a, 0xfc, 0x3d, 0x46, 0xbf, 0xa1, 0x26, 0x20, 0x1c,
0xeb, 0x4c, 0x66, 0x31, 0x84, 0x47, 0x46, 0x55, 0x5f, 0x4e, 0x06, 0x7a, 0x2a, 0x86, 0xf9, 0x7c,
0xf5, 0xe9, 0x3d, 0x6c, 0xaf, 0x06, 0xb5, 0xef, 0x2e, 0x81, 0xd6, 0xad, 0x7f, 0xa6, 0xe5, 0x01,
0x77, 0xbb, 0x52, 0xe8, 0x8b, 0x83, 0x4d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