Skip to content
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

Multiplying two UINT256 to a UINT512 #701

Open
Th0rgal opened this issue Dec 30, 2022 · 1 comment
Open

Multiplying two UINT256 to a UINT512 #701

Th0rgal opened this issue Dec 30, 2022 · 1 comment

Comments

@Th0rgal
Copy link

Th0rgal commented Dec 30, 2022

Hello,

I need to compute a multiplication of two integers a, b modulo a big prime P. Those integers and the prime fit in a UINT256, but to compute the result of a*b mod P I need to compute a*b which doesn't fit in a UINT256. Would it be possible to add another method perfect_mul (or another name) which gives the UINT512 result in an efficient way or should I use UINT512 everywhere?

Thanks for your work,
Thomas

@ordian
Copy link
Member

ordian commented Jan 29, 2023

Hey, sorry for the delay in reply. Take a look at

impl U256 {
/// Multiplies two 256-bit integers to produce full 512-bit integer.
/// Overflow is not possible.
#[inline(always)]
pub fn full_mul(self, other: U256) -> U512 {
U512(uint_full_mul_reg!(U256, 4, self, other))
}
}

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants