From 1ddb04196308135d64ae6dc4fddbd3382caa0170 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 27 Aug 2024 11:26:21 +0100 Subject: [PATCH 1/5] chore: address issues in `aes128_encrypt` docs --- .../cryptographic_primitives/ciphers.mdx | 12 +++--------- .../cryptographic_primitives/ciphers.mdx | 6 +++--- .../cryptographic_primitives/ciphers.mdx | 6 +++--- .../cryptographic_primitives/ciphers.mdx | 6 +++--- .../cryptographic_primitives/ciphers.mdx | 6 +++--- .../execution_success/aes_example/Nargo.toml | 7 +++++++ .../execution_success/aes_example/src/main.nr | 9 +++++++++ tmep/Nargo.toml | 7 +++++++ tmep/src/main.nr | 11 +++++++++++ 9 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 test_programs/execution_success/aes_example/Nargo.toml create mode 100644 test_programs/execution_success/aes_example/src/main.nr create mode 100644 tmep/Nargo.toml create mode 100644 tmep/src/main.nr diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx index 0103791d2e4..09be82f9988 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -15,14 +15,8 @@ Given a plaintext as an array of bytes, returns the corresponding aes128 ciphert #include_code aes128 noir_stdlib/src/aes128.nr rust -```rust -fn main() { - let input: [u8; 4] = [0, 12, 3, 15] // Random bytes, will be padded to 16 bytes. - let iv: [u8; 16] = [0; 16]; // Initialisation vector - let key: [u8; 16] = [0; 16] // AES key - let ciphertext = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); // In this case, the output length will be 16 bytes. -} -``` +#include_code aes128_example test_programs/execution_success/aes_example/src/main.nr rust - \ No newline at end of file + + diff --git a/docs/versioned_docs/version-v0.30.0/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/versioned_docs/version-v0.30.0/noir/standard_library/cryptographic_primitives/ciphers.mdx index e83e26efb97..144589c563a 100644 --- a/docs/versioned_docs/version-v0.30.0/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/versioned_docs/version-v0.30.0/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -23,10 +23,10 @@ pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8] {} fn main() { let input: [u8; 4] = [0, 12, 3, 15] // Random bytes, will be padded to 16 bytes. let iv: [u8; 16] = [0; 16]; // Initialisation vector - let key: [u8; 16] = [0; 16] // AES key - let ciphertext = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); // In this case, the output length will be 16 bytes. + let key: [u8; 16] = [0; 16]; // AES key + let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. } ``` - \ No newline at end of file + diff --git a/docs/versioned_docs/version-v0.31.0/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/versioned_docs/version-v0.31.0/noir/standard_library/cryptographic_primitives/ciphers.mdx index e83e26efb97..144589c563a 100644 --- a/docs/versioned_docs/version-v0.31.0/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/versioned_docs/version-v0.31.0/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -23,10 +23,10 @@ pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8] {} fn main() { let input: [u8; 4] = [0, 12, 3, 15] // Random bytes, will be padded to 16 bytes. let iv: [u8; 16] = [0; 16]; // Initialisation vector - let key: [u8; 16] = [0; 16] // AES key - let ciphertext = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); // In this case, the output length will be 16 bytes. + let key: [u8; 16] = [0; 16]; // AES key + let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. } ``` - \ No newline at end of file + diff --git a/docs/versioned_docs/version-v0.32.0/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/versioned_docs/version-v0.32.0/noir/standard_library/cryptographic_primitives/ciphers.mdx index d75e50d4b89..16a18212367 100644 --- a/docs/versioned_docs/version-v0.32.0/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/versioned_docs/version-v0.32.0/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -23,10 +23,10 @@ pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) - fn main() { let input: [u8; 4] = [0, 12, 3, 15] // Random bytes, will be padded to 16 bytes. let iv: [u8; 16] = [0; 16]; // Initialisation vector - let key: [u8; 16] = [0; 16] // AES key - let ciphertext = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); // In this case, the output length will be 16 bytes. + let key: [u8; 16] = [0; 16]; // AES key + let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. } ``` - \ No newline at end of file + diff --git a/docs/versioned_docs/version-v0.33.0/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/versioned_docs/version-v0.33.0/noir/standard_library/cryptographic_primitives/ciphers.mdx index d75e50d4b89..16a18212367 100644 --- a/docs/versioned_docs/version-v0.33.0/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/versioned_docs/version-v0.33.0/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -23,10 +23,10 @@ pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) - fn main() { let input: [u8; 4] = [0, 12, 3, 15] // Random bytes, will be padded to 16 bytes. let iv: [u8; 16] = [0; 16]; // Initialisation vector - let key: [u8; 16] = [0; 16] // AES key - let ciphertext = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()); // In this case, the output length will be 16 bytes. + let key: [u8; 16] = [0; 16]; // AES key + let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. } ``` - \ No newline at end of file + diff --git a/test_programs/execution_success/aes_example/Nargo.toml b/test_programs/execution_success/aes_example/Nargo.toml new file mode 100644 index 00000000000..751cb94ffb6 --- /dev/null +++ b/test_programs/execution_success/aes_example/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aes_example" +type = "bin" +authors = [""] +compiler_version = ">=0.27.0" + +[dependencies] diff --git a/test_programs/execution_success/aes_example/src/main.nr b/test_programs/execution_success/aes_example/src/main.nr new file mode 100644 index 00000000000..df519b64718 --- /dev/null +++ b/test_programs/execution_success/aes_example/src/main.nr @@ -0,0 +1,9 @@ +// docs:start:aes_example +fn main() -> pub [u8; 16] { + let input: [u8; 4] = [0, 12, 3, 15]; // Random bytes, will be padded to 16 bytes. + let iv: [u8; 16] = [0; 16]; // Initialisation vector + let key: [u8; 16] = [0; 16]; // AES key + let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. + ciphertext.as_array() +} +// docs:start:aes_example diff --git a/tmep/Nargo.toml b/tmep/Nargo.toml new file mode 100644 index 00000000000..66f7ab83572 --- /dev/null +++ b/tmep/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tmep" +type = "bin" +authors = [""] +compiler_version = ">=0.31.0" + +[dependencies] \ No newline at end of file diff --git a/tmep/src/main.nr b/tmep/src/main.nr new file mode 100644 index 00000000000..cbf36276949 --- /dev/null +++ b/tmep/src/main.nr @@ -0,0 +1,11 @@ +fn main(x: [Field; 2]) { + foo(x) +} + +fn foo(a: [T; N]) { + bar(a, |b, c| b < c); +} + +fn bar(a: [T; N], cmp: fn(T, T) -> bool) { + let _ = cmp(a[0], a[1]); +} From 6794cc686ecded92492d315ef58be138362a3550 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 27 Aug 2024 11:28:56 +0100 Subject: [PATCH 2/5] . --- test_programs/execution_success/aes_example/Prover.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test_programs/execution_success/aes_example/Prover.toml diff --git a/test_programs/execution_success/aes_example/Prover.toml b/test_programs/execution_success/aes_example/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d From 6dc4bcbcc40a74962caae698e6847857a7d5f1b3 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 27 Aug 2024 11:29:59 +0100 Subject: [PATCH 3/5] . --- tmep/Nargo.toml | 7 ------- tmep/src/main.nr | 11 ----------- 2 files changed, 18 deletions(-) delete mode 100644 tmep/Nargo.toml delete mode 100644 tmep/src/main.nr diff --git a/tmep/Nargo.toml b/tmep/Nargo.toml deleted file mode 100644 index 66f7ab83572..00000000000 --- a/tmep/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "tmep" -type = "bin" -authors = [""] -compiler_version = ">=0.31.0" - -[dependencies] \ No newline at end of file diff --git a/tmep/src/main.nr b/tmep/src/main.nr deleted file mode 100644 index cbf36276949..00000000000 --- a/tmep/src/main.nr +++ /dev/null @@ -1,11 +0,0 @@ -fn main(x: [Field; 2]) { - foo(x) -} - -fn foo(a: [T; N]) { - bar(a, |b, c| b < c); -} - -fn bar(a: [T; N], cmp: fn(T, T) -> bool) { - let _ = cmp(a[0], a[1]); -} From ee5cde412a0c2cc0822d8f6d5c91969d1fb2f0d7 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 27 Aug 2024 12:17:01 +0100 Subject: [PATCH 4/5] chore: fix snippet identifier --- .../noir/standard_library/cryptographic_primitives/ciphers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx index 09be82f9988..724b22a6529 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/ciphers.mdx @@ -15,7 +15,7 @@ Given a plaintext as an array of bytes, returns the corresponding aes128 ciphert #include_code aes128 noir_stdlib/src/aes128.nr rust -#include_code aes128_example test_programs/execution_success/aes_example/src/main.nr rust +#include_code aes_example test_programs/execution_success/aes_example/src/main.nr rust From 9fbe5354303e5632fed68653b762b580e753440b Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:34:23 +0100 Subject: [PATCH 5/5] Update test_programs/execution_success/aes_example/src/main.nr --- test_programs/execution_success/aes_example/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_programs/execution_success/aes_example/src/main.nr b/test_programs/execution_success/aes_example/src/main.nr index df519b64718..5139dd58428 100644 --- a/test_programs/execution_success/aes_example/src/main.nr +++ b/test_programs/execution_success/aes_example/src/main.nr @@ -6,4 +6,4 @@ fn main() -> pub [u8; 16] { let ciphertext = std::aes128::aes128_encrypt(input, iv, key); // In this case, the output length will be 16 bytes. ciphertext.as_array() } -// docs:start:aes_example +// docs:end:aes_example