Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/utctime/der_decode_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_decode_utctime.c | 12 @file der_decode_utctime.c |
15 ASN.1 DER, decode a UTCTIME, Tom St Denis | 13 ASN.1 DER, decode a UTCTIME, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef LTC_DER | 16 #ifdef LTC_DER |
19 | 17 |
20 static int char_to_int(unsigned char x) | 18 static int _char_to_int(unsigned char x) |
21 { | 19 { |
22 switch (x) { | 20 switch (x) { |
23 case '0': return 0; | 21 case '0': return 0; |
24 case '1': return 1; | 22 case '1': return 1; |
25 case '2': return 2; | 23 case '2': return 2; |
28 case '5': return 5; | 26 case '5': return 5; |
29 case '6': return 6; | 27 case '6': return 6; |
30 case '7': return 7; | 28 case '7': return 7; |
31 case '8': return 8; | 29 case '8': return 8; |
32 case '9': return 9; | 30 case '9': return 9; |
31 default: return 100; | |
33 } | 32 } |
34 return 100; | |
35 } | 33 } |
36 | 34 |
37 #define DECODE_V(y, max) \ | 35 #define DECODE_V(y, max) \ |
38 y = char_to_int(buf[x])*10 + char_to_int(buf[x+1]); \ | 36 y = _char_to_int(buf[x])*10 + _char_to_int(buf[x+1]); \ |
39 if (y >= max) return CRYPT_INVALID_PACKET; \ | 37 if (y >= max) return CRYPT_INVALID_PACKET; \ |
40 x += 2; | 38 x += 2; |
41 | 39 |
42 /** | 40 /** |
43 Decodes a UTC time structure in DER format (reads all 6 valid encoding formats) | 41 Decodes a UTC time structure in DER format (reads all 6 valid encoding formats) |
47 @return CRYPT_OK if successful | 45 @return CRYPT_OK if successful |
48 */ | 46 */ |
49 int der_decode_utctime(const unsigned char *in, unsigned long *inlen, | 47 int der_decode_utctime(const unsigned char *in, unsigned long *inlen, |
50 ltc_utctime *out) | 48 ltc_utctime *out) |
51 { | 49 { |
52 unsigned char buf[32]; | 50 unsigned char buf[32] = { 0 }; /* initialize as all zeroes */ |
53 unsigned long x; | 51 unsigned long x; |
54 int y; | 52 int y; |
55 | 53 |
56 LTC_ARGCHK(in != NULL); | 54 LTC_ARGCHK(in != NULL); |
57 LTC_ARGCHK(inlen != NULL); | 55 LTC_ARGCHK(inlen != NULL); |
71 buf[x] = y; | 69 buf[x] = y; |
72 } | 70 } |
73 *inlen = 2 + x; | 71 *inlen = 2 + x; |
74 | 72 |
75 | 73 |
76 /* possible encodings are | 74 /* possible encodings are |
77 YYMMDDhhmmZ | 75 YYMMDDhhmmZ |
78 YYMMDDhhmm+hh'mm' | 76 YYMMDDhhmm+hh'mm' |
79 YYMMDDhhmm-hh'mm' | 77 YYMMDDhhmm-hh'mm' |
80 YYMMDDhhmmssZ | 78 YYMMDDhhmmssZ |
81 YYMMDDhhmmss+hh'mm' | 79 YYMMDDhhmmss+hh'mm' |
82 YYMMDDhhmmss-hh'mm' | 80 YYMMDDhhmmss-hh'mm' |
83 | 81 |
84 So let's do a trivial decode upto [including] mm | 82 So let's do a trivial decode upto [including] mm |
85 */ | 83 */ |
86 | 84 |
87 x = 0; | 85 x = 0; |
88 DECODE_V(out->YY, 100); | 86 DECODE_V(out->YY, 100); |
89 DECODE_V(out->MM, 13); | 87 DECODE_V(out->MM, 13); |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 #endif | 121 #endif |
124 | 122 |
125 /* $Source$ */ | 123 /* ref: $Format:%D$ */ |
126 /* $Revision$ */ | 124 /* git commit: $Format:%H$ */ |
127 /* $Date$ */ | 125 /* commit time: $Format:%ai$ */ |