Change OPENSSL_hexstr2buf_ex() & OPENSSL_buf2hexstr_ex() to pass the separator
authorShane Lontis <shane.lontis@oracle.com>
Mon, 2 Nov 2020 02:41:23 +0000 (12:41 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Mon, 7 Dec 2020 07:14:58 +0000 (17:14 +1000)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13294)

crypto/o_str.c
crypto/params_from_text.c
doc/man3/OPENSSL_hexchar2int.pod
include/openssl/crypto.h.in
test/hexstr_test.c

index 933133a05c63e6d40b014e6f112cc435c0e27afd..142ac4ba44e0cb929dcb49679032f35ed06b427a 100644 (file)
@@ -176,9 +176,9 @@ static int hexstr2buf_sep(unsigned char *buf, size_t buf_n, size_t *buflen,
  * Given a string of hex digits convert to a buffer
  */
 int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, size_t *buflen,
-                          const char *str)
+                          const char *str, const char sep)
 {
-    return hexstr2buf_sep(buf, buf_n, buflen, str, DEFAULT_SEPARATOR);
+    return hexstr2buf_sep(buf, buf_n, buflen, str, sep);
 }
 
 unsigned char *openssl_hexstr2buf_sep(const char *str, long *buflen,
@@ -249,9 +249,10 @@ static int buf2hexstr_sep(char *str, size_t str_n, size_t *strlen,
 }
 
 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
-                          const unsigned char *buf, size_t buflen)
+                          const unsigned char *buf, size_t buflen,
+                          const char sep)
 {
-    return buf2hexstr_sep(str, str_n, strlen, buf, buflen, DEFAULT_SEPARATOR);
+    return buf2hexstr_sep(str, str_n, strlen, buf, buflen, sep);
 }
 
 char *openssl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep)
index 9f74dc1075cccb11c87a2434e0b9f0c8f8faee01..d458d31b2ea154a54b4e086cfaa09212d1945f5e 100644 (file)
@@ -145,7 +145,7 @@ static int construct_from_text(OSSL_PARAM *to, const OSSL_PARAM *paramdef,
             if (ishex) {
                 size_t l = 0;
 
-                if (!OPENSSL_hexstr2buf_ex(buf, buf_n, &l, value))
+                if (!OPENSSL_hexstr2buf_ex(buf, buf_n, &l, value, ':'))
                     return 0;
             } else {
                 memcpy(buf, value, buf_n);
index 930b32b61f74851ef80d1d9d16c80587016fac6b..bfb3c709ab6e56d8acd5d2ef99043241ece8d9ff 100644 (file)
@@ -13,10 +13,10 @@ OPENSSL_buf2hexstr_ex, OPENSSL_buf2hexstr
 
  int OPENSSL_hexchar2int(unsigned char c);
  int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, long *buflen,
-                           const char *str);
+                           const char *str, const char sep);
  unsigned char *OPENSSL_hexstr2buf(const char *str, long *len);
  int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
-                           const unsigned char *buf, long buflen);
+                           const unsigned char *buf, long buflen, const char sep);
  char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen);
 
 =head1 DESCRIPTION
@@ -26,6 +26,8 @@ equivalent.
 
 OPENSSL_hexstr2buf_ex() decodes the hex string B<str> and places the
 resulting string of bytes in the given I<buf>.
+The character I<sep> is the separator between the bytes, which is normally ':',
+Setting this to '\0' means that there is no seperator.
 I<buf_n> gives the size of the buffer.
 If I<buflen> is not NULL, it is filled in with the result length.
 To find out how large the result will be, call this function with NULL
@@ -41,6 +43,8 @@ released by calling OPENSSL_free().
 OPENSSL_buf2hexstr_ex() encodes the contents of the given I<buf> with
 length I<buflen> and places the resulting hexadecimal character string
 in the given I<str>.
+The character I<sep> is the separator between the bytes, which is normally ':',
+Setting this to '\0' means that there is no seperator.
 I<str_n> gives the size of the of the string buffer.
 If I<strlen> is not NULL, it is filled in with the result length.
 To find out how large the result will be, call this function with NULL
index f4f098b72e54309c270e4b90001dd086b8a28a7f..0641db3a44dfa9b5740d1b85a200237277e43fc4 100644 (file)
@@ -123,10 +123,11 @@ size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz);
 size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz);
 size_t OPENSSL_strnlen(const char *str, size_t maxlen);
 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
-                          const unsigned char *buf, size_t buflen);
+                          const unsigned char *buf, size_t buflen,
+                          const char sep);
 char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen);
 int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, size_t *buflen,
-                          const char *str);
+                          const char *str, const char sep);
 unsigned char *OPENSSL_hexstr2buf(const char *str, long *buflen);
 int OPENSSL_hexchar2int(unsigned char c);
 
index c4f13b6d534048923f356f2bc685fc24e1593eba..c03b58ef03950c92f40b53eb7ae4296eddbaea07 100644 (file)
@@ -118,9 +118,10 @@ static int test_hexstr_ex_to_from(int test_index)
     unsigned char buf[64];
     struct testdata *test = &tbl_testdata[test_index];
 
-    return TEST_true(OPENSSL_hexstr2buf_ex(buf, sizeof(buf), &len, test->in))
+    return TEST_true(OPENSSL_hexstr2buf_ex(buf, sizeof(buf), &len, test->in, ':'))
            && TEST_mem_eq(buf, len, test->expected, test->expected_len)
-           && TEST_true(OPENSSL_buf2hexstr_ex(out, sizeof(out), NULL, buf, len))
+           && TEST_true(OPENSSL_buf2hexstr_ex(out, sizeof(out), NULL, buf, len,
+                        ':'))
            && TEST_str_eq(out, test->in);
 }