Mercurial > dropbear
comparison src/pk/asn1/der/ia5/der_encode_ia5_string.c @ 380:d5faf4814ddb libtomcrypt-orig libtomcrypt-1.16
Update to LibTomCrypt 1.16
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 11 Jan 2007 02:22:00 +0000 |
parents | 59400faa4b44 |
children |
comparison
equal
deleted
inserted
replaced
280:59400faa4b44 | 380:d5faf4814ddb |
---|---|
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.org | 9 * Tom St Denis, [email protected], http://libtomcrypt.com |
10 */ | 10 */ |
11 #include "tomcrypt.h" | 11 #include "tomcrypt.h" |
12 | 12 |
13 /** | 13 /** |
14 @file der_encode_ia5_string.c | 14 @file der_encode_ia5_string.c |
40 return err; | 40 return err; |
41 } | 41 } |
42 | 42 |
43 /* too big? */ | 43 /* too big? */ |
44 if (len > *outlen) { | 44 if (len > *outlen) { |
45 *outlen = len; | |
45 return CRYPT_BUFFER_OVERFLOW; | 46 return CRYPT_BUFFER_OVERFLOW; |
46 } | 47 } |
47 | 48 |
48 /* encode the header+len */ | 49 /* encode the header+len */ |
49 x = 0; | 50 x = 0; |
50 out[x++] = 0x16; | 51 out[x++] = 0x16; |
51 if (inlen < 128) { | 52 if (inlen < 128) { |
52 out[x++] = inlen; | 53 out[x++] = (unsigned char)inlen; |
53 } else if (inlen < 256) { | 54 } else if (inlen < 256) { |
54 out[x++] = 0x81; | 55 out[x++] = 0x81; |
55 out[x++] = inlen; | 56 out[x++] = (unsigned char)inlen; |
56 } else if (inlen < 65536UL) { | 57 } else if (inlen < 65536UL) { |
57 out[x++] = 0x82; | 58 out[x++] = 0x82; |
58 out[x++] = (inlen>>8)&255; | 59 out[x++] = (unsigned char)((inlen>>8)&255); |
59 out[x++] = inlen&255; | 60 out[x++] = (unsigned char)(inlen&255); |
60 } else if (inlen < 16777216UL) { | 61 } else if (inlen < 16777216UL) { |
61 out[x++] = 0x83; | 62 out[x++] = 0x83; |
62 out[x++] = (inlen>>16)&255; | 63 out[x++] = (unsigned char)((inlen>>16)&255); |
63 out[x++] = (inlen>>8)&255; | 64 out[x++] = (unsigned char)((inlen>>8)&255); |
64 out[x++] = inlen&255; | 65 out[x++] = (unsigned char)(inlen&255); |
65 } else { | 66 } else { |
66 return CRYPT_INVALID_ARG; | 67 return CRYPT_INVALID_ARG; |
67 } | 68 } |
68 | 69 |
69 /* store octets */ | 70 /* store octets */ |
78 } | 79 } |
79 | 80 |
80 #endif | 81 #endif |
81 | 82 |
82 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */ | 83 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */ |
83 /* $Revision: 1.1 $ */ | 84 /* $Revision: 1.4 $ */ |
84 /* $Date: 2005/05/16 15:08:11 $ */ | 85 /* $Date: 2006/12/04 21:34:03 $ */ |