tpc sync
Karel Miko
7 years ago
678 | 678 |
int der_decode_utf8_string(const unsigned char *in, unsigned long inlen,
|
679 | 679 |
wchar_t *out, unsigned long *outlen);
|
680 | 680 |
unsigned long der_utf8_charsize(const wchar_t c);
|
|
681 |
int der_utf8_valid_char(const wchar_t c);
|
681 | 682 |
int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen);
|
682 | 683 |
|
683 | 684 |
|
70 | 70 |
|
71 | 71 |
/* this includes the internal hash ID and optional params (NULL in this case) */
|
72 | 72 |
LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0]));
|
73 | |
LTC_SET_ASN1(alg_id, 1, parameters_type, parameters, parameters_len);
|
|
73 |
LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)parameters_type, parameters, parameters_len);
|
74 | 74 |
|
75 | 75 |
/* the actual format of the SSL DER key is odd, it stores a RSAPublicKey
|
76 | 76 |
* in a **BIT** string ... so we have to extract it then proceed to convert bit to octet
|
36 | 36 |
|
37 | 37 |
/* get the size */
|
38 | 38 |
for (x = len = 0; x < inlen; x++) {
|
39 | |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
|
40 | |
if (in[x] > 0x10FFFF) return CRYPT_INVALID_ARG;
|
41 | |
#endif
|
42 | |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
|
43 | |
if (in[x] < 0) return CRYPT_INVALID_ARG;
|
44 | |
#endif
|
|
39 |
if (!der_utf8_valid_char(in[x])) return CRYPT_INVALID_ARG;
|
45 | 40 |
len += der_utf8_charsize(in[x]);
|
46 | 41 |
}
|
47 | 42 |
|
40 | 40 |
}
|
41 | 41 |
|
42 | 42 |
/**
|
|
43 |
Test whether the given code point is valid character
|
|
44 |
@param c The UTF-8 character to test
|
|
45 |
@return 1 - valid, 0 - invalid
|
|
46 |
*/
|
|
47 |
int der_utf8_valid_char(const wchar_t c)
|
|
48 |
{
|
|
49 |
LTC_UNUSED_PARAM(c);
|
|
50 |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
|
|
51 |
if (c > 0x10FFFF) return 0;
|
|
52 |
#endif
|
|
53 |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
|
|
54 |
if (c < 0) return 0;
|
|
55 |
#endif
|
|
56 |
return 1;
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
43 | 60 |
Gets length of DER encoding of UTF8 STRING
|
44 | 61 |
@param in The characters to measure the length of
|
45 | 62 |
@param noctets The number of octets in the string to encode
|
|
55 | 72 |
|
56 | 73 |
len = 0;
|
57 | 74 |
for (x = 0; x < noctets; x++) {
|
58 | |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ > 0xFFFF
|
59 | |
if (in[x] > 0x10FFFF) return CRYPT_INVALID_ARG;
|
60 | |
#endif
|
61 | |
#if !defined(__WCHAR_MAX__) || __WCHAR_MAX__ != 0xFFFF && __WCHAR_MAX__ != 0xFFFFFFFF
|
62 | |
if (in[x] < 0) return CRYPT_INVALID_ARG;
|
63 | |
#endif
|
|
75 |
if (!der_utf8_valid_char(in[x])) return CRYPT_INVALID_ARG;
|
64 | 76 |
len += der_utf8_charsize(in[x]);
|
65 | 77 |
}
|
66 | 78 |
|