Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ OpenSSL Releases

*William McCormack*

* The undocumented public functions `UTF8_putc()` and `UTF8_getc()`
were deprecated, and their functionality moved internal to the
library. No public replacement is planned.

*Bob Beck*

* Added IKEV2 KDF (EVP_KDF-IKEV2KDF) implementation.

*Helen Zhang*
Expand Down
52 changes: 26 additions & 26 deletions crypto/asn1/a_mbstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include <crypto/asn1.h>

static int traverse_string(const unsigned char *p, int len, int inform,
int (*rfunc)(unsigned long value, void *in),
int (*rfunc)(uint32_t value, void *in),
void *arg);
static int in_utf8(unsigned long value, void *arg);
static int out_utf8(unsigned long value, void *arg);
static int type_str(unsigned long value, void *arg);
static int cpy_asc(unsigned long value, void *arg);
static int cpy_bmp(unsigned long value, void *arg);
static int cpy_univ(unsigned long value, void *arg);
static int cpy_utf8(unsigned long value, void *arg);
static int in_utf8(uint32_t value, void *arg);
static int out_utf8(uint32_t value, void *arg);
static int type_str(uint32_t value, void *arg);
static int cpy_asc(uint32_t value, void *arg);
static int cpy_bmp(uint32_t value, void *arg);
static int cpy_univ(uint32_t value, void *arg);
static int cpy_utf8(uint32_t value, void *arg);

/*
* These functions take a string in UTF8, ASCII or multibyte form and a mask
Expand Down Expand Up @@ -52,7 +52,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
ASN1_STRING *dest;
unsigned char *p;
int nchar;
int (*cpyfunc)(unsigned long, void *) = NULL;
int (*cpyfunc)(uint32_t, void *) = NULL;
if (len == -1) {
size_t len_s = strlen((const char *)in);

Expand Down Expand Up @@ -224,10 +224,10 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
*/

