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
16 int pb_init_size(pb_poly
*a
, mp_int
*characteristic
, int size
)
20 /* enforce a minimum size */
25 /* pad size upwards */
26 size
+= (PB_TERMS
- (size
% PB_TERMS
));
29 /* init characteristic */
30 if ((err
= mp_init_copy(&(a
->characteristic
), characteristic
)) != MP_OKAY
) {
34 /* now allocate an array of mp_ints */
35 if ((a
->terms
= calloc(size
, sizeof(mp_int
))) == NULL
) {
36 mp_clear(&(a
->characteristic
));
40 /* now initialize them all */
41 for (x
= 0; x
< size
; x
++) {
42 if ((err
= mp_init(&(a
->terms
[x
]))) != MP_OKAY
) {
44 for (y
= 0; y
< x
; y
++) {
45 mp_clear(&(a
->terms
[y
]));
48 mp_clear(&(a
->characteristic
));
53 /* set our parameters */