comparison src/headers/tomcrypt_pk.h @ 210:4768b55c5240 libtomcrypt

propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 33c416b902f1a44913d825bae7ad9a160f703ed3) to branch 'au.asn.ucc.matt.dropbear.ltc' (head 4d6aec6e6121e13f68c11c149b6579c41cb63e74)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 12:10:23 +0000
parents 39d5d58461d6
children
comparison
equal deleted inserted replaced
199:8be64e2c86f4 210:4768b55c5240
82 82
83 /* Min and Max RSA key sizes (in bits) */ 83 /* Min and Max RSA key sizes (in bits) */
84 #define MIN_RSA_SIZE 1024 84 #define MIN_RSA_SIZE 1024
85 #define MAX_RSA_SIZE 4096 85 #define MAX_RSA_SIZE 4096
86 86
87 /* Stack required for temps (plus padding) */
88 // #define RSA_STACK (8 + (MAX_RSA_SIZE/8))
89
90 typedef struct Rsa_key { 87 typedef struct Rsa_key {
91 int type; 88 int type;
92 mp_int e, d, N, p, q, qP, dP, dQ; 89 mp_int e, d, N, p, q, qP, dP, dQ;
93 } rsa_key; 90 } rsa_key;
94 91
121 int rsa_verify_hash(const unsigned char *sig, unsigned long siglen, 118 int rsa_verify_hash(const unsigned char *sig, unsigned long siglen,
122 const unsigned char *hash, unsigned long hashlen, 119 const unsigned char *hash, unsigned long hashlen,
123 int hash_idx, unsigned long saltlen, 120 int hash_idx, unsigned long saltlen,
124 int *stat, rsa_key *key); 121 int *stat, rsa_key *key);
125 122
126 /* these use PKCS #1 v1.5 padding */
127 int rsa_v15_encrypt_key(const unsigned char *in, unsigned long inlen,
128 unsigned char *out, unsigned long *outlen,
129 prng_state *prng, int prng_idx,
130 rsa_key *key);
131
132 int rsa_v15_decrypt_key(const unsigned char *in, unsigned long inlen,
133 unsigned char *out, unsigned long outlen,
134 int *stat, rsa_key *key);
135
136 int rsa_v15_sign_hash(const unsigned char *in, unsigned long inlen,
137 unsigned char *out, unsigned long *siglen,
138 int hash_idx, rsa_key *key);
139
140 int rsa_v15_verify_hash(const unsigned char *sig, unsigned long siglen,
141 const unsigned char *hash, unsigned long hashlen,
142 int hash_idx, int *stat,
143 rsa_key *key);
144
145
146 /* PKCS #1 import/export */ 123 /* PKCS #1 import/export */
147 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); 124 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
148 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); 125 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
149 126
150 #endif 127 #endif
242 } dsa_key; 219 } dsa_key;
243 220
244 int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key); 221 int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
245 void dsa_free(dsa_key *key); 222 void dsa_free(dsa_key *key);
246 223
224
225 int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
226 mp_int *r, mp_int *s,
227 prng_state *prng, int wprng, dsa_key *key);
228
247 int dsa_sign_hash(const unsigned char *in, unsigned long inlen, 229 int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
248 unsigned char *out, unsigned long *outlen, 230 unsigned char *out, unsigned long *outlen,
249 prng_state *prng, int wprng, dsa_key *key); 231 prng_state *prng, int wprng, dsa_key *key);
250 232
233 int dsa_verify_hash_raw( mp_int *r, mp_int *s,
234 const unsigned char *hash, unsigned long hashlen,
235 int *stat, dsa_key *key);
236
251 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, 237 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
252 const unsigned char *hash, unsigned long hashlen, 238 const unsigned char *hash, unsigned long hashlen,
253 int *stat, dsa_key *key); 239 int *stat, dsa_key *key);
254 240
255 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key); 241 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
260 246
261 #endif 247 #endif
262 248
263 #ifdef LTC_DER 249 #ifdef LTC_DER
264 /* DER handling */ 250 /* DER handling */
251
252 enum {
253 LTC_ASN1_EOL,
254 LTC_ASN1_INTEGER,
255 LTC_ASN1_SHORT_INTEGER,
256 LTC_ASN1_BIT_STRING,
257 LTC_ASN1_OCTET_STRING,
258 LTC_ASN1_NULL,
259 LTC_ASN1_OBJECT_IDENTIFIER,
260 LTC_ASN1_IA5_STRING,
261 LTC_ASN1_PRINTABLE_STRING,
262 LTC_ASN1_UTCTIME,
263
264 LTC_ASN1_CHOICE,
265 LTC_ASN1_SEQUENCE
266 };
267
268 typedef struct {
269 int type;
270 void *data;
271 unsigned long size;
272 int used;
273 } ltc_asn1_list;
274
275 #define LTC_SET_ASN1(list, index, Type, Data, Size) \
276 do { \
277 int LTC_MACRO_temp = (index); \
278 ltc_asn1_list *LTC_MACRO_list = (list); \
279 LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
280 LTC_MACRO_list[LTC_MACRO_temp].data = (Data); \
281 LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
282 LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
283 } while (0);
284
285 /* SEQUENCE */
286 int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
287 unsigned char *out, unsigned long *outlen);
288
289 int der_decode_sequence(const unsigned char *in, unsigned long inlen,
290 ltc_asn1_list *list, unsigned long outlen);
291
292 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
293 unsigned long *outlen);
294
295 /* VA list handy helpers */
296 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
297 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
298
299 /* INTEGER */
265 int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen); 300 int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen);
266 int der_decode_integer(const unsigned char *in, unsigned long *inlen, mp_int *num); 301 int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num);
267 int der_length_integer(mp_int *num, unsigned long *len); 302 int der_length_integer(mp_int *num, unsigned long *len);
268 int der_put_multi_integer(unsigned char *dst, unsigned long *outlen, mp_int *num, ...); 303
269 int der_get_multi_integer(const unsigned char *src, unsigned long *inlen, mp_int *num, ...); 304 /* INTEGER -- handy for 0..2^32-1 values */
270 #endif 305 int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
306 int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen);
307 int der_length_short_integer(unsigned long num, unsigned long *outlen);
308
309 /* BIT STRING */
310 int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
311 unsigned char *out, unsigned long *outlen);
312 int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
313 unsigned char *out, unsigned long *outlen);
314 int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
315
316 /* OCTET STRING */
317 int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
318 unsigned char *out, unsigned long *outlen);
319 int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
320 unsigned char *out, unsigned long *outlen);
321 int der_length_octet_string(unsigned long noctets, unsigned long *outlen);
322
323 /* OBJECT IDENTIFIER */
324 int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
325 unsigned char *out, unsigned long *outlen);
326 int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
327 unsigned long *words, unsigned long *outlen);
328 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen);
329 unsigned long der_object_identifier_bits(unsigned long x);
330
331 /* IA5 STRING */
332 int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
333 unsigned char *out, unsigned long *outlen);
334 int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
335 unsigned char *out, unsigned long *outlen);
336 int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
337
338 int der_ia5_char_encode(int c);
339 int der_ia5_value_decode(int v);
340
341 /* Printable STRING */
342 int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
343 unsigned char *out, unsigned long *outlen);
344 int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
345 unsigned char *out, unsigned long *outlen);
346 int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen);
347
348 int der_printable_char_encode(int c);
349 int der_printable_value_decode(int v);
350
351 /* CHOICE */
352 int der_decode_choice(const unsigned char *in, unsigned long *inlen,
353 ltc_asn1_list *list, unsigned long outlen);
354
355 /* UTCTime */
356 typedef struct {
357 unsigned YY, /* year */
358 MM, /* month */
359 DD, /* day */
360 hh, /* hour */
361 mm, /* minute */
362 ss, /* second */
363 off_dir, /* timezone offset direction 0 == +, 1 == - */
364 off_hh, /* timezone offset hours */
365 off_mm; /* timezone offset minutes */
366 } ltc_utctime;
367
368 int der_encode_utctime(ltc_utctime *utctime,
369 unsigned char *out, unsigned long *outlen);
370
371 int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
372 ltc_utctime *out);
373
374 int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
375
376
377 #endif
378
379 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */
380 /* $Revision: 1.30 $ */
381 /* $Date: 2005/06/19 11:23:03 $ */