Lines Matching refs:key
134 /* copy the public key */
143 /* copy the private key */
245 * eckey An EC key object that contains domain params. The generated keypair
291 /* range of SM2 private key is [1, n-1) */
396 * Check the range of the EC public key.
402 * Returns 1 if the public key has a valid range, otherwise it returns 0.
404 static int ec_key_public_range_check(BN_CTX *ctx, const EC_KEY *key)
415 if (!EC_POINT_get_affine_coordinates(key->group, key->pub_key, x, y, ctx))
418 if (EC_GROUP_get_field_type(key->group) == NID_X9_62_prime_field) {
420 || BN_cmp(x, key->group->field) >= 0
422 || BN_cmp(y, key->group->field) >= 0) {
426 int m = EC_GROUP_get_degree(key->group);
454 /* 5.6.2.3.3 (Step 2) Test if the public key is in range */
508 * The private key is in the range [1, order-1]
570 * Returns 1 if the key is valid, otherwise it returns 0.
598 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
606 if (key == NULL || key->group == NULL || x == NULL || y == NULL) {
610 ctx = BN_CTX_new_ex(key->libctx);
615 point = EC_POINT_new(key->group);
625 if (!EC_POINT_set_affine_coordinates(key->group, point, x, y, ctx))
627 if (!EC_POINT_get_affine_coordinates(key->group, point, tx, ty, ctx))
640 if (!EC_KEY_set_public_key(key, point))
643 if (EC_KEY_check_key(key) == 0)
656 OSSL_LIB_CTX *ossl_ec_key_get_libctx(const EC_KEY *key)
658 return key->libctx;
661 const char *ossl_ec_key_get0_propq(const EC_KEY *key)
663 return key->propq;
666 void ossl_ec_key_set0_libctx(EC_KEY *key, OSSL_LIB_CTX *libctx)
668 key->libctx = libctx;
672 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
674 return key->group;
677 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
679 if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)
681 EC_GROUP_free(key->group);
682 key->group = EC_GROUP_dup(group);
683 if (key->group != NULL && EC_GROUP_get_curve_name(key->group) == NID_sm2)
684 EC_KEY_set_flags(key, EC_FLAG_SM2_RANGE);
686 key->dirty_cnt++;
687 return (key->group == NULL) ? 0 : 1;
690 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
692 return key->priv_key;
695 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
701 if (key->group == NULL || key->group->meth == NULL)
705 * Not only should key->group be set, but it should also be in a valid
710 * as an EC private key.
712 order = EC_GROUP_get0_order(key->group);
716 if (key->group->meth->set_private != NULL
717 && key->group->meth->set_private(key, priv_key) == 0)
719 if (key->meth->set_private != NULL
720 && key->meth->set_private(key, priv_key) == 0)
728 BN_clear_free(key->priv_key);
729 key->priv_key = NULL;
734 * We should never leak the bit length of the secret scalar in the key,
763 * generating a private key in EC cryptosystems and should fit all valid
783 BN_clear_free(key->priv_key);
784 key->priv_key = tmp_key;
785 key->dirty_cnt++;
790 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key)
792 return key->pub_key;
795 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key)
797 if (key->meth->set_public != NULL
798 && key->meth->set_public(key, pub_key) == 0)
800 EC_POINT_free(key->pub_key);
801 key->pub_key = EC_POINT_dup(pub_key, key->group);
802 key->dirty_cnt++;
803 return (key->pub_key == NULL) ? 0 : 1;
806 unsigned int EC_KEY_get_enc_flags(const EC_KEY *key)
808 return key->enc_flag;
811 void EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags)
813 key->enc_flag = flags;
816 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key)
818 return key->conv_form;
821 void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform)
823 key->conv_form = cform;
824 if (key->group != NULL)
825 EC_GROUP_set_point_conversion_form(key->group, cform);
828 void EC_KEY_set_asn1_flag(EC_KEY *key, int flag)
830 if (key->group != NULL)
831 EC_GROUP_set_asn1_flag(key->group, flag);
835 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx)
837 if (key->group == NULL)
839 return EC_GROUP_precompute_mult(key->group, ctx);
843 int EC_KEY_get_flags(const EC_KEY *key)
845 return key->flags;
848 void EC_KEY_set_flags(EC_KEY *key, int flags)
850 key->flags |= flags;
851 key->dirty_cnt++;
854 void EC_KEY_clear_flags(EC_KEY *key, int flags)
856 key->flags &= ~flags;
857 key->dirty_cnt++;
860 int EC_KEY_decoded_from_explicit_params(const EC_KEY *key)
862 if (key == NULL || key->group == NULL)
864 return key->group->decoded_from_explicit_params;
867 size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form,
870 if (key == NULL || key->pub_key == NULL || key->group == NULL)
872 return EC_POINT_point2buf(key->group, key->pub_key, form, pbuf, ctx);
875 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
878 if (key == NULL || key->group == NULL)
880 if (key->pub_key == NULL)
881 key->pub_key = EC_POINT_new(key->group);
882 if (key->pub_key == NULL)
884 if (EC_POINT_oct2point(key->group, key->pub_key, buf, len, ctx) == 0)
886 key->dirty_cnt++;
894 if ((key->group->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0)
895 key->conv_form = (point_conversion_form_t)(buf[0] & ~0x01);
1001 * NOTE: When generating keys for key-agreement schemes - FIPS 140-2 IG 9.9