2019-11-25 21:11:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
using LibHac.Crypto;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.CryptoTests;
|
|
|
|
|
|
|
|
|
|
public class Sha256Tests
|
2019-11-25 21:11:40 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static HashTestVector[] TestVectors =
|
|
|
|
|
RspReader.ReadHashTestVectorsArray("SHA256ShortMsg.rsp", "SHA256LongMsg.rsp");
|
2021-07-14 08:53:33 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public static void Encrypt()
|
|
|
|
|
{
|
|
|
|
|
foreach (HashTestVector tv in TestVectors)
|
2021-07-14 08:53:33 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Common.HashTestCore(tv.Message.AsSpan(0, tv.LengthBytes), tv.Digest, Sha256.CreateSha256Generator());
|
2021-07-14 08:53:33 +02:00
|
|
|
|
}
|
2021-11-14 20:08:57 +01:00
|
|
|
|
}
|
2021-07-14 08:53:33 +02:00
|
|
|
|
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// The above tests run all the test vectors in a single test to avoid having thousands of tests.
|
|
|
|
|
// Use the below tests if running each test vector as an individual test is needed.
|
2021-07-14 08:53:33 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2021-07-14 08:53:33 +02:00
|
|
|
|
|
|
|
|
|
#pragma warning disable xUnit1013 // Public method should be marked as test
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static TheoryData<HashTestVector> TestVectors_Individual =
|
|
|
|
|
RspReader.ReadHashTestVectors("SHA256ShortMsg.rsp", "SHA256LongMsg.rsp");
|
2019-11-25 21:11:40 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
//[Theory, MemberData(nameof(TestVectors_Individual))]
|
|
|
|
|
public static void Encrypt_Individual(HashTestVector tv)
|
|
|
|
|
{
|
|
|
|
|
Common.HashTestCore(tv.Message.AsSpan(0, tv.LengthBytes), tv.Digest, Sha256.CreateSha256Generator());
|
2019-11-25 21:11:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|