]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
EVP: Move the functions and controls for setting and getting distid
authorRichard Levitte <levitte@openssl.org>
Fri, 4 Sep 2020 16:00:29 +0000 (18:00 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 8 Sep 2020 10:07:40 +0000 (12:07 +0200)
Those functions were located in the EC files, but is really broader
than that, even thought currently only used for SM2.  They should
therefore be in a more central location, which was also indicated by
diverse TODOs.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12789)

crypto/ec/ec_ctrl.c
crypto/evp/pmeth_lib.c
include/openssl/ec.h
include/openssl/evp.h
util/libcrypto.num

index 84f3d8b39d97e42eb9a0b1cbfc0002d1122205ca..b47d7b606c188147cd9fbc53e6ad47a837042523 100644 (file)
@@ -443,86 +443,4 @@ int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid)
 
     return EVP_PKEY_CTX_set_group_name(ctx, OBJ_nid2sn(nid));
 }
-
-int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len)
-{
-    OSSL_PARAM params[2], *p = params;
-    int ret;
-
-    if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
-        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
-        /* Uses the same return values as EVP_PKEY_CTX_ctrl */
-        return -2;
-    }
-
-    *p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_DIST_ID,
-                                             /*
-                                              * Cast away the const. This is
-                                              * read only so should be safe
-                                              */
-                                             (void *)id, (size_t)len);
-    *p++ = OSSL_PARAM_construct_end();
-
-    ret = evp_pkey_ctx_set_params_strict(ctx, params);
-    if (ret == -2)
-        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
-    return ret;
-}
-
-int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len)
-{
-    return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
-                             EVP_PKEY_CTRL_SET1_ID, (int)len, (void*)(id));
-}
-
-static int get1_id_data(EVP_PKEY_CTX *ctx, void *id, size_t *id_len)
-{
-    int ret;
-    void *tmp_id = NULL;
-    OSSL_PARAM params[2], *p = params;
-
-    if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
-        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
-        /* Uses the same return values as EVP_PKEY_CTX_ctrl */
-        return -2;
-    }
-
-    *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_PKEY_PARAM_DIST_ID,
-                                          &tmp_id, 0);
-    *p++ = OSSL_PARAM_construct_end();
-
-    ret = evp_pkey_ctx_get_params_strict(ctx, params);
-    if (ret == -2) {
-        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
-    } else if (ret > 0) {
-        size_t tmp_id_len = params[0].return_size;
-
-        if (id != NULL)
-            memcpy(id, tmp_id, tmp_id_len);
-        if (id_len != NULL)
-            *id_len = tmp_id_len;
-    }
-    return ret;
-}
-
-int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id)
-{
-    return get1_id_data(ctx, id, NULL);
-}
-
-int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len)
-{
-    return get1_id_data(ctx, NULL, id_len);
-}
-
-int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id)
-{
-    return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET1_ID, 0, (void*)id);
-}
-
-int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len)
-{
-    return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
-                             EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)id_len);
-}
 #endif
index 94148850a0dd0b568396998766aced84d09c777f..e557e14e183ffcb780c303a67c26f92a16233d00 100644 (file)
@@ -1099,6 +1099,88 @@ int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key,
                                           key, keylen);
 }
 
+int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len)
+{
+    OSSL_PARAM params[2], *p = params;
+    int ret;
+
+    if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
+        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
+        /* Uses the same return values as EVP_PKEY_CTX_ctrl */
+        return -2;
+    }
+
+    *p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_DIST_ID,
+                                             /*
+                                              * Cast away the const. This is
+                                              * read only so should be safe
+                                              */
+                                             (void *)id, (size_t)len);
+    *p++ = OSSL_PARAM_construct_end();
+
+    ret = evp_pkey_ctx_set_params_strict(ctx, params);
+    if (ret == -2)
+        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
+    return ret;
+}
+
+int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len)
+{
+    return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
+                             EVP_PKEY_CTRL_SET1_ID, (int)len, (void*)(id));
+}
+
+static int get1_id_data(EVP_PKEY_CTX *ctx, void *id, size_t *id_len)
+{
+    int ret;
+    void *tmp_id = NULL;
+    OSSL_PARAM params[2], *p = params;
+
+    if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {
+        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
+        /* Uses the same return values as EVP_PKEY_CTX_ctrl */
+        return -2;
+    }
+
+    *p++ = OSSL_PARAM_construct_octet_ptr(OSSL_PKEY_PARAM_DIST_ID,
+                                          &tmp_id, 0);
+    *p++ = OSSL_PARAM_construct_end();
+
+    ret = evp_pkey_ctx_get_params_strict(ctx, params);
+    if (ret == -2) {
+        ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
+    } else if (ret > 0) {
+        size_t tmp_id_len = params[0].return_size;
+
+        if (id != NULL)
+            memcpy(id, tmp_id, tmp_id_len);
+        if (id_len != NULL)
+            *id_len = tmp_id_len;
+    }
+    return ret;
+}
+
+int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id)
+{
+    return get1_id_data(ctx, id, NULL);
+}
+
+int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len)
+{
+    return get1_id_data(ctx, NULL, id_len);
+}
+
+int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id)
+{
+    return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_GET1_ID, 0, (void*)id);
+}
+
+int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len)
+{
+    return EVP_PKEY_CTX_ctrl(ctx, -1, -1,
+                             EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)id_len);
+}
+
 static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
                                 int cmd, int p1, void *p2)
 {
index 24605d0055ebc1c22941e6e35f193e57ea5fbf66..9e0a6486cd117f8309d742bf7d7305c541554590 100644 (file)
@@ -1492,10 +1492,6 @@ int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
                                    int len);
 int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
 
