From 8c5649ea2407c198f03ce590fe00ac0772d06beb Mon Sep 17 00:00:00 2001 From: hasufell Date: Tue, 3 Jun 2014 18:09:57 +0200 Subject: [PATCH] RND: use function callback for random ints --- src/rnd.c | 5 +++-- src/rnd.h | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rnd.c b/src/rnd.c index 5e8608b..76cc524 100644 --- a/src/rnd.c +++ b/src/rnd.c @@ -86,7 +86,8 @@ void ntru_get_rnd_tern_poly_num(fmpz_poly_t poly, const ntru_context *ctx, uint32_t num_ones, - uint32_t num_neg_ones) + uint32_t num_neg_ones, + int (*rnd_int)(void)) { if (!poly || ! ctx) NTRU_ABORT("unexpected NULL parameters in" @@ -95,7 +96,7 @@ ntru_get_rnd_tern_poly_num(fmpz_poly_t poly, fmpz_poly_zero(poly); while (num_ones != 0 || num_neg_ones != 0) { - int32_t pos = get_rnd_int() % ctx->N; + int32_t pos = rnd_int() % ctx->N; if (!fmpz_cmp_si_n(fmpz_poly_get_coeff_ptr(poly, pos), 0)) { if (num_ones > 0) { diff --git a/src/rnd.h b/src/rnd.h index d29c694..10d838c 100644 --- a/src/rnd.h +++ b/src/rnd.h @@ -59,12 +59,15 @@ get_urnd_int(void); * @param ctx the NTRU context * @param num_ones the number of 1 coefficients * @param num_neg_ones the number of -1 coefficients + * @param rnd_int function callback which should return + * a random integer */ void ntru_get_rnd_tern_poly_num(fmpz_poly_t poly, const ntru_context *ctx, uint32_t num_ones, - uint32_t num_neg_ones); + uint32_t num_neg_ones, + int (*rnd_int)(void)); #endif /* NTRU_RND_H */