summaryrefslogtreecommitdiffstats
path: root/src/tests/data/test_validate_key_material/readme.txt
blob: cf14e06c4fd98d097aedbb627d9e529c923185c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}