comparison libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c @ 478:d4f32c3443ac dbclient-netcat-alike

propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2) to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 14 Sep 2008 06:47:51 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
comparison
equal deleted inserted replaced
296:6b41e2cbf071 478:d4f32c3443ac
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_octet_string.c 14 @file der_encode_octet_string.c
41 return err; 41 return err;
42 } 42 }
43 43
44 /* too big? */ 44 /* too big? */
45 if (len > *outlen) { 45 if (len > *outlen) {
46 *outlen = len;
46 return CRYPT_BUFFER_OVERFLOW; 47 return CRYPT_BUFFER_OVERFLOW;
47 } 48 }
48 49
49 /* encode the header+len */ 50 /* encode the header+len */
50 x = 0; 51 x = 0;
51 out[x++] = 0x04; 52 out[x++] = 0x04;
52 if (inlen < 128) { 53 if (inlen < 128) {
53 out[x++] = inlen; 54 out[x++] = (unsigned char)inlen;
54 } else if (inlen < 256) { 55 } else if (inlen < 256) {
55 out[x++] = 0x81; 56 out[x++] = 0x81;
56 out[x++] = inlen; 57 out[x++] = (unsigned char)inlen;
57 } else if (inlen < 65536UL) { 58 } else if (inlen < 65536UL) {
58 out[x++] = 0x82; 59 out[x++] = 0x82;
59 out[x++] = (inlen>>8)&255; 60 out[x++] = (unsigned char)((inlen>>8)&255);
60 out[x++] = inlen&255; 61 out[x++] = (unsigned char)(inlen&255);
61 } else if (inlen < 16777216UL) { 62 } else if (inlen < 16777216UL) {
62 out[x++] = 0x83; 63 out[x++] = 0x83;
63 out[x++] = (inlen>>16)&255; 64 out[x++] = (unsigned char)((inlen>>16)&255);
64 out[x++] = (inlen>>8)&255; 65 out[x++] = (unsigned char)((inlen>>8)&255);
65 out[x++] = inlen&255; 66 out[x++] = (unsigned char)(inlen&255);
66 } else { 67 } else {
67 return CRYPT_INVALID_ARG; 68 return CRYPT_INVALID_ARG;
68 } 69 }
69 70
70 /* store octets */ 71 /* store octets */
79 } 80 }
80 81
81 #endif 82 #endif
82 83
83 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c,v $ */ 84 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c,v $ */
84 /* $Revision: 1.1 $ */ 85 /* $Revision: 1.4 $ */
85 /* $Date: 2005/05/16 15:08:11 $ */ 86 /* $Date: 2006/12/04 21:34:03 $ */