paritytech / parity-common

Collection of crates used in Parity projects
https://www.paritytech.io/
Apache License 2.0
281 stars 213 forks source link

Multiplying two UINT256 to a UINT512 #701

Open Th0rgal opened 1 year ago

Th0rgal commented 1 year ago

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 commented 1 year ago

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

https://github.com/paritytech/parity-common/blob/854e68bb5af1bf285445228c47d1a1090e1f1bf3/primitive-types/src/lib.rs#L153-L160

Hope that helps.