Lines Matching defs:meth

52         GFMethod *meth;
54 meth = (GFMethod *) kmem_alloc(sizeof(GFMethod), kmflag);
56 meth = (GFMethod *) malloc(sizeof(GFMethod));
57 if (meth == NULL)
60 meth->constructed = MP_YES;
61 MP_DIGITS(&meth->irr) = 0;
62 meth->extra_free = NULL;
63 MP_CHECKOK(mp_init(&meth->irr, kmflag));
67 GFMethod_free(meth);
70 return meth;
79 GFMethod *meth = NULL;
81 meth = GFMethod_new(FLAG(irr));
82 if (meth == NULL)
85 MP_CHECKOK(mp_copy(irr, &meth->irr));
86 meth->irr_arr[0] = mpl_significant_bits(irr);
87 meth->irr_arr[1] = meth->irr_arr[2] = meth->irr_arr[3] =
88 meth->irr_arr[4] = 0;
89 switch(MP_USED(&meth->irr)) {
92 meth->field_add = &ec_GFp_add_3;
93 meth->field_sub = &ec_GFp_sub_3;
96 meth->field_add = &ec_GFp_add_4;
97 meth->field_sub = &ec_GFp_sub_4;
100 meth->field_add = &ec_GFp_add_5;
101 meth->field_sub = &ec_GFp_sub_5;
104 meth->field_add = &ec_GFp_add_6;
105 meth->field_sub = &ec_GFp_sub_6;
108 meth->field_add = &ec_GFp_add;
109 meth->field_sub = &ec_GFp_sub;
111 meth->field_neg = &ec_GFp_neg;
112 meth->field_mod = &ec_GFp_mod;
113 meth->field_mul = &ec_GFp_mul;
114 meth->field_sqr = &ec_GFp_sqr;
115 meth->field_div = &ec_GFp_div;
116 meth->field_enc = NULL;
117 meth->field_dec = NULL;
118 meth->extra1 = NULL;
119 meth->extra2 = NULL;
120 meth->extra_free = NULL;
124 GFMethod_free(meth);
127 return meth;
139 GFMethod *meth = NULL;
141 meth = GFMethod_new(FLAG(irr));
142 if (meth == NULL)
145 MP_CHECKOK(mp_copy(irr, &meth->irr));
148 meth->irr_arr[0] = irr_arr[0];
149 meth->irr_arr[1] = irr_arr[1];
150 meth->irr_arr[2] = irr_arr[2];
152 meth->irr_arr[3] = irr_arr[3];
153 meth->irr_arr[4] = irr_arr[4];
155 meth->irr_arr[3] = meth->irr_arr[4] = 0;
158 ret = mp_bpoly2arr(irr, meth->irr_arr, 5);
165 meth->field_add = &ec_GF2m_add;
166 meth->field_neg = &ec_GF2m_neg;
167 meth->field_sub = &ec_GF2m_add;
168 meth->field_mod = &ec_GF2m_mod;
169 meth->field_mul = &ec_GF2m_mul;
170 meth->field_sqr = &ec_GF2m_sqr;
171 meth->field_div = &ec_GF2m_div;
172 meth->field_enc = NULL;
173 meth->field_dec = NULL;
174 meth->extra1 = NULL;
175 meth->extra2 = NULL;
176 meth->extra_free = NULL;
180 GFMethod_free(meth);
183 return meth;
188 GFMethod_free(GFMethod *meth)
190 if (meth == NULL)
192 if (meth->constructed == MP_NO)
194 mp_clear(&meth->irr);
195 if (meth->extra_free != NULL)
196 meth->extra_free(meth);
198 kmem_free(meth, sizeof(GFMethod));
200 free(meth);
206 /* Add two field elements. Assumes that 0 <= a, b < meth->irr */
209 const GFMethod *meth)
211 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a + b (mod p) */
217 if (mp_cmp(r, &meth->irr) >= 0) {
218 return mp_sub(r, &meth->irr, r);
223 /* Negates a field element. Assumes that 0 <= a < meth->irr */
225 ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
227 /* PRE: 0 <= a < p = meth->irr POST: 0 <= r < p, r = -a (mod p) */
233 return mp_sub(&meth->irr, a, r);
236 /* Subtracts two field elements. Assumes that 0 <= a, b < meth->irr */
239 const GFMethod *meth)
243 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a - b (mod p) */
248 MP_CHECKOK(mp_add(r, &meth->irr, r));
250 MP_CHECKOK(ec_GFp_neg(r, r, meth));
253 MP_CHECKOK(mp_add(r, &meth->irr, r));
264 const GFMethod *meth)
314 a2 = MP_DIGIT(&meth->irr,2);
316 ((r2 == a2) && mp_cmp(r,&meth->irr) != MP_LT)) {
317 a1 = MP_DIGIT(&meth->irr,1);
318 a0 = MP_DIGIT(&meth->irr,0);
347 const GFMethod *meth)
404 a3 = MP_DIGIT(&meth->irr,3);
406 ((r3 == a3) && mp_cmp(r,&meth->irr) != MP_LT)) {
407 a2 = MP_DIGIT(&meth->irr,2);
408 a1 = MP_DIGIT(&meth->irr,1);
409 a0 = MP_DIGIT(&meth->irr,0);
441 const GFMethod *meth)
490 a4 = MP_DIGIT(&meth->irr,4);
492 ((r4 == a4) && mp_cmp(r,&meth->irr) != MP_LT)) {
493 a3 = MP_DIGIT(&meth->irr,3);
494 a2 = MP_DIGIT(&meth->irr,2);
495 a1 = MP_DIGIT(&meth->irr,1);
496 a0 = MP_DIGIT(&meth->irr,0);
518 const GFMethod *meth)
573 a5 = MP_DIGIT(&meth->irr,5);
575 ((r5 == a5) && mp_cmp(r,&meth->irr) != MP_LT)) {
576 a4 = MP_DIGIT(&meth->irr,4);
577 a3 = MP_DIGIT(&meth->irr,3);
578 a2 = MP_DIGIT(&meth->irr,2);
579 a1 = MP_DIGIT(&meth->irr,1);
580 a0 = MP_DIGIT(&meth->irr,0);
609 const GFMethod *meth)
653 b2 = MP_DIGIT(&meth->irr,2);
654 b1 = MP_DIGIT(&meth->irr,1);
655 b0 = MP_DIGIT(&meth->irr,0);
693 const GFMethod *meth)
743 b3 = MP_DIGIT(&meth->irr,3);
744 b2 = MP_DIGIT(&meth->irr,2);
745 b1 = MP_DIGIT(&meth->irr,1);
746 b0 = MP_DIGIT(&meth->irr,0);
786 const GFMethod *meth)
827 b4 = MP_DIGIT(&meth->irr,4);
828 b3 = MP_DIGIT(&meth->irr,3);
829 b2 = MP_DIGIT(&meth->irr,2);
830 b1 = MP_DIGIT(&meth->irr,1);
831 b0 = MP_DIGIT(&meth->irr,0);
854 const GFMethod *meth)
900 b5 = MP_DIGIT(&meth->irr,5);
901 b4 = MP_DIGIT(&meth->irr,4);
902 b3 = MP_DIGIT(&meth->irr,3);
903 b2 = MP_DIGIT(&meth->irr,2);
904 b1 = MP_DIGIT(&meth->irr,1);
905 b0 = MP_DIGIT(&meth->irr,0);
931 ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
933 return mp_mod(a, &meth->irr, r);
939 const GFMethod *meth)
941 return mp_mulmod(a, b, &meth->irr, r);
946 ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
948 return mp_sqrmod(a, &meth->irr, r);
955 const GFMethod *meth)
962 return mp_invmod(b, &meth->irr, r);
967 MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
968 MP_CHECKOK(mp_mulmod(a, &t, &meth->irr, r));
980 const GFMethod *meth)
988 ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
999 ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
1001 return mp_bmod(a, meth->irr_arr, r);
1007 const GFMethod *meth)
1009 return mp_bmulmod(a, b, meth->irr_arr, r);
1014 ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
1016 return mp_bsqrmod(a, meth->irr_arr, r);
1023 const GFMethod *meth)
1034 MP_CHECKOK(mp_bdivmod(&t, b, &meth->irr, meth->irr_arr, r));
1039 return mp_bdivmod(a, b, &meth->irr, meth->irr_arr, r);