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
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 ...
#2: Post edited
- 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
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.
