Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/generalizedtime/der_length_generalizedtime.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 | |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
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 #include "tomcrypt.h" | |
10 | |
11 /** | |
12 @file der_length_utctime.c | |
13 ASN.1 DER, get length of GeneralizedTime, Steffen Jaeckel | |
14 Based on der_length_utctime.c | |
15 */ | |
16 | |
17 #ifdef LTC_DER | |
18 | |
19 /** | |
20 Gets length of DER encoding of GeneralizedTime | |
21 @param gtime The GeneralizedTime structure to get the size of | |
22 @param outlen [out] The length of the DER encoding | |
23 @return CRYPT_OK if successful | |
24 */ | |
25 int der_length_generalizedtime(ltc_generalizedtime *gtime, unsigned long *outlen) | |
26 { | |
27 LTC_ARGCHK(outlen != NULL); | |
28 LTC_ARGCHK(gtime != NULL); | |
29 | |
30 if (gtime->fs == 0) { | |
31 /* we encode as YYYYMMDDhhmmssZ */ | |
32 *outlen = 2 + 14 + 1; | |
33 } else { | |
34 unsigned long len = 2 + 14 + 1; | |
35 unsigned fs = gtime->fs; | |
36 do { | |
37 fs /= 10; | |
38 len++; | |
39 } while(fs != 0); | |
40 if (gtime->off_hh == 0 && gtime->off_mm == 0) { | |
41 /* we encode as YYYYMMDDhhmmss.fsZ */ | |
42 len += 1; | |
43 } | |
44 else { | |
45 /* we encode as YYYYMMDDhhmmss.fs{+|-}hh'mm' */ | |
46 len += 5; | |
47 } | |
48 *outlen = len; | |
49 } | |
50 | |
51 return CRYPT_OK; | |
52 } | |
53 | |
54 #endif | |
55 | |
56 /* ref: $Format:%D$ */ | |
57 /* git commit: $Format:%H$ */ | |
58 /* commit time: $Format:%ai$ */ |