Lines Matching full:ec

63 static int sm2_ec_ctx_init(struct mpi_ec_ctx *ec)  in sm2_ec_ctx_init()  argument
83 ec->Q = mpi_point_new(0); in sm2_ec_ctx_init()
84 if (!ec->Q) in sm2_ec_ctx_init()
88 ec->G = mpi_point_new(0); in sm2_ec_ctx_init()
89 if (!ec->G) { in sm2_ec_ctx_init()
90 mpi_point_release(ec->Q); in sm2_ec_ctx_init()
94 mpi_set(ec->G->x, x); in sm2_ec_ctx_init()
95 mpi_set(ec->G->y, y); in sm2_ec_ctx_init()
96 mpi_set_ui(ec->G->z, 1); in sm2_ec_ctx_init()
99 ec->n = mpi_scanval(ecp->n); in sm2_ec_ctx_init()
100 if (!ec->n) { in sm2_ec_ctx_init()
101 mpi_point_release(ec->Q); in sm2_ec_ctx_init()
102 mpi_point_release(ec->G); in sm2_ec_ctx_init()
106 ec->h = ecp->h; in sm2_ec_ctx_init()
107 ec->name = ecp->desc; in sm2_ec_ctx_init()
108 mpi_ec_init(ec, ecp->model, ecp->dialect, 0, p, a, b); in sm2_ec_ctx_init()
123 static void sm2_ec_ctx_deinit(struct mpi_ec_ctx *ec) in sm2_ec_ctx_deinit() argument
125 mpi_ec_deinit(ec); in sm2_ec_ctx_deinit()
127 memset(ec, 0, sizeof(*ec)); in sm2_ec_ctx_deinit()
243 MPI_POINT point, struct mpi_ec_ctx *ec, unsigned int pbytes) in sm2_z_digest_update_point() argument
251 if (!mpi_ec_get_affine(x, y, point, ec) && in sm2_z_digest_update_point()
265 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_compute_z_digest() local
271 if (id_len > (USHRT_MAX / 8) || !ec->Q) in sm2_compute_z_digest()
278 pbytes = MPI_NBYTES(ec->p); in sm2_compute_z_digest()
285 if (sm2_z_digest_update(&sctx, ec->a, pbytes) || in sm2_compute_z_digest()
286 sm2_z_digest_update(&sctx, ec->b, pbytes) || in sm2_compute_z_digest()
287 sm2_z_digest_update_point(&sctx, ec->G, ec, pbytes) || in sm2_compute_z_digest()
288 sm2_z_digest_update_point(&sctx, ec->Q, ec, pbytes)) in sm2_compute_z_digest()
296 static int _sm2_verify(struct mpi_ec_ctx *ec, MPI hash, MPI sig_r, MPI sig_s) in _sm2_verify() argument
310 if (mpi_cmp_ui(sig_r, 1) < 0 || mpi_cmp(sig_r, ec->n) > 0 || in _sm2_verify()
311 mpi_cmp_ui(sig_s, 1) < 0 || mpi_cmp(sig_s, ec->n) > 0) { in _sm2_verify()
316 mpi_addm(t, sig_r, sig_s, ec->n); in _sm2_verify()
322 mpi_ec_mul_point(&sG, sig_s, ec->G, ec); in _sm2_verify()
323 mpi_ec_mul_point(&tP, t, ec->Q, ec); in _sm2_verify()
324 mpi_ec_add_points(&sG, &sG, &tP, ec); in _sm2_verify()
325 if (mpi_ec_get_affine(x1, y1, &sG, ec)) in _sm2_verify()
329 mpi_addm(t, hash, x1, ec->n); in _sm2_verify()
351 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_verify() local
357 if (unlikely(!ec->Q)) in sm2_verify()
380 ret = _sm2_verify(ec, hash, sig.sig_r, sig.sig_s); in sm2_verify()
393 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_set_pub_key() local
403 rc = sm2_ecc_os2ec(ec->Q, a); in sm2_set_pub_key()
417 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_init_tfm() local
419 return sm2_ec_ctx_init(ec); in sm2_init_tfm()
424 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_exit_tfm() local
426 sm2_ec_ctx_deinit(ec); in sm2_exit_tfm()