| 1 |
// 20221230 djb: add linker lines |
| 2 |
// 20221230 djb: split out of operations.c |
| 3 |
|
| 4 |
// linker define operation_keypair |
| 5 |
// linker use controlbitsfrompermutation genpoly_gen pk_gen |
| 6 |
|
| 7 |
#include "operations.h" |
| 8 |
|
| 9 |
#include "controlbits.h" |
| 10 |
#include "randombytes.h" |
| 11 |
#include "hash.h" |
| 12 |
#include "params.h" |
| 13 |
#include "sk_gen.h" |
| 14 |
#include "pk_gen.h" |
| 15 |
#include "util.h" |
| 16 |
|
| 17 |
#include <stdint.h> |
| 18 |
#include <string.h> |
| 19 |
|
| 20 |
void operation_keypair |
| 21 |
( |
| 22 |
unsigned char *pk, |
| 23 |
unsigned char *sk |
| 24 |
) |
| 25 |
{ |
| 26 |
int i; |
| 27 |
unsigned char seed[ 33 ] = {64}; |
| 28 |
unsigned char r[ SYS_N/8 + (1 << GFBITS)*sizeof(uint32_t) + SYS_T*2 + 32 ]; |
| 29 |
unsigned char *rp, *skp; |
| 30 |
|
| 31 |
gf f[ SYS_T ]; // element in GF(2^mt) |
| 32 |
gf irr[ SYS_T ]; // Goppa polynomial |
| 33 |
uint32_t perm[ 1 << GFBITS ]; // random permutation as 32-bit integers |
| 34 |
int16_t pi[ 1 << GFBITS ]; // random permutation |
| 35 |
|
| 36 |
randombytes(seed+1, 32); |
| 37 |
|
| 38 |
while (1) |
| 39 |
{ |
| 40 |
rp = &r[ sizeof(r)-32 ]; |
| 41 |
skp = sk; |
| 42 |
|
| 43 |
// expanding and updating the seed |
| 44 |
|
| 45 |
shake(r, sizeof(r), seed, 33); |
| 46 |
memcpy(skp, seed+1, 32); |
| 47 |
skp += 32 + 8; |
| 48 |
memcpy(seed+1, &r[ sizeof(r)-32 ], 32); |
| 49 |
|
| 50 |
// generating irreducible polynomial |
| 51 |
|
| 52 |
rp -= sizeof(f); |
| 53 |
|
| 54 |
for (i = 0; i < SYS_T; i++) |
| 55 |
f[i] = load_gf(rp + i*2); |
| 56 |
|
| 57 |
if (genpoly_gen(irr, f)) |
| 58 |
continue; |
| 59 |
|
| 60 |
for (i = 0; i < SYS_T; i++) |
| 61 |
store_gf(skp + i*2, irr[i]); |
| 62 |
|
| 63 |
skp += IRR_BYTES; |
| 64 |
|
| 65 |
// generating permutation |
| 66 |
|
| 67 |
rp -= sizeof(perm); |
| 68 |
|
| 69 |
for (i = 0; i < (1 << GFBITS); i++) |
| 70 |
perm[i] = load4(rp + i*4); |
| 71 |
|
| 72 |
if (pk_gen(pk, skp - IRR_BYTES, perm, pi)) |
| 73 |
continue; |
| 74 |
|
| 75 |
controlbitsfrompermutation(skp, pi, GFBITS, 1 << GFBITS); |
| 76 |
skp += COND_BYTES; |
| 77 |
|
| 78 |
// storing the random string s |
| 79 |
|
| 80 |
rp -= SYS_N/8; |
| 81 |
memcpy(skp, rp, SYS_N/8); |
| 82 |
|
| 83 |
// storing positions of the 32 pivots |
| 84 |
|
| 85 |
store8(sk + 32, 0xFFFFFFFF); |
| 86 |
|
| 87 |
break; |
| 88 |
} |
| 89 |
} |
| 90 |
|