POLY: implemented pb_normalize
normalizes a polynom by defining a numerical range for each factor of a polynom.
This commit is contained in:
parent
1412ba0d1a
commit
4030335661
34
src/poly.c
34
src/poly.c
@ -432,3 +432,37 @@ void draw_polynom(pb_poly * const poly)
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void pb_normalize(pb_poly *poly, int low_border, int high_border, ntru_context *ctx){
|
||||
unsigned int p = ctx->p;
|
||||
unsigned int N = ctx->N;
|
||||
|
||||
mp_int mp_p;
|
||||
mp_int mp_low_border;
|
||||
mp_int mp_high_border;
|
||||
|
||||
init_integer(&mp_low_border);
|
||||
init_integer(&mp_high_border);
|
||||
init_integer(&mp_p);
|
||||
|
||||
MP_SET_INT(&mp_p, p);
|
||||
MP_SET_INT(&mp_low_border,(unsigned long)abs(low_border));
|
||||
mp_neg(&mp_low_border,&mp_low_border);
|
||||
MP_SET_INT(&mp_high_border,high_border);
|
||||
|
||||
|
||||
unsigned int i;
|
||||
for(i = 0; i < N; i++){
|
||||
if(mp_cmp(&(poly->terms[i]),&mp_low_border) == MP_LT) {
|
||||
mp_add(&(poly->terms[i]),&mp_p,&(poly->terms[i]));
|
||||
} else if(mp_cmp(&(poly->terms[i]),&mp_high_border) == MP_GT) {
|
||||
mp_sub(&(poly->terms[i]),&mp_p,&(poly->terms[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_mp_int(mp_int *digit) {
|
||||
char buf[8192];
|
||||
mp_toradix(digit, buf, 10);
|
||||
printf("%s\n",buf);
|
||||
}
|
||||
|
@ -184,4 +184,11 @@ bool pb_inverse_poly_q(pb_poly *a,
|
||||
|
||||
void draw_polynom(pb_poly * const poly);
|
||||
|
||||
void pb_normalize(pb_poly*,
|
||||
int,
|
||||
int,
|
||||
ntru_context*);
|
||||
|
||||
void draw_mp_int(mp_int*);
|
||||
|
||||
#endif /* NTRU_POLY_H */
|
||||
|
Loading…
Reference in New Issue
Block a user