From f2b4183c688b57fec4848ffebfd4c9e9a03e5fdd Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 30 Apr 2014 17:19:58 +0200 Subject: [PATCH] POLY: add pb_mp_mul() --- src/poly.c | 23 +++++++++++++++++++++++ src/poly.h | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/poly.c b/src/poly.c index c60b24b..66b6898 100644 --- a/src/poly.c +++ b/src/poly.c @@ -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 * diff --git a/src/poly.h b/src/poly.h index 20132cb..b8589a6 100644 --- a/src/poly.h +++ b/src/poly.h @@ -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,