1 /* LibTomPoly, Polynomial Basis Math -- Tom St Denis
3 * LibTomPoly is a public domain library that provides
4 * polynomial basis arithmetic support. It relies on
5 * LibTomMath for large integer support.
7 * This library is free for all purposes without any
8 * express guarantee that it works.
10 * Tom St Denis, tomstdenis@iahu.ca, http://poly.libtomcrypt.org
14 int pb_mul(pb_poly
*a
, pb_poly
*b
, pb_poly
*c
)
21 if ((err
= pb_init_size(&tmp
, &(c
->characteristic
), a
->used
+ b
->used
)) != MP_OKAY
) {
25 if ((err
= mp_init(&tmp2
)) != MP_OKAY
) {
29 /* multiply the terms */
30 for (x
= 0; x
< a
->used
; x
++) {
31 for (y
= 0; y
< b
->used
; y
++) {
32 if ((err
= mp_mul(&(a
->terms
[x
]), &(b
->terms
[y
]), &tmp2
)) != MP_OKAY
) {
35 if ((err
= mp_add(&tmp2
, &(tmp
.terms
[x
+y
]), &(tmp
.terms
[x
+y
]))) != MP_OKAY
) {
41 /* now reduce the terms as required */
42 if (mp_iszero(&(c
->characteristic
)) == MP_NO
) {
43 for (x
= 0; x
< (a
->used
+ b
->used
); x
++) {
44 if ((err
= mp_mod(&(tmp
.terms
[x
]), &(c
->characteristic
), &(tmp
.terms
[x
]))) != MP_OKAY
) {
51 tmp
.used
= a
->used
+ b
->used
;
54 /* exchange tmp and c */
59 __TMP2
: mp_clear(&tmp2
);
60 __TMP
: pb_clear(&tmp
);