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_sub(pb_poly
*a
, pb_poly
*b
, pb_poly
*c
)
16 int neg
, err
, x
, y
, z
, characteristic
;
19 /* grow c to be the max size */
20 y
= PB_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
= PB_MIN(a
->used
, b
->used
);
32 for (x
= 0; x
< z
; x
++) {
33 if ((err
= mp_sub(&(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
) {
52 for (x
= z
; x
< y
; x
++) {
53 if (characteristic
== MP_NO
) {
54 if ((err
= mp_mod(&(tmp
->terms
[x
]), &(c
->characteristic
), &(c
->terms
[x
]))) != MP_OKAY
) {
58 if ((err
= mp_sub(&(c
->characteristic
), &(c
->terms
[x
]), &(c
->terms
[x
]))) != MP_OKAY
) {
64 if ((err
= mp_neg(&(tmp
->terms
[x
]), &(c
->terms
[x
]))) != MP_OKAY
) {
68 if ((err
= mp_copy(&(tmp
->terms
[x
]), &(c
->terms
[x
]))) != MP_OKAY
) {
77 for (x
= y
; x
< c
->used
; x
++) {
78 mp_zero(&(c
->terms
[x
]));