annotate src/headers/tomcrypt_pk.h @ 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 1c15b283127b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /* ---- NUMBER THEORY ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #ifdef MPI
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "ltc_tommath.h"
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 /* in/out macros */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 #define OUTPUT_BIGNUM(num, out, y, z) \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 { \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 z = (unsigned long)mp_unsigned_bin_size(num); \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 STORE32L(z, out+y); \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 y += 4; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 if ((y + z) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 if ((err = mp_to_unsigned_bin(num, out+y)) != MP_OKAY) { return mpi_to_ltc_error(err); } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 y += z; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 #define INPUT_BIGNUM(num, in, x, y, inlen) \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 { \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 /* load value */ \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 if ((y + 4) > inlen) { \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 err = CRYPT_INVALID_PACKET; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 goto error; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 LOAD32L(x, in+y); \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 y += 4; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 /* sanity check... */ \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 if ((x+y) > inlen) { \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 err = CRYPT_INVALID_PACKET; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 goto error; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 /* load it */ \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 if ((err = mp_read_unsigned_bin(num, (unsigned char *)in+y, (int)x)) != MP_OKAY) {\
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 err = mpi_to_ltc_error(err); \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 goto error; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 y += x; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 if ((err = mp_shrink(num)) != MP_OKAY) { \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 err = mpi_to_ltc_error(err); \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 goto error; \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 } \
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 }
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 int is_prime(mp_int *, int *);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 int rand_prime(mp_int *N, long len, prng_state *prng, int wprng);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 #else
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 #ifdef MRSA
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 #error RSA requires the big int library
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 #ifdef MECC
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #error ECC requires the big int library
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #ifdef MDH
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 #error DH requires the big int library
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 #ifdef MDSA
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 #error DSA requires the big int library
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 #endif /* MPI */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 /* ---- PUBLIC KEY CRYPTO ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 #define PK_PRIVATE 0 /* PK private keys */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 #define PK_PUBLIC 1 /* PK public keys */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 /* ---- PACKET ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 #ifdef PACKET
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 void packet_store_header(unsigned char *dst, int section, int subsection);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 int packet_valid_header(unsigned char *src, int section, int subsection);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 /* ---- RSA ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 #ifdef MRSA
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 /* Min and Max RSA key sizes (in bits) */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 #define MIN_RSA_SIZE 1024
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 #define MAX_RSA_SIZE 4096
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 typedef struct Rsa_key {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 int type;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 mp_int e, d, N, p, q, qP, dP, dQ;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 } rsa_key;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 int rsa_exptmod(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 unsigned char *out, unsigned long *outlen, int which,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 void rsa_free(rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 /* These use PKCS #1 v2.0 padding */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 int rsa_encrypt_key(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 const unsigned char *lparam, unsigned long lparamlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 prng_state *prng, int prng_idx, int hash_idx, rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 int rsa_decrypt_key(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 const unsigned char *lparam, unsigned long lparamlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 int hash_idx, int *stat,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 int rsa_sign_hash(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 prng_state *prng, int prng_idx,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 int hash_idx, unsigned long saltlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 int rsa_verify_hash(const unsigned char *sig, unsigned long siglen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 const unsigned char *hash, unsigned long hashlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 int hash_idx, unsigned long saltlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 int *stat, rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 /* PKCS #1 import/export */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 /* ---- DH Routines ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 #ifdef MDH
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 typedef struct Dh_key {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 int idx, type;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 mp_int x, y;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 } dh_key;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 int dh_test(void);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 void dh_sizes(int *low, int *high);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 int dh_get_size(dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 void dh_free(dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 int dh_shared_secret(dh_key *private_key, dh_key *public_key,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 unsigned char *out, unsigned long *outlen);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 int dh_encrypt_key(const unsigned char *in, unsigned long keylen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 prng_state *prng, int wprng, int hash,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 int dh_sign_hash(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 prng_state *prng, int wprng, dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 const unsigned char *hash, unsigned long hashlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 int *stat, dh_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 /* ---- ECC Routines ---- */
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 #ifdef MECC
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 typedef struct {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 mp_int x, y, z;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 } ecc_point;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 typedef struct {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 int type, idx;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 ecc_point pubkey;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 mp_int k;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 } ecc_key;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 int ecc_test(void);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 void ecc_sizes(int *low, int *high);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 int ecc_get_size(ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 void ecc_free(ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 unsigned char *out, unsigned long *outlen);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 prng_state *prng, int wprng, int hash,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 prng_state *prng, int wprng, ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 const unsigned char *hash, unsigned long hashlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 int *stat, ecc_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 #ifdef MDSA
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 typedef struct {
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 int type, qord;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 mp_int g, q, p, x, y;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 } dsa_key;
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 void dsa_free(dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
224
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
225 int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
226 mp_int *r, mp_int *s,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
227 prng_state *prng, int wprng, dsa_key *key);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
228
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 unsigned char *out, unsigned long *outlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 prng_state *prng, int wprng, dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
233 int dsa_verify_hash_raw( mp_int *r, mp_int *s,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
234 const unsigned char *hash, unsigned long hashlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
235 int *stat, dsa_key *key);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
236
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 const unsigned char *hash, unsigned long hashlen,
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 int *stat, dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 int dsa_verify_key(dsa_key *key, int *stat);
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 #endif
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 #ifdef LTC_DER
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 /* DER handling */
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
251
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
252 enum {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
253 LTC_ASN1_EOL,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
254 LTC_ASN1_INTEGER,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
255 LTC_ASN1_SHORT_INTEGER,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
256 LTC_ASN1_BIT_STRING,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
257 LTC_ASN1_OCTET_STRING,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
258 LTC_ASN1_NULL,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
259 LTC_ASN1_OBJECT_IDENTIFIER,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
260 LTC_ASN1_IA5_STRING,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
261 LTC_ASN1_PRINTABLE_STRING,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
262 LTC_ASN1_UTCTIME,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
263
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
264 LTC_ASN1_CHOICE,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
265 LTC_ASN1_SEQUENCE
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
266 };
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
267
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
268 typedef struct {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
269 int type;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
270 void *data;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
271 unsigned long size;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
272 int used;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
273 } ltc_asn1_list;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
274
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
275 #define LTC_SET_ASN1(list, index, Type, Data, Size) \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
276 do { \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
277 int LTC_MACRO_temp = (index); \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
278 ltc_asn1_list *LTC_MACRO_list = (list); \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
279 LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
280 LTC_MACRO_list[LTC_MACRO_temp].data = (Data); \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
281 LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
282 LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
283 } while (0);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
284
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
285 /* SEQUENCE */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
286 int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
287 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
288
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
289 int der_decode_sequence(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
290 ltc_asn1_list *list, unsigned long outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
291
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
292 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
293 unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
294
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
295 /* VA list handy helpers */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
296 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
297 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
298
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
299 /* INTEGER */
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen);
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
301 int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num);
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 int der_length_integer(mp_int *num, unsigned long *len);
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
303
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
304 /* INTEGER -- handy for 0..2^32-1 values */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
305 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
306 int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
307 int der_length_short_integer(unsigned long num, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
308
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
309 /* BIT STRING */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
310 int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
311 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
312 int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
313 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
314 int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
315
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
316 /* OCTET STRING */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
317 int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
318 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
319 int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
320 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
321 int der_length_octet_string(unsigned long noctets, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
322
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
323 /* OBJECT IDENTIFIER */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
324 int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
325 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
326 int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
327 unsigned long *words, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
328 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
329 unsigned long der_object_identifier_bits(unsigned long x);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
330
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
331 /* IA5 STRING */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
332 int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
333 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
334 int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
335 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
336 int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
337
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
338 int der_ia5_char_encode(int c);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
339 int der_ia5_value_decode(int v);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
340
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
341 /* Printable STRING */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
342 int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
343 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
344 int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
345 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
346 int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
347
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
348 int der_printable_char_encode(int c);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
349 int der_printable_value_decode(int v);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
350
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
351 /* CHOICE */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
352 int der_decode_choice(const unsigned char *in, unsigned long *inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
353 ltc_asn1_list *list, unsigned long outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
354
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
355 /* UTCTime */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
356 typedef struct {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
357 unsigned YY, /* year */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
358 MM, /* month */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
359 DD, /* day */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
360 hh, /* hour */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
361 mm, /* minute */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
362 ss, /* second */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
363 off_dir, /* timezone offset direction 0 == +, 1 == - */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
364 off_hh, /* timezone offset hours */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
365 off_mm; /* timezone offset minutes */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
366 } ltc_utctime;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
367
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
368 int der_encode_utctime(ltc_utctime *utctime,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
369 unsigned char *out, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
370
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
371 int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
372 ltc_utctime *out);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
373
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
374 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
375
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
376
191
1c15b283127b Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 #endif
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
378
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
379 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
380 /* $Revision: 1.30 $ */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents: 191
diff changeset
381 /* $Date: 2005/06/19 11:23:03 $ */