Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

57%
+2 −1
Q&A Constant-time modular multiplication library in Java?

Has anyone written a constant-time BigInteger modular multiplication function in Java? I need to use modular multiplication for a cryptographic protocol, and I don't want to try to write it myself ...

1 answer  ·  posted 8mo ago by skye‭  ·  last activity 5mo ago by Alexei‭

Question java
#2: Post edited by user avatar skye‭ · 2026-02-03T02:21:59Z (8 months ago)
I forgot to include half the cryptographic protocol in the first revision.
  • Has anyone written a constant-time `BigInteger` modular multiplication function in Java? I need to use modular multiplication for a cryptographic protocol, and I don't want to try to write it myself or rely on blinding.
  • For context, the reason I want to do this is to implement a cryptographic protocol to allow multiply peers peers, each of whom have a number $ a $ and a number $ b $, to decide whether the sum each peer's $ a $ value equals the sum of each peer's $ b $ value. My plan to implement this is to have each peer generate a random value $ r $, then publish $ g^{r+a} $ and $ g^{r+b} $. Since I assume $ a $ and $ b $ are high-entropy, this should not reveal a peer's value of $ a $ or $ b $.
  • I've also considered using ECC for this, but then I need to find a constant-time ECC implementation, and I'm more familiar with finite field arithmetic anyway.
  • Has anyone written a constant-time `BigInteger` modular multiplication function in Java? I need to use modular multiplication for a cryptographic protocol, and I don't want to try to write it myself or rely on blinding.
  • For context, the reason I want to do this is to implement a cryptographic protocol. The following arithmetic is in a finite field. Suppose a number of peers, each of whom have a number $ a $ and a number $ b $, want to decide whether the sum each peer's $ a $ value equals the sum of each peer's $ b $ value. My plan to implement this is to have each peer generate a random value $ r $ and compute $ g^r $, then publish $ g^rg^a $ and $ g^rg^b $. Then the product of every peer's $ g^rg^a $ value will equal the product of every peer's $ g^rg^b $ values, as long as the sum of every peer's $ a $ is equal to the sum of every peer's $ b $. Since I assume $ a $ and $ b $ are high-entropy, this should not reveal a peer's value of $ a $ or $ b $.
  • In this protocol, I need a constant-time guarantee for multiplying $ g^r $ with $ g^a $ or $ g^b $, since I assume a or b are long-lived. The modular exponentiation doesn't need to be constant-time, since I only ever need to compute $ g^r $, $ g^a $, or $ g^b $ once.
  • I've also considered using ECC for this, but then I need to find a constant-time ECC implementation, and I'm more familiar with finite field arithmetic anyway.
#1: Initial revision by user avatar skye‭ · 2026-02-03T02:07:51Z (8 months ago)
Constant-time modular multiplication library in Java?
Has anyone written a constant-time `BigInteger` modular multiplication function in Java? I need to use modular multiplication for a cryptographic protocol, and I don't want to try to write it myself or rely on blinding.

For context, the reason I want to do this is to implement a cryptographic protocol to allow multiply peers peers, each of whom have a number $ a $ and a number $ b $, to decide whether the sum each peer's $ a $ value equals the sum of each peer's $ b $ value. My plan to implement this is to have each peer generate a random value $ r $, then publish $ g^{r+a} $ and $ g^{r+b} $. Since I assume $ a $ and $ b $ are high-entropy, this should not reveal a peer's value of $ a $ or $ b $.

I've also considered using ECC for this, but then I need to find a constant-time ECC implementation, and I'm more familiar with finite field arithmetic anyway.