RND: use function callback for random ints
This commit is contained in:
parent
e88dc81c90
commit
8c5649ea24
|
@ -86,7 +86,8 @@ void
|
||||||
ntru_get_rnd_tern_poly_num(fmpz_poly_t poly,
|
ntru_get_rnd_tern_poly_num(fmpz_poly_t poly,
|
||||||
const ntru_context *ctx,
|
const ntru_context *ctx,
|
||||||
uint32_t num_ones,
|
uint32_t num_ones,
|
||||||
uint32_t num_neg_ones)
|
uint32_t num_neg_ones,
|
||||||
|
int (*rnd_int)(void))
|
||||||
{
|
{
|
||||||
if (!poly || ! ctx)
|
if (!poly || ! ctx)
|
||||||
NTRU_ABORT("unexpected NULL parameters in"
|
NTRU_ABORT("unexpected NULL parameters in"
|
||||||
|
@ -95,7 +96,7 @@ ntru_get_rnd_tern_poly_num(fmpz_poly_t poly,
|
||||||
fmpz_poly_zero(poly);
|
fmpz_poly_zero(poly);
|
||||||
|
|
||||||
while (num_ones != 0 || num_neg_ones != 0) {
|
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 (!fmpz_cmp_si_n(fmpz_poly_get_coeff_ptr(poly, pos), 0)) {
|
||||||
if (num_ones > 0) {
|
if (num_ones > 0) {
|
||||||
|
|
|
@ -59,12 +59,15 @@ get_urnd_int(void);
|
||||||
* @param ctx the NTRU context
|
* @param ctx the NTRU context
|
||||||
* @param num_ones the number of 1 coefficients
|
* @param num_ones the number of 1 coefficients
|
||||||
* @param num_neg_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
|
void
|
||||||
ntru_get_rnd_tern_poly_num(fmpz_poly_t poly,
|
ntru_get_rnd_tern_poly_num(fmpz_poly_t poly,
|
||||||
const ntru_context *ctx,
|
const ntru_context *ctx,
|
||||||
uint32_t num_ones,
|
uint32_t num_ones,
|
||||||
uint32_t num_neg_ones);
|
uint32_t num_neg_ones,
|
||||||
|
int (*rnd_int)(void));
|
||||||
|
|
||||||
|
|
||||||
#endif /* NTRU_RND_H */
|
#endif /* NTRU_RND_H */
|
||||||
|
|
Loading…
Reference in New Issue