Livt packages

Livt.Crypto

Version 1.0.5

Fixed-size cryptographic components for Livt, including AES, ChaCha20, SHA, MACs, and key derivation.

Published files (69)

tests/internal/AesSBoxTest.lvt

namespace Livt.Crypto.Tests.Internal
using Livt.Crypto.Internal



@Test
component AesSBoxTest
{
    new() {}

    // First and last entries of the 0x00–0x3F input range.
    // S[0x00] = 0x63, S[0x3F] = 0x75 per NIST FIPS 197 Table 4.
    // Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf
    @Test
    fn TestSubstituteQ0Boundaries()
    {
        var r0: byte = AesSBox.Substitute(0x00)
        var r1: byte = AesSBox.Substitute(0x3f)
        assert r0 == 0x63
        assert r1 == 0x75
    }

    // First and last entries of the 0x40–0x7F input range.
    // S[0x40] = 0x09, S[0x7F] = 0xD2 per NIST FIPS 197 Table 4.
    // Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf
    @Test
    fn TestSubstituteQ1Boundaries()
    {
        var r0: byte = AesSBox.Substitute(0x40)
        var r1: byte = AesSBox.Substitute(0x7f)
        assert r0 == 0x09
        assert r1 == 0xd2
    }

    // First and last entries of the 0x80–0xBF input range.
    // S[0x80] = 0xCD, S[0xBF] = 0x08 per NIST FIPS 197 Table 4.
    // Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf
    @Test
    fn TestSubstituteQ2Boundaries()
    {
        var r0: byte = AesSBox.Substitute(0x80)
        var r1: byte = AesSBox.Substitute(0xbf)
        assert r0 == 0xcd
        assert r1 == 0x08
    }

    // First and last entries of the 0xC0–0xFF input range.
    // S[0xC0] = 0xBA, S[0xFF] = 0x16 per NIST FIPS 197 Table 4.
    // Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf
    @Test
    fn TestSubstituteQ3Boundaries()
    {
        var r0: byte = AesSBox.Substitute(0xc0)
        var r1: byte = AesSBox.Substitute(0xff)
        assert r0 == 0xba
        assert r1 == 0x16
    }
}