Lines Matching defs:meth

61 	GFMethod *meth;
63 meth = (GFMethod *) kmem_alloc(sizeof(GFMethod), kmflag);
65 meth = (GFMethod *) malloc(sizeof(GFMethod));
66 if (meth == NULL)
69 meth->constructed = MP_YES;
70 MP_DIGITS(&meth->irr) = 0;
71 meth->extra_free = NULL;
72 MP_CHECKOK(mp_init(&meth->irr, kmflag));
76 GFMethod_free(meth);
79 return meth;
88 GFMethod *meth = NULL;
90 meth = GFMethod_new(FLAG(irr));
91 if (meth == NULL)
94 MP_CHECKOK(mp_copy(irr, &meth->irr));
95 meth->irr_arr[0] = mpl_significant_bits(irr);
96 meth->irr_arr[1] = meth->irr_arr[2] = meth->irr_arr[3] =
97 meth->irr_arr[4] = 0;
98 switch(MP_USED(&meth->irr)) {
101 meth->field_add = &ec_GFp_add_3;
102 meth->field_sub = &ec_GFp_sub_3;
105 meth->field_add = &ec_GFp_add_4;
106 meth->field_sub = &ec_GFp_sub_4;
109 meth->field_add = &ec_GFp_add_5;
110 meth->field_sub = &ec_GFp_sub_5;
113 meth->field_add = &ec_GFp_add_6;
114 meth->field_sub = &ec_GFp_sub_6;
117 meth->field_add = &ec_GFp_add;
118 meth->field_sub = &ec_GFp_sub;
120 meth->field_neg = &ec_GFp_neg;
121 meth->field_mod = &ec_GFp_mod;
122 meth->field_mul = &ec_GFp_mul;
123 meth->field_sqr = &ec_GFp_sqr;
124 meth->field_div = &ec_GFp_div;
125 meth->field_enc = NULL;
126 meth->field_dec = NULL;
127 meth->extra1 = NULL;
128 meth->extra2 = NULL;
129 meth->extra_free = NULL;
133 GFMethod_free(meth);
136 return meth;
148 GFMethod *meth = NULL;
150 meth = GFMethod_new(FLAG(irr));
151 if (meth == NULL)
154 MP_CHECKOK(mp_copy(irr, &meth->irr));
157 meth->irr_arr[0] = irr_arr[0];
158 meth->irr_arr[1] = irr_arr[1];
159 meth->irr_arr[2] = irr_arr[2];
161 meth->irr_arr[3] = irr_arr[3];
162 meth->irr_arr[4] = irr_arr[4];
164 meth->irr_arr[3] = meth->irr_arr[4] = 0;
167 ret = mp_bpoly2arr(irr, meth->irr_arr, 5);
174 meth->field_add = &ec_GF2m_add;
175 meth->field_neg = &ec_GF2m_neg;
176 meth->field_sub = &ec_GF2m_add;
177 meth->field_mod = &ec_GF2m_mod;
178 meth->field_mul = &ec_GF2m_mul;
179 meth->field_sqr = &ec_GF2m_sqr;
180 meth->field_div = &ec_GF2m_div;
181 meth->field_enc = NULL;
182 meth->field_dec = NULL;
183 meth->extra1 = NULL;
184 meth->extra2 = NULL;
185 meth->extra_free = NULL;
189 GFMethod_free(meth);
192 return meth;
197 GFMethod_free(GFMethod *meth)
199 if (meth == NULL)
201 if (meth->constructed == MP_NO)
203 mp_clear(&meth->irr);
204 if (meth->extra_free != NULL)
205 meth->extra_free(meth);
207 kmem_free(meth, sizeof(GFMethod));
209 free(meth);
215 /* Add two field elements. Assumes that 0 <= a, b < meth->irr */
218 const GFMethod *meth)
220 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a + b (mod p) */
226 if (mp_cmp(r, &meth->irr) >= 0) {
227 return mp_sub(r, &meth->irr, r);
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) */
242 return mp_sub(&meth->irr, a, r);
245 /* Subtracts two field elements. Assumes that 0 <= a, b < meth->irr */
248 const GFMethod *meth)
252 /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a - b (mod p) */
257 MP_CHECKOK(mp_add(r, &meth->irr, r));
259 MP_CHECKOK(ec_GFp_neg(r, r, meth));
262 MP_CHECKOK(mp_add(r, &meth->irr, r));
273 const GFMethod *meth)
323 a2 = MP_DIGIT(&meth->irr,2);
325 ((r2 == a2) && mp_cmp(r,&meth->irr) != MP_LT)) {
326 a1 = MP_DIGIT(&meth->irr,1);
327 a0 = MP_DIGIT(&meth->irr,0);
356 const GFMethod *meth)
413 a3 = MP_DIGIT(&meth->irr,3);
415 ((r3 == a3) && mp_cmp(r,&meth->irr) != MP_LT)) {
416 a2 = MP_DIGIT(&meth->irr,2);
417 a1 = MP_DIGIT(&meth->irr,1);
418 a0 = MP_DIGIT(&meth->irr,0);
450 const GFMethod *meth)
499 a4 = MP_DIGIT(&meth->irr,4);
501 ((r4 == a4) && mp_cmp(r,&meth->irr) != MP_LT)) {
502 a3 = MP_DIGIT(&meth->irr,3);
503 a2 = MP_DIGIT(&meth->irr,2);
504 a1 = MP_DIGIT(&meth->irr,1);
505 a0 = MP_DIGIT(&meth->irr,0);
527 const GFMethod *meth)
582 a5 = MP_DIGIT(&meth->irr,5);
584 ((r5 == a5) && mp_cmp(r,&meth->irr) != MP_LT)) {
585 a4 = MP_DIGIT(&meth->irr,4);
586 a3 = MP_DIGIT(&meth->irr,3);
587 a2 = MP_DIGIT(&meth->irr,2);
588 a1 = MP_DIGIT(&meth->irr,1);
589 a0 = MP_DIGIT(&meth->irr,0);
618 const GFMethod *meth)
662 b2 = MP_DIGIT(&meth->irr,2);
663 b1 = MP_DIGIT(&meth->irr,1);
664 b0 = MP_DIGIT(&meth->irr,0);
702 const GFMethod *meth)
752 b3 = MP_DIGIT(&meth->irr,3);
753 b2 = MP_DIGIT(&meth->irr,2);
754 b1 = MP_DIGIT(&meth->irr,1);
755 b0 = MP_DIGIT(&meth->irr,0);
795 const GFMethod *meth)
836 b4 = MP_DIGIT(&meth->irr,4);
837 b3 = MP_DIGIT(&meth->irr,3);
838 b2 = MP_DIGIT(&meth->irr,2);
839 b1 = MP_DIGIT(&meth->irr,1);
840 b0 = MP_DIGIT(&meth->irr,0);
863 const GFMethod *meth)
909 b5 = MP_DIGIT(&meth->irr,5);
910 b4 = MP_DIGIT(&meth->irr,4);
911 b3 = MP_DIGIT(&meth->irr,3);
912 b2 = MP_DIGIT(&meth->irr,2);
913 b1 = MP_DIGIT(&meth->irr,1);
914 b0 = MP_DIGIT(&meth->irr,0);
940 ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
942 return mp_mod(a, &meth->irr, r);
948 const GFMethod *meth)
950 return mp_mulmod(a, b, &meth->irr, r);
955 ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
957 return mp_sqrmod(a, &meth->irr, r);
964 const GFMethod *meth)
971 return mp_invmod(b, &meth->irr, r);
976 MP_CHECKOK(mp_invmod(b, &meth->irr, &t));
977 MP_CHECKOK(mp_mulmod(a, &t, &meth->irr, r));
989 const GFMethod *meth)
997 ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth)
1008 ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth)
1010 return mp_bmod(a, meth->irr_arr, r);
1016 const GFMethod *meth)
1018 return mp_bmulmod(a, b, meth->irr_arr, r);
1023 ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth)
1025 return mp_bsqrmod(a, meth->irr_arr, r);
1032 const GFMethod *meth)
1043 MP_CHECKOK(mp_bdivmod(&t, b, &meth->irr, meth->irr_arr, r));
1048 return mp_bdivmod(a, b, &meth->irr, meth->irr_arr, r);