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_toraw(pb_poly
*a
, unsigned char *dst
)
18 /* store the # of terms */
19 dst
[0] = a
->used
& 255;
20 dst
[1] = (a
->used
>> 8) & 255;
23 /* store the characteristic */
24 z
= mp_signed_bin_size(&(a
->characteristic
));
26 dst
[y
++] = (z
>>8)&255;
27 if ((err
= mp_to_signed_bin(&(a
->characteristic
), dst
+y
)) != MP_OKAY
) { return err
; }
30 for (x
= 0; x
< a
->used
; x
++) {
31 z
= mp_signed_bin_size(&(a
->terms
[x
]));
33 dst
[y
++] = (z
>>8)&255;
34 if ((err
= mp_to_signed_bin(&(a
->terms
[x
]), dst
+y
)) != MP_OKAY
) { return err
; }