change some parameters in the library to meet the needs of the website httpbin.org
Fork of MiniTLS-GPL by
math/bin/fp_read_unsigned_bin.c@5:95f70ebfe61f, 2015-02-06 (annotated)
- Committer:
- shiyilei
- Date:
- Fri Feb 06 06:17:33 2015 +0000
- Revision:
- 5:95f70ebfe61f
- Parent:
- 0:35aa5be3b78d
change some parameters in the library to meet the needs of httpbin.org
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MiniTLS | 0:35aa5be3b78d | 1 | /* TomsFastMath, a fast ISO C bignum library. |
MiniTLS | 0:35aa5be3b78d | 2 | * |
MiniTLS | 0:35aa5be3b78d | 3 | * This project is meant to fill in where LibTomMath |
MiniTLS | 0:35aa5be3b78d | 4 | * falls short. That is speed ;-) |
MiniTLS | 0:35aa5be3b78d | 5 | * |
MiniTLS | 0:35aa5be3b78d | 6 | * This project is public domain and free for all purposes. |
MiniTLS | 0:35aa5be3b78d | 7 | * |
MiniTLS | 0:35aa5be3b78d | 8 | * Tom St Denis, tomstdenis@gmail.com |
MiniTLS | 0:35aa5be3b78d | 9 | */ |
MiniTLS | 0:35aa5be3b78d | 10 | #include <tfm.h> |
MiniTLS | 0:35aa5be3b78d | 11 | |
MiniTLS | 0:35aa5be3b78d | 12 | void fp_read_unsigned_bin(fp_int *a, unsigned char *b, int c) |
MiniTLS | 0:35aa5be3b78d | 13 | { |
MiniTLS | 0:35aa5be3b78d | 14 | /* zero the int */ |
MiniTLS | 0:35aa5be3b78d | 15 | fp_zero (a); |
MiniTLS | 0:35aa5be3b78d | 16 | |
MiniTLS | 0:35aa5be3b78d | 17 | /* If we know the endianness of this architecture, and we're using |
MiniTLS | 0:35aa5be3b78d | 18 | 32-bit fp_digits, we can optimize this */ |
MiniTLS | 0:35aa5be3b78d | 19 | #if (defined(ENDIAN_LITTLE) || defined(ENDIAN_BIG)) && !defined(FP_64BIT) |
MiniTLS | 0:35aa5be3b78d | 20 | /* But not for both simultaneously */ |
MiniTLS | 0:35aa5be3b78d | 21 | #if defined(ENDIAN_LITTLE) && defined(ENDIAN_BIG) |
MiniTLS | 0:35aa5be3b78d | 22 | #error Both ENDIAN_LITTLE and ENDIAN_BIG defined. |
MiniTLS | 0:35aa5be3b78d | 23 | #endif |
MiniTLS | 0:35aa5be3b78d | 24 | { |
MiniTLS | 0:35aa5be3b78d | 25 | unsigned char *pd = (unsigned char *)a->dp; |
MiniTLS | 0:35aa5be3b78d | 26 | |
MiniTLS | 0:35aa5be3b78d | 27 | if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) { |
MiniTLS | 0:35aa5be3b78d | 28 | int excess = c - (FP_SIZE * sizeof(fp_digit)); |
MiniTLS | 0:35aa5be3b78d | 29 | c -= excess; |
MiniTLS | 0:35aa5be3b78d | 30 | b += excess; |
MiniTLS | 0:35aa5be3b78d | 31 | } |
MiniTLS | 0:35aa5be3b78d | 32 | a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit); |
MiniTLS | 0:35aa5be3b78d | 33 | /* read the bytes in */ |
MiniTLS | 0:35aa5be3b78d | 34 | #ifdef ENDIAN_BIG |
MiniTLS | 0:35aa5be3b78d | 35 | { |
MiniTLS | 0:35aa5be3b78d | 36 | /* Use Duff's device to unroll the loop. */ |
MiniTLS | 0:35aa5be3b78d | 37 | int idx = (c - 1) & ~3; |
MiniTLS | 0:35aa5be3b78d | 38 | switch (c % 4) { |
MiniTLS | 0:35aa5be3b78d | 39 | case 0: do { pd[idx+0] = *b++; |
MiniTLS | 0:35aa5be3b78d | 40 | case 3: pd[idx+1] = *b++; |
MiniTLS | 0:35aa5be3b78d | 41 | case 2: pd[idx+2] = *b++; |
MiniTLS | 0:35aa5be3b78d | 42 | case 1: pd[idx+3] = *b++; |
MiniTLS | 0:35aa5be3b78d | 43 | idx -= 4; |
MiniTLS | 0:35aa5be3b78d | 44 | } while ((c -= 4) > 0); |
MiniTLS | 0:35aa5be3b78d | 45 | } |
MiniTLS | 0:35aa5be3b78d | 46 | } |
MiniTLS | 0:35aa5be3b78d | 47 | #else |
MiniTLS | 0:35aa5be3b78d | 48 | for (c -= 1; c >= 0; c -= 1) { |
MiniTLS | 0:35aa5be3b78d | 49 | pd[c] = *b++; |
MiniTLS | 0:35aa5be3b78d | 50 | } |
MiniTLS | 0:35aa5be3b78d | 51 | #endif |
MiniTLS | 0:35aa5be3b78d | 52 | } |
MiniTLS | 0:35aa5be3b78d | 53 | #else |
MiniTLS | 0:35aa5be3b78d | 54 | /* read the bytes in */ |
MiniTLS | 0:35aa5be3b78d | 55 | for (; c > 0; c--) { |
MiniTLS | 0:35aa5be3b78d | 56 | fp_mul_2d (a, 8, a); |
MiniTLS | 0:35aa5be3b78d | 57 | a->dp[0] |= *b++; |
MiniTLS | 0:35aa5be3b78d | 58 | a->used += 1; |
MiniTLS | 0:35aa5be3b78d | 59 | } |
MiniTLS | 0:35aa5be3b78d | 60 | #endif |
MiniTLS | 0:35aa5be3b78d | 61 | fp_clamp (a); |
MiniTLS | 0:35aa5be3b78d | 62 | } |
MiniTLS | 0:35aa5be3b78d | 63 | |
MiniTLS | 0:35aa5be3b78d | 64 | /* $Source: /cvs/libtom/tomsfastmath/src/bin/fp_read_unsigned_bin.c,v $ */ |
MiniTLS | 0:35aa5be3b78d | 65 | /* $Revision: 1.2 $ */ |
MiniTLS | 0:35aa5be3b78d | 66 | /* $Date: 2007/02/17 02:58:19 $ */ |