Revision control

Copy as Markdown

Other Tools

Some of ElGamal samples were generated by using the following custom key generation snippet:
{
std::unique_ptr<Botan::RandomNumberGenerator> rng;
rng.reset(new Botan::System_RNG);
Botan::BigInt p = Botan::random_prime(*rng, keybits, 0, 2, 3, 64);
Botan::BigInt p1(p - 1);
Botan::BigInt sg = 1;
Botan::BigInt g;
size_t mod = 2;
while (mod < 65536) {
if (p1 % mod == 0) {
if (sg * mod > (1 << 16)) {
break;
}
RNP_LOG("Reduced by %zu", mod);
p1 = p1 / mod;
sg *= mod;
continue;
}
mod++;
}
if (Botan::power_mod(3, p - 1, p).cmp_word(1) != 0) {
RNP_LOG("3 ^ (p - 1) != 1 (mod p)");
goto end;
}
Botan::BigInt ng = Botan::power_mod(3, p1, p);
if (Botan::power_mod(ng, sg, p).cmp_word(1) != 0) {
RNP_LOG("ng ^ sg != 1 (mod p)");
goto end;
}
g = ng;
Botan::BigInt x(*rng, keybits, true);
Botan::BigInt y = Botan::power_mod(g, x, p);
key->p.len = p.bytes();
p.binary_encode(key->p.mpi);
key->g.len = g.bytes();
g.binary_encode(key->g.mpi);
key->x.len = x.bytes();
x.binary_encode(key->x.mpi);
key->y.len = y.bytes();
y.binary_encode(key->y.mpi);
ret = RNP_SUCCESS;
}