1 /* ---- NUMBER THEORY ---- */
2 module tomcrypt.pk;
3 
4 import core.stdc.config : c_ulong;
5 import core.stdc.stddef : wchar_t; 
6 
7 import tomcrypt.prng;
8 import tomcrypt.pkcs;
9 
10 extern(C) nothrow:
11 
12 enum 
13 {
14    PK_PUBLIC=0,
15    PK_PRIVATE=1
16 }
17 
18 int rand_prime(void *N, long len, prng_state *prng, int wprng);
19 
20 /* ---- RSA ---- */
21 version(LTC_MRSA)
22 {
23 
24     /* Min and Max RSA key sizes (in bits) */
25     enum MIN_RSA_SIZE = 1024;
26     enum MAX_RSA_SIZE = 4096;
27     
28     /** RSA LTC_PKCS style key */
29     struct rsa_key 
30     {
31         /** Type of key, PK_PRIVATE or PK_PUBLIC */
32         int type;
33         /** The public exponent */
34         void *e; 
35         /** The private exponent */
36         void *d; 
37         /** The modulus */
38         void *N; 
39         /** The p factor of N */
40         void *p; 
41         /** The q factor of N */
42         void *q; 
43         /** The 1/q mod p CRT param */
44         void *qP; 
45         /** The d mod (p - 1) CRT param */
46         void *dP; 
47         /** The d mod (q - 1) CRT param */
48         void *dQ;
49     }
50     
51     int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
52     
53     int rsa_exptmod(const ubyte* _in,   c_ulong inlen,
54                           ubyte* _out,  c_ulong *outlen, int which,
55                           rsa_key *key);
56     
57     void rsa_free(rsa_key *key);
58     
59     /* These use LTC_PKCS #1 v2.0 padding */
60     int rsa_encrypt_key(const ubyte* _in,     c_ulong inlen,
61                               ubyte* _out,    c_ulong *outlen,
62                         const ubyte* lparam, c_ulong lparamlen,
63                         prng_state *prng, int prng_idx, int hash_idx, rsa_key *key)
64     {
65        return rsa_encrypt_key_ex(_in, inlen, _out, outlen, lparam, lparamlen, prng, prng_idx, hash_idx, LTC_LTC_PKCS_1_OAEP, key);
66     }
67     
68     int rsa_decrypt_key(const ubyte* _in,       c_ulong  inlen,
69                                  ubyte* _out,      c_ulong *outlen,
70                            const ubyte* lparam,    c_ulong  lparamlen,
71                                  int               hash_idx,
72                                  int              *stat,     rsa_key       *key)
73     {
74         return rsa_decrypt_key_ex(_in, inlen, _out, outlen, lparam, lparamlen, hash_idx, LTC_LTC_PKCS_1_OAEP, stat, key);
75     }
76     
77     int rsa_sign_hash(const ubyte* _in,       c_ulong  inlen,
78                                ubyte* _out,      c_ulong *outlen,
79                                prng_state    *prng,     int            prng_idx,
80                                int            hash_idx, c_ulong        saltlen,
81                                rsa_key *key)
82     {
83         return rsa_sign_hash_ex(_in, inlen, _out, outlen, LTC_LTC_PKCS_1_PSS, prng, prng_idx, hash_idx, saltlen, key);
84     }
85     
86     int rsa_verify_hash_ex(const ubyte* sig,      c_ulong siglen,
87                            const ubyte* hash,     c_ulong hashlen,
88                                  int            hash_idx, c_ulong       saltlen,
89                                  int           *stat,     rsa_key      *key)
90     {
91         return rsa_verify_hash_ex(sig, siglen, hash, hashlen, LTC_LTC_PKCS_1_PSS, hash_idx, saltlen, stat, key);
92     }
93     
94     /* These can be switched between LTC_PKCS #1 v2.x and LTC_PKCS #1 v1.5 paddings */
95     int rsa_encrypt_key_ex(const ubyte* _in,     c_ulong inlen,
96                                  ubyte* _out,    c_ulong *outlen,
97                            const ubyte* lparam, c_ulong lparamlen,
98                            prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key);
99     
100     int rsa_decrypt_key_ex(const ubyte* _in,       c_ulong  inlen,
101                                  ubyte* _out,      c_ulong *outlen,
102                            const ubyte* lparam,    c_ulong  lparamlen,
103                                  int               hash_idx, int            padding,
104                                  int              *stat,     rsa_key       *key);
105     
106     int rsa_sign_hash_ex(const ubyte* _in,       c_ulong  inlen,
107                                ubyte* _out,      c_ulong *outlen,
108                                int            padding,
109                                prng_state    *prng,     int            prng_idx,
110                                int            hash_idx, c_ulong        saltlen,
111                                rsa_key *key);
112     
113     int rsa_verify_hash_ex(const ubyte* sig,      c_ulong siglen,
114                            const ubyte* hash,     c_ulong hashlen,
115                                  int            padding,
116                                  int            hash_idx, c_ulong       saltlen,
117                                  int           *stat,     rsa_key      *key);
118     
119     /* LTC_PKCS #1 import/export */
120     int rsa_export(ubyte* _out, c_ulong *outlen, int type, rsa_key *key);
121     int rsa_import(const ubyte* _in, c_ulong inlen, rsa_key *key);
122                         
123 }
124 
125 /* ---- Katja ---- */
126 version(MKAT)
127 {
128     /* Min and Max KAT key sizes (in bits) */
129     enum MIN_KAT_SIZE = 1024;
130     enum MAX_KAT_SIZE = 4096;
131     
132     /** Katja LTC_PKCS style key */
133     struct katja_key 
134     {
135         /** Type of key, PK_PRIVATE or PK_PUBLIC */
136         int type;
137         /** The private exponent */
138         void *d; 
139         /** The modulus */
140         void *N; 
141         /** The p factor of N */
142         void *p; 
143         /** The q factor of N */
144         void *q; 
145         /** The 1/q mod p CRT param */
146         void *qP; 
147         /** The d mod (p - 1) CRT param */
148         void *dP; 
149         /** The d mod (q - 1) CRT param */
150         void *dQ;
151         /** The pq param */
152         void *pq;
153     }
154     
155     int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key);
156     
157     int katja_exptmod(const ubyte* _in,   c_ulong inlen,
158                             ubyte* _out,  c_ulong *outlen, int which,
159                             katja_key *key);
160     
161     void katja_free(katja_key *key);
162     
163     /* These use LTC_PKCS #1 v2.0 padding */
164     int katja_encrypt_key(const ubyte* _in,     c_ulong inlen,
165                                 ubyte* _out,    c_ulong *outlen,
166                           const ubyte* lparam, c_ulong lparamlen,
167                           prng_state *prng, int prng_idx, int hash_idx, katja_key *key);
168                                             
169     int katja_decrypt_key(const ubyte* _in,       c_ulong  inlen,
170                                 ubyte* _out,      c_ulong *outlen, 
171                           const ubyte* lparam,    c_ulong  lparamlen,
172                                 int            hash_idx, int *stat,
173                                 katja_key       *key);
174     
175     /* LTC_PKCS #1 import/export */
176     int katja_export(ubyte* _out, c_ulong *outlen, int type, katja_key *key);
177     int katja_import(const ubyte* _in, c_ulong inlen, katja_key *key);      
178 }
179 
180 /* ---- ECC Routines ---- */
181 version(LTC_MECC)
182 {
183     
184     /* size of our temp buffers for exported keys */
185     enum ECC_BUF_SIZE = 256;
186     
187     /* max private key size */
188     enum ECC_MAXSIZE  = 66;
189     
190     /** Structure defines a NIST GF(p) curve */
191     struct ltc_ecc_set_type
192     {
193        /** The size of the curve in octets */
194        int size;
195     
196        /** name of curve */
197        char *name; 
198     
199        /** The prime that defines the field the curve is in (encoded in hex) */
200        char *prime;
201     
202        /** The fields B param (hex) */
203        char *B;
204     
205        /** The order of the curve (hex) */
206        char *order;
207       
208        /** The x co-ordinate of the base point on the curve (hex) */
209        char *Gx;
210      
211        /** The y co-ordinate of the base point on the curve (hex) */
212        char *Gy;
213     }
214     
215     /** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */
216     struct ecc_point
217     {
218         /** The x co-ordinate */
219         void *x;
220     
221         /** The y co-ordinate */
222         void *y;
223     
224         /** The z co-ordinate */
225         void *z;
226     }
227     
228     /** An ECC key */
229     struct ecc_key
230     {
231         /** Type of key, PK_PRIVATE or PK_PUBLIC */
232         int type;
233     
234         /** Index into the ltc_ecc_sets[] for the parameters of this curve; if -1, then this key is using user supplied curve in dp */
235         int idx;
236     
237         /** pointer to domain parameters; either points to NIST curves (identified by idx >= 0) or user supplied curve */
238         const ltc_ecc_set_type *dp;
239     
240         /** The public key */
241         ecc_point pubkey;
242     
243         /** The private key */
244         void *k;
245     }
246     
247     /** the ECC params provided */
248     extern const __gshared ltc_ecc_set_type[] ltc_ecc_sets;
249     
250     int  ecc_test();
251     void ecc_sizes(int *low, int *high);
252     int  ecc_get_size(ecc_key *key);
253     
254     int  ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
255     int  ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_set_type *dp);
256     void ecc_free(ecc_key *key);
257     
258     int  ecc_export(ubyte* _out, c_ulong *outlen, int type, ecc_key *key);
259     int  ecc_import(const ubyte* _in, c_ulong inlen, ecc_key *key);
260     int  ecc_import_ex(const ubyte* _in, c_ulong inlen, ecc_key *key, const ltc_ecc_set_type *dp);
261     
262     int ecc_ansi_x963_export(ecc_key *key, ubyte* _out, c_ulong *outlen);
263     int ecc_ansi_x963_import(const ubyte* _in, c_ulong inlen, ecc_key *key);
264     int ecc_ansi_x963_import_ex(const ubyte* _in, c_ulong inlen, ecc_key *key, ltc_ecc_set_type *dp);
265     
266     int  ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, 
267                            ubyte* _out, c_ulong *outlen);
268     
269     int  ecc_encrypt_key(const ubyte* _in,   c_ulong inlen,
270                                ubyte* _out,  c_ulong *outlen, 
271                                prng_state *prng, int wprng, int hash, 
272                                ecc_key *key);
273     
274     int  ecc_decrypt_key(const ubyte* _in,  c_ulong  inlen,
275                                ubyte* _out, c_ulong *outlen, 
276                                ecc_key *key);
277     
278     int  ecc_sign_hash(const ubyte* _in,  c_ulong inlen, 
279                              ubyte* _out, c_ulong *outlen, 
280                              prng_state *prng, int wprng, ecc_key *key);
281     
282     int  ecc_verify_hash(const ubyte* sig,  c_ulong siglen,
283                          const ubyte* hash, c_ulong hashlen, 
284                          int *stat, ecc_key *key);
285     
286     /* low level functions */
287     ecc_point *ltc_ecc_new_point();
288     void       ltc_ecc_del_point(ecc_point *p);
289     int        ltc_ecc_is_valid_idx(int n);
290     
291     /* point ops (mp == montgomery digit) */
292     version(LTM_LTC_DESC)
293     {
294         /* R = 2P */
295         int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp);
296         
297         /* R = P + Q */
298         int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);        
299     }
300     else version(GMP_LTC_DESC)
301     {
302         /* R = 2P */
303         int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp);
304         
305         /* R = P + Q */
306         int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);        
307     }
308     else version(LTC_MECC_ACCEL) {}
309     else
310     {
311         /* R = 2P */
312         int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp);
313         
314         /* R = P + Q */
315         int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);        
316     }
317     
318     version(LTC_MECC_FP)
319     {
320         /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */
321         int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
322         
323         /* functions for saving/loading/freeing/adding to fixed point cache */
324         int ltc_ecc_fp_save_state(ubyte* *_out, c_ulong *outlen);
325         int ltc_ecc_fp_restore_state(ubyte* _in, c_ulong inlen);
326         void ltc_ecc_fp_free();
327         int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock);
328         
329         /* lock/unlock all points currently in fixed point cache */
330         void ltc_ecc_fp_tablelock(int lock);
331     }
332     
333     /* R = kG */
334     int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
335     
336     version(LTC_ECC_SHAMIR)
337     {
338         /* kA*A + kB*B = C */
339         int ltc_ecc_mul2add(ecc_point *A, void *kA,
340                             ecc_point *B, void *kB,
341                             ecc_point *C,
342                                  void *modulus);
343     
344         version(LTC_MECC_FP)
345         {
346         /* Shamir's trick with optimized point multiplication using fixed point cache */
347         int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
348                                ecc_point *B, void *kB,
349                                ecc_point *C, void *modulus);
350         }
351     }
352     
353     
354     /* map P to affine from projective */
355     int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
356 }
357 
358 version(LTC_MDSA)
359 {
360 
361     /* Max diff between group and modulus size in bytes */
362     enum LTC_MDSA_DELTA     = 512;
363     
364     /* Max DSA group size in bytes (default allows 4k-bit groups) */
365     enum LTC_MDSA_MAX_GROUP = 512;
366     
367     /** DSA key structure */
368     struct dsa_key
369     {
370        /** The key type, PK_PRIVATE or PK_PUBLIC */
371        int type; 
372     
373        /** The order of the sub-group used in octets */
374        int qord;
375     
376        /** The generator  */
377        void *g;
378     
379        /** The prime used to generate the sub-group */
380        void *q;
381     
382        /** The large prime that generats the field the contains the sub-group */
383        void *p;
384     
385        /** The private key */
386        void *x;
387     
388        /** The public key */
389        void *y;
390     }
391     
392     int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
393     void dsa_free(dsa_key *key);
394     
395     int dsa_sign_hash_raw(const ubyte* _in,  c_ulong inlen,
396                                        void *r,   void *s,
397                                    prng_state *prng, int wprng, dsa_key *key);
398     
399     int dsa_sign_hash(const ubyte* _in,  c_ulong inlen,
400                             ubyte* _out, c_ulong *outlen,
401                             prng_state *prng, int wprng, dsa_key *key);
402     
403     int dsa_verify_hash_raw(         void *r,          void *s,
404                         const ubyte* hash, c_ulong hashlen, 
405                                         int *stat,      dsa_key *key);
406     
407     int dsa_verify_hash(const ubyte* sig,  c_ulong siglen,
408                         const ubyte* hash, c_ulong hashlen, 
409                               int           *stat, dsa_key       *key);
410     
411     int dsa_encrypt_key(const ubyte* _in,   c_ulong inlen,
412                               ubyte* _out,  c_ulong *outlen, 
413                               prng_state *prng, int wprng, int hash, 
414                               dsa_key *key);
415                           
416     int dsa_decrypt_key(const ubyte* _in,  c_ulong  inlen,
417                               ubyte* _out, c_ulong *outlen, 
418                               dsa_key *key);
419                               
420     int dsa_import(const ubyte* _in, c_ulong inlen, dsa_key *key);
421     int dsa_export(ubyte* _out, c_ulong *outlen, int type, dsa_key *key);
422     int dsa_verify_key(dsa_key *key, int *stat);
423     
424     int dsa_shared_secret(void          *private_key, void *base,
425                           dsa_key       *public_key,
426                           ubyte* _out,         c_ulong *outlen);
427 }
428 
429 version(LTC_DER)
430 {
431     /* DER handling */
432     
433     enum 
434     {
435      LTC_ASN1_EOL,
436      LTC_ASN1_BOOLEAN,
437      LTC_ASN1_INTEGER,
438      LTC_ASN1_SHORT_INTEGER,
439      LTC_ASN1_BIT_STRING,
440      LTC_ASN1_OCTET_STRING,
441      LTC_ASN1_NULL,
442      LTC_ASN1_OBJECT_IDENTIFIER,
443      LTC_ASN1_IA5_STRING,
444      LTC_ASN1_PRINTABLE_STRING,
445      LTC_ASN1_UTF8_STRING,
446      LTC_ASN1_UTCTIME,
447      LTC_ASN1_CHOICE,
448      LTC_ASN1_SEQUENCE,
449      LTC_ASN1_SET,
450      LTC_ASN1_SETOF
451     }
452     
453     /** A LTC ASN.1 list type */
454     struct ltc_asn1_list 
455     {
456        /** The LTC ASN.1 enumerated type identifier */
457        int           type;
458        /** The data to encode or place for decoding */
459        void         *data;
460        /** The size of the input or resulting output */
461        c_ulong size;
462        /** The used flag, this is used by the CHOICE ASN.1 type to indicate which choice was made */
463        int           used;
464        /** prev/next entry in the list */
465        ltc_asn1_list* prev, next, child, parent;
466     } 
467     
468     void LTC_SET_ASN1(ltc_asn1_list* list, int index, int Type, void* Data, c_ulong Size)
469     {                            
470         int LTC_MACRO_temp            = index;       
471         ltc_asn1_list* LTC_MACRO_list = list;        
472         LTC_MACRO_list[LTC_MACRO_temp].type = Type;  
473         LTC_MACRO_list[LTC_MACRO_temp].data = Data;  
474         LTC_MACRO_list[LTC_MACRO_temp].size = Size;  
475         LTC_MACRO_list[LTC_MACRO_temp].used = 0;      
476     } 
477     
478     /* SEQUENCE */
479     int der_encode_sequence_ex(ltc_asn1_list *list, c_ulong inlen,
480                                ubyte* _out,         c_ulong *outlen, int type_of);
481     
482     int der_encode_sequence_ex(ltc_asn1_list *list, c_ulong inlen,
483                                    ubyte* _out,     c_ulong *outlen)
484     {
485         return der_encode_sequence_ex(list, inlen, _out, outlen, LTC_ASN1_SEQUENCE);
486     }    
487     
488     int der_decode_sequence_ex(const ubyte* _in,        c_ulong  inlen,
489                                ltc_asn1_list *list,     c_ulong  outlen, int ordered);
490     
491     int der_decode_sequence(const ubyte* _in,        c_ulong  inlen,
492                                ltc_asn1_list *list,     c_ulong  outlen)                          
493     {
494         return der_decode_sequence_ex(_in, inlen, list, outlen, 1);
495     }
496     
497     int der_length_sequence(ltc_asn1_list *list, c_ulong inlen,
498                             c_ulong *outlen);
499     
500     /* SET */
501     int der_decode_set(const ubyte* _in,        c_ulong  inlen,
502                                ltc_asn1_list *list,     c_ulong  outlen)
503     {
504         return der_decode_sequence_ex(_in, inlen, list, outlen, 0);
505     }
506 
507     alias der_length_set = der_length_sequence;
508     int der_encode_set(ltc_asn1_list *list, c_ulong inlen,
509                        ubyte* _out,  c_ulong *outlen);
510     
511     int der_encode_setof(ltc_asn1_list *list, c_ulong inlen,
512                          ubyte* _out,  c_ulong *outlen);
513                             
514     /* VA list handy helpers with triplets of <type, size, data> */
515     int der_encode_sequence_multi(ubyte* _out, c_ulong *outlen, ...);
516     int der_decode_sequence_multi(const ubyte* _in, c_ulong inlen, ...);
517     
518     /* FLEXI DECODER handle unknown list decoder */
519     int  der_decode_sequence_flexi(const ubyte* _in, c_ulong *inlen, ltc_asn1_list **_out);
520     void der_free_sequence_flexi(ltc_asn1_list *list);
521     void der_sequence_free(ltc_asn1_list *_in);
522     
523     /* BOOLEAN */
524     int der_length_boolean(c_ulong *outlen);
525     int der_encode_boolean(int _in, 
526                            ubyte* _out, c_ulong *outlen);
527     int der_decode_boolean(const ubyte* _in, c_ulong inlen,
528                                            int *_out);              
529     /* INTEGER */
530     int der_encode_integer(void *num, ubyte* _out, c_ulong *outlen);
531     int der_decode_integer(const ubyte* _in, c_ulong inlen, void *num);
532     int der_length_integer(void *num, c_ulong *len);
533     
534     /* INTEGER -- handy for 0..2^32-1 values */
535     int der_decode_short_integer(const ubyte* _in, c_ulong inlen, c_ulong *num);
536     int der_encode_short_integer(c_ulong num, ubyte* _out, c_ulong *outlen);
537     int der_length_short_integer(c_ulong num, c_ulong *outlen);
538     
539     /* BIT STRING */
540     int der_encode_bit_string(const ubyte* _in, c_ulong inlen,
541                                     ubyte* _out, c_ulong *outlen);
542     int der_decode_bit_string(const ubyte* _in, c_ulong inlen,
543                                     ubyte* _out, c_ulong *outlen);
544     int der_length_bit_string(c_ulong nbits, c_ulong *outlen);
545     
546     /* OCTET STRING */
547     int der_encode_octet_string(const ubyte* _in, c_ulong inlen,
548                                       ubyte* _out, c_ulong *outlen);
549     int der_decode_octet_string(const ubyte* _in, c_ulong inlen,
550                                       ubyte* _out, c_ulong *outlen);
551     int der_length_octet_string(c_ulong noctets, c_ulong *outlen);
552     
553     /* OBJECT IDENTIFIER */
554     int der_encode_object_identifier(c_ulong *words, c_ulong  nwords,
555                                      ubyte* _out,   c_ulong *outlen);
556     int der_decode_object_identifier(const ubyte* _in,    c_ulong  inlen,
557                                            c_ulong *words, c_ulong *outlen);
558     int der_length_object_identifier(c_ulong *words, c_ulong nwords, c_ulong *outlen);
559     c_ulong der_object_identifier_bits(c_ulong x);
560     
561     /* IA5 STRING */
562     int der_encode_ia5_string(const ubyte* _in, c_ulong inlen,
563                                     ubyte* _out, c_ulong *outlen);
564     int der_decode_ia5_string(const ubyte* _in, c_ulong inlen,
565                                     ubyte* _out, c_ulong *outlen);
566     int der_length_ia5_string(const ubyte* octets, c_ulong noctets, c_ulong *outlen);
567     
568     int der_ia5_char_encode(int c);
569     int der_ia5_value_decode(int v);
570     
571     /* Printable STRING */
572     int der_encode_printable_string(const ubyte* _in, c_ulong inlen,
573                                     ubyte* _out, c_ulong *outlen);
574     int der_decode_printable_string(const ubyte* _in, c_ulong inlen,
575                                     ubyte* _out, c_ulong *outlen);
576     int der_length_printable_string(const ubyte* octets, c_ulong noctets, c_ulong *outlen);
577     
578     int der_printable_char_encode(int c);
579     int der_printable_value_decode(int v);
580     
581     /* UTF-8 */
582     
583     int der_encode_utf8_string(const wchar_t *_in,  c_ulong inlen,
584                                ubyte* _out, c_ulong *outlen);
585     
586     int der_decode_utf8_string(const ubyte* _in,  c_ulong inlen,
587                                            wchar_t *_out, c_ulong *outlen);
588     c_ulong der_utf8_charsize(const wchar_t c);
589     int der_length_utf8_string(const wchar_t *_in, c_ulong noctets, c_ulong *outlen);
590     
591     
592     /* CHOICE */
593     int der_decode_choice(const ubyte* _in,   c_ulong *inlen,
594                                 ltc_asn1_list *list, c_ulong  outlen);
595     
596     /* UTCTime */
597     struct ltc_utctime 
598     {
599        uint     YY, /* year */
600                 MM, /* month */
601                 DD, /* day */
602                 hh, /* hour */
603                 mm, /* minute */
604                 ss, /* second */
605                 off_dir, /* timezone offset direction 0 == +, 1 == - */
606                 off_hh, /* timezone offset hours */
607                 off_mm; /* timezone offset minutes */
608     }
609     
610     int der_encode_utctime(ltc_utctime *utctime, 
611                            ubyte* _out,   c_ulong *outlen);
612     
613     int der_decode_utctime(const ubyte* _in, c_ulong *inlen,
614                                  ltc_utctime   *_out);
615     
616     int der_length_utctime(ltc_utctime *utctime, c_ulong *outlen);
617 }
618 
619 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */
620 /* $Revision: 1.81 $ */
621 /* $Date: 2007/05/12 14:32:35 $ */