static int traverse_string(const unsigned char *p, int len, int inform,
int (*rfunc)(unsigned long value, void *in),
int (*rfunc)(uint32_t value, void *in),
void *arg)
{
unsigned long value;
uint32_t value;
int ret;
while (len) {
if (inform == MBSTRING_ASC) {
Expand All @@ -238,13 +238,13 @@ static int traverse_string(const unsigned char *p, int len, int inform,
value |= *p++;
len -= 2;
} else if (inform == MBSTRING_UNIV) {
value = ((unsigned long)*p++) << 24;
value |= ((unsigned long)*p++) << 16;
value = ((uint32_t)*p++) << 24;
value |= ((uint32_t)*p++) << 16;
value |= *p++ << 8;
value |= *p++;
len -= 4;
} else {
ret = UTF8_getc(p, len, &value);
ret = ossl_utf8_getc_internal(p, len, &value);
if (ret < 0)
return -1;
len -= ret;
Expand All @@ -263,7 +263,7 @@ static int traverse_string(const unsigned char *p, int len, int inform,

/* Just count number of characters */

static int in_utf8(unsigned long value, void *arg)
static int in_utf8(uint32_t value, void *arg)
{
int *nchar;

Expand All @@ -276,11 +276,11 @@ static int in_utf8(unsigned long value, void *arg)

/* Determine size of output as a UTF8 String */

static int out_utf8(unsigned long value, void *arg)
static int out_utf8(uint32_t value, void *arg)
{
int *outlen, len;

len = UTF8_putc(NULL, -1, value);
len = ossl_utf8_putc_internal(NULL, -1, value);
if (len <= 0)
return len;
outlen = arg;
Expand All @@ -293,10 +293,10 @@ static int out_utf8(unsigned long value, void *arg)
* "mask".
*/

static int type_str(unsigned long value, void *arg)
static int type_str(uint32_t value, void *arg)
{
unsigned long usable_types = *((unsigned long *)arg);
unsigned long types = usable_types;
uint32_t usable_types = *((unsigned long *)arg);
uint32_t types = usable_types;
const int native = value > INT_MAX ? INT_MAX : ossl_fromascii(value);

/*
Expand Down Expand Up @@ -332,13 +332,13 @@ static int type_str(unsigned long value, void *arg)
types &= ~B_ASN1_UTF8STRING;
if (!types)
return -1;
*((unsigned long *)arg) = types;
*((uint32_t *)arg) = types;
return 1;
}

/* Copy one byte per character ASCII like strings */

static int cpy_asc(unsigned long value, void *arg)
static int cpy_asc(uint32_t value, void *arg)
{
unsigned char **p, *q;
p = arg;
Expand All @@ -350,7 +350,7 @@ static int cpy_asc(unsigned long value, void *arg)

/* Copy two byte per character BMPStrings */

static int cpy_bmp(unsigned long value, void *arg)
static int cpy_bmp(uint32_t value, void *arg)
{
unsigned char **p, *q;
p = arg;
Expand All @@ -363,7 +363,7 @@ static int cpy_bmp(unsigned long value, void *arg)

/* Copy four byte per character UniversalStrings */

static int cpy_univ(unsigned long value, void *arg)
static int cpy_univ(uint32_t value, void *arg)
{
unsigned char **p, *q;
p = arg;
Expand All @@ -378,13 +378,13 @@ static int cpy_univ(unsigned long value, void *arg)

/* Copy to a UTF8String */

static int cpy_utf8(unsigned long value, void *arg)
static int cpy_utf8(uint32_t value, void *arg)
{
unsigned char **p;
int ret;
p = arg;
/* We already know there is enough room so pass 0xff as the length */
ret = UTF8_putc(*p, 0xff, value);
ret = ossl_utf8_putc_internal(*p, 0xff, value);
if (ret < 0)
return ret;
*p += ret;
Expand Down
25 changes: 12 additions & 13 deletions crypto/asn1/a_strex.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <inttypes.h>

#include "charmap.h"

Expand Down Expand Up @@ -56,27 +57,25 @@ typedef int char_io(void *arg, const void *buf, int len);

/*
* This function handles display of strings, one character at a time. It is
* passed an unsigned long for each character because it could come from 2 or
* passed an uint32_t for each character because it could come from 2 or
* even 4 byte forms.
*/

static int do_esc_char(unsigned long c, unsigned short flags, char *do_quotes,
static int do_esc_char(uint32_t c, unsigned short flags, char *do_quotes,
char_io *io_ch, void *arg)
{
unsigned short chflgs;
unsigned char chtmp;
char tmphex[HEX_SIZE(long) + 3];

if (c > 0xffffffffL)
return -1;
if (c > 0xffff) {
BIO_snprintf(tmphex, sizeof(tmphex), "\\W%08lX", c);
BIO_snprintf(tmphex, sizeof(tmphex), "\\W%08" PRIX32, c);
if (!io_ch(arg, tmphex, 10))
return -1;
return 10;
}
if (c > 0xff) {
BIO_snprintf(tmphex, sizeof(tmphex), "\\U%04lX", c);
BIO_snprintf(tmphex, sizeof(tmphex), "\\U%04" PRIX32, c);
if (!io_ch(arg, tmphex, 6))
return -1;
return 6;
Expand Down Expand Up @@ -137,7 +136,7 @@ static int do_buf(unsigned char *buf, int buflen,
int i, outlen, len, charwidth;
unsigned short orflags;
unsigned char *p, *q;
unsigned long c;
uint32_t c;

p = buf;
q = buf + buflen;
Expand Down Expand Up @@ -169,14 +168,14 @@ static int do_buf(unsigned char *buf, int buflen,

switch (charwidth) {
case 4:
c = ((unsigned long)*p++) << 24;
c |= ((unsigned long)*p++) << 16;
c |= ((unsigned long)*p++) << 8;
c = ((uint32_t)*p++) << 24;
c |= ((uint32_t)*p++) << 16;
c |= ((uint32_t)*p++) << 8;
c |= *p++;
break;

case 2:
c = ((unsigned long)*p++) << 8;
c = ((uint32_t)*p++) << 8;
c |= *p++;
break;

Expand All @@ -185,7 +184,7 @@ static int do_buf(unsigned char *buf, int buflen,
break;

case 0:
i = UTF8_getc(p, buflen, &c);
i = ossl_utf8_getc_internal(p, buflen, &c);
if (i < 0)
return -1; /* Invalid UTF8String */
buflen -= i;
Expand All @@ -198,7 +197,7 @@ static int do_buf(unsigned char *buf, int buflen,
orflags = CHARTYPE_LAST_ESC_2253;
if (type & BUF_TYPE_CONVUTF8) {
unsigned char utfbuf[6];
int utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c);
int utflen = ossl_utf8_putc_internal(utfbuf, sizeof(utfbuf), c);

if (utflen < 0)
return -1; /* error happened with UTF8 */
Expand Down
29 changes: 26 additions & 3 deletions crypto/asn1/a_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "internal/cryptlib.h"
#include "internal/unicode.h"
#include <openssl/asn1.h>
#include <crypto/asn1.h>

/* UTF8 utilities */

Expand All @@ -25,10 +26,10 @@
* -4 = character encoded incorrectly (not minimal length).
*/

int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
int ossl_utf8_getc_internal(const unsigned char *str, int len, uint32_t *val)
{
const unsigned char *p;
unsigned long value;
uint32_t value;
int ret;
if (len <= 0)
return 0;
Expand Down Expand Up @@ -82,6 +83,21 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
return ret;
}

#if !defined(OPENSSL_NO_DEPRECATED_4_1)
int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
{
uint32_t value = 0;
int ret;

ret = ossl_utf8_getc_internal(str, len, &value);

if (ret)
*val = (unsigned long)value;

return ret;
}
#endif /* !defined(OPENSSL_NO_DEPRECATED_4_1) */

/*
* This takes a character 'value' and writes the UTF8 encoded value in 'str'
* where 'str' is a buffer containing 'len' characters. Returns the number of
Expand All @@ -90,7 +106,7 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
* characters. It will need at most 4 characters.
*/

int UTF8_putc(unsigned char *str, int len, unsigned long value)
int ossl_utf8_putc_internal(unsigned char *str, int len, uint32_t value)
{
if (!str)
len = 4; /* Maximum we will need */
Expand Down Expand Up @@ -135,3 +151,10 @@ int UTF8_putc(unsigned char *str, int len, unsigned long value)
}
return -2;
}

#if !defined(OPENSSL_NO_DEPRECATED_4_1)
int UTF8_putc(unsigned char *str, int len, unsigned long value)
{
return ossl_utf8_putc_internal(str, len, (uint32_t)value);
}
#endif
14 changes: 8 additions & 6 deletions crypto/pkcs12/p12_utl.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <openssl/pkcs12.h>
#include "p12_local.h"
#include "crypto/pkcs7/pk7_local.h"
#include <crypto/asn1.h>

/* Cheap and nasty Unicode stuff */

Expand Down Expand Up @@ -79,13 +80,14 @@ unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
{
int ulen, i, j;
unsigned char *unitmp, *ret;
unsigned long utf32chr = 0;
uint32_t utf32chr = 0;

if (asclen == -1)
asclen = (int)strlen(asc);

for (ulen = 0, i = 0; i < asclen; i += j) {
j = UTF8_getc((const unsigned char *)asc + i, asclen - i, &utf32chr);
j = ossl_utf8_getc_internal((const unsigned char *)asc + i, asclen - i,
&utf32chr);

/*
* Following condition is somewhat opportunistic is sense that
Expand Down Expand Up @@ -121,7 +123,8 @@ unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,
return NULL;
/* re-run the loop writing down UTF-16 characters in big-endian order */
for (unitmp = ret, i = 0; i < asclen; i += j) {
j = UTF8_getc((const unsigned char *)asc + i, asclen - i, &utf32chr);
j = ossl_utf8_getc_internal((const unsigned char *)asc + i, asclen - i,
&utf32chr);
if (utf32chr >= 0x10000) { /* pair if UTF-16 characters */
unsigned int hi, lo;

Expand Down Expand Up @@ -149,7 +152,7 @@ unsigned char *OPENSSL_utf82uni(const char *asc, int asclen,

static int bmp_to_utf8(char *str, const unsigned char *utf16, int len)
{
unsigned long utf32chr;
uint32_t utf32chr;

if (len == 0)
return 0;
Expand All @@ -175,9 +178,8 @@ static int bmp_to_utf8(char *str, const unsigned char *utf16, int len)
utf32chr += 0x10000;
}

return UTF8_putc((unsigned char *)str, 4, utf32chr);
return ossl_utf8_putc_internal((unsigned char *)str, 4, utf32chr);
}

char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen)
{
int asclen, i, j;
Expand Down
3 changes: 3 additions & 0 deletions include/crypto/asn1.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,7 @@ int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,

ASN1_TIME *ossl_asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type);

int ossl_utf8_getc_internal(const unsigned char *str, int len, uint32_t *val);
int ossl_utf8_putc_internal(unsigned char *str, int len, uint32_t value);

#endif /* ndef OSSL_CRYPTO_ASN1_H */
8 changes: 5 additions & 3 deletions include/internal/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#define OSSL_INTERNAL_UNICODE_H
#pragma once

#include <stdint.h>

typedef enum {
SURROGATE_MIN = 0xd800UL,
SURROGATE_MAX = 0xdfffUL,
UNICODE_MAX = 0x10ffffUL,
SURROGATE_MIN = UINT32_C(0xd800),
SURROGATE_MAX = UINT32_C(0xdfff),
UNICODE_MAX = UINT32_C(0x10ffff),
UNICODE_LIMIT
} UNICODE_CONSTANTS;

Expand Down
Loading
Loading