1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
10 /* ---- NUMBER THEORY ---- */
17 /* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
20 int rand_prime(void *N, long len, prng_state *prng, int wprng);
23 /* internal helper functions */
24 int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng);
25 int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
27 enum public_key_algorithms {
33 unsigned long OID[16];
34 /** Number of OID digits in use */
38 int pk_get_oid(int pk, oid_st *st);
39 #endif /* LTC_SOURCE */
44 /** RSA PKCS style key */
45 typedef struct Rsa_key {
46 /** Type of key, PK_PRIVATE or PK_PUBLIC */
48 /** The public exponent */
50 /** The private exponent */
54 /** The p factor of N */
56 /** The q factor of N */
58 /** The 1/q mod p CRT param */
60 /** The d mod (p - 1) CRT param */
62 /** The d mod (q - 1) CRT param */
66 int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
68 int rsa_get_size(rsa_key *key);
70 int rsa_exptmod(const unsigned char *in, unsigned long inlen,
71 unsigned char *out, unsigned long *outlen, int which,
74 void rsa_free(rsa_key *key);
76 /* These use PKCS #1 v2.0 padding */
77 #define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, _key) \
78 rsa_encrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, LTC_PKCS_1_OAEP, _key)
80 #define rsa_decrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, _stat, _key) \
81 rsa_decrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, LTC_PKCS_1_OAEP, _stat, _key)
83 #define rsa_sign_hash(_in, _inlen, _out, _outlen, _prng, _prng_idx, _hash_idx, _saltlen, _key) \
84 rsa_sign_hash_ex(_in, _inlen, _out, _outlen, LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _key)
86 #define rsa_verify_hash(_sig, _siglen, _hash, _hashlen, _hash_idx, _saltlen, _stat, _key) \
87 rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key)
89 #define rsa_sign_saltlen_get_max(_hash_idx, _key) \
90 rsa_sign_saltlen_get_max_ex(LTC_PKCS_1_PSS, _hash_idx, _key)
92 /* These can be switched between PKCS #1 v2.x and PKCS #1 v1.5 paddings */
93 int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
94 unsigned char *out, unsigned long *outlen,
95 const unsigned char *lparam, unsigned long lparamlen,
96 prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key);
98 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
99 unsigned char *out, unsigned long *outlen,
100 const unsigned char *lparam, unsigned long lparamlen,
101 int hash_idx, int padding,
102 int *stat, rsa_key *key);
104 int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen,
105 unsigned char *out, unsigned long *outlen,
107 prng_state *prng, int prng_idx,
108 int hash_idx, unsigned long saltlen,
111 int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
112 const unsigned char *hash, unsigned long hashlen,
114 int hash_idx, unsigned long saltlen,
115 int *stat, rsa_key *key);
117 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, rsa_key *key);
119 /* PKCS #1 import/export */
120 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
121 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
123 int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key);
124 int rsa_import_pkcs8(const unsigned char *in, unsigned long inlen,
125 const void *passwd, unsigned long passwdlen, rsa_key *key);
127 int rsa_set_key(const unsigned char *N, unsigned long Nlen,
128 const unsigned char *e, unsigned long elen,
129 const unsigned char *d, unsigned long dlen,
131 int rsa_set_factors(const unsigned char *p, unsigned long plen,
132 const unsigned char *q, unsigned long qlen,
134 int rsa_set_crt_params(const unsigned char *dP, unsigned long dPlen,
135 const unsigned char *dQ, unsigned long dQlen,
136 const unsigned char *qP, unsigned long qPlen,
140 /* ---- Katja ---- */
143 /* Min and Max KAT key sizes (in bits) */
144 #define MIN_KAT_SIZE 1024
145 #define MAX_KAT_SIZE 4096
147 /** Katja PKCS style key */
148 typedef struct KAT_key {
149 /** Type of key, PK_PRIVATE or PK_PUBLIC */
151 /** The private exponent */
155 /** The p factor of N */
157 /** The q factor of N */
159 /** The 1/q mod p CRT param */
161 /** The d mod (p - 1) CRT param */
163 /** The d mod (q - 1) CRT param */
169 int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key);
171 int katja_exptmod(const unsigned char *in, unsigned long inlen,
172 unsigned char *out, unsigned long *outlen, int which,
175 void katja_free(katja_key *key);
177 /* These use PKCS #1 v2.0 padding */
178 int katja_encrypt_key(const unsigned char *in, unsigned long inlen,
179 unsigned char *out, unsigned long *outlen,
180 const unsigned char *lparam, unsigned long lparamlen,
181 prng_state *prng, int prng_idx, int hash_idx, katja_key *key);
183 int katja_decrypt_key(const unsigned char *in, unsigned long inlen,
184 unsigned char *out, unsigned long *outlen,
185 const unsigned char *lparam, unsigned long lparamlen,
186 int hash_idx, int *stat,
189 /* PKCS #1 import/export */
190 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key);
191 int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key);
195 /* ---- DH Routines ---- */
206 int dh_get_groupsize(dh_key *key);
208 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
209 int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
211 int dh_set_pg(const unsigned char *p, unsigned long plen,
212 const unsigned char *g, unsigned long glen,
214 int dh_set_pg_dhparam(const unsigned char *dhparam, unsigned long dhparamlen, dh_key *key);
215 int dh_set_pg_groupsize(int groupsize, dh_key *key);
217 int dh_set_key(const unsigned char *in, unsigned long inlen, int type, dh_key *key);
218 int dh_generate_key(prng_state *prng, int wprng, dh_key *key);
220 int dh_shared_secret(dh_key *private_key, dh_key *public_key,
221 unsigned char *out, unsigned long *outlen);
223 void dh_free(dh_key *key);
225 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key);
230 const char *name, *base, *prime;
233 extern const ltc_dh_set_type ltc_dh_sets[];
235 /* internal helper functions */
236 int dh_check_pubkey(dh_key *key);
242 /* ---- ECC Routines ---- */
245 /* size of our temp buffers for exported keys */
246 #define ECC_BUF_SIZE 256
248 /* max private key size */
249 #define ECC_MAXSIZE 66
251 /** Structure defines a NIST GF(p) curve */
253 /** The size of the curve in octets */
259 /** The prime that defines the field the curve is in (encoded in hex) */
262 /** The fields B param (hex) */
265 /** The order of the curve (hex) */
268 /** The x co-ordinate of the base point on the curve (hex) */
271 /** The y co-ordinate of the base point on the curve (hex) */
275 /** 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 */
277 /** The x co-ordinate */
280 /** The y co-ordinate */
283 /** The z co-ordinate */
289 /** Type of key, PK_PRIVATE or PK_PUBLIC */
292 /** Index into the ltc_ecc_sets[] for the parameters of this curve; if -1, then this key is using user supplied curve in dp */
295 /** pointer to domain parameters; either points to NIST curves (identified by idx >= 0) or user supplied curve */
296 const ltc_ecc_set_type *dp;
298 /** The public key */
301 /** The private key */
305 /** the ECC params provided */
306 extern const ltc_ecc_set_type ltc_ecc_sets[];
309 void ecc_sizes(int *low, int *high);
310 int ecc_get_size(ecc_key *key);
312 int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
313 int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_set_type *dp);
314 void ecc_free(ecc_key *key);
316 int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
317 int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
318 int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_set_type *dp);
320 int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen);
321 int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
322 int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, ltc_ecc_set_type *dp);
324 int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
325 unsigned char *out, unsigned long *outlen);
327 int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
328 unsigned char *out, unsigned long *outlen,
329 prng_state *prng, int wprng, int hash,
332 int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
333 unsigned char *out, unsigned long *outlen,
336 int ecc_sign_hash_rfc7518(const unsigned char *in, unsigned long inlen,
337 unsigned char *out, unsigned long *outlen,
338 prng_state *prng, int wprng, ecc_key *key);
340 int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
341 unsigned char *out, unsigned long *outlen,
342 prng_state *prng, int wprng, ecc_key *key);
344 int ecc_verify_hash_rfc7518(const unsigned char *sig, unsigned long siglen,
345 const unsigned char *hash, unsigned long hashlen,
346 int *stat, ecc_key *key);
348 int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
349 const unsigned char *hash, unsigned long hashlen,
350 int *stat, ecc_key *key);
352 /* low level functions */
353 ecc_point *ltc_ecc_new_point(void);
354 void ltc_ecc_del_point(ecc_point *p);
355 int ltc_ecc_is_valid_idx(int n);
357 /* point ops (mp == montgomery digit) */
358 #if !defined(LTC_MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC)
360 int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp);
363 int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
366 #if defined(LTC_MECC_FP)
367 /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */
368 int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
370 /* functions for saving/loading/freeing/adding to fixed point cache */
371 int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen);
372 int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen);
373 void ltc_ecc_fp_free(void);
374 int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock);
376 /* lock/unlock all points currently in fixed point cache */
377 void ltc_ecc_fp_tablelock(int lock);
381 int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
383 #ifdef LTC_ECC_SHAMIR
384 /* kA*A + kB*B = C */
385 int ltc_ecc_mul2add(ecc_point *A, void *kA,
386 ecc_point *B, void *kB,
391 /* Shamir's trick with optimized point multiplication using fixed point cache */
392 int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
393 ecc_point *B, void *kB,
394 ecc_point *C, void *modulus);
400 /* map P to affine from projective */
401 int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
407 /* Max diff between group and modulus size in bytes */
408 #define LTC_MDSA_DELTA 512
410 /* Max DSA group size in bytes (default allows 4k-bit groups) */
411 #define LTC_MDSA_MAX_GROUP 512
413 /** DSA key structure */
415 /** The key type, PK_PRIVATE or PK_PUBLIC */
418 /** The order of the sub-group used in octets */
424 /** The prime used to generate the sub-group */
427 /** The large prime that generats the field the contains the sub-group */
430 /** The private key */
433 /** The public key */
437 int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
439 int dsa_set_pqg(const unsigned char *p, unsigned long plen,
440 const unsigned char *q, unsigned long qlen,
441 const unsigned char *g, unsigned long glen,
443 int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamlen, dsa_key *key);
444 int dsa_generate_pqg(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
446 int dsa_set_key(const unsigned char *in, unsigned long inlen, int type, dsa_key *key);
447 int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key);
449 void dsa_free(dsa_key *key);
451 int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
453 prng_state *prng, int wprng, dsa_key *key);
455 int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
456 unsigned char *out, unsigned long *outlen,
457 prng_state *prng, int wprng, dsa_key *key);
459 int dsa_verify_hash_raw( void *r, void *s,
460 const unsigned char *hash, unsigned long hashlen,
461 int *stat, dsa_key *key);
463 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
464 const unsigned char *hash, unsigned long hashlen,
465 int *stat, dsa_key *key);
467 int dsa_encrypt_key(const unsigned char *in, unsigned long inlen,
468 unsigned char *out, unsigned long *outlen,
469 prng_state *prng, int wprng, int hash,
472 int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
473 unsigned char *out, unsigned long *outlen,
476 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
477 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
478 int dsa_verify_key(dsa_key *key, int *stat);
480 /* internal helper functions */
481 int dsa_int_validate_xy(dsa_key *key, int *stat);
482 int dsa_int_validate_pqg(dsa_key *key, int *stat);
483 int dsa_int_validate_primes(dsa_key *key, int *stat);
485 int dsa_shared_secret(void *private_key, void *base,
487 unsigned char *out, unsigned long *outlen);
493 typedef enum ltc_asn1_type_ {
498 LTC_ASN1_SHORT_INTEGER,
501 LTC_ASN1_OCTET_STRING,
503 LTC_ASN1_OBJECT_IDENTIFIER,
505 LTC_ASN1_PRINTABLE_STRING,
507 LTC_ASN1_UTF8_STRING,
514 LTC_ASN1_RAW_BIT_STRING,
515 LTC_ASN1_TELETEX_STRING,
516 LTC_ASN1_CONSTRUCTED,
517 LTC_ASN1_CONTEXT_SPECIFIC,
519 LTC_ASN1_GENERALIZEDTIME,
522 /** A LTC ASN.1 list type */
523 typedef struct ltc_asn1_list_ {
524 /** The LTC ASN.1 enumerated type identifier */
526 /** The data to encode or place for decoding */
528 /** The size of the input or resulting output */
530 /** The used flag, this is used by the CHOICE ASN.1 type to indicate which choice was made */
532 /** prev/next entry in the list */
533 struct ltc_asn1_list_ *prev, *next, *child, *parent;
536 #define LTC_SET_ASN1(list, index, Type, Data, Size) \
538 int LTC_MACRO_temp = (index); \
539 ltc_asn1_list *LTC_MACRO_list = (list); \
540 LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
541 LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \
542 LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
543 LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
547 int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
548 unsigned char *out, unsigned long *outlen, int type_of);
550 #define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)
552 int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
553 ltc_asn1_list *list, unsigned long outlen, int ordered);
555 #define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 1)
557 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
558 unsigned long *outlen);
562 /* internal helper functions */
563 int der_length_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
564 unsigned long *outlen, unsigned long *payloadlen);
565 /* SUBJECT PUBLIC KEY INFO */
566 int der_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen,
567 unsigned int algorithm, void* public_key, unsigned long public_key_len,
568 unsigned long parameters_type, void* parameters, unsigned long parameters_len);
570 int der_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen,
571 unsigned int algorithm, void* public_key, unsigned long* public_key_len,
572 unsigned long parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len);
573 #endif /* LTC_SOURCE */
576 #define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 0)
577 #define der_length_set der_length_sequence
578 int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
579 unsigned char *out, unsigned long *outlen);
581 int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
582 unsigned char *out, unsigned long *outlen);
584 /* VA list handy helpers with triplets of <type, size, data> */
585 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
586 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
588 /* FLEXI DECODER handle unknown list decoder */
589 int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out);
590 #define der_free_sequence_flexi der_sequence_free
591 void der_sequence_free(ltc_asn1_list *in);
592 void der_sequence_shrink(ltc_asn1_list *in);
595 int der_length_boolean(unsigned long *outlen);
596 int der_encode_boolean(int in,
597 unsigned char *out, unsigned long *outlen);
598 int der_decode_boolean(const unsigned char *in, unsigned long inlen,
601 int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen);
602 int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num);
603 int der_length_integer(void *num, unsigned long *len);
605 /* INTEGER -- handy for 0..2^32-1 values */
606 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
607 int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen);
608 int der_length_short_integer(unsigned long num, unsigned long *outlen);
611 int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
612 unsigned char *out, unsigned long *outlen);
613 int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
614 unsigned char *out, unsigned long *outlen);
615 int der_encode_raw_bit_string(const unsigned char *in, unsigned long inlen,
616 unsigned char *out, unsigned long *outlen);
617 int der_decode_raw_bit_string(const unsigned char *in, unsigned long inlen,
618 unsigned char *out, unsigned long *outlen);
619 int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
622 int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
623 unsigned char *out, unsigned long *outlen);
624 int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
625 unsigned char *out, unsigned long *outlen);
626 int der_length_octet_string(unsigned long noctets, unsigned long *outlen);
628 /* OBJECT IDENTIFIER */
629 int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
630 unsigned char *out, unsigned long *outlen);
631 int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
632 unsigned long *words, unsigned long *outlen);
633 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen);
634 unsigned long der_object_identifier_bits(unsigned long x);
637 int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
638 unsigned char *out, unsigned long *outlen);
639 int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
640 unsigned char *out, unsigned long *outlen);
641 int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
643 int der_ia5_char_encode(int c);
644 int der_ia5_value_decode(int v);
647 int der_decode_teletex_string(const unsigned char *in, unsigned long inlen,
648 unsigned char *out, unsigned long *outlen);
649 int der_length_teletex_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
652 /* internal helper functions */
653 int der_teletex_char_encode(int c);
654 int der_teletex_value_decode(int v);
655 #endif /* LTC_SOURCE */
658 /* PRINTABLE STRING */
659 int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
660 unsigned char *out, unsigned long *outlen);
661 int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
662 unsigned char *out, unsigned long *outlen);
663 int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
665 int der_printable_char_encode(int c);
666 int der_printable_value_decode(int v);
669 #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(__WCHAR_MAX__) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR)
670 #if defined(__WCHAR_MAX__)
671 #define LTC_WCHAR_MAX __WCHAR_MAX__
674 #define LTC_WCHAR_MAX WCHAR_MAX
676 /* please note that it might happen that LTC_WCHAR_MAX is undefined */
678 typedef ulong32 wchar_t;
679 #define LTC_WCHAR_MAX 0xFFFFFFFF
682 int der_encode_utf8_string(const wchar_t *in, unsigned long inlen,
683 unsigned char *out, unsigned long *outlen);
685 int der_decode_utf8_string(const unsigned char *in, unsigned long inlen,
686 wchar_t *out, unsigned long *outlen);
687 unsigned long der_utf8_charsize(const wchar_t c);
689 /* internal helper functions */
690 int der_utf8_valid_char(const wchar_t c);
691 #endif /* LTC_SOURCE */
692 int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen);
696 int der_decode_choice(const unsigned char *in, unsigned long *inlen,
697 ltc_asn1_list *list, unsigned long outlen);
701 unsigned YY, /* year */
707 off_dir, /* timezone offset direction 0 == +, 1 == - */
708 off_hh, /* timezone offset hours */
709 off_mm; /* timezone offset minutes */
712 int der_encode_utctime(ltc_utctime *utctime,
713 unsigned char *out, unsigned long *outlen);
715 int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
718 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
720 /* GeneralizedTime */
722 unsigned YYYY, /* year */
728 fs, /* fractional seconds */
729 off_dir, /* timezone offset direction 0 == +, 1 == - */
730 off_hh, /* timezone offset hours */
731 off_mm; /* timezone offset minutes */
732 } ltc_generalizedtime;
734 int der_encode_generalizedtime(ltc_generalizedtime *gtime,
735 unsigned char *out, unsigned long *outlen);
737 int der_decode_generalizedtime(const unsigned char *in, unsigned long *inlen,
738 ltc_generalizedtime *out);
740 int der_length_generalizedtime(ltc_generalizedtime *gtime, unsigned long *outlen);
745 /* ref: $Format:%D$ */
746 /* git commit: $Format:%H$ */
747 /* commit time: $Format:%ai$ */