| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 #ifndef __ecl_priv_h_ | 5 #ifndef __ecl_priv_h_ |
| 6 #define __ecl_priv_h_ | 6 #define __ecl_priv_h_ |
| 7 | 7 |
| 8 #include "ecl.h" | 8 #include "ecl.h" |
| 9 #include "mpi.h" | 9 #include "mpi.h" |
| 10 #include "mplogic.h" | 10 #include "mplogic.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #define ECL_BITS (sizeof(mp_digit)*8) | 22 #define ECL_BITS (sizeof(mp_digit)*8) |
| 23 #define ECL_MAX_FIELD_SIZE_DIGITS (80/sizeof(mp_digit)) | 23 #define ECL_MAX_FIELD_SIZE_DIGITS (80/sizeof(mp_digit)) |
| 24 | 24 |
| 25 /* Gets the i'th bit in the binary representation of a. If i >= length(a), | 25 /* Gets the i'th bit in the binary representation of a. If i >= length(a), |
| 26 * then return 0. (The above behaviour differs from mpl_get_bit, which | 26 * then return 0. (The above behaviour differs from mpl_get_bit, which |
| 27 * causes an error if i >= length(a).) */ | 27 * causes an error if i >= length(a).) */ |
| 28 #define MP_GET_BIT(a, i) \ | 28 #define MP_GET_BIT(a, i) \ |
| 29 ((i) >= mpl_significant_bits((a))) ? 0 : mpl_get_bit((a), (i)) | 29 ((i) >= mpl_significant_bits((a))) ? 0 : mpl_get_bit((a), (i)) |
| 30 | 30 |
| 31 #if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) | 31 #if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) |
| 32 #define MP_ADD_CARRY(a1, a2, s, cin, cout) \ | 32 #define MP_ADD_CARRY(a1, a2, s, carry) \ |
| 33 { mp_word w; \ | 33 { mp_word w; \ |
| 34 w = ((mp_word)(cin)) + (a1) + (a2); \ | 34 w = ((mp_word)carry) + (a1) + (a2); \ |
| 35 s = ACCUM(w); \ | 35 s = ACCUM(w); \ |
| 36 cout = CARRYOUT(w); } | 36 carry = CARRYOUT(w); } |
| 37 | 37 |
| 38 #define MP_SUB_BORROW(a1, a2, s, bin, bout) \ | 38 #define MP_SUB_BORROW(a1, a2, s, borrow) \ |
| 39 { mp_word w; \ | 39 { mp_word w; \ |
| 40 w = ((mp_word)(a1)) - (a2) - (bin); \ | 40 w = ((mp_word)(a1)) - (a2) - borrow; \ |
| 41 s = ACCUM(w); \ | 41 s = ACCUM(w); \ |
| 42 bout = (w >> MP_DIGIT_BIT) & 1; } | 42 borrow = (w >> MP_DIGIT_BIT) & 1; } |
| 43 | 43 |
| 44 #else | 44 #else |
| 45 /* NOTE, | 45 /* NOTE, |
| 46 * cin and cout could be the same variable. | 46 * carry and borrow are both read and written. |
| 47 * bin and bout could be the same variable. | |
| 48 * a1 or a2 and s could be the same variable. | 47 * a1 or a2 and s could be the same variable. |
| 49 * don't trash those outputs until their respective inputs have | 48 * don't trash those outputs until their respective inputs have |
| 50 * been read. */ | 49 * been read. */ |
| 51 #define MP_ADD_CARRY(a1, a2, s, cin, cout) \ | 50 #define MP_ADD_CARRY(a1, a2, s, carry) \ |
| 52 { mp_digit tmp,sum; \ | 51 { mp_digit tmp,sum; \ |
| 53 tmp = (a1); \ | 52 tmp = (a1); \ |
| 54 sum = tmp + (a2); \ | 53 sum = tmp + (a2); \ |
| 55 tmp = (sum < tmp); /* detect overflow */ \ | 54 tmp = (sum < tmp); /* detect overflow */ \ |
| 56 s = sum += (cin); \ | 55 s = sum += carry; \ |
| 57 cout = tmp + (sum < (cin)); } | 56 carry = tmp + (sum < carry); } |
| 58 | 57 |
| 59 #define MP_SUB_BORROW(a1, a2, s, bin, bout) \ | 58 #define MP_SUB_BORROW(a1, a2, s, borrow) \ |
| 60 { mp_digit tmp; \ | 59 { mp_digit tmp; \ |
| 61 tmp = (a1); \ | 60 tmp = (a1); \ |
| 62 s = tmp - (a2); \ | 61 s = tmp - (a2); \ |
| 63 tmp = (s > tmp); /* detect borrow */ \ | 62 tmp = (s > tmp); /* detect borrow */ \ |
| 64 if ((bin) && !s--) tmp++;» \ | 63 if (borrow && !s--) tmp++;» \ |
| 65 bout = tmp; } | 64 borrow = tmp; } |
| 66 #endif | 65 #endif |
| 67 | 66 |
| 68 | 67 |
| 69 struct GFMethodStr; | 68 struct GFMethodStr; |
| 70 typedef struct GFMethodStr GFMethod; | 69 typedef struct GFMethodStr GFMethod; |
| 71 struct GFMethodStr { | 70 struct GFMethodStr { |
| 72 /* Indicates whether the structure was constructed from dynamic memory | 71 /* Indicates whether the structure was constructed from dynamic memory |
| 73 * or statically created. */ | 72 * or statically created. */ |
| 74 int constructed; | 73 int constructed; |
| 75 /* Irreducible that defines the field. For prime fields, this is the | 74 /* Irreducible that defines the field. For prime fields, this is the |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 mp_err ec_group_set_gfp256_32(ECGroup *group, ECCurveName name); | 239 mp_err ec_group_set_gfp256_32(ECGroup *group, ECCurveName name); |
| 241 | 240 |
| 242 /* Optimized floating-point arithmetic */ | 241 /* Optimized floating-point arithmetic */ |
| 243 #ifdef ECL_USE_FP | 242 #ifdef ECL_USE_FP |
| 244 mp_err ec_group_set_secp160r1_fp(ECGroup *group); | 243 mp_err ec_group_set_secp160r1_fp(ECGroup *group); |
| 245 mp_err ec_group_set_nistp192_fp(ECGroup *group); | 244 mp_err ec_group_set_nistp192_fp(ECGroup *group); |
| 246 mp_err ec_group_set_nistp224_fp(ECGroup *group); | 245 mp_err ec_group_set_nistp224_fp(ECGroup *group); |
| 247 #endif | 246 #endif |
| 248 | 247 |
| 249 #endif /* __ecl_priv_h_ */ | 248 #endif /* __ecl_priv_h_ */ |
| OLD | NEW |