3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * \license GPLv3 or later
33 typedef uint32_t bigint_word_t;
34 typedef uint64_t bigint_wordplus_t;
35 typedef int64_t bigint_wordplus_signed_t;
36 #define BIGINT_WORD_SIZE 32
38 #define BIGINT_FBS_MASK (BIGINT_WORD_SIZE-1) /* the last five bits indicate which is the first bit set */
39 #define BIGINT_NEG_MASK 0x80 /* this bit indicates a negative value */
43 bigint_word_t *wordv; /* word vector, pointing to the LSB */
48 /******************************************************************************/
50 void bigint_adjust(bigint_t* a);
51 void bigint_copy(bigint_t* dest, const bigint_t* src);
52 void bigint_add_u(bigint_t* dest, const bigint_t* a, const bigint_t* b);
53 void bigint_add_scale_u(bigint_t* dest, const bigint_t* a, uint16_t scale);
54 void bigint_sub_u(bigint_t* dest, const bigint_t* a, const bigint_t* b);
55 int8_t bigint_cmp_u(const bigint_t * a, const bigint_t * b);
56 void bigint_add_s(bigint_t* dest, const bigint_t* a, const bigint_t* b);
57 void bigint_sub_s(bigint_t* dest, const bigint_t* a, const bigint_t* b);
58 int8_t bigint_cmp_s(const bigint_t* a, const bigint_t* b);
59 void bigint_shiftleft(bigint_t* a, uint16_t shift);
60 void bigint_shiftright(bigint_t* a, uint16_t shift);
61 void bigint_xor(bigint_t* dest, const bigint_t* a);
62 void bigint_set_zero(bigint_t* a);
63 void bigint_mul_u(bigint_t* dest, const bigint_t* a, const bigint_t* b);
64 void bigint_mul_s(bigint_t* dest, const bigint_t* a, const bigint_t* b);
65 void bigint_square(bigint_t* dest, const bigint_t* a);
66 void bigint_sub_u_bitscale(bigint_t* a, const bigint_t* b, uint16_t bitscale);
67 void bigint_reduce(bigint_t* a, const bigint_t* r);
68 void bigint_expmod_u(bigint_t* dest, const bigint_t* a, const bigint_t* exp, const bigint_t* r);
69 void bigint_gcdext(bigint_t* gcd, bigint_t* a, bigint_t* b, const bigint_t* x, const bigint_t* y);
70 void bigint_inverse(bigint_t* dest, const bigint_t* a, const bigint_t* m);
71 void bigint_changeendianess(bigint_t* a);
72 /******************************************************************************/