3
|
1 #ifdef KR |
|
2 |
|
3 #if !defined(MRSA) || !defined(MDH) || !defined(MECC) |
|
4 #error "Keyring code requires all three public key algorithms." |
|
5 #endif |
|
6 |
|
7 #define MAXLEN 256 |
|
8 |
|
9 enum { |
|
10 NON_KEY=0, |
|
11 RSA_KEY, |
|
12 DH_KEY, |
|
13 ECC_KEY |
|
14 }; |
|
15 |
|
16 typedef union { |
|
17 rsa_key rsa; |
|
18 dh_key dh; |
|
19 ecc_key ecc; |
|
20 } _pk_key; |
|
21 |
|
22 typedef struct Pk_key { |
|
23 int key_type, /* PUBLIC, PRIVATE, PRIVATE_OPTIMIZED */ |
|
24 system; /* RSA, ECC or DH ? */ |
|
25 |
|
26 unsigned char |
|
27 name[MAXLEN], /* various info's about this key */ |
|
28 email[MAXLEN], |
|
29 description[MAXLEN]; |
|
30 |
|
31 unsigned long ID; /* CRC32 of the name/email/description together */ |
|
32 |
|
33 _pk_key key; |
|
34 |
|
35 struct Pk_key *next; /* linked list chain */ |
|
36 } pk_key; |
|
37 |
|
38 extern int kr_init(pk_key **pk); |
|
39 |
|
40 extern unsigned long kr_crc(const unsigned char *name, const unsigned char *email, const unsigned char *description); |
|
41 |
|
42 extern pk_key *kr_find(pk_key *pk, unsigned long ID); |
|
43 extern pk_key *kr_find_name(pk_key *pk, const char *name); |
|
44 |
|
45 extern int kr_add(pk_key *pk, int key_type, int sys, const unsigned char *name, |
|
46 const unsigned char *email, const unsigned char *description, const _pk_key *key); |
|
47 |
|
48 extern int kr_del(pk_key **_pk, unsigned long ID); |
|
49 extern int kr_clear(pk_key **pk); |
|
50 extern int kr_make_key(pk_key *pk, prng_state *prng, int wprng, |
|
51 int sys, int keysize, const unsigned char *name, |
|
52 const unsigned char *email, const unsigned char *description); |
|
53 |
|
54 extern int kr_export(pk_key *pk, unsigned long ID, int key_type, unsigned char *out, unsigned long *outlen); |
|
55 extern int kr_import(pk_key *pk, const unsigned char *in, unsigned long inlen); |
|
56 |
|
57 extern int kr_load(pk_key **pk, FILE *in, symmetric_CTR *ctr); |
|
58 extern int kr_save(pk_key *pk, FILE *out, symmetric_CTR *ctr); |
|
59 |
|
60 extern int kr_encrypt_key(pk_key *pk, unsigned long ID, |
|
61 const unsigned char *in, unsigned long inlen, |
|
62 unsigned char *out, unsigned long *outlen, |
|
63 prng_state *prng, int wprng, int hash); |
|
64 |
|
65 extern int kr_decrypt_key(pk_key *pk, const unsigned char *in, |
|
66 unsigned char *out, unsigned long *outlen); |
|
67 |
|
68 extern int kr_sign_hash(pk_key *pk, unsigned long ID, |
|
69 const unsigned char *in, unsigned long inlen, |
|
70 unsigned char *out, unsigned long *outlen, |
|
71 prng_state *prng, int wprng); |
|
72 |
|
73 extern int kr_verify_hash(pk_key *pk, const unsigned char *in, |
|
74 const unsigned char *hash, unsigned long hashlen, |
|
75 int *stat); |
|
76 |
|
77 extern int kr_fingerprint(pk_key *pk, unsigned long ID, int hash, |
|
78 unsigned char *out, unsigned long *outlen); |
|
79 |
|
80 #endif |
|
81 |