Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/utf8/der_decode_utf8_string.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file der_decode_utf8_string.c | 12 @file der_decode_utf8_string.c |
29 int der_decode_utf8_string(const unsigned char *in, unsigned long inlen, | 27 int der_decode_utf8_string(const unsigned char *in, unsigned long inlen, |
30 wchar_t *out, unsigned long *outlen) | 28 wchar_t *out, unsigned long *outlen) |
31 { | 29 { |
32 wchar_t tmp; | 30 wchar_t tmp; |
33 unsigned long x, y, z, len; | 31 unsigned long x, y, z, len; |
32 int err; | |
34 | 33 |
35 LTC_ARGCHK(in != NULL); | 34 LTC_ARGCHK(in != NULL); |
36 LTC_ARGCHK(out != NULL); | 35 LTC_ARGCHK(out != NULL); |
37 LTC_ARGCHK(outlen != NULL); | 36 LTC_ARGCHK(outlen != NULL); |
38 | 37 |
71 | 70 |
72 /* proceed to decode */ | 71 /* proceed to decode */ |
73 for (y = 0; x < inlen; ) { | 72 for (y = 0; x < inlen; ) { |
74 /* get first byte */ | 73 /* get first byte */ |
75 tmp = in[x++]; | 74 tmp = in[x++]; |
76 | 75 |
77 /* count number of bytes */ | 76 /* count number of bytes */ |
78 for (z = 0; (tmp & 0x80) && (z <= 4); z++, tmp = (tmp << 1) & 0xFF); | 77 for (z = 0; (tmp & 0x80) && (z <= 4); z++, tmp = (tmp << 1) & 0xFF); |
79 | 78 |
80 if (z > 4 || (x + (z - 1) > inlen)) { | 79 if (z > 4 || (x + (z - 1) > inlen)) { |
81 return CRYPT_INVALID_PACKET; | 80 return CRYPT_INVALID_PACKET; |
82 } | 81 } |
83 | 82 |
84 /* decode, grab upper bits */ | 83 /* decode, grab upper bits */ |
91 return CRYPT_INVALID_PACKET; | 90 return CRYPT_INVALID_PACKET; |
92 } | 91 } |
93 tmp = (tmp << 6) | ((wchar_t)in[x++] & 0x3F); | 92 tmp = (tmp << 6) | ((wchar_t)in[x++] & 0x3F); |
94 } | 93 } |
95 | 94 |
96 if (y > *outlen) { | 95 if (y < *outlen) { |
97 *outlen = y; | 96 out[y] = tmp; |
98 return CRYPT_BUFFER_OVERFLOW; | |
99 } | 97 } |
100 out[y++] = tmp; | 98 y++; |
99 } | |
100 if (y > *outlen) { | |
101 err = CRYPT_BUFFER_OVERFLOW; | |
102 } else { | |
103 err = CRYPT_OK; | |
101 } | 104 } |
102 *outlen = y; | 105 *outlen = y; |
103 | 106 |
104 return CRYPT_OK; | 107 return err; |
105 } | 108 } |
106 | 109 |
107 #endif | 110 #endif |
108 | 111 |
109 /* $Source$ */ | 112 /* ref: $Format:%D$ */ |
110 /* $Revision$ */ | 113 /* git commit: $Format:%H$ */ |
111 /* $Date$ */ | 114 /* commit time: $Format:%ai$ */ |