Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
aes128.test.cpp File Reference

Go to the source code of this file.

Classes

class  StdlibAes128< Builder >
 

Typedefs

using BuilderTypes = ::testing::Types< bb::UltraCircuitBuilder, bb::MegaCircuitBuilder >
 

Functions

 TYPED_TEST_SUITE (StdlibAes128, BuilderTypes)
 
template<class Builder >
stdlib::field_t< Buildercreate_field_element (Builder &builder, const uint256_t &value, bool as_witness)
 
template<class Builder >
void test_aes128_combination (bool key_as_witness, bool iv_as_witness, bool input_as_witness)
 
template<class Builder >
void test_aes128_mixed_input (bool key_as_witness, bool iv_as_witness, const std::vector< bool > &input_block_config)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_all_witness)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_all_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_witness_iv_constant_input_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_constant_iv_witness_input_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_constant_iv_constant_input_witness)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_witness_iv_witness_input_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_witness_iv_constant_input_witness)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_key_constant_iv_witness_input_witness)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_original)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_first_witness_rest_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_alternating_witness_constant)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_first_constant_rest_witness)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_key_witness_mixed_blocks)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_iv_witness_mixed_blocks)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_key_iv_witness_mixed_blocks)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_all_witness_blocks)
 
 TYPED_TEST (StdlibAes128, encrypt_64_bytes_mixed_input_all_constant_blocks)
 
 TEST (stdlib_aes128_sparse, sparse_form_roundtrip)
 Test that sparse form correctly represents bytes.
 
 TEST (stdlib_aes128_sparse, sparse_addition_equals_xor_native)
 Test that addition of sparse forms equals XOR after normalization (native)
 
 TEST (stdlib_aes128_sparse, sparse_form_lookup_table)
 Test that when using AES input table, sparse form is correctly applied to the input bytes.
 
 TEST (stdlib_aes128_sparse, sparse_xor_circuit)
 Test sparse XOR in circuit using plookup normalization.
 
 TEST (stdlib_aes128_sparse, sparse_multi_xor_circuit)
 Test multi-way XOR via sparse form (a XOR b XOR c)
 
 TEST (stdlib_aes128_sparse, sparse_addition_limit)
 Test the maximum number of additions before overflow.
 
 TEST (stdlib_aes128_sparse, sparse_addition_overflow)
 Test the minimum number of additions with overflow.
 

Variables

constexpr uint64_t AES_SPARSE_BASE = 9
 

Typedef Documentation

◆ BuilderTypes

Definition at line 19 of file aes128.test.cpp.

Function Documentation

◆ create_field_element()

template<class Builder >
stdlib::field_t< Builder > create_field_element ( Builder builder,
const uint256_t value,
bool  as_witness 
)

Definition at line 24 of file aes128.test.cpp.

◆ TEST() [1/7]

TEST ( stdlib_aes128_sparse  ,
sparse_addition_equals_xor_native   
)

Test that addition of sparse forms equals XOR after normalization (native)

This tests the mathematical property without circuit constraints.

Definition at line 328 of file aes128.test.cpp.

◆ TEST() [2/7]

TEST ( stdlib_aes128_sparse  ,
sparse_addition_limit   
)

Test the maximum number of additions before overflow.

With base-9, each digit can hold values 0-8 before overflowing. This means we can safely add up to 8 sparse bytes (each with digits 0 or 1) before normalization is required.

Definition at line 523 of file aes128.test.cpp.

◆ TEST() [3/7]

TEST ( stdlib_aes128_sparse  ,
sparse_addition_overflow   
)

Test the minimum number of additions with overflow.

With base-9, each digit can hold values 0-8 before overflowing. This means we need to add 9 sparse bytes (each with digits 0 or 1) to overflow.

Definition at line 571 of file aes128.test.cpp.

◆ TEST() [4/7]

TEST ( stdlib_aes128_sparse  ,
sparse_form_lookup_table   
)

Test that when using AES input table, sparse form is correctly applied to the input bytes.

Parameters
builderThe circuit builder to use
inputThe input bytes to test
expectedThe expected sparse form of the input bytes
Returns
True if the test passes, false otherwise

