Mercurial > dropbear
comparison src/pk/asn1/der/utctime/der_encode_utctime.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05
Import of libtomcrypt 1.05
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 03:53:40 +0000 |
parents | |
children | d5faf4814ddb |
comparison
equal
deleted
inserted
replaced
191:1c15b283127b | 209:39d5d58461d6 |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file der_encode_utctime.c | |
15 ASN.1 DER, encode a UTCTIME, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef LTC_DER | |
19 | |
20 static const char *baseten = "0123456789"; | |
21 | |
22 #define STORE_V(y) \ | |
23 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \ | |
24 out[x++] = der_ia5_char_encode(baseten[y % 10]); | |
25 | |
26 /** | |
27 Gets length of DER encoding of UTCTIME | |
28 @param outlen [out] The length of the DER encoding | |
29 @return CRYPT_OK if successful | |
30 */ | |
31 int der_encode_utctime(ltc_utctime *utctime, | |
32 unsigned char *out, unsigned long *outlen) | |
33 { | |
34 unsigned long x, tmplen; | |
35 int err; | |
36 | |
37 LTC_ARGCHK(utctime != NULL); | |
38 LTC_ARGCHK(out != NULL); | |
39 LTC_ARGCHK(outlen != NULL); | |
40 | |
41 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) { | |
42 return err; | |
43 } | |
44 if (tmplen > *outlen) { | |
45 return CRYPT_BUFFER_OVERFLOW; | |
46 } | |
47 | |
48 /* store header */ | |
49 out[0] = 0x17; | |
50 | |
51 /* store values */ | |
52 x = 2; | |
53 STORE_V(utctime->YY); | |
54 STORE_V(utctime->MM); | |
55 STORE_V(utctime->DD); | |
56 STORE_V(utctime->hh); | |
57 STORE_V(utctime->mm); | |
58 STORE_V(utctime->ss); | |
59 | |
60 if (utctime->off_mm || utctime->off_hh) { | |
61 out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+'); | |
62 STORE_V(utctime->off_hh); | |
63 STORE_V(utctime->off_mm); | |
64 } else { | |
65 out[x++] = der_ia5_char_encode('Z'); | |
66 } | |
67 | |
68 /* store length */ | |
69 out[1] = x - 2; | |
70 | |
71 /* all good let's return */ | |
72 *outlen = x; | |
73 return CRYPT_OK; | |
74 } | |
75 | |
76 #endif | |
77 | |
78 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c,v $ */ | |
79 /* $Revision: 1.5 $ */ | |
80 /* $Date: 2005/06/19 12:07:00 $ */ |