Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
skgen.c
Go to the documentation of this file.
1#include <string.h>
2#include <assert.h>
3
4#include "primes.h"
5#include "random.h"
6
7#ifdef CTIDH
8#include "../CTIDH/ctidh.h"
9
10// WOMBat keygen
11void ctidh_private(private_key *priv)
12{
13 memset(priv, 0, sizeof(private_key));
14
15 uint8_t rnd;
16
17 uint64_t batch_sumkeys = 0;
18 for (uint32_t b = 0; b < primes_batches; b++)
19 {
20 random_wombats(priv->ells, batch_numkeys[b], batch_start[b], batch_stop[b], batch_sumkeys);
21 batch_sumkeys += batch_numkeys[b];
22 }
23
24 // todo: uniform sampling needed!
25 for (uint32_t b = 0; b < WOMBATKEYS; b++)
26 {
27 randombytes(&rnd, 1);
28 priv->directions[b] = (rnd % 3);
29 }
30
31#if defined(_M1_)
32 priv->radical_length = 1;
33 randombytes(&rnd, 1);
34 priv->radical_direction = rnd % 2;
35#elif defined(_M2_)
36 randombytes(&rnd, 1);
37 priv->radical_length = rnd % 3;
38 randombytes(&rnd, 1);
39 priv->radical_direction = rnd % 2;
40#elif defined(_M3_)
41 randombytes(&rnd, 1);
42 priv->radical_length = rnd % 5;
43 randombytes(&rnd, 1);
44 priv->radical_direction = rnd % 2;
45#elif defined(_M4_)
46 randombytes(&rnd, 1);
47 priv->radical_length = rnd % 9;
48 randombytes(&rnd, 1);
49 priv->radical_direction = rnd % 2;
50#elif defined(_M5_)
51 randombytes(&rnd, 1);
52 priv->radical_length = rnd % 17;
53 randombytes(&rnd, 1);
54 priv->radical_direction = rnd % 2;
55#else
56 priv->radical_length = 0;
57 priv->radical_direction = 0;
58#endif
59}
60
61#else
62#include "../CSIDH/csidh.h"
63
65{
66 int i;
67 uint8_t rnd;
68 for (i = 0; i < (int)N; i++)
69 {
70 randombytes(&rnd, 1);
71 rnd = rnd & 0x1;
72 priv->e[i] = rnd - (rnd ^ 0x1);
73 };
74 // memset(priv->e, 1, sizeof(private_key));
75}
76
77#endif
void randombytes(void *x, size_t l)
Definition rng.c:8
#define ctidh_private
Definition ctidh.h:47
for i
#define batch_start
Definition primes.h:55
#define batch_numkeys
Definition primes.h:59
#define batch_stop
Definition primes.h:56
void random_wombats(uint8_t *key, const long long numkeys, const long long batch_start, const long long batch_stop, const long long batch_sumykeys)
Definition random.c:15
void csidh_private(private_key *priv)
Definition skgen.c:64
uint8_t radical_direction
Definition ctidh.h:35
uint8_t radical_length
Definition ctidh.h:34
uint8_t ells[WOMBATKEYS]
Definition ctidh.h:32
uint8_t directions[WOMBATKEYS]
Definition ctidh.h:33