Definition at line 381 of file aes128.test.cpp.

◆ TEST() [5/7]

TEST ( stdlib_aes128_sparse  ,
sparse_form_roundtrip   
)

Test that sparse form correctly represents bytes.

Verifies map_into_sparse_form and map_from_sparse_form are inverses.

Definition at line 313 of file aes128.test.cpp.

◆ TEST() [6/7]

TEST ( stdlib_aes128_sparse  ,
sparse_multi_xor_circuit   
)

Test multi-way XOR via sparse form (a XOR b XOR c)

In AES, we often XOR multiple values together (e.g., in AddRoundKey, MixColumns). Sparse form allows accumulating multiple additions before normalizing.

Definition at line 476 of file aes128.test.cpp.

◆ TEST() [7/7]

TEST ( stdlib_aes128_sparse  ,
sparse_xor_circuit   
)

Test sparse XOR in circuit using plookup normalization.

This tests the actual circuit operation used in AES.

Definition at line 431 of file aes128.test.cpp.

◆ test_aes128_combination()

template<class Builder >
void test_aes128_combination ( bool  key_as_witness,
bool  iv_as_witness,
bool  input_as_witness 
)

Definition at line 44 of file aes128.test.cpp.

◆ test_aes128_mixed_input()

template<class Builder >
void test_aes128_mixed_input ( bool  key_as_witness,
bool  iv_as_witness,
const std::vector< bool > &  input_block_config 
)

Definition at line 100 of file aes128.test.cpp.

◆ TYPED_TEST() [1/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_all_constant   
)

Definition at line 161 of file aes128.test.cpp.

◆ TYPED_TEST() [2/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_all_witness   
)

Definition at line 156 of file aes128.test.cpp.

◆ TYPED_TEST() [3/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_constant_iv_constant_input_witness   
)

Definition at line 176 of file aes128.test.cpp.

◆ TYPED_TEST() [4/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_constant_iv_witness_input_constant   
)

Definition at line 171 of file aes128.test.cpp.

◆ TYPED_TEST() [5/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_constant_iv_witness_input_witness   
)

Definition at line 191 of file aes128.test.cpp.

◆ TYPED_TEST() [6/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_witness_iv_constant_input_constant   
)

Definition at line 166 of file aes128.test.cpp.

◆ TYPED_TEST() [7/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_witness_iv_constant_input_witness   
)

Definition at line 186 of file aes128.test.cpp.

◆ TYPED_TEST() [8/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_key_witness_iv_witness_input_constant   
)

Definition at line 181 of file aes128.test.cpp.

◆ TYPED_TEST() [9/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_all_constant_blocks   
)

Definition at line 287 of file aes128.test.cpp.

◆ TYPED_TEST() [10/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_all_witness_blocks   
)

Definition at line 282 of file aes128.test.cpp.

◆ TYPED_TEST() [11/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_alternating_witness_constant   
)

Definition at line 257 of file aes128.test.cpp.

◆ TYPED_TEST() [12/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_first_constant_rest_witness   
)

Definition at line 262 of file aes128.test.cpp.

◆ TYPED_TEST() [13/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_first_witness_rest_constant   
)

Definition at line 252 of file aes128.test.cpp.

◆ TYPED_TEST() [14/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_iv_witness_mixed_blocks   
)

Definition at line 272 of file aes128.test.cpp.

◆ TYPED_TEST() [15/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_key_iv_witness_mixed_blocks   
)

Definition at line 277 of file aes128.test.cpp.

◆ TYPED_TEST() [16/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_mixed_input_key_witness_mixed_blocks   
)

Definition at line 267 of file aes128.test.cpp.

◆ TYPED_TEST() [17/17]

TYPED_TEST ( StdlibAes128  ,
encrypt_64_bytes_original   
)

Definition at line 197 of file aes128.test.cpp.

◆ TYPED_TEST_SUITE()

TYPED_TEST_SUITE ( StdlibAes128  ,
BuilderTypes   
)

Variable Documentation

◆ AES_SPARSE_BASE

constexpr uint64_t AES_SPARSE_BASE = 9
constexpr

Definition at line 306 of file aes128.test.cpp.