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_add(pb_poly
*a
, pb_poly
*b
, pb_poly
*c
)
16 int err
, x
, y
, z
, characteristic
;
19 /* grow c to be the max size */
20 y
= MAX(a
->used
, b
->used
);
22 if ((err
= pb_grow(c
, y
)) != MP_OKAY
) {
27 /* do we need to concern char */
28 characteristic
= mp_iszero(&(c
->characteristic
));
31 z
= MIN(a
->used
, b
->used
);
32 for (x
= 0; x
< z
; x
++) {
33 if ((err
= mp_add(&(a
->terms
[x
]), &(b
->terms
[x
]), &(c
->terms
[x
]))) != MP_OKAY
) {
36 if (characteristic
== MP_NO
) {
37 if ((err
= mp_mod(&(c
->terms
[x
]), &(c
->characteristic
), &(c
->terms
[x
]))) != MP_OKAY
) {
50 for (x
= z
; x
< y
; x
++) {
51 if (characteristic
== MP_NO
) {
52 if ((err
= mp_mod(&(tmp
->terms
[x
]), &(c
->characteristic
), &(c
->terms
[x
]))) != MP_OKAY
) {
56 if ((err
= mp_copy(&(tmp
->terms
[x
]), &(c
->terms
[x
]))) != MP_OKAY
) {
64 for (x
= y
; x
< c
->used
; x
++) {
65 mp_zero(&(c
->terms
[x
]));