X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=bigint%2Fbigint.h;h=0ae129ccb9bbb0b04ac7d9f02832ba5ce0a78607;hp=f42ae18992d3010ae9c8da8890bf4d91040fe0d0;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=b3cf9d2f35e428cae278fffb8a8f5820d40c833b diff --git a/bigint/bigint.h b/bigint/bigint.h index f42ae18..0ae129c 100644 --- a/bigint/bigint.h +++ b/bigint/bigint.h @@ -1,7 +1,7 @@ /* bigint.h */ /* This file is part of the ARM-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,13 +30,28 @@ #include #include +#include +#define BIGINT_WORD_SIZE 8 + +#if BIGINT_WORD_SIZE == 8 typedef uint8_t bigint_word_t; typedef uint16_t bigint_wordplus_t; typedef int16_t bigint_wordplus_signed_t; -#define BIGINT_WORD_SIZE 8 - -#define BIGINT_FBS_MASK (BIGINT_WORD_SIZE-1) /* the last five bits indicate which is the first bit set */ +#elif BIGINT_WORD_SIZE == 16 +typedef uint16_t bigint_word_t; +typedef uint32_t bigint_wordplus_t; +typedef int32_t bigint_wordplus_signed_t; +#elif BIGINT_WORD_SIZE == 32 +typedef uint32_t bigint_word_t; +typedef uint64_t bigint_wordplus_t; +typedef int64_t bigint_wordplus_signed_t; +#else +#error "INVALID VALUE FOR BIGINT_WORD_SIZE" +#endif + + +#define BIGINT_FBS_MASK (BIGINT_WORD_SIZE - 1) /* the last five bits indicate which is the first bit set */ #define BIGINT_NEG_MASK 0x80 /* this bit indicates a negative value */ typedef size_t bigint_length_t; @@ -53,8 +68,8 @@ typedef struct{ /******************************************************************************/ void bigint_adjust(bigint_t *a); -uint32_t bigint_get_first_set_bit(const bigint_t *a); -uint32_t bigint_get_last_set_bit(const bigint_t *a); +int32_t bigint_get_first_set_bit(const bigint_t *a); +int32_t bigint_get_last_set_bit(const bigint_t *a); bigint_length_t bigint_length_b(const bigint_t *a); bigint_length_t bigint_length_B(const bigint_t *a); void bigint_copy(bigint_t *dest, const bigint_t *src); @@ -65,7 +80,10 @@ int8_t bigint_cmp_u(const bigint_t * a, const bigint_t * b); void bigint_add_s(bigint_t *dest, const bigint_t *a, const bigint_t *b); void bigint_sub_s(bigint_t *dest, const bigint_t *a, const bigint_t *b); int8_t bigint_cmp_s(const bigint_t *a, const bigint_t *b); +void bigint_shiftleft_bits(bigint_t *a, uint8_t shift); void bigint_shiftleft(bigint_t *a, bigint_length_t shift); +void bigint_shiftright_1bit(bigint_t *a); +void bigint_shiftright_1word(bigint_t *a); void bigint_shiftright(bigint_t *a, bigint_length_t shift); void bigint_xor(bigint_t *dest, const bigint_t *a); void bigint_set_zero(bigint_t *a); @@ -87,6 +105,7 @@ void bigint_mont_trans(bigint_t *dest, const bigint_t *a, const bigint_t *m); void bigint_expmod_u(bigint_t *dest, const bigint_t *a, const bigint_t *exp, const bigint_t *r); void bigint_expmod_u_sam(bigint_t *dest, const bigint_t *a, const bigint_t *exp, const bigint_t *r); void bigint_expmod_u_mont_sam(bigint_t *dest, const bigint_t *a, const bigint_t *exp, const bigint_t *r); +void bigint_expmod_u_mont_accel(bigint_t *dest, const bigint_t *a, const bigint_t *exp, const bigint_t *r, const bigint_t *m_); #endif /*BIGINT_H_*/