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/aes/AesDecryptBlock192Test.lvt
namespace Livt.Crypto.Tests.Aes
using Livt.Crypto.Aes
@Test
component AesDecryptBlock192Test
{
aes: DecryptBlock192
enc: EncryptBlock192
new()
{
this.aes = new DecryptBlock192()
this.enc = new EncryptBlock192()
}
// NIST FIPS 197 Appendix C.2 AES-192 decryption vector.
// Key: 000102030405060708090a0b0c0d0e0f1011121314151617
// Ciphertext: dda97ca4864cdfe06eaf70a0ec0d7191
// Plaintext: 00112233445566778899aabbccddeeff
// Verify: echo "dda97ca4864cdfe06eaf70a0ec0d7191" | xxd -r -p | openssl enc -d -aes-192-ecb -K 000102030405060708090a0b0c0d0e0f1011121314151617 -nopad 2>/dev/null | xxd -p
@Test
fn TestNistFips197()
{
var key: byte[24] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]
var ciphertext: byte[16] = [
0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91]
this.aes.SetKey(key)
this.aes.LoadBlock(ciphertext)
this.aes.DecryptBlock()
var pt: byte[16] = this.aes.GetBlock()
assert pt[0] == 0x00
assert pt[1] == 0x11
assert pt[2] == 0x22
assert pt[3] == 0x33
assert pt[4] == 0x44
assert pt[5] == 0x55
assert pt[6] == 0x66
assert pt[7] == 0x77
assert pt[8] == 0x88
assert pt[9] == 0x99
assert pt[10] == 0xaa
assert pt[11] == 0xbb
assert pt[12] == 0xcc
assert pt[13] == 0xdd
assert pt[14] == 0xee
assert pt[15] == 0xff
}
// NIST SP 800-38A Appendix F.1.3 AES-192 ECB — block 1 decryption.
// Key: 8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b
// Ciphertext: bd334f1d6e45f25ff712a214571fa5cc
// Plaintext: 6bc1bee22e409f96e93d7e117393172a
// Verify: echo "bd334f1d6e45f25ff712a214571fa5cc" | xxd -r -p | openssl enc -d -aes-192-ecb -K 8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b -nopad 2>/dev/null | xxd -p
@Test
fn TestNistSp80038ABlock1()
{
var key: byte[24] = [
0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b]
var ciphertext: byte[16] = [
0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f,
0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc]
this.aes.SetKey(key)
this.aes.LoadBlock(ciphertext)
this.aes.DecryptBlock()
var pt: byte[16] = this.aes.GetBlock()
assert pt[0] == 0x6b
assert pt[1] == 0xc1
assert pt[2] == 0xbe
assert pt[3] == 0xe2
assert pt[4] == 0x2e
assert pt[5] == 0x40
assert pt[6] == 0x9f
assert pt[7] == 0x96
assert pt[8] == 0xe9
assert pt[9] == 0x3d
assert pt[10] == 0x7e
assert pt[11] == 0x11
assert pt[12] == 0x73
assert pt[13] == 0x93
assert pt[14] == 0x17
assert pt[15] == 0x2a
}
// All-zero 192-bit key: decrypt aae06992acbf52a3e8f4a96ec9300bd7 → all zeros.
// Verify: echo "aae06992acbf52a3e8f4a96ec9300bd7" | xxd -r -p | openssl enc -d -aes-192-ecb -K 000000000000000000000000000000000000000000000000 -nopad 2>/dev/null | xxd -p
@Test
fn TestAllZeroKeyAndCiphertext()
{
var key: byte[24] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
var ciphertext: byte[16] = [
0xaa, 0xe0, 0x69, 0x92, 0xac, 0xbf, 0x52, 0xa3,
0xe8, 0xf4, 0xa9, 0x6e, 0xc9, 0x30, 0x0b, 0xd7]
this.aes.SetKey(key)
this.aes.LoadBlock(ciphertext)
this.aes.DecryptBlock()
var pt: byte[16] = this.aes.GetBlock()
assert pt[0] == 0x00
assert pt[1] == 0x00
assert pt[2] == 0x00
assert pt[3] == 0x00
assert pt[4] == 0x00
assert pt[5] == 0x00
assert pt[6] == 0x00
assert pt[7] == 0x00
assert pt[8] == 0x00
assert pt[9] == 0x00
assert pt[10] == 0x00
assert pt[11] == 0x00
assert pt[12] == 0x00
assert pt[13] == 0x00
assert pt[14] == 0x00
assert pt[15] == 0x00
}
// User behaviour: encrypt a block then decrypt the result — must recover the
// original plaintext. Uses the NIST FIPS 197 Appendix C.2 key.
@Test
fn TestEncryptDecryptRoundtrip()
{
var key: byte[24] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]
var plaintext: byte[16] = [
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]
this.enc.SetKey(key)
this.enc.LoadBlock(plaintext)
this.enc.EncryptBlock()
var ciphertext: byte[16] = this.enc.GetBlock()
this.aes.SetKey(key)
this.aes.LoadBlock(ciphertext)
this.aes.DecryptBlock()
var recovered: byte[16] = this.aes.GetBlock()
assert recovered[0] == 0x00
assert recovered[1] == 0x11
assert recovered[2] == 0x22
assert recovered[3] == 0x33
assert recovered[4] == 0x44
assert recovered[5] == 0x55
assert recovered[6] == 0x66
assert recovered[7] == 0x77
assert recovered[8] == 0x88
assert recovered[9] == 0x99
assert recovered[10] == 0xaa
assert recovered[11] == 0xbb
assert recovered[12] == 0xcc
assert recovered[13] == 0xdd
assert recovered[14] == 0xee
assert recovered[15] == 0xff
}
}