diff options
author | lloyd <[email protected]> | 2009-09-17 13:59:56 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-09-17 13:59:56 +0000 |
commit | e1d81327dde6c6837ed81c61c58876bd261fb47d (patch) | |
tree | d2453db622ac788d3832110e6b70a9fb3f45f5f2 /src/pubkey/workfactor.cpp | |
parent | 7d51181d2841b29277da9a31752cae612d64b534 (diff) |
Split up util.h into 3 files
- rounding.h (round_up, round_down)
- workfactor.h (dl_work_factor)
- timer.h (system_time)
And update all users of the previous util.h
Diffstat (limited to 'src/pubkey/workfactor.cpp')
-rw-r--r-- | src/pubkey/workfactor.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/pubkey/workfactor.cpp b/src/pubkey/workfactor.cpp new file mode 100644 index 000000000..e40b7919c --- /dev/null +++ b/src/pubkey/workfactor.cpp @@ -0,0 +1,51 @@ +/* +* Public Key Work Factor Functions +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/workfactor.h> +#include <algorithm> +#include <cmath> + +namespace Botan { + +/* +* Choose the exponent size for a DL group +*/ +u32bit dl_work_factor(u32bit bits) + { +#if 0 + /* + These values were taken from RFC 3526 + */ + if(bits <= 1536) + return 90; + else if(bits <= 2048) + return 110; + else if(bits <= 3072) + return 130; + else if(bits <= 4096) + return 150; + else if(bits <= 6144) + return 170; + else if(bits <= 8192) + return 190; + return 256; +#else + const u32bit MIN_ESTIMATE = 64; + + const double log_x = bits / 1.44; + + const double strength = + 2.76 * std::pow(log_x, 1.0/3.0) * std::pow(std::log(log_x), 2.0/3.0); + + if(strength > MIN_ESTIMATE) + return static_cast<u32bit>(strength); + return MIN_ESTIMATE; +#endif + } + + +} |