Skip to content

Commit

Permalink
Don't pollute the global namespace with internal routines.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yawning committed Nov 3, 2015
1 parent b018ba6 commit 4c70707
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
18 changes: 9 additions & 9 deletions rlwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static uint32_t single_sample_ct(uint64_t *in) {
return index;
}

void sample_ct(uint32_t *s, RAND_CTX *rand_ctx) {
void rlwe_sample_ct(uint32_t *s, RAND_CTX *rand_ctx) {
int i, j;
for (i = 0; i < 16; i++) {
uint64_t r = RANDOM64(rand_ctx);
Expand All @@ -173,7 +173,7 @@ void sample_ct(uint32_t *s, RAND_CTX *rand_ctx) {
}
}

void round2_ct(uint64_t *out, const uint32_t *in) {
void rlwe_round2_ct(uint64_t *out, const uint32_t *in) {
int i;
memset(out, 0, 128);
for (i = 0; i < 1024; i++) {
Expand All @@ -183,7 +183,7 @@ void round2_ct(uint64_t *out, const uint32_t *in) {
}
}

void crossround2_ct(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
void rlwe_crossround2_ct(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
int i, j;
memset(out, 0, 128);
for (i = 0; i < 64; i++) {
Expand All @@ -200,7 +200,7 @@ void crossround2_ct(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
}
}

void rec_ct(uint64_t *out, const uint32_t *w, const uint64_t *b) {
void rlwe_rec_ct(uint64_t *out, const uint32_t *w, const uint64_t *b) {
int i;
memset(out, 0, 128);
for (i = 0; i < 1024; i++) {
Expand All @@ -217,7 +217,7 @@ void rec_ct(uint64_t *out, const uint32_t *w, const uint64_t *b) {

#else

void sample(uint32_t *s, RAND_CTX *rand_ctx) {
void rlwe_sample(uint32_t *s, RAND_CTX *rand_ctx) {
int i, j;
for (i = 0; i < 16; i++) {
uint64_t r = RANDOM64(rand_ctx);
Expand All @@ -236,7 +236,7 @@ void sample(uint32_t *s, RAND_CTX *rand_ctx) {
}
}

void round2(uint64_t *out, const uint32_t *in) {
void rlwe_round2(uint64_t *out, const uint32_t *in) {
int i;

// out should have enough space for 1024-bits
Expand All @@ -250,7 +250,7 @@ void round2(uint64_t *out, const uint32_t *in) {
}
}

void crossround2(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
void rlwe_crossround2(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
int i, j;
// out should have enough space for 1024-bits
memset(out, 0, 128);
Expand All @@ -268,7 +268,7 @@ void crossround2(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx) {
}
}

void rec(uint64_t *out, const uint32_t *w, const uint64_t *b) {
void rlwe_rec(uint64_t *out, const uint32_t *w, const uint64_t *b) {
int i;

// out should have enough space for 1024-bits
Expand All @@ -292,7 +292,7 @@ void rec(uint64_t *out, const uint32_t *w, const uint64_t *b) {

#endif

void key_gen(uint32_t *out, const uint32_t *a, const uint32_t *s, const uint32_t *e, FFT_CTX *ctx) {
void rlwe_key_gen(uint32_t *out, const uint32_t *a, const uint32_t *s, const uint32_t *e, FFT_CTX *ctx) {
FFT_mul(out, a, s, ctx);
FFT_add(out, out, e);
}
Expand Down
18 changes: 9 additions & 9 deletions rlwe.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
#include "rlwe_rand.h"

#ifdef CONSTANT_TIME
void sample_ct(uint32_t *s, RAND_CTX *rand_ctx);
void round2_ct(uint64_t *out, const uint32_t *in);
void crossround2_ct(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx);
void rec_ct(uint64_t *out, const uint32_t *w, const uint64_t *b);
void rlwe_sample_ct(uint32_t *s, RAND_CTX *rand_ctx);
void rlwe_round2_ct(uint64_t *out, const uint32_t *in);
void rlwe_crossround2_ct(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx);
void rlwe_rec_ct(uint64_t *out, const uint32_t *w, const uint64_t *b);
#else
void sample(uint32_t *s, RAND_CTX *rand_ctx);
void round2(uint64_t *out, const uint32_t *in);
void crossround2(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx);
void rec(uint64_t *out, const uint32_t *w, const uint64_t *b);
void rlwe_sample(uint32_t *s, RAND_CTX *rand_ctx);
void rlwe_round2(uint64_t *out, const uint32_t *in);
void rlwe_crossround2(uint64_t *out, const uint32_t *in, RAND_CTX *rand_ctx);
void rlwe_rec(uint64_t *out, const uint32_t *w, const uint64_t *b);
#endif

void key_gen(uint32_t *out, const uint32_t *a, const uint32_t *s, const uint32_t *e, FFT_CTX *ctx);
void rlwe_key_gen(uint32_t *out, const uint32_t *a, const uint32_t *s, const uint32_t *e, FFT_CTX *ctx);

#endif /* _RLWE_H_ */
20 changes: 10 additions & 10 deletions rlwe_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ int main() {
printf("------------------------------------------------------------------------------\n");

#ifdef CONSTANT_TIME
TIME_OPERATION(sample_ct(s, &rand_ctx), "sample_ct", ITERATIONS / 50)
TIME_OPERATION(rlwe_sample_ct(s, &rand_ctx), "sample_ct", ITERATIONS / 50)
TIME_OPERATION(FFT_mul(b, rlwe_a, s, &ctx), "FFT_mul", ITERATIONS / 50)
sample_ct(e, &rand_ctx);
rlwe_sample_ct(e, &rand_ctx);
TIME_OPERATION(FFT_add(b, b, e), "FFT_add", ITERATIONS)
TIME_OPERATION(crossround2_ct(c, b, &rand_ctx), "crossround2_ct", ITERATIONS / 10)
TIME_OPERATION(round2_ct(k, b), "round2_ct", ITERATIONS / 10)
TIME_OPERATION(rec_ct(k, b, c), "rec_ct", ITERATIONS)
TIME_OPERATION(rlwe_crossround2_ct(c, b, &rand_ctx), "crossround2_ct", ITERATIONS / 10)
TIME_OPERATION(rlwe_round2_ct(k, b), "round2_ct", ITERATIONS / 10)
TIME_OPERATION(rlwe_rec_ct(k, b, c), "rec_ct", ITERATIONS)
#else
TIME_OPERATION(sample(s, &rand_ctx), "sample", ITERATIONS / 50)
TIME_OPERATION(rlwe_sample(s, &rand_ctx), "sample", ITERATIONS / 50)
TIME_OPERATION(FFT_mul(b, rlwe_a, s, &ctx), "FFT_mul", ITERATIONS / 50)
sample(e, &rand_ctx);
rlwe_sample(e, &rand_ctx);
TIME_OPERATION(FFT_add(b, b, e), "FFT_add", ITERATIONS)
TIME_OPERATION(crossround2(c, b, &rand_ctx), "crossround2", ITERATIONS / 10)
TIME_OPERATION(round2(k, b), "round2", ITERATIONS / 10)
TIME_OPERATION(rec(k, b, c), "rec", ITERATIONS)
TIME_OPERATION(rlwe_crossround2(c, b, &rand_ctx), "crossround2", ITERATIONS / 10)
TIME_OPERATION(rlwe_round2(k, b), "round2", ITERATIONS / 10)
TIME_OPERATION(rlwe_rec(k, b, c), "rec", ITERATIONS)
#endif
TIME_OPERATION(rlwe_kex_generate_keypair(rlwe_a, s, b, &ctx), "rlwe_kex_generate_keypair", ITERATIONS / 50)
TIME_OPERATION(rlwe_kex_compute_key_bob(b, s, c, k, &ctx), "rlwe_kex_compute_key_bob", ITERATIONS / 50)
Expand Down
28 changes: 14 additions & 14 deletions rlwe_kex.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ void rlwe_kex_generate_keypair(const uint32_t *a, uint32_t s[1024], uint32_t b[1
return;
}
#if CONSTANT_TIME
sample_ct(s, &rand_ctx);
sample_ct(e, &rand_ctx);
rlwe_sample_ct(s, &rand_ctx);
rlwe_sample_ct(e, &rand_ctx);
#else
sample(s, &rand_ctx);
sample(e, &rand_ctx);
rlwe_sample(s, &rand_ctx);
rlwe_sample(e, &rand_ctx);
#endif
key_gen(b, a, s, e, ctx);
rlwe_key_gen(b, a, s, e, ctx);
memset((char *) e, 0, 1024 * sizeof(uint32_t));
RAND_CTX_cleanup(&rand_ctx);
}
Expand All @@ -41,9 +41,9 @@ void rlwe_kex_compute_key_alice(const uint32_t b[1024], const uint32_t s[1024],
uint32_t w[1024];
FFT_mul(w, b, s, ctx);
#if CONSTANT_TIME
rec_ct(k, w, c);
rlwe_rec_ct(k, w, c);
#else
rec(k, w, c);
rlwe_rec(k, w, c);
#endif
memset((char *) w, 0, 1024 * sizeof(uint32_t));
}
Expand All @@ -57,17 +57,17 @@ void rlwe_kex_compute_key_bob(const uint32_t b[1024], const uint32_t s[1024], ui
return;
}
#if CONSTANT_TIME
sample_ct(eprimeprime, &rand_ctx);
rlwe_sample_ct(eprimeprime, &rand_ctx);
#else
sample(eprimeprime, &rand_ctx);
rlwe_sample(eprimeprime, &rand_ctx);
#endif
key_gen(v, b, s, eprimeprime, ctx);
rlwe_key_gen(v, b, s, eprimeprime, ctx);
#if CONSTANT_TIME
crossround2_ct(c, v, &rand_ctx);
round2_ct(k, v);
rlwe_crossround2_ct(c, v, &rand_ctx);
rlwe_round2_ct(k, v);
#else
crossround2(c, v, &rand_ctx);
round2(k, v);
rlwe_crossround2(c, v, &rand_ctx);
rlwe_round2(k, v);
#endif
memset((char *) v, 0, 1024 * sizeof(uint32_t));
memset((char *) eprimeprime, 0, 1024 * sizeof(uint32_t));
Expand Down

0 comments on commit 4c70707

Please sign in to comment.