Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.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_encode_utctime.c | 12 @file der_encode_utctime.c |
15 ASN.1 DER, encode a UTCTIME, Tom St Denis | 13 ASN.1 DER, encode a UTCTIME, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef LTC_DER | 16 #ifdef LTC_DER |
19 | 17 |
20 static const char *baseten = "0123456789"; | 18 static const char * const baseten = "0123456789"; |
21 | 19 |
22 #define STORE_V(y) \ | 20 #define STORE_V(y) \ |
23 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \ | 21 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \ |
24 out[x++] = der_ia5_char_encode(baseten[y % 10]); | 22 out[x++] = der_ia5_char_encode(baseten[y % 10]); |
25 | 23 |
28 @param utctime The UTC time structure to encode | 26 @param utctime The UTC time structure to encode |
29 @param out The destination of the DER encoding of the UTC time structure | 27 @param out The destination of the DER encoding of the UTC time structure |
30 @param outlen [in/out] The length of the DER encoding | 28 @param outlen [in/out] The length of the DER encoding |
31 @return CRYPT_OK if successful | 29 @return CRYPT_OK if successful |
32 */ | 30 */ |
33 int der_encode_utctime(ltc_utctime *utctime, | 31 int der_encode_utctime(ltc_utctime *utctime, |
34 unsigned char *out, unsigned long *outlen) | 32 unsigned char *out, unsigned long *outlen) |
35 { | 33 { |
36 unsigned long x, tmplen; | 34 unsigned long x, tmplen; |
37 int err; | 35 int err; |
38 | 36 |
39 LTC_ARGCHK(utctime != NULL); | 37 LTC_ARGCHK(utctime != NULL); |
40 LTC_ARGCHK(out != NULL); | 38 LTC_ARGCHK(out != NULL); |
41 LTC_ARGCHK(outlen != NULL); | 39 LTC_ARGCHK(outlen != NULL); |
42 | 40 |
43 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) { | 41 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) { |
45 } | 43 } |
46 if (tmplen > *outlen) { | 44 if (tmplen > *outlen) { |
47 *outlen = tmplen; | 45 *outlen = tmplen; |
48 return CRYPT_BUFFER_OVERFLOW; | 46 return CRYPT_BUFFER_OVERFLOW; |
49 } | 47 } |
50 | 48 |
51 /* store header */ | 49 /* store header */ |
52 out[0] = 0x17; | 50 out[0] = 0x17; |
53 | 51 |
54 /* store values */ | 52 /* store values */ |
55 x = 2; | 53 x = 2; |
68 out[x++] = der_ia5_char_encode('Z'); | 66 out[x++] = der_ia5_char_encode('Z'); |
69 } | 67 } |
70 | 68 |
71 /* store length */ | 69 /* store length */ |
72 out[1] = (unsigned char)(x - 2); | 70 out[1] = (unsigned char)(x - 2); |
73 | 71 |
74 /* all good let's return */ | 72 /* all good let's return */ |
75 *outlen = x; | 73 *outlen = x; |
76 return CRYPT_OK; | 74 return CRYPT_OK; |
77 } | 75 } |
78 | 76 |
79 #endif | 77 #endif |
80 | 78 |
81 /* $Source$ */ | 79 /* ref: $Format:%D$ */ |
82 /* $Revision$ */ | 80 /* git commit: $Format:%H$ */ |
83 /* $Date$ */ | 81 /* commit time: $Format:%ai$ */ |