Skip to content
This repository was archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Created docs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
linesthatinterlace committed May 23, 2022
1 parent 31b2db0 commit 08cd072
Show file tree
Hide file tree
Showing 2,662 changed files with 865,080 additions and 0 deletions.
Binary file added docs/classic-mceliece-v3.pdf
Binary file not shown.
Binary file added docs/controlbits.pdf
Binary file not shown.
File renamed without changes.
Binary file added docs/mcbits.pdf
Binary file not shown.
Binary file added docs/mceliece-20201010.tar.gz
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kat_kem.rsp: kat
./run

kat: Makefile nist/kat_kem.c nist/rng.c nist/rng.h randombytes.h benes.c bm.c controlbits.c decrypt.c encrypt.c fft.c fft_tr.c gf.c int32_minmax_x86.c int32_sort.c operations.c pk_gen.c sk_gen.c vec.c vec256.c consts.S syndrome_asm.S transpose_64x256_sp_asm.S transpose_64x64_asm.S update_asm.S vec128_mul_asm.S vec256_mul_asm.S vec_mul_asm.S vec_mul_sp_asm.S vec_reduce_asm.S
./build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define CRYPTO_PUBLICKEYBYTES 261120
#define CRYPTO_SECRETKEYBYTES 6492
#define CRYPTO_CIPHERTEXTBYTES 128
#define CRYPTO_BYTES 32

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
amd64
x86
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/*
This file is for Benes network related functions
For the implementation strategy, see
https://eprint.iacr.org/2017/793.pdf
*/

#include "util.h"
#include "transpose.h"
#include "params.h"
#include "benes.h"

static void layer_0(uint64_t *bs, uint64_t *cond)
{
int x;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 2)
{
diff = bs[ x ] ^ bs[ x+1 ];
diff &= *cond++;
bs[ x ] ^= diff;
bs[ x+1 ] ^= diff;
}
}

static void layer_1(uint64_t *bs, uint64_t *cond)
{
int x;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 4)
{
diff = bs[ x+0 ] ^ bs[ x+2 ];
diff &= cond[0];
bs[ x+0 ] ^= diff;
bs[ x+2 ] ^= diff;

diff = bs[ x+1 ] ^ bs[ x+3 ];
diff &= cond[1];
bs[ x+1 ] ^= diff;
bs[ x+3 ] ^= diff;

cond += 2;
}
}

static void layer_2(uint64_t *bs, uint64_t *cond)
{
int x;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 8)
{
diff = bs[ x+0 ] ^ bs[ x+4 ];
diff &= cond[0];
bs[ x+0 ] ^= diff;
bs[ x+4 ] ^= diff;

diff = bs[ x+1 ] ^ bs[ x+5 ];
diff &= cond[1];
bs[ x+1 ] ^= diff;
bs[ x+5 ] ^= diff;

diff = bs[ x+2 ] ^ bs[ x+6 ];
diff &= cond[2];
bs[ x+2 ] ^= diff;
bs[ x+6 ] ^= diff;

diff = bs[ x+3 ] ^ bs[ x+7 ];
diff &= cond[3];
bs[ x+3 ] ^= diff;
bs[ x+7 ] ^= diff;

cond += 4;
}
}

static void layer_3(uint64_t *bs, uint64_t *cond)
{
int x, s;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 16)
for (s = x; s < x + 8; s += 4)
{
diff = bs[ s+0 ] ^ bs[ s+8 ];
diff &= cond[0];
bs[ s+0 ] ^= diff;
bs[ s+8 ] ^= diff;

diff = bs[ s+1 ] ^ bs[ s+9 ];
diff &= cond[1];
bs[ s+1 ] ^= diff;
bs[ s+9 ] ^= diff;

diff = bs[ s+2 ] ^ bs[ s+10 ];
diff &= cond[2];
bs[ s+2 ] ^= diff;
bs[ s+10 ] ^= diff;

diff = bs[ s+3 ] ^ bs[ s+11 ];
diff &= cond[3];
bs[ s+3 ] ^= diff;
bs[ s+11 ] ^= diff;

cond += 4;
}
}

static void layer_4(uint64_t *bs, uint64_t *cond)
{
int x, s;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 32)
for (s = x; s < x + 16; s += 4)
{
diff = bs[ s+0 ] ^ bs[ s+16 ];
diff &= cond[0];
bs[ s+0 ] ^= diff;
bs[ s+16 ] ^= diff;

diff = bs[ s+1 ] ^ bs[ s+17 ];
diff &= cond[1];
bs[ s+1 ] ^= diff;
bs[ s+17 ] ^= diff;

diff = bs[ s+2 ] ^ bs[ s+18 ];
diff &= cond[2];
bs[ s+2 ] ^= diff;
bs[ s+18 ] ^= diff;

diff = bs[ s+3 ] ^ bs[ s+19 ];
diff &= cond[3];
bs[ s+3 ] ^= diff;
bs[ s+19 ] ^= diff;

cond += 4;
}
}

