-
Notifications
You must be signed in to change notification settings - Fork 599
feat!: AES blackbox #6016
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
Merged
Merged
feat!: AES blackbox #6016
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
eddeaf3
stronger note and storage struct detection
Thunkar 6bba9b9
Merge branch 'master' of github.com:AztecProtocol/aztec-packages
Thunkar 86eb0c5
initial attempt
Thunkar 61f341a
got bb compiling
Thunkar 60c1b73
correct serialization, failing proofs
Thunkar 3190ef4
padding and respecting the test impl
Thunkar 957dfe7
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 3b6d9b2
changed declaration order
Thunkar 0063cc4
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 3893133
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar b5340c3
added aes128 to brillig
Thunkar ec87992
working bb tests
Thunkar c566e37
noir padding
Thunkar f584bf8
correctly sized outputs
Thunkar 4c74d23
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 26e7861
merge changes
Thunkar dc0b8c5
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 50d7b40
fixed tests
Thunkar 42d89a1
brillig fixes, comments
Thunkar 3274629
comments from review
Thunkar b67547e
removed fn from trait
Thunkar 891b0b2
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar d68a6cd
temporarily removed brillig test
Thunkar 5b1520c
fixed brillig memory corruption ft alvaro
Thunkar a977aee
comments from PR
Thunkar a2b088d
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 8a5e43e
handle dynamicarray
Thunkar 84b050a
perf optmizations
Thunkar 150cfc3
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 6b17570
reverted change, removed _as_slice version
Thunkar 53ef841
added docs
Thunkar 90c72fd
updated codegen
Thunkar 57001c3
fixed ts test
Thunkar 900f2b0
Merge branch 'master' into gj/aes_blackbox
Thunkar 1359e19
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 12f0351
Merge branch 'gj/aes_blackbox' of github.com:AztecProtocol/aztec-pack…
Thunkar b20ad97
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 60b9421
Update noir/noir-repo/noir_stdlib/src/aes128.nr
TomAFrench 7dc5319
Update noir/noir-repo/noir_stdlib/src/aes128.nr
TomAFrench 46ae1ac
Merge branch 'gj/aes_blackbox' of github.com:AztecProtocol/aztec-pack…
Thunkar e9a366e
Merge branch 'master' into gj/aes_blackbox
Thunkar 3d987c3
Merge branches 'gj/aes_blackbox' and 'gj/aes_blackbox' of github.com:…
Thunkar d533462
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar 5d96c99
fixed test
Thunkar 9edb7f5
Merge branch 'master' into gj/aes_blackbox
Thunkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
barretenberg/cpp/src/barretenberg/dsl/acir_format/aes128_constraint.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #include "aes128_constraint.hpp" | ||
| #include "barretenberg/stdlib/encryption/aes128/aes128.hpp" | ||
| #include <cstdint> | ||
| #include <cstdio> | ||
| #include <span> | ||
|
|
||
| namespace acir_format { | ||
|
|
||
| template <typename Builder> void create_aes128_constraints(Builder& builder, const AES128Constraint& constraint) | ||
| { | ||
|
|
||
| using field_ct = bb::stdlib::field_t<Builder>; | ||
|
|
||
| // Packs 16 bytes from the inputs (plaintext, iv, key) into a field element | ||
| const auto convert_input = [&](std::span<const AES128Input, std::dynamic_extent> inputs, size_t padding) { | ||
| field_ct converted = 0; | ||
| for (size_t i = 0; i < 16 - padding; ++i) { | ||
| converted *= 256; | ||
| field_ct byte = field_ct::from_witness_index(&builder, inputs[i].witness); | ||
| converted += byte; | ||
| } | ||
| for (size_t i = 0; i < padding; ++i) { | ||
| converted *= 256; | ||
| field_ct byte = padding; | ||
| converted += byte; | ||
| } | ||
| return converted; | ||
| }; | ||
|
|
||
| // Packs 16 bytes from the outputs (witness indexes) into a field element for comparison | ||
| const auto convert_output = [&](std::span<const uint32_t, 16> outputs) { | ||
| field_ct converted = 0; | ||
| for (const auto& output : outputs) { | ||
| converted *= 256; | ||
| field_ct byte = field_ct::from_witness_index(&builder, output); | ||
| converted += byte; | ||
| } | ||
| return converted; | ||
| }; | ||
|
|
||
| const size_t padding_size = 16 - constraint.inputs.size() % 16; | ||
|
|
||
| // Perform the conversions from array of bytes to field elements | ||
| std::vector<field_ct> converted_inputs; | ||
| for (size_t i = 0; i < constraint.inputs.size(); i += 16) { | ||
| field_ct to_add; | ||
| if (i + 16 > constraint.inputs.size()) { | ||
| to_add = convert_input( | ||
| std::span<const AES128Input, std::dynamic_extent>{ &constraint.inputs[i], 16 - padding_size }, | ||
| padding_size); | ||
| } else { | ||
| to_add = convert_input(std::span<const AES128Input, 16>{ &constraint.inputs[i], 16 }, 0); | ||
| } | ||
| converted_inputs.emplace_back(to_add); | ||
| } | ||
|
|
||
| std::vector<field_ct> converted_outputs; | ||
| for (size_t i = 0; i < constraint.outputs.size(); i += 16) { | ||
| std::span<const uint32_t, 16> outputs{ &constraint.outputs[i], 16 }; | ||
| converted_outputs.emplace_back(convert_output(outputs)); | ||
| } | ||
|
|
||
| const std::vector<field_ct> output_bytes = bb::stdlib::aes128::encrypt_buffer_cbc<Builder>( | ||
| converted_inputs, convert_input(constraint.iv, 0), convert_input(constraint.key, 0)); | ||
|
|
||
| for (size_t i = 0; i < output_bytes.size(); ++i) { | ||
| builder.assert_equal(output_bytes[i].normalize().witness_index, converted_outputs[i].normalize().witness_index); | ||
| } | ||
| } | ||
|
|
||
| template void create_aes128_constraints<UltraCircuitBuilder>(UltraCircuitBuilder& builder, | ||
| const AES128Constraint& constraint); | ||
|
|
||
| template void create_aes128_constraints<GoblinUltraCircuitBuilder>(GoblinUltraCircuitBuilder& builder, | ||
| const AES128Constraint& constraint); | ||
|
|
||
| } // namespace acir_format | ||
31 changes: 31 additions & 0 deletions
31
barretenberg/cpp/src/barretenberg/dsl/acir_format/aes128_constraint.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
| #include "barretenberg/dsl/types.hpp" | ||
| #include "barretenberg/serialize/msgpack.hpp" | ||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| namespace acir_format { | ||
|
|
||
| struct AES128Input { | ||
Thunkar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uint32_t witness; | ||
| uint32_t num_bits; | ||
|
|
||
| // For serialization, update with any new fields | ||
| MSGPACK_FIELDS(witness, num_bits); | ||
| friend bool operator==(AES128Input const& lhs, AES128Input const& rhs) = default; | ||
| }; | ||
|
|
||
| struct AES128Constraint { | ||
| std::vector<AES128Input> inputs; | ||
| std::array<AES128Input, 16> iv; | ||
| std::array<AES128Input, 16> key; | ||
| std::vector<uint32_t> outputs; | ||
|
|
||
| // For serialization, update with any new fields | ||
| MSGPACK_FIELDS(inputs, iv, key, outputs); | ||
| friend bool operator==(AES128Constraint const& lhs, AES128Constraint const& rhs) = default; | ||
| }; | ||
|
|
||
| template <typename Builder> void create_aes128_constraints(Builder& builder, const AES128Constraint& constraint); | ||
|
|
||
| } // namespace acir_format | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.