Skip to content

Commit 5c50711

Browse files
authored
refactor: secret derivation funcs naming cleanup (#10637)
1 parent 9836036 commit 5c50711

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use dep::protocol_types::{
55
scalar::Scalar,
66
};
77

8-
use crate::keys::point_to_symmetric_key::point_to_symmetric_key;
8+
use crate::keys::secret_derivation::derive_aes_secret;
99

1010
use std::aes128::aes128_encrypt;
1111

@@ -22,7 +22,7 @@ impl EncryptedLogHeader {
2222
where
2323
T: ToPoint,
2424
{
25-
let full_key = point_to_symmetric_key(secret, pk.to_point());
25+
let full_key = derive_aes_secret(secret, pk.to_point());
2626
let mut sym_key = [0; 16];
2727
let mut iv = [0; 16];
2828

noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414

1515
use crate::{
1616
encrypted_logs::header::EncryptedLogHeader,
17-
keys::point_to_symmetric_key::point_to_symmetric_key,
17+
keys::secret_derivation::derive_aes_secret,
1818
oracle::{
1919
notes::{get_app_tag_as_sender, increment_app_tagging_secret_index_as_sender},
2020
random::random,
@@ -208,7 +208,7 @@ pub fn compute_incoming_body_ciphertext<let P: u32>(
208208
eph_sk: Scalar,
209209
address_point: AddressPoint,
210210
) -> [u8] {
211-
let full_key = point_to_symmetric_key(eph_sk, address_point.to_point());
211+
let full_key = derive_aes_secret(eph_sk, address_point.to_point());
212212
let mut sym_key = [0; 16];
213213
let mut iv = [0; 16];
214214

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod constants;
22
pub mod getters;
3-
pub mod point_to_symmetric_key;
3+
pub mod secret_derivation;

noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr noir-projects/aztec-nr/aztec/src/keys/secret_derivation.nr

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use crate::utils::point::point_to_bytes;
22
use dep::protocol_types::{constants::GENERATOR_INDEX__SYMMETRIC_KEY, point::Point, scalar::Scalar};
33
use std::{embedded_curve_ops::multi_scalar_mul, hash::sha256};
44

5-
// TODO(#5726): This function is called deriveAESSecret in TS. I don't like point_to_symmetric_key name much since
6-
// point is not the only input of the function. Unify naming with TS once we have a better name.
7-
pub fn point_to_symmetric_key(secret: Scalar, point: Point) -> [u8; 32] {
5+
pub fn derive_aes_secret(secret: Scalar, point: Point) -> [u8; 32] {
86
let shared_secret = point_to_bytes(multi_scalar_mul([point], [secret]));
97

108
let mut shared_secret_bytes_with_separator: [u8; 33] = std::mem::zeroed();
@@ -18,7 +16,7 @@ pub fn point_to_symmetric_key(secret: Scalar, point: Point) -> [u8; 32] {
1816
}
1917

2018
#[test]
21-
unconstrained fn test_point_to_symmetric_key_matches_noir() {
19+
unconstrained fn test_derive_aes_secret_matches_noir() {
2220
// Value taken from "derive shared secret" test in encrypt_buffer.test.ts
2321
let secret = Scalar {
2422
lo: 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd,
@@ -30,7 +28,7 @@ unconstrained fn test_point_to_symmetric_key_matches_noir() {
3028
is_infinite: false,
3129
};
3230

33-
let key = point_to_symmetric_key(secret, point);
31+
let key = derive_aes_secret(secret, point);
3432

3533
// The following value was generated by `encrypt_buffer.test.ts`.
3634
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.

yarn-project/circuit-types/src/logs/l1_payload/encryption_util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type GrumpkinScalar, type PublicKey } from '@aztec/circuits.js';
22
import { Aes128 } from '@aztec/circuits.js/barretenberg';
33

4-
import { deriveDiffieHellmanAESSecret } from './shared_secret_derivation.js';
4+
import { deriveAESSecret } from './shared_secret_derivation.js';
55

66
/**
77
* Encrypts the plaintext using the secret key and public key
@@ -16,7 +16,7 @@ export function encrypt(
1616
plaintext: Buffer,
1717
secret: GrumpkinScalar,
1818
publicKey: PublicKey,
19-
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
19+
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveAESSecret,
2020
): Buffer {
2121
const aesSecret = deriveSecret(secret, publicKey);
2222
const key = aesSecret.subarray(0, 16);
@@ -38,7 +38,7 @@ export function decrypt(
3838
ciphertext: Buffer,
3939
secret: GrumpkinScalar,
4040
publicKey: PublicKey,
41-
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveDiffieHellmanAESSecret,
41+
deriveSecret: (secret: GrumpkinScalar, publicKey: PublicKey) => Buffer = deriveAESSecret,
4242
): Buffer {
4343
const aesSecret = deriveSecret(secret, publicKey);
4444
const key = aesSecret.subarray(0, 16);

yarn-project/circuit-types/src/logs/l1_payload/shared_secret_derivation.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import { numToUInt8 } from '@aztec/foundation/serialize';
1313
* @param publicKey - The public key used to derive shared secret.
1414
* @returns A derived AES secret key.
1515
* @throws If the public key is zero.
16-
* TODO(#5726): This function is called point_to_symmetric_key in Noir. I don't like that name much since point is not
17-
* the only input of the function. Unify naming once we have a better name.
1816
*/
19-
export function deriveDiffieHellmanAESSecret(secretKey: GrumpkinScalar, publicKey: PublicKey): Buffer {
17+
export function deriveAESSecret(secretKey: GrumpkinScalar, publicKey: PublicKey): Buffer {
2018
if (publicKey.isZero()) {
2119
throw new Error(
2220
`Attempting to derive AES secret with a zero public key. You have probably passed a zero public key in your Noir code somewhere thinking that the note won't broadcasted... but it was.`,

0 commit comments

Comments
 (0)