comparison src/pk/asn1/der/octet/der_encode_octet_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_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 $ */