-int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len);
-int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id);
-int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
-
 #  define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID         (EVP_PKEY_ALG_CTRL + 1)
 #  define EVP_PKEY_CTRL_EC_PARAM_ENC                  (EVP_PKEY_ALG_CTRL + 2)
 #  define EVP_PKEY_CTRL_EC_ECDH_COFACTOR              (EVP_PKEY_ALG_CTRL + 3)
@@ -1506,10 +1502,6 @@ int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
 #  define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN             (EVP_PKEY_ALG_CTRL + 8)
 #  define EVP_PKEY_CTRL_EC_KDF_UKM                    (EVP_PKEY_ALG_CTRL + 9)
 #  define EVP_PKEY_CTRL_GET_EC_KDF_UKM                (EVP_PKEY_ALG_CTRL + 10)
-/* TODO move next three #defines to evp.h when 'breaking' change is possible */
-#  define EVP_PKEY_CTRL_SET1_ID                       15
-#  define EVP_PKEY_CTRL_GET1_ID                       16
-#  define EVP_PKEY_CTRL_GET1_ID_LEN                   17
 
 /* KDF types */
 #  define EVP_PKEY_ECDH_KDF_NONE                      1
index 6bd6e26edf915429c37ae98491a0e08e230ec617..74f97fd3e2ad1c2ec0188fae05b752d553c1c0e2 100644 (file)
@@ -1496,6 +1496,10 @@ void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
 
+int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len);
+int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id);
+int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
+
 # define EVP_PKEY_OP_UNDEFINED           0
 # define EVP_PKEY_OP_PARAMGEN            (1<<1)
 # define EVP_PKEY_OP_KEYGEN              (1<<2)
@@ -1544,7 +1548,9 @@ int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key,
 # define EVP_PKEY_CTRL_CIPHER            12
 # define EVP_PKEY_CTRL_GET_MD            13
 # define EVP_PKEY_CTRL_SET_DIGEST_SIZE   14
-/* TODO move here three #defines of EVP_PKEY_CTRL_*ET1_ID* from ec.h */
+# define EVP_PKEY_CTRL_SET1_ID           15
+# define EVP_PKEY_CTRL_GET1_ID           16
+# define EVP_PKEY_CTRL_GET1_ID_LEN       17
 
 # define EVP_PKEY_ALG_CTRL               0x1000
 
index 854e447ada5eb14749f653ef09b2650e4e330174..4982a7f93c43741c857e8326bce26d5426fee9bc 100644 (file)
@@ -5296,6 +5296,6 @@ asn1_d2i_read_bio                       ? 3_0_0   EXIST::FUNCTION:
 EVP_PKCS82PKEY_with_libctx              ?      3_0_0   EXIST::FUNCTION:
 ossl_b2i                                ?      3_0_0   EXIST::FUNCTION:DSA
 ossl_b2i_bio                            ?      3_0_0   EXIST::FUNCTION:DSA
-EVP_PKEY_CTX_set1_id                    ?      3_0_0   EXIST::FUNCTION:EC
-EVP_PKEY_CTX_get1_id                    ?      3_0_0   EXIST::FUNCTION:EC
-EVP_PKEY_CTX_get1_id_len                ?      3_0_0   EXIST::FUNCTION:EC
+EVP_PKEY_CTX_set1_id                    ?      3_0_0   EXIST::FUNCTION:
+EVP_PKEY_CTX_get1_id                    ?      3_0_0   EXIST::FUNCTION:
+EVP_PKEY_CTX_get1_id_len                ?      3_0_0   EXIST::FUNCTION: