-
Notifications
You must be signed in to change notification settings - Fork 296
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: computing sym key for incoming ciphertext #6020
Merged
benesjan
merged 11 commits into
master
from
04-25-feat_computing_sym_key_for_incoming_ciphertext
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
062a82f
feat: computing sym key for incoming ciphertext
benesjan 275db2c
WIP
benesjan 3f1f0e3
nuked unnecessary curve param
benesjan 1414840
PTSK test matching with noir
benesjan 652abd8
added TODOs
benesjan fcb0d7d
make updateInlineTestData match multiline string
benesjan 955e51e
fix
benesjan 6bab191
updated GENERATOR_INDEX__SYMMETRIC_KEY
benesjan d22136a
comments
benesjan aa6a24e
fixing key naming + arg order
benesjan b8ebbc3
updated test snapshot
benesjan 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
This file contains 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 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 @@ | ||
mod point_to_symmetric_key; |
34 changes: 34 additions & 0 deletions
34
noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr
This file contains 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,34 @@ | ||
use dep::protocol_types::{constants::GENERATOR_INDEX__SYMMETRIC_KEY, grumpkin_point::GrumpkinPoint, utils::arr_copy_slice}; | ||
use dep::std::{hash::sha256, grumpkin_scalar::GrumpkinScalar, scalar_mul::variable_base_embedded_curve}; | ||
|
||
// TODO(#5726): This function is called deriveAESSecret in TS. I don't like point_to_symmetric_key name much since | ||
// point is not the only input of the function. Unify naming with TS once we have a better name. | ||
pub fn point_to_symmetric_key(secret: GrumpkinScalar, point: GrumpkinPoint) -> [u8; 32] { | ||
let shared_secret_fields = variable_base_embedded_curve(point.x, point.y, secret.low, secret.high); | ||
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6061): make the func return Point struct directly | ||
let shared_secret = GrumpkinPoint::new(shared_secret_fields[0], shared_secret_fields[1]); | ||
let mut shared_secret_bytes_with_separator = [0 as u8; 65]; | ||
shared_secret_bytes_with_separator = arr_copy_slice(shared_secret.to_be_bytes(), shared_secret_bytes_with_separator, 0); | ||
LHerskind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shared_secret_bytes_with_separator[64] = GENERATOR_INDEX__SYMMETRIC_KEY; | ||
sha256(shared_secret_bytes_with_separator) | ||
} | ||
|
||
#[test] | ||
fn check_point_to_symmetric_key() { | ||
benesjan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Value taken from "derive shared secret" test in encrypt_buffer.test.ts | ||
let secret = GrumpkinScalar::new( | ||
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, | ||
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 | ||
); | ||
let point = GrumpkinPoint::new( | ||
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, | ||
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e | ||
); | ||
|
||
let key = point_to_symmetric_key(secret, point); | ||
// The following value gets updated when running encrypt_buffer.test.ts with AZTEC_GENERATE_TEST_DATA=1 | ||
let expected_key = [ | ||
198, 74, 242, 51, 177, 36, 183, 8, 2, 246, 197, 138, 59, 166, 86, 96, 155, 50, 186, 34, 242, 3, 208, 144, 161, 64, 69, 165, 70, 57, 226, 139 | ||
]; | ||
assert_eq(key, expected_key); | ||
} |
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ mod deploy; | |
mod hash; | ||
mod history; | ||
mod initializer; | ||
mod keys; | ||
mod log; | ||
mod messaging; | ||
mod note; | ||
|
This file contains 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 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 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 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
deriveAESSecret
as a name will be a pain with the outgoing as it derives an AES secret, but not from the point.secretAndPointToSymmetricKey
incoming 😆