POLY: add pb_mp_mul()

This commit is contained in:
hasufell 2014-04-30 17:19:58 +02:00
parent 9c89b79627
commit f2b4183c68
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 33 additions and 0 deletions

View File

@ -270,6 +270,29 @@ void pb_starmultiply(pb_poly *a,
delete_polynom(a_tmp);
}
/**
* Calculate c = a * b where c and a are polynomials
* and b is an mp_int.
*
* @param a polynom
* @param b mp_int
* @param c polynom [out]
* @return error code of pb_mul()
*/
int pb_mp_mul(pb_poly *a, mp_int *b, pb_poly *c)
{
int result;
pb_poly *b_poly = build_polynom(NULL, 1);
MP_COPY(b, &(b_poly->terms[0]));
printf("u converted to poly: "); draw_polynom(b_poly);
result = pb_mul(a, b_poly, c);
delete_polynom(b_poly);
return result;
}
/**
* c = a XOR b
*

View File

@ -135,6 +135,14 @@ unsigned int get_degree(pb_poly const * const poly);
mp_error_to_string(result)); \
}
#define PB_MP_MUL(...) \
{ \
int result; \
if ((result = pb_mp_mul(__VA_ARGS__)) != MP_OKAY) \
NTRU_ABORT("Error multiplying polynomial with mp_int. %s", \
mp_error_to_string(result)); \
}
#define PB_ADD(...) \
{ \
int result; \
@ -187,6 +195,8 @@ void pb_starmultiply(pb_poly *a,
ntru_context *ctx,
unsigned int modulus);
int pb_mp_mul(pb_poly *a, mp_int *b, pb_poly *c);
void pb_xor(pb_poly *a,
pb_poly *b,
pb_poly *c,