Lines Matching +full:- +full:s

1 // SPDX-License-Identifier: BSD-2-Clause
20 #include "sm2-dsa.h"
21 #include "sm2-pke.h"
38 static void ecc_free_public_key(struct ecc_public_key *s) in ecc_free_public_key() argument
40 if (!s) in ecc_free_public_key()
43 crypto_bignum_free(&s->x); in ecc_free_public_key()
44 crypto_bignum_free(&s->y); in ecc_free_public_key()
119 res = ecc_get_keysize(key->curve, 0, &key_size_bytes, &key_size_bits); in ecc_generate_keypair()
129 gid = curve_to_group_id(key->curve); in ecc_generate_keypair()
154 crypto_bignum_copy(key->d, (void *)&ecdsa.d); in ecc_generate_keypair()
155 crypto_bignum_copy(key->x, (void *)&ecdsa.Q.X); in ecc_generate_keypair()
156 crypto_bignum_copy(key->y, (void *)&ecdsa.Q.Y); in ecc_generate_keypair()
176 mbedtls_mpi s; in ecc_sign() local
181 memset(&s, 0, sizeof(s)); in ecc_sign()
187 mbedtls_mpi_init(&s); in ecc_sign()
191 gid = curve_to_group_id(key->curve); in ecc_sign()
198 ecdsa.d = *(mbedtls_mpi *)key->d; in ecc_sign()
200 res = ecc_get_keysize(key->curve, algo, &key_size_bytes, in ecc_sign()
217 lmd_res = mbedtls_ecdsa_sign(&ecdsa.grp, &r, &s, &ecdsa.d, msg, in ecc_sign()
222 mbedtls_mpi_write_binary(&r, sig + *sig_len / 2 - in ecc_sign()
226 mbedtls_mpi_write_binary(&s, sig + *sig_len - in ecc_sign()
227 mbedtls_mpi_size(&s), in ecc_sign()
228 mbedtls_mpi_size(&s)); in ecc_sign()
231 FMSG("mbedtls_ecdsa_sign failed, returned 0x%x", -lmd_res); in ecc_sign()
236 mbedtls_mpi_free(&s); in ecc_sign()
254 mbedtls_mpi s; in ecc_verify() local
259 memset(&s, 0, sizeof(s)); in ecc_verify()
265 mbedtls_mpi_init(&s); in ecc_verify()
269 gid = curve_to_group_id(key->curve); in ecc_verify()
276 ecdsa.Q.X = *(mbedtls_mpi *)key->x; in ecc_verify()
277 ecdsa.Q.Y = *(mbedtls_mpi *)key->y; in ecc_verify()
280 res = ecc_get_keysize(key->curve, algo, in ecc_verify()
294 mbedtls_mpi_read_binary(&s, sig + sig_len / 2, sig_len / 2); in ecc_verify()
297 &r, &s); in ecc_verify()
299 FMSG("mbedtls_ecdsa_verify failed, returned 0x%x", -lmd_res); in ecc_verify()
304 mbedtls_mpi_free(&s); in ecc_verify()
326 gid = curve_to_group_id(private_key->curve); in ecc_shared_secret()
334 ecdh.ctx.mbed_ecdh.d = *(mbedtls_mpi *)private_key->d; in ecc_shared_secret()
335 ecdh.ctx.mbed_ecdh.Qp.X = *(mbedtls_mpi *)public_key->x; in ecc_shared_secret()
336 ecdh.ctx.mbed_ecdh.Qp.Y = *(mbedtls_mpi *)public_key->y; in ecc_shared_secret()
399 TEE_Result crypto_asym_alloc_ecc_keypair(struct ecc_keypair *s, in crypto_asym_alloc_ecc_keypair() argument
403 memset(s, 0, sizeof(*s)); in crypto_asym_alloc_ecc_keypair()
408 s->ops = &ecc_keypair_ops; in crypto_asym_alloc_ecc_keypair()
414 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_keypair()
415 s->ops = &sm2_dsa_keypair_ops; in crypto_asym_alloc_ecc_keypair()
421 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_keypair()
422 s->ops = &sm2_pke_keypair_ops; in crypto_asym_alloc_ecc_keypair()
428 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_keypair()
429 s->ops = &sm2_kep_keypair_ops; in crypto_asym_alloc_ecc_keypair()
435 s->d = crypto_bignum_allocate(key_size_bits); in crypto_asym_alloc_ecc_keypair()
436 if (!s->d) in crypto_asym_alloc_ecc_keypair()
438 s->x = crypto_bignum_allocate(key_size_bits); in crypto_asym_alloc_ecc_keypair()
439 if (!s->x) in crypto_asym_alloc_ecc_keypair()
441 s->y = crypto_bignum_allocate(key_size_bits); in crypto_asym_alloc_ecc_keypair()
442 if (!s->y) in crypto_asym_alloc_ecc_keypair()
448 crypto_bignum_free(&s->d); in crypto_asym_alloc_ecc_keypair()
449 crypto_bignum_free(&s->x); in crypto_asym_alloc_ecc_keypair()
499 TEE_Result crypto_asym_alloc_ecc_public_key(struct ecc_public_key *s, in crypto_asym_alloc_ecc_public_key() argument
503 memset(s, 0, sizeof(*s)); in crypto_asym_alloc_ecc_public_key()
508 s->ops = &ecc_public_key_ops; in crypto_asym_alloc_ecc_public_key()
514 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_public_key()
515 s->ops = &sm2_dsa_public_key_ops; in crypto_asym_alloc_ecc_public_key()
521 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_public_key()
522 s->ops = &sm2_pke_public_key_ops; in crypto_asym_alloc_ecc_public_key()
528 s->curve = TEE_ECC_CURVE_SM2; in crypto_asym_alloc_ecc_public_key()
529 s->ops = &sm2_kep_public_key_ops; in crypto_asym_alloc_ecc_public_key()
535 s->x = crypto_bignum_allocate(key_size_bits); in crypto_asym_alloc_ecc_public_key()
536 if (!s->x) in crypto_asym_alloc_ecc_public_key()
538 s->y = crypto_bignum_allocate(key_size_bits); in crypto_asym_alloc_ecc_public_key()
539 if (!s->y) in crypto_asym_alloc_ecc_public_key()
545 crypto_bignum_free(&s->x); in crypto_asym_alloc_ecc_public_key()