]> granicus.if.org Git - openssl/commitdiff
OSSL_PARAM_construct_utf8_string computes the string length.
authorPauli <paul.dale@oracle.com>
Wed, 4 Sep 2019 09:27:08 +0000 (19:27 +1000)
committerPauli <paul.dale@oracle.com>
Wed, 4 Sep 2019 09:41:22 +0000 (19:41 +1000)
If the passed string length is zero, the function computes the string length
from the passed string.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9760)

crypto/crmf/crmf_pbm.c
crypto/evp/p_lib.c
crypto/evp/pkey_mac.c
crypto/kdf/sskdf.c
crypto/kdf/tls1_prf.c
crypto/modes/siv128.c
crypto/params.c
doc/man3/EVP_MAC.pod
doc/man3/OSSL_PARAM_int.pod
test/evp_test.c

index aef676f2523f2c02e411ab3aa5baa1006d943f94..a3ac45557d1a043a28305acfb6ddd41d1c08377a 100644 (file)
@@ -208,7 +208,7 @@ int OSSL_CRMF_pbm_new(const OSSL_CRMF_PBMPARAMETER *pbmp,
 
     macparams[0] =
         OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
-                                         (char *)mdname, strlen(mdname) + 1);
+                                         (char *)mdname, 0);
     macparams[1] =
         OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, basekey, bklen);
     if ((mac = EVP_MAC_fetch(NULL, "HMAC", NULL)) == NULL
index 5691fffae3a9b12a114b63b99af321f701351f08..5ec519d27cd9a4ecade7f31d5b6c9d4832fdf9ac 100644 (file)
@@ -345,14 +345,12 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
     if (engine_id != NULL)
         params[paramsn++] =
             OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
-                                             (char *)engine_id,
-                                             strlen(engine_id) + 1);
+                                             (char *)engine_id, 0);
 # endif
 
     params[paramsn++] =
         OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
-                                         (char *)cipher_name,
-                                         strlen(cipher_name) + 1);
+                                         (char *)cipher_name, 0);
     params[paramsn++] =
         OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
                                           (char *)priv, len);
index 05eb2b1b3ab3b1f1dbfc0e8865e36f3fdf3dc9f7..fc600fb8456a2e0070fd6552eefb512f4bb12632 100644 (file)
@@ -279,13 +279,11 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
 
                 params[params_n++] =
                     OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
-                                                     engineid,
-                                                     strlen(engineid) + 1);
+                                                     engineid, 0);
 #endif
                 params[params_n++] =
                     OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
-                                                     ciphname,
-                                                     strlen(ciphname) + 1);
+                                                     ciphname, 0);
                 params[params_n] = OSSL_PARAM_construct_end();
 
                 if (!EVP_MAC_CTX_set_params(hctx->ctx, params)
@@ -403,17 +401,14 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
                     ? NULL : (char *)ENGINE_get_id(ctx->engine);
 
                 if (engineid != NULL) {
-                    size_t engineid_l = strlen(engineid) + 1;
                     params[params_n++] =
                         OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ENGINE,
-                                                         engineid,
-                                                         engineid_l);
+                                                         engineid, 0);
                 }
 #endif
                 params[params_n++] =
                     OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
-                                                     mdname,
-                                                     strlen(mdname) + 1);
+                                                     mdname, 0);
                 params[params_n++] =
                     OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
                                                       key->data, key->length);
index 916a06e5a1ebbbcc72b89d22c0cd9e6cb3619263..b20eff2865fbb2dbdb8c0ab82ec697304b2e0a10 100644 (file)
@@ -223,8 +223,7 @@ static int SSKDF_mac_kdm(EVP_MAC *kdf_mac, const EVP_MD *hmac_md,
         const char *mdname = EVP_MD_name(hmac_md);
         params[params_n++] =
             OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
-                                             (char *)mdname,
-                                             strlen(mdname) + 1);
+                                             (char *)mdname, 0);
     }
     params[params_n++] =
         OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, (void *)salt,
index f5d2314681b31938615f5eedf3699165e5d82082..edd7f05ce06441f9b6839e3339a707068b2734f8 100644 (file)
@@ -252,8 +252,7 @@ static int tls1_prf_P_hash(const EVP_MD *md,
     mac_flags = EVP_MD_CTX_FLAG_NON_FIPS_ALLOW;
     params[0] = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_FLAGS, &mac_flags);
     params[1] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
-                                                 (char *)mdname,
-                                                 strlen(mdname) + 1);
+                                                 (char *)mdname, 0);
     params[2] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
                                                   (void *)sec, sec_len);
     params[3] = OSSL_PARAM_construct_end();
