Lines Matching +full:use +full:- +full:push +full:- +full:pull
2 * Copyright (C) 2017 - This file is part of libecc project
7 * Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
22 * -1 on error
28 MUST_HAVE(((A != NULL) && (A->magic == PRIV_KEY_MAGIC) && (A->params != NULL)), ret, err); in priv_key_check_initialized()
36 * match the one passed using 'alg_type'. Returns 0 on success, -1 on error.
43 MUST_HAVE(((A != NULL) && (A->magic == PRIV_KEY_MAGIC) && in priv_key_check_initialized_and_type()
44 (A->params != NULL) && (A->key_type == alg_type)), ret, err); in priv_key_check_initialized_and_type()
54 * performed. The function returns 0 on success, -1 on error.
65 ret = nn_init_from_buf(&(priv_key->x), priv_key_buf, priv_key_buf_len); EG(ret, err); in ec_priv_key_import_from_buf()
68 priv_key->key_type = ec_key_alg; in ec_priv_key_import_from_buf()
69 priv_key->params = (const ec_params *)params; in ec_priv_key_import_from_buf()
70 priv_key->magic = PRIV_KEY_MAGIC; in ec_priv_key_import_from_buf()
78 * 'priv_key_buf_len'. The function returns 0 on sucess, -1 on error.
92 ret = nn_bitlen(&(priv_key->x), &blen); EG(ret, err); in ec_priv_key_export_to_buf()
96 ret = nn_export_to_buf(priv_key_buf, priv_key_buf_len, &(priv_key->x)); in ec_priv_key_export_to_buf()
104 * -1 on error
110 MUST_HAVE(((A != NULL) && (A->magic == PUB_KEY_MAGIC) && (A->params != NULL)), ret, err); in pub_key_check_initialized()
118 * match the one passed using 'alg_type'. Returns 0 on success, -1 on error.
125 MUST_HAVE(((A != NULL) && (A->magic == PUB_KEY_MAGIC) && in pub_key_check_initialized_and_type()
126 (A->params != NULL) && (A->key_type == alg_type)), ret, err); in pub_key_check_initialized_and_type()
137 * returns 0 on success, -1 on error.
148 ret = prj_pt_import_from_buf(&(pub_key->y), in ec_pub_key_import_from_buf()
150 (ec_shortw_crv_src_t)&(params->ec_curve)); EG(ret, err); in ec_pub_key_import_from_buf()
153 * our public key is indeed in the sub-group generated by in ec_pub_key_import_from_buf()
159 ret = nn_isone(&(params->ec_gen_cofactor), &isone); EG(ret, err); in ec_pub_key_import_from_buf()
161 ret = check_prj_pt_order(&(pub_key->y), &(params->ec_gen_order), PUBLIC_PT, &check); EG(ret, err); in ec_pub_key_import_from_buf()
166 pub_key->key_type = ec_key_alg; in ec_pub_key_import_from_buf()
167 pub_key->params = (const ec_params *)params; in ec_pub_key_import_from_buf()
168 pub_key->magic = PUB_KEY_MAGIC; in ec_pub_key_import_from_buf()
179 * returns 0 on success, -1 on error.
190 ret = prj_pt_import_from_aff_buf(&(pub_key->y), in ec_pub_key_import_from_aff_buf()
192 (ec_shortw_crv_src_t)&(params->ec_curve)); EG(ret, err); in ec_pub_key_import_from_aff_buf()
195 * our public key is indeed in the sub-group generated by in ec_pub_key_import_from_aff_buf()
201 ret = nn_isone(&(params->ec_gen_cofactor), &isone); EG(ret, err); in ec_pub_key_import_from_aff_buf()
203 ret = check_prj_pt_order(&(pub_key->y), &(params->ec_gen_order), PUBLIC_PT, &check); EG(ret, err); in ec_pub_key_import_from_aff_buf()
208 pub_key->key_type = ec_key_alg; in ec_pub_key_import_from_aff_buf()
209 pub_key->params = (const ec_params *)params; in ec_pub_key_import_from_aff_buf()
210 pub_key->magic = PUB_KEY_MAGIC; in ec_pub_key_import_from_aff_buf()
218 * success, -1 on error.
226 ret = prj_pt_export_to_buf(&(pub_key->y), pub_key_buf, pub_key_buf_len); in ec_pub_key_export_to_buf()
234 * success, -1 on error.
242 ret = prj_pt_export_to_aff_buf(&(pub_key->y), pub_key_buf, in ec_pub_key_export_to_aff_buf()
251 * -1 on error
259 ret = priv_key_check_initialized(&A->priv_key); EG(ret, err); in key_pair_check_initialized()
260 ret = pub_key_check_initialized(&A->pub_key); in key_pair_check_initialized()
268 * match the one passed using 'alg_type'. Returns 0 on success, -1 on error.
277 ret = priv_key_check_initialized_and_type(&A->priv_key, alg_type); EG(ret, err); in key_pair_check_initialized_and_type()
278 ret = pub_key_check_initialized_and_type(&A->pub_key, alg_type); in key_pair_check_initialized_and_type()
287 * success, -1 on error.
299 ret = ec_priv_key_import_from_buf(&(kp->priv_key), params, priv_key, in ec_key_pair_import_from_priv_key_buf()
302 ret = init_pubkey_from_privkey(&(kp->pub_key), &(kp->priv_key)); in ec_key_pair_import_from_priv_key_buf()
310 * checks. The function returns 0 on success, -1 on error.
323 /* We first pull the metadata, consisting of: in ec_structured_priv_key_import_from_buf()
324 * - One byte = the key type (public or private) in ec_structured_priv_key_import_from_buf()
325 * - One byte = the algorithm type (ECDSA, ECKCDSA, ...) in ec_structured_priv_key_import_from_buf()
326 * - One byte = the curve type (FRP256V1, ...) in ec_structured_priv_key_import_from_buf()
329 MUST_HAVE((params != NULL) && (params->curve_name != NULL), ret, err); in ec_structured_priv_key_import_from_buf()
331 /* Pull and check the key type */ in ec_structured_priv_key_import_from_buf()
334 /* Pull and check the algorithm type */ in ec_structured_priv_key_import_from_buf()
337 /* Pull and check the curve type */ in ec_structured_priv_key_import_from_buf()
338 ret = local_strlen((const char *)params->curve_name, &len); EG(ret, err); in ec_structured_priv_key_import_from_buf()
344 params->curve_name, crv_name_len); EG(ret, err); in ec_structured_priv_key_import_from_buf()
347 (u8)(priv_key_buf_len - metadata_len), in ec_structured_priv_key_import_from_buf()
356 * checks. The function returns 0 on success, -1 on error.
371 …MUST_HAVE((priv_key_buf != NULL) && (priv_key_buf_len > metadata_len) && (priv_key->params->curve_… in ec_structured_priv_key_export_to_buf()
375 * - One byte = the key type (public or private) in ec_structured_priv_key_export_to_buf()
376 * - One byte = the algorithm type (ECDSA, ECKCDSA, ...) in ec_structured_priv_key_export_to_buf()
377 * - One byte = the curve type (FRP256V1, ...) in ec_structured_priv_key_export_to_buf()
380 /* Push the key type */ in ec_structured_priv_key_export_to_buf()
383 /* Push the algorithm type */ in ec_structured_priv_key_export_to_buf()
384 priv_key_buf[1] = (u8)priv_key->key_type; in ec_structured_priv_key_export_to_buf()
386 /* Push the curve type */ in ec_structured_priv_key_export_to_buf()
387 curve_name = priv_key->params->curve_name; in ec_structured_priv_key_export_to_buf()
397 /* Push the raw private key buffer */ in ec_structured_priv_key_export_to_buf()
399 (u8)(priv_key_buf_len - metadata_len)); in ec_structured_priv_key_export_to_buf()
407 * checks. The function returns 0 on success, -1 on error.
421 MUST_HAVE((params != NULL) && (params->curve_name != NULL), ret, err); in ec_structured_pub_key_import_from_buf()
424 * We first pull the metadata, consisting of: in ec_structured_pub_key_import_from_buf()
425 * - One byte = the key type (public or private) in ec_structured_pub_key_import_from_buf()
426 * - One byte = the algorithm type (ECDSA, ECKCDSA, ...) in ec_structured_pub_key_import_from_buf()
427 * - One byte = the curve type (FRP256V1, ...) in ec_structured_pub_key_import_from_buf()
430 /* Pull and check the key type */ in ec_structured_pub_key_import_from_buf()
433 /* Pull and check the algorithm type */ in ec_structured_pub_key_import_from_buf()
436 /* Pull and check the curve type */ in ec_structured_pub_key_import_from_buf()
437 ret = local_strlen((const char *)params->curve_name, &len); EG(ret, err); in ec_structured_pub_key_import_from_buf()
443 params->curve_name, crv_name_len); EG(ret, err); in ec_structured_pub_key_import_from_buf()
446 (u8)(pub_key_buf_len - metadata_len), in ec_structured_pub_key_import_from_buf()
455 * checks. The function returns 0 on success, -1 on error.
470 MUST_HAVE((pub_key->params->curve_name != NULL), ret, err); in ec_structured_pub_key_export_to_buf()
474 * - One byte = the key type (public or private) in ec_structured_pub_key_export_to_buf()
475 * - One byte = the algorithm type (ECDSA, ECKCDSA, ...) in ec_structured_pub_key_export_to_buf()
476 * - One byte = the curve type (FRP256V1, ...) in ec_structured_pub_key_export_to_buf()
479 /* Push the key type */ in ec_structured_pub_key_export_to_buf()
482 /* Push the algorithm type */ in ec_structured_pub_key_export_to_buf()
483 pub_key_buf[1] = (u8)pub_key->key_type; in ec_structured_pub_key_export_to_buf()
485 /* Push the curve type */ in ec_structured_pub_key_export_to_buf()
486 curve_name = pub_key->params->curve_name; in ec_structured_pub_key_export_to_buf()
496 /* Push the raw pub key buffer */ in ec_structured_pub_key_export_to_buf()
498 (u8)(pub_key_buf_len - metadata_len)); in ec_structured_pub_key_export_to_buf()
506 * some sanity checks. The function returns 0 on success, -1 on error.
520 MUST_HAVE((params != NULL) && (params->curve_name != NULL), ret, err); in ec_structured_key_pair_import_from_priv_key_buf()
522 /* We first pull the metadata, consisting on: in ec_structured_key_pair_import_from_priv_key_buf()
523 * - One byte = the key type (public or private) in ec_structured_key_pair_import_from_priv_key_buf()
524 * - One byte = the algorithm type (ECDSA, ECKCDSA, ...) in ec_structured_key_pair_import_from_priv_key_buf()
525 * - One byte = the curve type (FRP256V1, ...) in ec_structured_key_pair_import_from_priv_key_buf()
528 /* Pull and check the key type */ in ec_structured_key_pair_import_from_priv_key_buf()
531 /* Pull and check the algorithm type */ in ec_structured_key_pair_import_from_priv_key_buf()
534 /* Pull and check the curve type */ in ec_structured_key_pair_import_from_priv_key_buf()
535 ret = local_strlen((const char *)params->curve_name, &len); EG(ret, err); in ec_structured_key_pair_import_from_priv_key_buf()
541 params->curve_name, crv_name_len); EG(ret, err); in ec_structured_key_pair_import_from_priv_key_buf()
544 (u8)(priv_key_buf_len - metadata_len), in ec_structured_key_pair_import_from_priv_key_buf()
554 * The function returns 0 on success, -1 on error.
556 * NOTE: please use this API with care as it does not check the consistency
560 * of the private/public key pair. If unsure, it is advised to use the
577 ret = ec_structured_pub_key_import_from_buf(&kp->pub_key, params, in ec_structured_key_pair_import_from_buf()
581 ret = ec_structured_priv_key_import_from_buf(&kp->priv_key, params, in ec_structured_key_pair_import_from_buf()
592 * given EC params. The function returns 0 on success, -1 on error.
602 ret = nn_get_random_mod(&(kp->priv_key.x), &(params->ec_gen_order)); EG(ret, err); in ec_key_pair_gen()
605 kp->priv_key.key_type = ec_key_alg; in ec_key_pair_gen()
606 kp->priv_key.params = (const ec_params *)params; in ec_key_pair_gen()
607 kp->priv_key.magic = PRIV_KEY_MAGIC; in ec_key_pair_gen()
610 ret = gen_priv_key(&(kp->priv_key)); EG(ret, err); in ec_key_pair_gen()
613 ret = init_pubkey_from_privkey(&(kp->pub_key), &(kp->priv_key)); in ec_key_pair_gen()