Lines Matching defs:a
7 * the License. You may obtain a copy of the License at
35 * the provisions above, a recipient may use your version of this file under
56 /* Allocate memory for a new GFMethod object. */
82 /* Construct a generic GFMethod for arithmetic over prime fields with
139 /* Construct a generic GFMethod for arithmetic over binary polynomial
195 /* Free the memory allocated (if any) to a GFMethod object. */
215 /* Add two field elements. Assumes that 0 <= a, b < meth->irr */
217 ec_GFp_add(const mp_int *a, const mp_int *b, mp_int *r,
220 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a + b (mod p) */
223 if ((res = mp_add(a, b, r)) != MP_OKAY) {
232 /* Negates a field element. Assumes that 0 <= a < meth->irr */
234 ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
236 /* PRE: 0 <= a < p = meth->irr POST: 0 <= r < p, r = -a (mod p) */
238 if (mp_cmp_z(a) == 0) {
242 return mp_sub(&meth->irr, a, r);
245 /* Subtracts two field elements. Assumes that 0 <= a, b < meth->irr */
247 ec_GFp_sub(const mp_int *a, const mp_int *b, mp_int *r,
252 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a - b (mod p) */
253 res = mp_sub(a, b, r);
255 MP_CHECKOK(mp_sub(b, a, r));
272 ec_GFp_add_3(const mp_int *a, const mp_int *b, mp_int *r,
280 switch(MP_USED(a)) {
282 a2 = MP_DIGIT(a,2);
284 a1 = MP_DIGIT(a,1);
286 a0 = MP_DIGIT(a,0);
355 ec_GFp_add_4(const mp_int *a, const mp_int *b, mp_int *r,
363 switch(MP_USED(a)) {
365 a3 = MP_DIGIT(a,3);
367 a2 = MP_DIGIT(a,2);
369 a1 = MP_DIGIT(a,1);
371 a0 = MP_DIGIT(a,0);
449 ec_GFp_add_5(const mp_int *a, const mp_int *b, mp_int *r,
457 switch(MP_USED(a)) {
459 a4 = MP_DIGIT(a,4);
461 a3 = MP_DIGIT(a,3);
463 a2 = MP_DIGIT(a,2);
465 a1 = MP_DIGIT(a,1);
467 a0 = MP_DIGIT(a,0);
526 ec_GFp_add_6(const mp_int *a, const mp_int *b, mp_int *r,
534 switch(MP_USED(a)) {
536 a5 = MP_DIGIT(a,5);
538 a4 = MP_DIGIT(a,4);
540 a3 = MP_DIGIT(a,3);
542 a2 = MP_DIGIT(a,2);
544 a1 = MP_DIGIT(a,1);
546 a0 = MP_DIGIT(a,0);
617 ec_GFp_sub_3(const mp_int *a, const mp_int *b, mp_int *r,
625 switch(MP_USED(a)) {
627 r2 = MP_DIGIT(a,2);
629 r1 = MP_DIGIT(a,1);
631 r0 = MP_DIGIT(a,0);
701 ec_GFp_sub_4(const mp_int *a, const mp_int *b, mp_int *r,
709 switch(MP_USED(a)) {
711 r3 = MP_DIGIT(a,3);
713 r2 = MP_DIGIT(a,2);
715 r1 = MP_DIGIT(a,1);
717 r0 = MP_DIGIT(a,0);
794 ec_GFp_sub_5(const mp_int *a, const mp_int *b, mp_int *r,
802 switch(MP_USED(a)) {
804 r4 = MP_DIGIT(a,4);
806 r3 = MP_DIGIT(a,3);
808 r2 = MP_DIGIT(a,2);
810 r1 = MP_DIGIT(a,1);
812 r0 = MP_DIGIT(a,0);
862 ec_GFp_sub_6(const mp_int *a, const mp_int *b, mp_int *r,
870 switch(MP_USED(a)) {
872 r5 = MP_DIGIT(a,5);
874 r4 = MP_DIGIT(a,4);
876 r3 = MP_DIGIT(a,3);
878 r2 = MP_DIGIT(a,2);
880 r1 = MP_DIGIT(a,1);
882 r0 = MP_DIGIT(a,0);
938 /* Reduces an integer to a field element. */
940 ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
942 return mp_mod(a, &meth->irr, r);
947 ec_GFp_mul(const mp_int *a, const mp_int *b, mp_int *r,
950 return mp_mulmod(a, b, &meth->irr, r);
953 /* Squares a field element. */
955 ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
957 return mp_sqrmod(a, &meth->irr, r);
960 /* Divides two field elements. If a is NULL, then returns the inverse of
963 ec_GFp_div(const mp_int *a, const mp_int *b, mp_int *r,
969 /* If a is NULL, then return the inverse of b, otherwise return a/b. */
970 if (a == NULL) {
977 MP_CHECKOK(mp_mulmod(a, &t, &meth->irr, r));
988 ec_GF2m_add(const mp_int *a, const mp_int *b, mp_int *r,
991 return mp_badd(a, b, r);
994 /* Negates a field element. Note that for binary polynomial fields, the
995 * negation of a field element is the field element itself. */
997 ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
999 if (a == r) {
1002 return mp_copy(a, r);
1006 /* Reduces a binary polynomial to a field element. */
1008 ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
1010 return mp_bmod(a, meth->irr_arr, r);
1015 ec_GF2m_mul(const mp_int *a, const mp_int *b, mp_int *r,
1018 return mp_bmulmod(a, b, meth->irr_arr, r);
1021 /* Squares a field element. */
1023 ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
1025 return mp_bsqrmod(a, meth->irr_arr, r);
1028 /* Divides two field elements. If a is NULL, then returns the inverse of
1031 ec_GF2m_div(const mp_int *a, const mp_int *b, mp_int *r,
1037 /* If a is NULL, then return the inverse of b, otherwise return a/b. */
1038 if (a == NULL) {
1048 return mp_bdivmod(a, b, &meth->irr, meth->irr_arr, r);