Re-licensed all code under WTFPL, c.f. http://sam.zoy.org/wtfpl/
[libtompoly.git] / pb_submod.c
blobbfa2f8e42d82727d679a282e2cd66409a4d96784
1 /* LibTomPoly, Polynomial Basis Math -- Tom St Denis
2 *
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
12 #include <tompoly.h>
14 int pb_submod(pb_poly *a, pb_poly *b, pb_poly *c, pb_poly *d)
16 int err;
17 pb_poly tmp;
19 if ((err = pb_init(&tmp, &(d->characteristic))) != MP_OKAY) {
20 return err;
22 if ((err = pb_sub(a, b, &tmp)) != MP_OKAY) {
23 goto __TMP;
25 if ((err = pb_mod(&tmp, c, d)) != MP_OKAY) {
26 goto __TMP;
29 err = MP_OKAY;
30 __TMP: pb_clear(&tmp);
31 return err;