Lines Matching +full:in2 +full:-
2 * Copyright (C) 2017 - This file is part of libecc project
7 * Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
29 * Returns 0 on success, -1 on error.
35 MUST_HAVE(((ctx != NULL) && (ctx->magic == FP_CTX_MAGIC)), ret, err); in fp_ctx_check_initialized()
43 * - p: pointer to the prime defining Fp
44 * - p_bitlen: the bit length of p
45 * - r, r_square, mpinv: pointers to the Montgomery parameters r,
46 * (2^|p|) mod p), r^2 mod p and -p^-1 mod B (where B is the
49 * - p_shift, p_normalized and p_reciprocal are precomputed
52 * Returns 0 on success, -1 on error.
67 ret = nn_copy(&(ctx->p), p); EG(ret, err); in fp_ctx_init()
68 ctx->p_bitlen = p_bitlen; in fp_ctx_init()
69 ctx->mpinv = mpinv; in fp_ctx_init()
70 ctx->p_shift = p_shift; in fp_ctx_init()
71 ctx->p_reciprocal = p_reciprocal; in fp_ctx_init()
72 ret = nn_copy(&(ctx->p_normalized), p_normalized); EG(ret, err); in fp_ctx_init()
73 ret = nn_copy(&(ctx->r), r); EG(ret, err); in fp_ctx_init()
74 ret = nn_copy(&(ctx->r_square), r_square); EG(ret, err); in fp_ctx_init()
75 ctx->magic = FP_CTX_MAGIC; in fp_ctx_init()
85 * -1 on error.
134 * Returns 0 on success, -1 on error.
140 …MUST_HAVE(((in != NULL) && (in->magic == FP_MAGIC) && (in->ctx != NULL) && (in->ctx->magic == FP_C… in fp_check_initialized()
148 * value of Fp element is set to 0.Returns 0 on success, -1 on error.
157 ret = nn_init(&(in->fp_val), (u16)((fpctx->p.wlen) * WORD_BYTES)); EG(ret, err); in fp_init()
159 in->ctx = fpctx; in fp_init()
160 in->magic = FP_MAGIC; in fp_init()
169 * be less than p. Returns 0 on success, -1 on error.
191 if((in != NULL) && (in->magic == FP_MAGIC) && (in->ctx != NULL)){ in fp_uninit()
192 nn_uninit(&in->fp_val); in fp_uninit()
194 in->ctx = NULL; in fp_uninit()
195 in->magic = WORD(0); in fp_uninit()
204 * p is performed by the function. Returns 0 on success, -1 on error.
212 ret = nn_copy(&(out->fp_val), in); EG(ret, err); in fp_set_nn()
213 ret = nn_cmp(&(out->fp_val), &(out->ctx->p), &cmp); EG(ret, err); in fp_set_nn()
218 ret = nn_set_wlen(&(out->fp_val), out->ctx->p.wlen); in fp_set_nn()
226 * on success, -1 on error.
233 ret = nn_set_word_value(&(out->fp_val), 0); EG(ret, err); in fp_zero()
235 ret = nn_set_wlen(&(out->fp_val), out->ctx->p.wlen); in fp_zero()
243 * 0 on success, -1 on error.
252 ret = nn_isone(&(out->ctx->p), &isone); EG(ret, err); in fp_one()
256 ret = nn_set_word_value(&(out->fp_val), val); EG(ret, err); in fp_one()
259 ret = nn_set_wlen(&(out->fp_val), out->ctx->p.wlen); in fp_one()
273 ret = nn_cmp_word(&(out->ctx->p), val, &cmp); EG(ret, err); in fp_set_word_value()
277 ret = nn_set_word_value(&(out->fp_val), val); EG(ret, err); in fp_set_word_value()
280 ret = nn_set_wlen(&(out->fp_val), out->ctx->p.wlen); in fp_set_word_value()
288 * Compare given Fp elements. The function returns -1 if the value of in1 is
289 * less than that of in2, 0 if they are equal and 1 if the value of in2 is
292 * context). Returns 0 on success, -1 on error.
294 int fp_cmp(fp_src_t in1, fp_src_t in2, int *cmp) in fp_cmp() argument
299 ret = fp_check_initialized(in2); EG(ret, err); in fp_cmp()
301 MUST_HAVE((in1->ctx == in2->ctx), ret, err); in fp_cmp()
303 ret = nn_cmp(&(in1->fp_val), &(in2->fp_val), cmp); in fp_cmp()
309 /* Check if given Fp element has value 0. Returns 0 on success, -1 on error. */
315 ret = nn_iszero(&(in->fp_val), iszero); in fp_iszero()
326 * on success, -1 on error.
338 if ((out->magic == FP_MAGIC) && (out->ctx != NULL)) { in fp_copy()
339 MUST_HAVE((out->ctx == in->ctx), ret, err); in fp_copy()
341 ret = fp_init(out, in->ctx); EG(ret, err); in fp_copy()
344 ret = nn_copy(&(out->fp_val), &(in->fp_val)); in fp_copy()
361 * Returns 0 on success, -1 on error.
379 p = &(out->ctx->p); in fp_tabselect()
381 p_wlen = p->wlen; in fp_tabselect()
384 ret = nn_zero(&(out->fp_val)); EG(ret, err); in fp_tabselect()
385 out->fp_val.wlen = p_wlen; in fp_tabselect()
391 MUST_HAVE(((&(tab[k]->ctx->p)) == p), ret, err); in fp_tabselect()
396 out->fp_val.val[i] |= (tab[k]->fp_val.val[i] & mask); in fp_tabselect()
405 * The function tests if in1 and in2 parameters are equal or opposite in
407 * in2 are not equal or opposite, 'eq_or_opp' is set to 0. The function
408 * returns 0 on success and -1 on error. 'eq_or_opp' is only meaningful
413 int fp_eq_or_opp(fp_src_t in1, fp_src_t in2, int *eq_or_opp) in fp_eq_or_opp() argument
421 ret = fp_check_initialized(in2); EG(ret, err); in fp_eq_or_opp()
422 MUST_HAVE((in1->ctx == in2->ctx), ret, err); in fp_eq_or_opp()
424 ret = fp_init(&opp, in1->ctx); EG(ret, err); in fp_eq_or_opp()
425 ret = fp_neg(&opp, in2); EG(ret, err); in fp_eq_or_opp()
426 ret = nn_cmp(&(in1->fp_val), &(in2->fp_val), &cmp_eq); EG(ret, err); in fp_eq_or_opp()
427 ret = nn_cmp(&(in1->fp_val), &(opp.fp_val), &cmp_opp); EG(ret, err); in fp_eq_or_opp()
442 * returns 0 on success and -1 on error.
449 ret = nn_init_from_buf(&(out_fp->fp_val), buf, buflen); EG(ret, err); in fp_import_from_buf()
450 ret = nn_cmp(&(out_fp->fp_val), &(out_fp->ctx->p), &cmp); EG(ret, err); in fp_import_from_buf()
459 * primitive. The function returns 0 on sucess, -1 on error.
466 ret = nn_export_to_buf(buf, buflen, &(in_fp->fp_val)); in fp_export_to_buf()