Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Speed-up Rescue inverse SBoxes by performing custom exponentiation #4

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

Nashtare
Copy link
Contributor

Implements custom Inverse S-Box for Rescue-252 and Rescue-63.

Similarly to what has been done for the SBox permutation, or what is done for the inverse() method of the PrimeField implementations in this library dependencies, computing manually the exponentiation by ALPHA_INV results in a saving of about 25% in each instantiations.

@@ -49,8 +56,33 @@ pub fn apply_sbox(state: &mut [Fp]) {
/// Applies exponentiation of the current hash state
/// elements with the Rescue inverse S-Box.
pub fn apply_inv_sbox(state: &mut [Fp]) {
// found using https://github.com/kwantam/addchain for M - 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this apply to the chain in src/rescue_252_4_2/mod.rs as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! adding it in the documentation, thanks!

Copy link
Contributor

@baumbata baumbata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Glad we can keep adding these types of speed-ups.

@Nashtare
Copy link
Contributor Author

The speed-up is only beneficial to native hashing, not inside the AIR program though. I opened a related issue here on the cheetah repo to see if we could leverage this through a direct implementation of winterfell field traits inside cheetah.

@Nashtare Nashtare merged commit 37867aa into main Nov 24, 2021
@Nashtare Nashtare deleted the rescue-inv-sbox branch November 24, 2021 07:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants