diff options
author | Jack Lloyd <[email protected]> | 2018-12-24 12:15:34 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-12-24 12:15:34 -0500 |
commit | a57ce5a4fd2ed8a6e0aff4d6fbd22b7be45ea919 (patch) | |
tree | 77a0cf1ae28b8a4be963792cf80ce1540457588d /src/lib/pubkey/sm2 | |
parent | f99827300605b7f4da4520e5d9cd402bd790fe15 (diff) |
Address a side channel in RSA and SM2
Barrett will branch to a different (and slower) algorithm if the input
is larger than the square of the modulus. This branch can be detected
by a side channel.
For RSA we need to compute m % p and m % q to get CRT started. Being
able to detect if m > q*q (assuming q is the smaller prime) allows a
binary search on the secret prime. This attack is blocked by input
blinding, but still seems dangerous. Unfortunately changing to use the
generic const time modulo instead of Barrett introduces a rather
severe performance regression in RSA signing.
In SM2, reduce k-r*x modulo the order before multiplying it with (x-1)^-1.
Otherwise the need for slow modulo vs Barrett leaks information about
k and/or x.
Diffstat (limited to 'src/lib/pubkey/sm2')
-rw-r--r-- | src/lib/pubkey/sm2/sm2.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lib/pubkey/sm2/sm2.cpp b/src/lib/pubkey/sm2/sm2.cpp index cf08d0f1c..5ffd547cf 100644 --- a/src/lib/pubkey/sm2/sm2.cpp +++ b/src/lib/pubkey/sm2/sm2.cpp @@ -153,7 +153,7 @@ SM2_Signature_Operation::sign(RandomNumberGenerator& rng) const BigInt r = m_group.mod_order( m_group.blinded_base_point_multiply_x(k, rng, m_ws) + e); - const BigInt s = m_group.multiply_mod_order(m_da_inv, (k - r*m_x)); + const BigInt s = m_group.multiply_mod_order(m_da_inv, m_group.mod_order(k - r*m_x)); return BigInt::encode_fixed_length_int_pair(r, s, m_group.get_order().bytes()); } |