Make string_to_hex/hex_to_string public

Give the API new names, document it.

Reviewed-by: Richard Levitte <levitte@openssl.org>
diff --git a/apps/apps.c b/apps/apps.c
index 7ba12fe..6d8c489 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -2340,45 +2340,6 @@
 #endif
 }
 
-int app_hex(char c)
-{
-    switch (c) {
-    default:
-    case '0':
-        return 0;
-    case '1':
-        return 1;
-    case '2':
-        return 2;
-    case '3':
-        return 3;
-    case '4':
-          return 4;
-    case '5':
-          return 5;
-    case '6':
-          return 6;
-    case '7':
-          return 7;
-    case '8':
-          return 8;
-    case '9':
-          return 9;
-    case 'a': case 'A':
-          return 0x0A;
-    case 'b': case 'B':
-          return 0x0B;
-    case 'c': case 'C':
-          return 0x0C;
-    case 'd': case 'D':
-          return 0x0D;
-    case 'e': case 'E':
-          return 0x0E;
-    case 'f': case 'F':
-          return 0x0F;
-    }
-}
-
 /* app_isdir section */
 #ifdef _WIN32
 int app_isdir(const char *name)
diff --git a/apps/apps.h b/apps/apps.h
index a310dd2..10e1534 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -624,7 +624,6 @@
 
 # define SERIAL_RAND_BITS        64
 
-int app_hex(char);
 int app_isdir(const char *);
 int app_access(const char *, int flag);
 int raw_read_stdin(void *, int);
diff --git a/apps/cms.c b/apps/cms.c
index a74ca9d..95f2124 100644
--- a/apps/cms.c
+++ b/apps/cms.c
@@ -453,7 +453,7 @@
             noout = print = 1;
             break;
         case OPT_SECRETKEY:
-            secret_key = string_to_hex(opt_arg(), &ltmp);
+            secret_key = OPENSSL_hexstr2buf(opt_arg(), &ltmp);
             if (secret_key == NULL) {
                 BIO_printf(bio_err, "Invalid key %s\n", opt_arg());
                 goto end;
@@ -461,7 +461,7 @@
             secret_keylen = (size_t)ltmp;
             break;
         case OPT_SECRETKEYID:
-            secret_keyid = string_to_hex(opt_arg(), &ltmp);
+            secret_keyid = OPENSSL_hexstr2buf(opt_arg(), &ltmp);
             if (secret_keyid == NULL) {
                 BIO_printf(bio_err, "Invalid id %s\n", opt_arg());
                 goto opthelp;
diff --git a/apps/enc.c b/apps/enc.c
index 7f25009..9e7d069 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -636,7 +636,7 @@
             BIO_printf(bio_err, "non-hex digit\n");
             return (0);
         }
-        j = (unsigned char)app_hex(j);
+        j = (unsigned char)OPENSSL_hexchar2int(j);
         if (i & 1)
             out[i / 2] |= j;
         else
diff --git a/apps/ocsp.c b/apps/ocsp.c
index 24d88da..ca293a9 100644
--- a/apps/ocsp.c
+++ b/apps/ocsp.c
@@ -1075,7 +1075,9 @@
         if (*p != '%')
             *out++ = *p;
         else if (isxdigit(_UC(p[1])) && isxdigit(_UC(p[2]))) {
-            *out++ = (app_hex(p[1]) << 4) | app_hex(p[2]);
+            /* Don't check, can't fail because of ixdigit() call. */
+            *out++ = (OPENSSL_hexchar2int(p[1]) << 4)
+                   | OPENSSL_hexchar2int(p[2]);
             p += 2;
         }
         else
diff --git a/apps/rehash.c b/apps/rehash.c
index 38084a2..895a222 100644
--- a/apps/rehash.c
+++ b/apps/rehash.c
@@ -210,7 +210,7 @@
         if (!isxdigit(ch))
             return -1;
         hash <<= 4;
-        hash += app_hex(ch);
+        hash += OPENSSL_hexchar2int(ch);
     }
     if (filename[i++] != '.')
         return -1;
diff --git a/apps/ts.c b/apps/ts.c
index ec0cfa9..70a9013 100644
--- a/apps/ts.c
+++ b/apps/ts.c
@@ -567,7 +567,7 @@
         EVP_MD_CTX_free(md_ctx);
     } else {
         long digest_len;
-        *md_value = string_to_hex(digest, &digest_len);
+        *md_value = OPENSSL_hexstr2buf(digest, &digest_len);
         if (!*md_value || md_value_len != digest_len) {
             OPENSSL_free(*md_value);
             *md_value = NULL;
@@ -939,7 +939,7 @@
                 goto err;
         } else if (digest != NULL) {
             long imprint_len;
-            unsigned char *hexstr = string_to_hex(digest, &imprint_len);
+            unsigned char *hexstr = OPENSSL_hexstr2buf(digest, &imprint_len);
             f |= TS_VFY_IMPRINT;
             if (TS_VERIFY_CTX_set_imprint(ctx, hexstr, imprint_len) == NULL) {
                 BIO_printf(bio_err, "invalid digest string\n");