| 114 | } |
| 115 | |
| 116 | BigUint math::RandomNumber(BigUint min, BigUint max) { |
| 117 | const int random_max = 2 << 14; |
| 118 | BigUint distance = max - min; |
| 119 | if (distance == 0) { |
| 120 | return 0; |
| 121 | } |
| 122 | if (distance < random_max) { |
| 123 | return rand() % distance; |
| 124 | } |
| 125 | |
| 126 | BigUint result = 0; |
| 127 | while (distance >= random_max) { |
| 128 | result = result * random_max + rand(); |
| 129 | distance /= random_max; |
| 130 | } |
| 131 | |
| 132 | result += min; |
| 133 | |
| 134 | while (result > max) { |
| 135 | result >>= 1; |
| 136 | } |
| 137 | |
| 138 | return result; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | BigUint rsa::GeneratePrime(int bits) { |
nothing calls this directly
no outgoing calls
no test coverage detected