1 /*                    Wrapper for encryption protocols                    */
2 /*             Copyright (C) 2001-2003 William Tompkins                   */
3 
4 /* This plugin is free software, distributed under the GNU General Public */
5 /* License.                                                               */
6 /* Please see the file "COPYING" distributed with this source code        */
7 /* for more details                                                       */
8 /*                                                                        */
9 /*                                                                        */
10 /*    This software is distributed in the hope that it will be useful,    */
11 /*   but WITHOUT ANY WARRANTY; without even the implied warranty of       */
12 /*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    */
13 /*   General Public License for more details.                             */
14 
15 /*   To compile and use:                                                  */
16 /*     See INSTALL file.                                                  */
17 
18 #ifndef CRYPTPROTO_H
19 #define CRYPTPROTO_H
20 
21 #include "debug.h"
22 
23 #include "rsa_nss.h"
24 
25 
26 
27 /* Defined so that keys.h can use it: */
28 typedef union {
29 /*   rsa_crypt_key rsa; */
30 /*   RSA* rsa_ssl;      */
31    RSA_NSS_KEY rsa_nss;
32 } proto_union;
33 
34 struct crypt_key;
35 
36 struct crypt_proto {
37    /*Crypto operations: each returns the length, and g_malloc's the first argument for you */
38    int (*encrypt) (unsigned char** encrypted, unsigned char* msg, int msg_len,
39                    struct crypt_key* key);
40    int (*decrypt) (unsigned char** decrypted, unsigned char* msg, int msg_len,
41                    struct crypt_key* key);
42    int (*sign)    (unsigned char** signedmsg, unsigned char* msg, int msg_len,
43                    struct crypt_key* key, struct crypt_key* to_key);
44    int (*auth)    (unsigned char** authed, unsigned char* msg, int msg_len,
45                    struct crypt_key* key, const char* name);
46 
47 
48    int (*calc_unencrypted_size) (struct crypt_key* key, int size);
49    int (*calc_unsigned_size)    (struct crypt_key* key, int size);
50 
51    /* Key <-> String operations */
52 
53    struct crypt_key* (*make_key_from_str)  (char *);
54    GString*          (*key_to_gstr)        (struct crypt_key* key);
55 
56    char *            (*parseable)          (char *keymsg);
57    struct crypt_key* (*parse_sent_key)     (char *);
58    GString*          (*make_sendable_key)  (struct crypt_key* key, const char* name);
59 
60    gchar*            (*make_key_id)        (struct crypt_key* key);
61    /* Key creation / destruction */
62 
63    struct crypt_key* (*make_pub_from_priv) (struct crypt_key* priv_key);
64    void              (*free)               (struct crypt_key*);
65    void              (*gen_key_pair)       (struct crypt_key **, struct crypt_key **,
66                                             const char* name,
67                                             int keysize);
68    /* Name of the protocol */
69    char* name;
70 };
71 
72 typedef struct crypt_proto crypt_proto;
73 
74 extern GSList*  crypt_proto_list;
75 
76 int            PE_calc_unencrypted_size(struct crypt_key* enc_key,
77                                         struct crypt_key* sign_key,
78                                         int size);
79 char*    PE_encrypt(char* msg, struct crypt_key* key);
80 char*    PE_decrypt(char* msg, struct crypt_key* key);
81 void     PE_encrypt_signed(char** out, char* msg, struct crypt_key* key1,
82                            struct crypt_key* key2);
83 int      PE_decrypt_signed(char** authed, char* msg, struct crypt_key* key1,
84                            struct crypt_key* key2, const char* name);
85 GString* PE_key_to_gstr(struct crypt_key* key);
86 
87 void     PE_free_key(struct crypt_key*);
88 
89 GString* PE_make_sendable_key(struct crypt_key* key, const char* name);
90 gchar*   PE_make_key_id(struct crypt_key* key);
91 
92 #endif
93