1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
12 void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
17 /* If we know the endianness of this architecture, and we're using
18 32-bit fp_digits, we can optimize this */
19 #if (defined(ENDIAN_LITTLE) || defined(ENDIAN_BIG)) && !defined(FP_64BIT)
20 /* But not for both simultaneously */
21 #if defined(ENDIAN_LITTLE) && defined(ENDIAN_BIG)
22 #error Both ENDIAN_LITTLE and ENDIAN_BIG defined.
25 unsigned char *pd = (unsigned char *)a->dp;
27 if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) {
28 int excess = c - (FP_SIZE * sizeof(fp_digit));
32 a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
33 /* read the bytes in */
36 /* Use Duff's device to unroll the loop. */
37 int idx = (c - 1) & ~3;
39 case 0: do { pd[idx+0] = *b++;
40 case 3: pd[idx+1] = *b++;
41 case 2: pd[idx+2] = *b++;
42 case 1: pd[idx+3] = *b++;
44 } while ((c -= 4) > 0);
48 for (c -= 1; c >= 0; c -= 1) {
54 /* read the bytes in */