LibHac/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs

77 lines
3 KiB
C#
Raw Normal View History

2019-11-19 02:31:06 +01:00
using LibHac.Crypto;
2019-11-09 08:32:13 +01:00
using Xunit;
namespace LibHac.Tests.CryptoTests
{
public class AesCbcTests
{
public static TheoryData<EncryptionTestVector> EncryptTestVectors =
2019-11-25 21:11:40 +01:00
RspReader.ReadEncryptionTestVectors(true, "CBCVarKey128.rsp", "CBCVarTxt128.rsp", "CBCKeySbox128.rsp", "CBCGFSbox128.rsp");
2019-11-09 08:32:13 +01:00
public static TheoryData<EncryptionTestVector> DecryptTestVectors =
2019-11-25 21:11:40 +01:00
RspReader.ReadEncryptionTestVectors(false, "CBCVarKey128.rsp", "CBCVarTxt128.rsp", "CBCKeySbox128.rsp", "CBCGFSbox128.rsp");
2019-11-09 08:32:13 +01:00
public static TheoryData<EncryptionTestVector> EncryptMultiTestVectors =
2019-11-25 21:11:40 +01:00
RspReader.ReadEncryptionTestVectors(true, "CBCMMT128.rsp");
2019-11-09 08:32:13 +01:00
public static TheoryData<EncryptionTestVector> DecryptMultiTestVectors =
2019-11-25 21:11:40 +01:00
RspReader.ReadEncryptionTestVectors(false, "CBCMMT128.rsp");
2019-11-09 08:32:13 +01:00
[Theory]
[MemberData(nameof(EncryptTestVectors))]
public static void Encrypt(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv, true));
2019-11-09 08:32:13 +01:00
}
[Theory]
[MemberData(nameof(DecryptTestVectors))]
public static void Decrypt(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv, true));
2019-11-09 08:32:13 +01:00
}
[Theory]
[MemberData(nameof(EncryptMultiTestVectors))]
public static void EncryptMulti(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv, true));
2019-11-09 08:32:13 +01:00
}
[Theory]
[MemberData(nameof(DecryptMultiTestVectors))]
public static void DecryptMulti(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv, true));
2019-11-09 08:32:13 +01:00
}
[AesIntrinsicsRequiredTheory]
[MemberData(nameof(EncryptTestVectors))]
public static void EncryptIntrinsics(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv));
2019-11-09 08:32:13 +01:00
}
[AesIntrinsicsRequiredTheory]
[MemberData(nameof(DecryptTestVectors))]
public static void DecryptIntrinsics(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv));
2019-11-09 08:32:13 +01:00
}
[AesIntrinsicsRequiredTheory]
[MemberData(nameof(EncryptMultiTestVectors))]
public static void EncryptMultiIntrinsics(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv));
2019-11-09 08:32:13 +01:00
}
[AesIntrinsicsRequiredTheory]
[MemberData(nameof(DecryptMultiTestVectors))]
public static void DecryptMultiIntrinsics(EncryptionTestVector tv)
{
2019-11-19 02:20:21 +01:00
Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv));
2019-11-09 08:32:13 +01:00
}
}
}