index de6a3b853f19121eb102c0e6ba7289b63c16575b..1d91ee78ee08b0098277bf0a45b960fb017fd02a 100644 (file)
@@ -173,8 +173,7 @@ int CRYPTO_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen,
     const char *cbc_name = EVP_CIPHER_name(cbc);
 
     params[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
-                                                 (char *)cbc_name,
-                                                 strlen(cbc_name) + 1);
+                                                 (char *)cbc_name, 0);
     params[1] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,
                                                   (void *)key, klen);
     params[2] = OSSL_PARAM_construct_end();
index b3fbb12b9ba1a6eef1081eee2d4d89a079fb19a2..20082ad90bda03d306313187896f65ce5fdbcfdb 100644 (file)
@@ -808,6 +808,8 @@ int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val,
 OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
                                             size_t bsize)
 {
+    if (buf != NULL && bsize == 0)
+        bsize = strlen(buf) + 1;
     return ossl_param_construct(key, OSSL_PARAM_UTF8_STRING, buf, bsize);
 }
 
index 6daa82d7537c21dcee4fcb7e44e5cebe6096f6af..4d3b22393464530d2dc0d61a37c1c6a3270c7862 100644 (file)
@@ -305,12 +305,10 @@ EVP_MAC_do_all_ex() returns nothing at all.
 
       if (cipher != NULL)
           params[params_n++] =
-              OSSL_PARAM_construct_utf8_string("cipher", cipher,
-                                               strlen(cipher) + 1, NULL);
+              OSSL_PARAM_construct_utf8_string("cipher", cipher, 0, NULL);
       if (digest != NULL)
           params[params_n++] =
-              OSSL_PARAM_construct_utf8_string("digest", digest,
-                                               strlen(digest) + 1, NULL);
+              OSSL_PARAM_construct_utf8_string("digest", digest, 0, NULL);
       params[params_n++] =
           OSSL_PARAM_construct_octet_string("key", key, strlen(key), NULL);
       params[params_n] = OSSL_PARAM_construct_end();
index b73d2b16c23f5a586aab968afa52e5a4ccdbe1d0..742e8d57745942e1d1ad428d257d3b30165e7505 100644 (file)
@@ -166,23 +166,22 @@ size B<rsize> is created.
 
 OSSL_PARAM_construct_utf8_string() is a function that constructs a UTF8
 string OSSL_PARAM structure.
-A parameter with name B<key>, storage B<buf>, size B<bsize> and return
-size B<rsize> is created.
+A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
+If B<bsize> is zero, the string length is determined using strlen(3).
 
 OSSL_PARAM_construct_octet_string() is a function that constructs an OCTET
 string OSSL_PARAM structure.
-A parameter with name B<key>, storage B<buf>, size B<bsize> and return
-size B<rsize> is created.
+A parameter with name B<key>, storage B<buf> and size B<bsize> is created.
 
 OSSL_PARAM_construct_utf8_ptr() is a function that constructes a UTF string
 pointer OSSL_PARAM structure.
-A parameter with name B<key>, storage pointer B<*buf>, size B<bsize> and
-return size B<rsize> is created.
+A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
+is created.
 
 OSSL_PARAM_construct_octet_ptr() is a function that constructes an OCTET string
 pointer OSSL_PARAM structure.
-A parameter with name B<key>, storage pointer B<*buf>, size B<bsize> and
-return size B<rsize> is created.
+A parameter with name B<key>, storage pointer B<*buf> and size B<bsize>
+is created.
 
 OSSL_PARAM_construct_end() is a function that constructs the terminating
 OSSL_PARAM structure.
index fd50c713546dff453e5b6c306b8b72ef30246a50..b2047d591aecc4a413b7637fe9f067f0abdad2ea 100644 (file)
@@ -1173,14 +1173,12 @@ static int mac_test_run_mac(EVP_TEST *t)
                                     OSSL_MAC_PARAM_CIPHER) != NULL) {
             params[params_n++] =
                 OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
-                                                 expected->alg,
-                                                 strlen(expected->alg) + 1);
+                                                 expected->alg, 0);
         } else if (OSSL_PARAM_locate_const(defined_params,
                                            OSSL_MAC_PARAM_DIGEST) != NULL) {
             params[params_n++] =
                 OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
-                                                 expected->alg,
-                                                 strlen(expected->alg) + 1);
+                                                 expected->alg, 0);
         } else {
             t->err = "MAC_BAD_PARAMS";
             goto err;