diff options
author | lloyd <[email protected]> | 2008-04-12 03:25:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-04-12 03:25:27 +0000 |
commit | fe767bdcee2b44d23786dad911143f16f5a4162a (patch) | |
tree | 0be0d919186be81869640fa8fc1a80acd9ab9e69 | |
parent | 66d92bc063a4cbb69e4242a15c3a90daa3db069e (diff) |
Make the size of the random value used to blind the private key
operations (to prevent timing attacks) a compile time constant.
-rw-r--r-- | misc/config/buildh.in | 1 | ||||
-rw-r--r-- | src/pk_core.cpp | 19 |
2 files changed, 5 insertions, 15 deletions
diff --git a/misc/config/buildh.in b/misc/config/buildh.in index 1976b58e9..46743aac9 100644 --- a/misc/config/buildh.in +++ b/misc/config/buildh.in @@ -13,6 +13,7 @@ #define BOTAN_MP_WORD_BITS @{var:mp_bits} #define BOTAN_DEFAULT_BUFFER_SIZE 4096 #define BOTAN_MEM_POOL_CHUNK_SIZE 64*1024 +#define BOTAN_PRIVATE_KEY_OP_BLINDING_BITS 64 #define BOTAN_KARAT_MUL_THRESHOLD 12 #define BOTAN_KARAT_SQR_THRESHOLD 12 diff --git a/src/pk_core.cpp b/src/pk_core.cpp index 09170ff37..529dbef8a 100644 --- a/src/pk_core.cpp +++ b/src/pk_core.cpp @@ -14,18 +14,7 @@ namespace Botan { namespace { -/************************************************* -* Return a new blinding factor * -*************************************************/ -BigInt blinding_factor(u32bit modulus_size) - { - const u32bit BLINDING_BITS = - to_u32bit(global_config().option("pk/blinder_size")); - - if(BLINDING_BITS == 0) - return 0; - return random_integer(std::min(modulus_size - 1, BLINDING_BITS)); - } +const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; } @@ -40,7 +29,7 @@ IF_Core::IF_Core(const BigInt& e, const BigInt& n, const BigInt& d, if(d != 0) { - BigInt k = blinding_factor(n.bits()); + BigInt k = random_integer(std::min(n.bits()-1, BLINDING_BITS)); if(k != 0) blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n); } @@ -191,7 +180,7 @@ ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y, const BigInt& x) const BigInt& p = group.get_p(); p_bytes = group.get_p().bytes(); - BigInt k = blinding_factor(p.bits()); + BigInt k = random_integer(std::min(group.get_p().bits()-1, BLINDING_BITS)); if(k != 0) blinder = Blinder(k, power_mod(k, x, p), p); } @@ -253,7 +242,7 @@ DH_Core::DH_Core(const DL_Group& group, const BigInt& x) op = Engine_Core::dh_op(group, x); const BigInt& p = group.get_p(); - BigInt k = blinding_factor(p.bits()); + BigInt k = random_integer(std::min(p.bits()-1, BLINDING_BITS)); if(k != 0) blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p); } |