Lines Matching refs:ec
63 static int sm2_ec_ctx_init(struct mpi_ec_ctx *ec) in sm2_ec_ctx_init() argument
83 ec->G = mpi_point_new(0); in sm2_ec_ctx_init()
84 if (!ec->G) in sm2_ec_ctx_init()
87 mpi_set(ec->G->x, x); in sm2_ec_ctx_init()
88 mpi_set(ec->G->y, y); in sm2_ec_ctx_init()
89 mpi_set_ui(ec->G->z, 1); in sm2_ec_ctx_init()
92 ec->n = mpi_scanval(ecp->n); in sm2_ec_ctx_init()
93 if (!ec->n) { in sm2_ec_ctx_init()
94 mpi_point_release(ec->G); in sm2_ec_ctx_init()
98 ec->h = ecp->h; in sm2_ec_ctx_init()
99 ec->name = ecp->desc; in sm2_ec_ctx_init()
100 mpi_ec_init(ec, ecp->model, ecp->dialect, 0, p, a, b); in sm2_ec_ctx_init()
115 static void sm2_ec_ctx_deinit(struct mpi_ec_ctx *ec) in sm2_ec_ctx_deinit() argument
117 mpi_ec_deinit(ec); in sm2_ec_ctx_deinit()
119 memset(ec, 0, sizeof(*ec)); in sm2_ec_ctx_deinit()
122 static int sm2_ec_ctx_reset(struct mpi_ec_ctx *ec) in sm2_ec_ctx_reset() argument
124 sm2_ec_ctx_deinit(ec); in sm2_ec_ctx_reset()
125 return sm2_ec_ctx_init(ec); in sm2_ec_ctx_reset()
248 MPI_POINT point, struct mpi_ec_ctx *ec, unsigned int pbytes) in sm2_z_digest_update_point() argument
256 if (!mpi_ec_get_affine(x, y, point, ec) && in sm2_z_digest_update_point()
270 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_compute_z_digest() local
276 if (id_len > (USHRT_MAX / 8) || !ec->Q) in sm2_compute_z_digest()
283 pbytes = MPI_NBYTES(ec->p); in sm2_compute_z_digest()
290 if (sm2_z_digest_update(desc, ec->a, pbytes) || in sm2_compute_z_digest()
291 sm2_z_digest_update(desc, ec->b, pbytes) || in sm2_compute_z_digest()
292 sm2_z_digest_update_point(desc, ec->G, ec, pbytes) || in sm2_compute_z_digest()
293 sm2_z_digest_update_point(desc, ec->Q, ec, pbytes)) in sm2_compute_z_digest()
301 static int _sm2_verify(struct mpi_ec_ctx *ec, MPI hash, MPI sig_r, MPI sig_s) in _sm2_verify() argument
315 if (mpi_cmp_ui(sig_r, 1) < 0 || mpi_cmp(sig_r, ec->n) > 0 || in _sm2_verify()
316 mpi_cmp_ui(sig_s, 1) < 0 || mpi_cmp(sig_s, ec->n) > 0) { in _sm2_verify()
321 mpi_addm(t, sig_r, sig_s, ec->n); in _sm2_verify()
327 mpi_ec_mul_point(&sG, sig_s, ec->G, ec); in _sm2_verify()
328 mpi_ec_mul_point(&tP, t, ec->Q, ec); in _sm2_verify()
329 mpi_ec_add_points(&sG, &sG, &tP, ec); in _sm2_verify()
330 if (mpi_ec_get_affine(x1, y1, &sG, ec)) in _sm2_verify()
334 mpi_addm(t, hash, x1, ec->n); in _sm2_verify()
356 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_verify() local
362 if (unlikely(!ec->Q)) in sm2_verify()
385 ret = _sm2_verify(ec, hash, sig.sig_r, sig.sig_s); in sm2_verify()
398 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_set_pub_key() local
402 rc = sm2_ec_ctx_reset(ec); in sm2_set_pub_key()
406 ec->Q = mpi_point_new(0); in sm2_set_pub_key()
407 if (!ec->Q) in sm2_set_pub_key()
417 rc = sm2_ecc_os2ec(ec->Q, a); in sm2_set_pub_key()
425 mpi_point_release(ec->Q); in sm2_set_pub_key()
426 ec->Q = NULL; in sm2_set_pub_key()
438 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_init_tfm() local
440 return sm2_ec_ctx_init(ec); in sm2_init_tfm()
445 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_exit_tfm() local
447 sm2_ec_ctx_deinit(ec); in sm2_exit_tfm()