Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update aes128_encrypt to return an array #6973

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
fail-fast: false
matrix:
include:
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, is_library: true }
# - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, is_library: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset, take_average: true }
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/acir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ impl<F: AcirField, B: BlackBoxFunctionSolver<F>> AcirContext<F, B> {
}
}?;
output_count = input_size + (16 - input_size % 16);
(vec![], vec![F::from(output_count as u128)])
(vec![], vec![])
}
BlackBoxFunc::RecursiveAggregation => {
let proof_type_var = match inputs.pop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,14 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
BlackBoxFunc::AES128Encrypt => {
if let (
[inputs, BrilligVariable::BrilligArray(iv), BrilligVariable::BrilligArray(key)],
[BrilligVariable::SingleAddr(out_len), BrilligVariable::BrilligVector(outputs)],
[outputs],
) = (function_arguments, function_results)
{
let inputs = convert_array_or_vector(brillig_context, *inputs, bb_func);
let iv = brillig_context.codegen_brillig_array_to_heap_array(*iv);
let key = brillig_context.codegen_brillig_array_to_heap_array(*key);

let outputs_vector =
brillig_context.codegen_brillig_vector_to_heap_vector(*outputs);
let outputs_vector = convert_array_or_vector(brillig_context, *outputs, bb_func);

brillig_context.black_box_op_instruction(BlackBoxOp::AES128Encrypt {
inputs,
Expand All @@ -372,11 +371,6 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
outputs: outputs_vector,
});

brillig_context.mov_instruction(out_len.address, outputs_vector.size);
// Returns slice, so we need to allocate memory for it after the fact

brillig_context.initialize_externally_returned_vector(*outputs, outputs_vector);

brillig_context.deallocate_heap_vector(inputs);
brillig_context.deallocate_heap_vector(outputs_vector);
brillig_context.deallocate_heap_array(iv);
Expand Down
6 changes: 5 additions & 1 deletion noir_stdlib/src/aes128.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#[foreign(aes128_encrypt)]
// docs:start:aes128
pub fn aes128_encrypt<let N: u32>(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8] {}
pub fn aes128_encrypt<let N: u32>(
input: [u8; N],
iv: [u8; 16],
key: [u8; 16],
) -> [u8; N + 16 - N % 16] {}
// docs:end:aes128
4 changes: 2 additions & 2 deletions test_programs/execution_success/aes128_encrypt/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ unconstrained fn decode_hex<let N: u32, let M: u32>(s: str<N>) -> [u8; M] {

unconstrained fn cipher(plaintext: [u8; 12], iv: [u8; 16], key: [u8; 16]) -> [u8; 16] {
let result = std::aes128::aes128_encrypt(plaintext, iv, key);
result.as_array()
result
}

fn main(inputs: str<12>, iv: str<16>, key: str<16>, output: str<32>) {
let result: [u8; 16] =
std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()).as_array();
std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes());

let output_bytes: [u8; 16] = unsafe {
//@safety: testing context
Expand Down
Loading