aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/o_str.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2019-07-11 15:53:59 +1000
committerPauli <paul.dale@oracle.com>2019-07-11 15:53:59 +1000
commitb60cba3c5d25dcd5cea2c97193a30b730c8a0f28 (patch)
tree5594bbc7d0d4c6f0a9e2e762ff00ef44d200e28f /crypto/o_str.c
parent06c8331c51797f43881e5262b4c114aacc6d0ca0 (diff)
downloadopenssl-b60cba3c5d25dcd5cea2c97193a30b730c8a0f28.tar.gz
Make allocation/free/clean available to providers
Also make OPENSSL_hexstr2buf available to providers. EVP control functions need hexstring conversion, so move any memory-allocating functions in o_str.c into new file mem_str.c Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/8886)
Diffstat (limited to 'crypto/o_str.c')
-rw-r--r--crypto/o_str.c122
1 files changed, 0 insertions, 122 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c
index 467ceb2054..35bb6540f8 100644
--- a/crypto/o_str.c
+++ b/crypto/o_str.c
@@ -12,51 +12,6 @@
#include <openssl/crypto.h>
#include "internal/cryptlib.h"
-char *CRYPTO_strdup(const char *str, const char* file, int line)
-{
- char *ret;
-
- if (str == NULL)
- return NULL;
- ret = CRYPTO_malloc(strlen(str) + 1, file, line);
- if (ret != NULL)
- strcpy(ret, str);
- return ret;
-}
-
-char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line)
-{
- size_t maxlen;
- char *ret;
-
- if (str == NULL)
- return NULL;
-
- maxlen = OPENSSL_strnlen(str, s);
-
- ret = CRYPTO_malloc(maxlen + 1, file, line);
- if (ret) {
- memcpy(ret, str, maxlen);
- ret[maxlen] = '\0';
- }
- return ret;
-}
-
-void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)
-{
- void *ret;
-
- if (data == NULL || siz >= INT_MAX)
- return NULL;
-
- ret = CRYPTO_malloc(siz, file, line);
- if (ret == NULL) {
- CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- return memcpy(ret, data, siz);
-}
-
size_t OPENSSL_strnlen(const char *str, size_t maxlen)
{
const char *p;
@@ -129,83 +84,6 @@ int OPENSSL_hexchar2int(unsigned char c)
return -1;
}
-/*
- * Give a string of hex digits convert to a buffer
- */
-unsigned char *OPENSSL_hexstr2buf(const char *str, long *len)
-{
- unsigned char *hexbuf, *q;
- unsigned char ch, cl;
- int chi, cli;
- const unsigned char *p;
- size_t s;
-
- s = strlen(str);
- if ((hexbuf = OPENSSL_malloc(s >> 1)) == NULL) {
- CRYPTOerr(CRYPTO_F_OPENSSL_HEXSTR2BUF, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- for (p = (const unsigned char *)str, q = hexbuf; *p; ) {
- ch = *p++;
- if (ch == ':')
- continue;
- cl = *p++;
- if (!cl) {
- CRYPTOerr(CRYPTO_F_OPENSSL_HEXSTR2BUF,
- CRYPTO_R_ODD_NUMBER_OF_DIGITS);
- OPENSSL_free(hexbuf);
- return NULL;
- }
- cli = OPENSSL_hexchar2int(cl);
- chi = OPENSSL_hexchar2int(ch);
- if (cli < 0 || chi < 0) {
- OPENSSL_free(hexbuf);
- CRYPTOerr(CRYPTO_F_OPENSSL_HEXSTR2BUF, CRYPTO_R_ILLEGAL_HEX_DIGIT);
- return NULL;
- }
- *q++ = (unsigned char)((chi << 4) | cli);
- }
-
- if (len)
- *len = q - hexbuf;
- return hexbuf;
-}
-
-/*
- * Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
- * hex representation @@@ (Contents of buffer are always kept in ASCII, also
- * on EBCDIC machines)
- */
-char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len)
-{
- static const char hexdig[] = "0123456789ABCDEF";
- char *tmp, *q;
- const unsigned char *p;
- int i;
-
- if (len == 0)
- {
- return OPENSSL_zalloc(1);
- }
-
- if ((tmp = OPENSSL_malloc(len * 3)) == NULL) {
- CRYPTOerr(CRYPTO_F_OPENSSL_BUF2HEXSTR, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- q = tmp;
- for (i = 0, p = buffer; i < len; i++, p++) {
- *q++ = hexdig[(*p >> 4) & 0xf];
- *q++ = hexdig[*p & 0xf];
- *q++ = ':';
- }
- q[-1] = 0;
-#ifdef CHARSET_EBCDIC
- ebcdic2ascii(tmp, tmp, q - tmp - 1);
-#endif
-
- return tmp;
-}
-
int openssl_strerror_r(int errnum, char *buf, size_t buflen)
{
#if defined(_MSC_VER) && _MSC_VER>=1400