Lines Matching full:ec
66 static int __sm2_set_pub_key(struct mpi_ec_ctx *ec,
69 static int sm2_ec_ctx_init(struct mpi_ec_ctx *ec) in sm2_ec_ctx_init() argument
89 ec->Q = mpi_point_new(0); in sm2_ec_ctx_init()
90 if (!ec->Q) in sm2_ec_ctx_init()
94 ec->G = mpi_point_new(0); in sm2_ec_ctx_init()
95 if (!ec->G) { in sm2_ec_ctx_init()
96 mpi_point_release(ec->Q); in sm2_ec_ctx_init()
100 mpi_set(ec->G->x, x); in sm2_ec_ctx_init()
101 mpi_set(ec->G->y, y); in sm2_ec_ctx_init()
102 mpi_set_ui(ec->G->z, 1); in sm2_ec_ctx_init()
105 ec->n = mpi_scanval(ecp->n); in sm2_ec_ctx_init()
106 if (!ec->n) { in sm2_ec_ctx_init()
107 mpi_point_release(ec->Q); in sm2_ec_ctx_init()
108 mpi_point_release(ec->G); in sm2_ec_ctx_init()
112 ec->h = ecp->h; in sm2_ec_ctx_init()
113 ec->name = ecp->desc; in sm2_ec_ctx_init()
114 mpi_ec_init(ec, ecp->model, ecp->dialect, 0, p, a, b); in sm2_ec_ctx_init()
129 static void sm2_ec_ctx_deinit(struct mpi_ec_ctx *ec) in sm2_ec_ctx_deinit() argument
131 mpi_ec_deinit(ec); in sm2_ec_ctx_deinit()
133 memset(ec, 0, sizeof(*ec)); in sm2_ec_ctx_deinit()
250 MPI_POINT point, struct mpi_ec_ctx *ec, in sm2_z_digest_update_point() argument
259 ret = mpi_ec_get_affine(x, y, point, ec) ? -EINVAL : in sm2_z_digest_update_point()
271 struct mpi_ec_ctx *ec; in sm2_compute_z_digest() local
277 ec = kmalloc(sizeof(*ec), GFP_KERNEL); in sm2_compute_z_digest()
278 if (!ec) in sm2_compute_z_digest()
281 err = sm2_ec_ctx_init(ec); in sm2_compute_z_digest()
285 err = __sm2_set_pub_key(ec, key, keylen); in sm2_compute_z_digest()
293 pbytes = MPI_NBYTES(ec->p); in sm2_compute_z_digest()
309 err = sm2_z_digest_update(desc, ec->a, pbytes) ?: in sm2_compute_z_digest()
310 sm2_z_digest_update(desc, ec->b, pbytes) ?: in sm2_compute_z_digest()
311 sm2_z_digest_update_point(desc, ec->G, ec, pbytes) ?: in sm2_compute_z_digest()
312 sm2_z_digest_update_point(desc, ec->Q, ec, pbytes); in sm2_compute_z_digest()
319 sm2_ec_ctx_deinit(ec); in sm2_compute_z_digest()
321 kfree(ec); in sm2_compute_z_digest()
326 static int _sm2_verify(struct mpi_ec_ctx *ec, MPI hash, MPI sig_r, MPI sig_s) in _sm2_verify() argument
340 if (mpi_cmp_ui(sig_r, 1) < 0 || mpi_cmp(sig_r, ec->n) > 0 || in _sm2_verify()
341 mpi_cmp_ui(sig_s, 1) < 0 || mpi_cmp(sig_s, ec->n) > 0) { in _sm2_verify()
346 mpi_addm(t, sig_r, sig_s, ec->n); in _sm2_verify()
352 mpi_ec_mul_point(&sG, sig_s, ec->G, ec); in _sm2_verify()
353 mpi_ec_mul_point(&tP, t, ec->Q, ec); in _sm2_verify()
354 mpi_ec_add_points(&sG, &sG, &tP, ec); in _sm2_verify()
355 if (mpi_ec_get_affine(x1, y1, &sG, ec)) in _sm2_verify()
359 mpi_addm(t, hash, x1, ec->n); in _sm2_verify()
381 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_verify() local
387 if (unlikely(!ec->Q)) in sm2_verify()
410 ret = _sm2_verify(ec, hash, sig.sig_r, sig.sig_s); in sm2_verify()
423 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_set_pub_key() local
425 return __sm2_set_pub_key(ec, key, keylen); in sm2_set_pub_key()
429 static int __sm2_set_pub_key(struct mpi_ec_ctx *ec, in __sm2_set_pub_key() argument
441 rc = sm2_ecc_os2ec(ec->Q, a); in __sm2_set_pub_key()
455 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_init_tfm() local
457 return sm2_ec_ctx_init(ec); in sm2_init_tfm()
462 struct mpi_ec_ctx *ec = akcipher_tfm_ctx(tfm); in sm2_exit_tfm() local
464 sm2_ec_ctx_deinit(ec); in sm2_exit_tfm()