Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/utf8/der_encode_utf8_string.c @ 1437:871b18fd7065 fuzz
merge from main (libtommath/libtomcrypt/curve25510-donna updates)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Jun 2017 22:51:45 +0800 |
parents | f849a5ca2efc |
children | 6dba84798cd5 |
comparison
equal
deleted
inserted
replaced
1432:41dca1e5ea34 | 1437:871b18fd7065 |
---|---|
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 * | 8 * |
9 * Tom St Denis, [email protected], http://libtomcrypt.com | 9 * Tom St Denis, [email protected], http://libtom.org |
10 */ | 10 */ |
11 #include "tomcrypt.h" | 11 #include "tomcrypt.h" |
12 | 12 |
13 /** | 13 /** |
14 @file der_encode_utf8_string.c | 14 @file der_encode_utf8_string.c |
63 | 63 |
64 /* encode the header+len */ | 64 /* encode the header+len */ |
65 x = 0; | 65 x = 0; |
66 out[x++] = 0x0C; | 66 out[x++] = 0x0C; |
67 if (len < 128) { | 67 if (len < 128) { |
68 out[x++] = len; | 68 out[x++] = (unsigned char)len; |
69 } else if (len < 256) { | 69 } else if (len < 256) { |
70 out[x++] = 0x81; | 70 out[x++] = 0x81; |
71 out[x++] = len; | 71 out[x++] = (unsigned char)len; |
72 } else if (len < 65536UL) { | 72 } else if (len < 65536UL) { |
73 out[x++] = 0x82; | 73 out[x++] = 0x82; |
74 out[x++] = (len>>8)&255; | 74 out[x++] = (unsigned char)((len>>8)&255); |
75 out[x++] = len&255; | 75 out[x++] = (unsigned char)(len&255); |
76 } else if (len < 16777216UL) { | 76 } else if (len < 16777216UL) { |
77 out[x++] = 0x83; | 77 out[x++] = 0x83; |
78 out[x++] = (len>>16)&255; | 78 out[x++] = (unsigned char)((len>>16)&255); |
79 out[x++] = (len>>8)&255; | 79 out[x++] = (unsigned char)((len>>8)&255); |
80 out[x++] = len&255; | 80 out[x++] = (unsigned char)(len&255); |
81 } else { | 81 } else { |
82 return CRYPT_INVALID_ARG; | 82 return CRYPT_INVALID_ARG; |
83 } | 83 } |
84 | 84 |
85 /* store UTF8 */ | 85 /* store UTF8 */ |
86 for (y = 0; y < inlen; y++) { | 86 for (y = 0; y < inlen; y++) { |
87 switch (der_utf8_charsize(in[y])) { | 87 switch (der_utf8_charsize(in[y])) { |
88 case 1: out[x++] = in[y]; break; | 88 case 1: out[x++] = (unsigned char)in[y]; break; |
89 case 2: out[x++] = 0xC0 | ((in[y] >> 6) & 0x1F); out[x++] = 0x80 | (in[y] & 0x3F); break; | 89 case 2: out[x++] = 0xC0 | ((in[y] >> 6) & 0x1F); out[x++] = 0x80 | (in[y] & 0x3F); break; |
90 case 3: out[x++] = 0xE0 | ((in[y] >> 12) & 0x0F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; | 90 case 3: out[x++] = 0xE0 | ((in[y] >> 12) & 0x0F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; |
91 case 4: out[x++] = 0xF0 | ((in[y] >> 18) & 0x07); out[x++] = 0x80 | ((in[y] >> 12) & 0x3F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; | 91 case 4: out[x++] = 0xF0 | ((in[y] >> 18) & 0x07); out[x++] = 0x80 | ((in[y] >> 12) & 0x3F); out[x++] = 0x80 | ((in[y] >> 6) & 0x3F); out[x++] = 0x80 | (in[y] & 0x3F); break; |
92 } | 92 } |
93 } | 93 } |
98 return CRYPT_OK; | 98 return CRYPT_OK; |
99 } | 99 } |
100 | 100 |
101 #endif | 101 #endif |
102 | 102 |
103 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utf8/der_encode_utf8_string.c,v $ */ | 103 /* $Source$ */ |
104 /* $Revision: 1.7 $ */ | 104 /* $Revision$ */ |
105 /* $Date: 2006/12/16 17:41:21 $ */ | 105 /* $Date$ */ |