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
15 int pb_init_size(pb_poly
*a
, mp_int
*characteristic
, int size
)
19 /* enforce a minimum size */
24 /* pad size upwards */
25 size
+= (PB_TERMS
- (size
% PB_TERMS
));
28 /* init characteristic */
29 if ((err
= mp_init_copy(&(a
->characteristic
), characteristic
)) != MP_OKAY
) {
33 /* now allocate an array of mp_ints */
34 if ((a
->terms
= calloc(size
, sizeof(mp_int
))) == NULL
) {
35 mp_clear(&(a
->characteristic
));
39 /* now initialize them all */
40 for (x
= 0; x
< size
; x
++) {
41 if ((err
= mp_init(&(a
->terms
[x
]))) != MP_OKAY
) {
43 for (y
= 0; y
< x
; y
++) {
44 mp_clear(&(a
->terms
[y
]));
47 mp_clear(&(a
->characteristic
));
52 /* set our parameters */