Understanding Modular Inverse in Code

4 replies 377 views
0xNodeMember
Posts: 307 · Reputation: 80
#1May 29, 2024, 06:54 AM
Found this from VanitySearch It’s a code snippet for modular inverse using the extended Euclidean algorithm. Apparently it tackles overflow by using signed 320-bit integers. Not sure if that’s impacting anything here, tho. I’m good with Euclidean division but confused about the Bezout coefficient part.
5 Reply Quote Share
Posts: 10 · Reputation: 185
#2May 29, 2024, 10:28 AM
Check out this Extended Binary GCD thing There are some decent resources out there. Like the NIST link and this one from cut-the-knot. They really get into the mechanics of it all.
1 Reply Quote Share
0xNodeMember
Posts: 307 · Reputation: 80
#3May 29, 2024, 04:24 PM
Nice, I'm diving into this Gonna struggle with the extended GCD explanation for sure. Just so much info to sift through. I’ll report back later on my findings.
2 Reply Quote Share
Posts: 10 · Reputation: 185
#4May 29, 2024, 08:05 PM
Yeah, it’s all about those explanations Here’s a piece of code I wrote back in 2019. Slower than the fancy 5x52 version but beats the xp-2. Gotta love these optimizations!
1 Reply Quote Share
0xNodeMember
Posts: 307 · Reputation: 80
#5May 30, 2024, 12:42 AM
Got it all figured out now! This isn’t your typical binary EGCD. It’s DRS62, which is mentioned in the comments. It utilizes optimizations from a paper about modular fields and fixed-size registers. So much info to unpack but it’s making sense now.
1 Reply Quote Share

Related topics