Lines Matching refs:ret

21 	int ret;  in aff_pt_montgomery_check_initialized()  local
23 MUST_HAVE(((in != NULL) && (in->magic == AFF_PT_MONTGOMERY_MAGIC)), ret, err); in aff_pt_montgomery_check_initialized()
24 ret = ec_montgomery_crv_check_initialized(in->crv); in aff_pt_montgomery_check_initialized()
27 return ret; in aff_pt_montgomery_check_initialized()
38 int ret; in aff_pt_montgomery_init() local
40 MUST_HAVE((in != NULL), ret, err); in aff_pt_montgomery_init()
41 ret = ec_montgomery_crv_check_initialized(curve); EG(ret, err); in aff_pt_montgomery_init()
43 ret = fp_init(&(in->u), curve->A.ctx); EG(ret, err); in aff_pt_montgomery_init()
44 ret = fp_init(&(in->v), curve->A.ctx); EG(ret, err); in aff_pt_montgomery_init()
50 return ret; in aff_pt_montgomery_init()
63 int ret; in aff_pt_montgomery_init_from_coords() local
65 ret = aff_pt_montgomery_init(in, curve); EG(ret, err); in aff_pt_montgomery_init_from_coords()
66 ret = fp_copy(&(in->u), ucoord); EG(ret, err); in aff_pt_montgomery_init_from_coords()
67 ret = fp_copy(&(in->v), vcoord); in aff_pt_montgomery_init_from_coords()
70 return ret; in aff_pt_montgomery_init_from_coords()
103 int ret, cmp; in is_on_montgomery_curve() local
106 MUST_HAVE((on_curve != NULL), ret, err); in is_on_montgomery_curve()
107 ret = ec_montgomery_crv_check_initialized(curve); EG(ret, err); in is_on_montgomery_curve()
109 ret = fp_check_initialized(u); EG(ret, err); in is_on_montgomery_curve()
110 ret = fp_check_initialized(v); EG(ret, err); in is_on_montgomery_curve()
112 MUST_HAVE((u->ctx == v->ctx), ret, err); in is_on_montgomery_curve()
113 MUST_HAVE((u->ctx == curve->A.ctx), ret, err); in is_on_montgomery_curve()
115 ret = fp_init(&Bv2, v->ctx); EG(ret, err); in is_on_montgomery_curve()
116 ret = fp_sqr(&Bv2, v); EG(ret, err); in is_on_montgomery_curve()
117 ret = fp_mul(&Bv2, &(curve->B), &Bv2); EG(ret, err); in is_on_montgomery_curve()
119 ret = fp_init(&Au2, u->ctx); EG(ret, err); in is_on_montgomery_curve()
120 ret = fp_sqr(&Au2, u); EG(ret, err); in is_on_montgomery_curve()
121 ret = fp_copy(&u3, &Au2); EG(ret, err); in is_on_montgomery_curve()
122 ret = fp_mul(&Au2, &(curve->A), &Au2); EG(ret, err); in is_on_montgomery_curve()
124 ret = fp_mul(&u3, &u3, u); EG(ret, err); in is_on_montgomery_curve()
126 ret = fp_init(&tmp, u->ctx); EG(ret, err); in is_on_montgomery_curve()
127 ret = fp_add(&tmp, &u3, &Au2); EG(ret, err); in is_on_montgomery_curve()
128 ret = fp_add(&tmp, &tmp, u); EG(ret, err); in is_on_montgomery_curve()
130 ret = fp_cmp(&tmp, &Bv2, &cmp); EG(ret, err); in is_on_montgomery_curve()
140 return ret; in is_on_montgomery_curve()
150 int ret; in aff_pt_montgomery_is_on_curve() local
152 ret = aff_pt_montgomery_check_initialized(pt); EG(ret, err); in aff_pt_montgomery_is_on_curve()
154 ret = is_on_montgomery_curve(&(pt->u), &(pt->v), pt->crv, on_curve); in aff_pt_montgomery_is_on_curve()
157 return ret; in aff_pt_montgomery_is_on_curve()
166 int ret; in ec_montgomery_aff_copy() local
168 ret = aff_pt_montgomery_check_initialized(in); EG(ret, err); in ec_montgomery_aff_copy()
170 ret = aff_pt_montgomery_init(out, in->crv); EG(ret, err); in ec_montgomery_aff_copy()
171 ret = fp_copy(&(out->u), &(in->u)); EG(ret, err); in ec_montgomery_aff_copy()
172 ret = fp_copy(&(out->v), &(in->v)); in ec_montgomery_aff_copy()
175 return ret; in ec_montgomery_aff_copy()
186 int ret, cmp1, cmp2; in ec_montgomery_aff_cmp() local
188 MUST_HAVE((cmp != NULL), ret, err); in ec_montgomery_aff_cmp()
189 ret = aff_pt_montgomery_check_initialized(in1); EG(ret, err); in ec_montgomery_aff_cmp()
190 ret = aff_pt_montgomery_check_initialized(in2); EG(ret, err); in ec_montgomery_aff_cmp()
191 MUST_HAVE((in1->crv == in2->crv), ret, err); in ec_montgomery_aff_cmp()
193 ret = fp_cmp(&(in1->u), &(in2->u), &cmp1); EG(ret, err); in ec_montgomery_aff_cmp()
194 ret = fp_cmp(&(in1->v), &(in2->v), &cmp2); EG(ret, err); in ec_montgomery_aff_cmp()
199 return ret; in ec_montgomery_aff_cmp()
217 int ret, on_curve; in aff_pt_montgomery_import_from_buf() local
219 ret = ec_montgomery_crv_check_initialized(crv); EG(ret, err); in aff_pt_montgomery_import_from_buf()
220 MUST_HAVE((pt_buf != NULL) && (pt != NULL), ret, err); in aff_pt_montgomery_import_from_buf()
225 MUST_HAVE((pt_buf_len == (2 * coord_len)), ret, err); in aff_pt_montgomery_import_from_buf()
227 ret = fp_init_from_buf(&(pt->u), ctx, pt_buf, coord_len); EG(ret, err); in aff_pt_montgomery_import_from_buf()
228 ret = fp_init_from_buf(&(pt->v), ctx, pt_buf + coord_len, coord_len); EG(ret, err); in aff_pt_montgomery_import_from_buf()
239 ret = aff_pt_montgomery_is_on_curve(pt, &on_curve); EG(ret, err); in aff_pt_montgomery_import_from_buf()
242 ret = -1; in aff_pt_montgomery_import_from_buf()
246 return ret; in aff_pt_montgomery_import_from_buf()
262 int ret, on_curve; in aff_pt_montgomery_export_to_buf() local
264 ret = aff_pt_montgomery_check_initialized(pt); EG(ret, err); in aff_pt_montgomery_export_to_buf()
265 MUST_HAVE((pt_buf != NULL), ret, err); in aff_pt_montgomery_export_to_buf()
268 ret = aff_pt_montgomery_is_on_curve(pt, &on_curve); EG(ret, err); in aff_pt_montgomery_export_to_buf()
269 MUST_HAVE(on_curve, ret, err); in aff_pt_montgomery_export_to_buf()
274 MUST_HAVE((pt_buf_len == (2 * coord_len)), ret, err); in aff_pt_montgomery_export_to_buf()
277 ret = fp_export_to_buf(pt_buf, coord_len, &(pt->u)); EG(ret, err); in aff_pt_montgomery_export_to_buf()
278 ret = fp_export_to_buf(pt_buf + coord_len, coord_len, &(pt->v)); in aff_pt_montgomery_export_to_buf()
281 return ret; in aff_pt_montgomery_export_to_buf()
297 int ret; in curve_montgomery_to_shortw() local
300 ret = ec_montgomery_crv_check_initialized(montgomery_crv); EG(ret, err); in curve_montgomery_to_shortw()
302 ret = fp_init(&tmp, montgomery_crv->A.ctx); EG(ret, err); in curve_montgomery_to_shortw()
303 ret = fp_init(&tmp2, montgomery_crv->A.ctx); EG(ret, err); in curve_montgomery_to_shortw()
304 ret = fp_init(&a, montgomery_crv->A.ctx); EG(ret, err); in curve_montgomery_to_shortw()
305 ret = fp_init(&b, montgomery_crv->A.ctx); EG(ret, err); in curve_montgomery_to_shortw()
308 ret = fp_sqr(&tmp, &(montgomery_crv->B)); EG(ret, err); in curve_montgomery_to_shortw()
309 ret = fp_set_word_value(&tmp2, WORD(3)); EG(ret, err); in curve_montgomery_to_shortw()
311 ret = fp_mul(&tmp, &tmp, &tmp2); EG(ret, err); in curve_montgomery_to_shortw()
313 ret = fp_inv(&tmp, &tmp); EG(ret, err); in curve_montgomery_to_shortw()
316 ret = fp_sqr(&tmp2, &(montgomery_crv->A)); EG(ret, err); in curve_montgomery_to_shortw()
317 ret = fp_set_word_value(&a, WORD(3)); EG(ret, err); in curve_montgomery_to_shortw()
318 ret = fp_sub(&tmp2, &a, &tmp2); EG(ret, err); in curve_montgomery_to_shortw()
320 ret = fp_mul(&a, &tmp2, &tmp); EG(ret, err); in curve_montgomery_to_shortw()
323 ret = fp_sqr(&tmp, &(montgomery_crv->B)); EG(ret, err); in curve_montgomery_to_shortw()
324 ret = fp_mul(&tmp, &tmp, &(montgomery_crv->B)); EG(ret, err); in curve_montgomery_to_shortw()
325 ret = fp_set_word_value(&tmp2, WORD(27)); EG(ret, err); in curve_montgomery_to_shortw()
327 ret = fp_mul(&tmp, &tmp, &tmp2); EG(ret, err); in curve_montgomery_to_shortw()
329 ret = fp_inv(&tmp, &tmp); EG(ret, err); in curve_montgomery_to_shortw()
332 ret = fp_set_word_value(&tmp2, WORD(2)); EG(ret, err); in curve_montgomery_to_shortw()
333 ret = fp_mul(&tmp2, &tmp2, &(montgomery_crv->A)); EG(ret, err); in curve_montgomery_to_shortw()
334 ret = fp_mul(&tmp2, &tmp2, &(montgomery_crv->A)); EG(ret, err); in curve_montgomery_to_shortw()
335 ret = fp_mul(&tmp2, &tmp2, &(montgomery_crv->A)); EG(ret, err); in curve_montgomery_to_shortw()
337 ret = fp_set_word_value(&b, WORD(9)); EG(ret, err); in curve_montgomery_to_shortw()
338 ret = fp_mul(&b, &b, &(montgomery_crv->A)); EG(ret, err); in curve_montgomery_to_shortw()
339 ret = fp_sub(&b, &tmp2, &b); EG(ret, err); in curve_montgomery_to_shortw()
341 ret = fp_mul(&b, &b, &tmp); EG(ret, err); in curve_montgomery_to_shortw()
344 ret = ec_shortw_crv_init(shortw_crv, &a, &b, &(montgomery_crv->order)); in curve_montgomery_to_shortw()
352 return ret; in curve_montgomery_to_shortw()
363 int ret, cmp; in curve_montgomery_shortw_check() local
367 ret = ec_shortw_crv_check_initialized(shortw_crv); EG(ret, err); in curve_montgomery_shortw_check()
368 ret = curve_montgomery_to_shortw(montgomery_crv, &check); EG(ret, err); in curve_montgomery_shortw_check()
371 MUST_HAVE((!fp_cmp(&(check.a), &(shortw_crv->a), &cmp)) && (!cmp), ret, err); in curve_montgomery_shortw_check()
372 MUST_HAVE((!fp_cmp(&(check.b), &(shortw_crv->b), &cmp)) && (!cmp), ret, err); in curve_montgomery_shortw_check()
373 MUST_HAVE((!nn_cmp(&(check.order), &(shortw_crv->order), &cmp)) && (!cmp), ret, err); in curve_montgomery_shortw_check()
378 return ret; in curve_montgomery_shortw_check()
395 int ret, cmp; in curve_shortw_to_montgomery() local
399 ret = ec_shortw_crv_check_initialized(shortw_crv); EG(ret, err); in curve_shortw_to_montgomery()
400 ret = fp_check_initialized(alpha); EG(ret, err); in curve_shortw_to_montgomery()
401 ret = fp_check_initialized(gamma); EG(ret, err); in curve_shortw_to_montgomery()
402 MUST_HAVE((alpha->ctx == shortw_crv->a.ctx) && (gamma->ctx == shortw_crv->a.ctx), ret, err); in curve_shortw_to_montgomery()
404 ret = fp_init(&A, shortw_crv->a.ctx); EG(ret, err); in curve_shortw_to_montgomery()
405 ret = fp_init(&gamma_inv, shortw_crv->a.ctx); EG(ret, err); in curve_shortw_to_montgomery()
406 ret = fp_init(&c, shortw_crv->a.ctx); EG(ret, err); in curve_shortw_to_montgomery()
407 ret = fp_init(&tmp, shortw_crv->a.ctx); EG(ret, err); in curve_shortw_to_montgomery()
410 ret = fp_inv(&gamma_inv, gamma); EG(ret, err); in curve_shortw_to_montgomery()
413 ret = fp_set_word_value(&A, WORD(3)); EG(ret, err); in curve_shortw_to_montgomery()
414 ret = fp_mul(&A, &A, alpha); EG(ret, err); in curve_shortw_to_montgomery()
415 ret = fp_mul(&A, &A, &gamma_inv); EG(ret, err); in curve_shortw_to_montgomery()
418 ret = fp_set_word_value(&c, WORD(3)); EG(ret, err); in curve_shortw_to_montgomery()
419 ret = fp_mul(&c, &c, alpha); EG(ret, err); in curve_shortw_to_montgomery()
420 ret = fp_mul(&c, &c, alpha); EG(ret, err); in curve_shortw_to_montgomery()
421 ret = fp_add(&c, &c, &(shortw_crv->a)); EG(ret, err); in curve_shortw_to_montgomery()
422 ret = fp_sqr(&tmp, gamma); EG(ret, err); in curve_shortw_to_montgomery()
424 MUST_HAVE((!fp_cmp(&c, &tmp, &cmp)) && (!cmp), ret, err); in curve_shortw_to_montgomery()
427 ret = ec_montgomery_crv_init(montgomery_crv, &A, &gamma_inv, &(shortw_crv->order)); in curve_shortw_to_montgomery()
435 return ret; in curve_shortw_to_montgomery()
448 int ret, on_curve; in aff_pt_montgomery_to_shortw() local
452 ret = ec_shortw_crv_check_initialized(shortw_crv); EG(ret, err); in aff_pt_montgomery_to_shortw()
455 MUST_HAVE((!aff_pt_montgomery_is_on_curve(in_montgomery, &on_curve)) && on_curve, ret, err); in aff_pt_montgomery_to_shortw()
457 ret = fp_init(&tmp, in_montgomery->crv->A.ctx); EG(ret, err); in aff_pt_montgomery_to_shortw()
458 ret = fp_init(&tmp2, in_montgomery->crv->A.ctx); EG(ret, err); in aff_pt_montgomery_to_shortw()
460 ret = aff_pt_montgomery_check_initialized(in_montgomery); EG(ret, err); in aff_pt_montgomery_to_shortw()
461 ret = curve_montgomery_shortw_check(in_montgomery->crv, shortw_crv); EG(ret, err); in aff_pt_montgomery_to_shortw()
463 ret = aff_pt_init(out_shortw, shortw_crv); EG(ret, err); in aff_pt_montgomery_to_shortw()
465 ret = fp_inv(&tmp, &(in_montgomery->crv->B)); EG(ret, err); in aff_pt_montgomery_to_shortw()
466 ret = fp_mul(&tmp, &tmp, &(in_montgomery->u)); EG(ret, err); in aff_pt_montgomery_to_shortw()
468 ret = fp_set_word_value(&tmp2, WORD(3)); EG(ret, err); in aff_pt_montgomery_to_shortw()
469 ret = fp_mul(&tmp2, &tmp2, &(in_montgomery->crv->B)); EG(ret, err); in aff_pt_montgomery_to_shortw()
470 ret = fp_inv(&tmp2, &tmp2); EG(ret, err); in aff_pt_montgomery_to_shortw()
471 ret = fp_mul(&tmp2, &tmp2, &(in_montgomery->crv->A)); EG(ret, err); in aff_pt_montgomery_to_shortw()
473 ret = fp_add(&(out_shortw->x), &tmp, &tmp2); EG(ret, err); in aff_pt_montgomery_to_shortw()
475 ret = fp_inv(&tmp, &(in_montgomery->crv->B)); EG(ret, err); in aff_pt_montgomery_to_shortw()
476 ret = fp_mul(&(out_shortw->y), &tmp, &(in_montgomery->v)); EG(ret, err); in aff_pt_montgomery_to_shortw()
479 MUST_HAVE((!aff_pt_is_on_curve(out_shortw, &on_curve)) && on_curve, ret, err); in aff_pt_montgomery_to_shortw()
485 return ret; in aff_pt_montgomery_to_shortw()
499 int ret, on_curve; in aff_pt_shortw_to_montgomery() local
503 ret = ec_montgomery_crv_check_initialized(montgomery_crv); EG(ret, err); in aff_pt_shortw_to_montgomery()
506 MUST_HAVE((!aff_pt_is_on_curve(in_shortw, &on_curve)) && on_curve, ret, err); in aff_pt_shortw_to_montgomery()
508 ret = fp_init(&tmp, in_shortw->crv->a.ctx); EG(ret, err); in aff_pt_shortw_to_montgomery()
509 ret = fp_init(&tmp2, in_shortw->crv->a.ctx); EG(ret, err); in aff_pt_shortw_to_montgomery()
511 ret = curve_montgomery_shortw_check(montgomery_crv, in_shortw->crv); EG(ret, err); in aff_pt_shortw_to_montgomery()
513 ret = aff_pt_montgomery_init(out_montgomery, montgomery_crv); EG(ret, err); in aff_pt_shortw_to_montgomery()
516 ret = fp_inv_word(&tmp, WORD(3)); EG(ret, err); in aff_pt_shortw_to_montgomery()
517 ret = fp_mul(&tmp, &tmp, &(montgomery_crv->A)); EG(ret, err); in aff_pt_shortw_to_montgomery()
520 ret = fp_mul(&tmp2, &(montgomery_crv->B), &(in_shortw->x)); EG(ret, err); in aff_pt_shortw_to_montgomery()
523 ret = fp_sub(&(out_montgomery->u), &tmp2, &tmp); EG(ret, err); in aff_pt_shortw_to_montgomery()
526 ret = fp_mul(&(out_montgomery->v), &(montgomery_crv->B), &(in_shortw->y)); EG(ret, err); in aff_pt_shortw_to_montgomery()
529 MUST_HAVE((!aff_pt_montgomery_is_on_curve(out_montgomery, &on_curve)) && on_curve, ret, err); in aff_pt_shortw_to_montgomery()
535 return ret; in aff_pt_shortw_to_montgomery()
549 int ret; in aff_pt_montgomery_v_from_u() local
552 ret = fp_check_initialized(u); EG(ret, err); in aff_pt_montgomery_v_from_u()
553 ret = ec_montgomery_crv_check_initialized(crv); EG(ret, err); in aff_pt_montgomery_v_from_u()
554 MUST_HAVE((u->ctx == crv->A.ctx) && (u->ctx == crv->B.ctx), ret, err); in aff_pt_montgomery_v_from_u()
555 MUST_HAVE((v1 != NULL) && (v2 != NULL), ret, err); in aff_pt_montgomery_v_from_u()
557 MUST_HAVE((v1 != v2) && (v1 != u), ret, err); in aff_pt_montgomery_v_from_u()
560 ret = fp_init(v1, u->ctx); EG(ret, err); in aff_pt_montgomery_v_from_u()
561 ret = fp_init(v2, u->ctx); EG(ret, err); in aff_pt_montgomery_v_from_u()
566 ret = fp_sqr(v2, u); EG(ret, err); in aff_pt_montgomery_v_from_u()
567 ret = fp_mul(v1, v2, u); EG(ret, err); in aff_pt_montgomery_v_from_u()
568 ret = fp_mul(v2, v2, &(crv->A)); EG(ret, err); in aff_pt_montgomery_v_from_u()
569 ret = fp_add(v1, v1, v2); EG(ret, err); in aff_pt_montgomery_v_from_u()
570 ret = fp_add(v1, v1, u); EG(ret, err); in aff_pt_montgomery_v_from_u()
571 ret = fp_inv(v2, &(crv->B)); EG(ret, err); in aff_pt_montgomery_v_from_u()
572 ret = fp_mul(v1, v1, v2); EG(ret, err); in aff_pt_montgomery_v_from_u()
575 ret = fp_sqrt(v1, v2, v1); in aff_pt_montgomery_v_from_u()
578 return ret; in aff_pt_montgomery_v_from_u()