Botan 3.3.0
Crypto and TLS for C&
workfactor.cpp
Go to the documentation of this file.
1/*
2* Public Key Work Factor Functions
3* (C) 1999-2007,2012 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/workfactor.h>
9#include <algorithm>
10#include <cmath>
11
12namespace Botan {
13
14size_t ecp_work_factor(size_t bits) {
15 return bits / 2;
16}
17
18namespace {
19
20size_t nfs_workfactor(size_t bits, double log2_k) {
21 // approximates natural logarithm of an integer of given bitsize
22 const double log2_e = 1.44269504088896340736;
23 const double log_p = bits / log2_e;
24
25 const double log_log_p = std::log(log_p);
26
27 // RFC 3766: k * e^((1.92 + o(1)) * cubrt(ln(n) * (ln(ln(n)))^2))
28 const double est = 1.92 * std::pow(log_p * log_log_p * log_log_p, 1.0 / 3.0);
29
30 // return log2 of the workfactor
31 return static_cast<size_t>(log2_k + log2_e * est);
32}
33
34} // namespace
35
36size_t if_work_factor(size_t bits) {
37 if(bits < 512) {
38 return 0;
39 }
40
41 // RFC 3766 estimates k at .02 and o(1) to be effectively zero for sizes of interest
42
43 const double log2_k = -5.6438; // log2(.02)
44 return nfs_workfactor(bits, log2_k);
45}
46
47size_t dl_work_factor(size_t bits) {
48 // Lacking better estimates...
49 return if_work_factor(bits);
50}
51
52size_t dl_exponent_size(size_t bits) {
53 if(bits == 0) {
54 return 0;
55 }
56 if(bits <= 256) {
57 return bits - 1;
58 }
59 if(bits <= 1024) {
60 return 192;
61 }
62 if(bits <= 1536) {
63 return 224;
64 }
65 if(bits <= 2048) {
66 return 256;
67 }
68 if(bits <= 4096) {
69 return 384;
70 }
71 return 512;
72}
73
74} // namespace Botan
size_t ecp_work_factor(size_t bits)
size_t dl_work_factor(size_t bits)
size_t dl_exponent_size(size_t bits)
size_t if_work_factor(size_t bits)