-
Notifications
You must be signed in to change notification settings - Fork 274
refactor: replace byte-level operations with word-level operations #692
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
refactor: replace byte-level operations with word-level operations #692
Conversation
… cryptographic functions
@newpavlov please lmk if this is a step in the right direction at least |
is there any way to benchmark such that I can get stats for individual functions, so I can see where my bottleneck is, without wrapping every function inside a timing block |
cargo flamegraph is a common tool for this. You also could use |
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.
Looks like a good step forward even without noticeable performance improvements.
which I think is because we're still having to split the values up when doing the row rotation and substitution operations
Yeah, you should probably minimize number of conversion to and from bytes and operate over 64-bit integers whenever possible.
@@ -147,4 +137,4 @@ impl SerializableState for KupynaLongVarCore { | |||
} | |||
|
|||
#[cfg(feature = "zeroize")] | |||
impl ZeroizeOnDrop for KupynaLongVarCore {} | |||
impl ZeroizeOnDrop for KupynaLongVarCore {} |
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.
Please keep the empty last line in all files.
|
||
// println!("prev vector:="); | ||
// for v in prev_vector.iter() { | ||
// println!("{:016X?}", v); |
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.
Remove these comments.
for nu in 0..ROUNDS { | ||
state = add_constant_plus(state, nu as usize); | ||
state = apply_s_box(state); | ||
state = rotate_rows(state); | ||
state = mix_columns(state); | ||
} | ||
matrix_to_block(state) | ||
state |
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.
It may be worth to change add_constant_plus
, apply_s_box
, rotate_rows
, and mix_columns
to work in-place, i.e. over &mut [u64; COLS]
.
@@ -14,6 +14,7 @@ rust-version = "1.85" | |||
|
|||
[dependencies] | |||
digest = "=0.11.0-pre.10" | |||
hex-literal = "1" |
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.
I don't think you need this dependency.
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.
I've set up a main.rs file to verify the code works as expected while making changes to the functions, this is the reason for both the hex-literal dependency and the print statements. will clean them all up once I'm done making large changes to the functions, it just helps to pinpoint error faster if some math goes wrong
# Conflicts: # kupyna/src/long.rs # kupyna/src/long_compress.rs # kupyna/src/short.rs # kupyna/src/short_compress.rs
finally got to this, I'm sorry for being so late ;-;
pre-refactor bench results:
post-refactor bench results:
not seeing any increase yet, which I think is because we're still having to split the values up when doing the row rotation and substitution operations. need to look into the math of that so I can handle it, will probably require a refactor in how our sbox and mds tables are stored. still, bulk of the work seems done