static void layer_5(uint64_t *bs, uint64_t *cond)
{
int x, s;
uint64_t diff;

for (x = 0; x < (1 << 6); x += 64)
for (s = x; s < x + 32; s += 4)
{
diff = bs[ s+0 ] ^ bs[ s+32 ];
diff &= cond[0];
bs[ s+0 ] ^= diff;
bs[ s+32 ] ^= diff;

diff = bs[ s+1 ] ^ bs[ s+33 ];
diff &= cond[1];
bs[ s+1 ] ^= diff;
bs[ s+33 ] ^= diff;

diff = bs[ s+2 ] ^ bs[ s+34 ];
diff &= cond[2];
bs[ s+2 ] ^= diff;
bs[ s+34 ] ^= diff;

diff = bs[ s+3 ] ^ bs[ s+35 ];
diff &= cond[3];
bs[ s+3 ] ^= diff;
bs[ s+35 ] ^= diff;

cond += 4;
}
}

/* input: bits, control bits as array of bytes */
/* output: out, control bits as array of 64-bit vectors */
void load_bits(uint64_t out[][32], const unsigned char * bits)
{
int i, low, block = 0;

uint64_t cond[64];

//

for (low = 0; low <= 5; low++)
{
for (i = 0; i < 64; i++) cond[i] = load4(bits + block*256 + i*4);
transpose_64x64(cond);

for (i = 0; i < 32; i++) out[ block ][i] = cond[i];
block++;
}

for (low = 0; low <= 5; low++)
{
for (i = 0; i < 32; i++) out[ block ][i] = load8(bits + block*256 + i*8);
block++;
}

for (low = 4; low >= 0; low--)
{
for (i = 0; i < 32; i++) out[ block ][i] = load8(bits + block*256 + i*8);
block++;
}

for (low = 5; low >= 0; low--)
{
for (i = 0; i < 64; i++) cond[i] = load4(bits + block*256 + i*4);
transpose_64x64(cond);

for (i = 0; i < 32; i++) out[ block ][i] = cond[i];
block++;
}
}

/* input: r, sequence of bits to be permuted */
/* cond, control bits as array of 64-bit vectors */
/* rev, 0 for normal application; !0 for inverse */
/* output: r, permuted bits */
void benes(uint64_t * r, uint64_t cond[][32], int rev)
{
int block, inc;

uint64_t *bs = r;

//

if (rev == 0) {block = 0; inc = 1;}
else {block = 22; inc = -1;}

transpose_64x64(bs);

layer_0(bs, cond[ block ]); block += inc;
layer_1(bs, cond[ block ]); block += inc;
layer_2(bs, cond[ block ]); block += inc;
layer_3(bs, cond[ block ]); block += inc;
layer_4(bs, cond[ block ]); block += inc;
layer_5(bs, cond[ block ]); block += inc;

transpose_64x64(bs);

layer_0(bs, cond[ block ]); block += inc;
layer_1(bs, cond[ block ]); block += inc;
layer_2(bs, cond[ block ]); block += inc;
layer_3(bs, cond[ block ]); block += inc;
layer_4(bs, cond[ block ]); block += inc;
layer_5(bs, cond[ block ]); block += inc;
layer_4(bs, cond[ block ]); block += inc;
layer_3(bs, cond[ block ]); block += inc;
layer_2(bs, cond[ block ]); block += inc;
layer_1(bs, cond[ block ]); block += inc;
layer_0(bs, cond[ block ]); block += inc;

transpose_64x64(bs);

layer_5(bs, cond[ block ]); block += inc;
layer_4(bs, cond[ block ]); block += inc;
layer_3(bs, cond[ block ]); block += inc;
layer_2(bs, cond[ block ]); block += inc;
layer_1(bs, cond[ block ]); block += inc;
layer_0(bs, cond[ block ]); block += inc;

transpose_64x64(bs);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
This file is for Benes network related functions
*/

#ifndef BENES_H
#define BENES_H
#define benes CRYPTO_NAMESPACE(benes)
#define load_bits CRYPTO_NAMESPACE(load_bits)
#define support_gen CRYPTO_NAMESPACE(support_gen)

#include "gf.h"

void load_bits(uint64_t [][32], const unsigned char *);
void benes(uint64_t *, uint64_t [][32], int);
void support_gen(gf *, const unsigned char *);

#endif

Loading

0 comments on commit 08cd072

Please sign in to comment.