Update copyright headers for dual licensing.
[gd/nettle] / pgp.h
1 /* pgp.h
2
3    PGP related functions.
4
5    Copyright (C) 2001, 2002 Niels Möller
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
12      * the GNU Lesser General Public License as published by the Free
13        Software Foundation; either version 3 of the License, or (at your
14        option) any later version.
15
16    or
17
18      * the GNU General Public License as published by the Free
19        Software Foundation; either version 2 of the License, or (at your
20        option) any later version.
21
22    or both in parallel, as here.
23
24    GNU Nettle is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28
29    You should have received copies of the GNU General Public License and
30    the GNU Lesser General Public License along with this program.  If
31    not, see http://www.gnu.org/licenses/.
32 */
33
34 #ifndef NETTLE_PGP_H_INCLUDED
35 #define NETTLE_PGP_H_INCLUDED
36
37 #include <time.h>
38
39 #include "nettle-types.h"
40 #include "bignum.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Name mangling */
47 #define pgp_put_uint32 nettle_pgp_put_uint32
48 #define pgp_put_uint16 nettle_pgp_put_uint16
49 #define pgp_put_mpi nettle_pgp_put_mpi
50 #define pgp_put_string nettle_pgp_put_string
51 #define pgp_put_length nettle_pgp_put_length
52 #define pgp_put_header nettle_pgp_put_header
53 #define pgp_put_header_length nettle_pgp_put_header_length
54 #define pgp_sub_packet_start nettle_pgp_sub_packet_start
55 #define pgp_put_sub_packet nettle_pgp_put_sub_packet
56 #define pgp_sub_packet_end nettle_pgp_sub_packet_end
57 #define pgp_put_public_rsa_key nettle_pgp_put_public_rsa_key
58 #define pgp_put_rsa_sha1_signature nettle_pgp_put_rsa_sha1_signature
59 #define pgp_put_userid nettle_pgp_put_userid
60 #define pgp_crc24 nettle_pgp_crc24
61 #define pgp_armor nettle_pgp_armor
62
63 struct nettle_buffer;
64 struct rsa_public_key;
65 struct rsa_private_key;
66 struct sha1_ctx;
67
68 int
69 pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i);
70
71 int
72 pgp_put_uint16(struct nettle_buffer *buffer, unsigned i);
73
74 int
75 pgp_put_mpi(struct nettle_buffer *buffer, const mpz_t x);
76
77 int
78 pgp_put_string(struct nettle_buffer *buffer,
79                unsigned length,
80                const uint8_t *s);
81
82 int
83 pgp_put_length(struct nettle_buffer *buffer,
84                unsigned length);
85
86 int
87 pgp_put_header(struct nettle_buffer *buffer,
88                unsigned tag, unsigned length);
89
90 void
91 pgp_put_header_length(struct nettle_buffer *buffer,
92                       /* start of the header */
93                       unsigned start,
94                       unsigned field_size);
95
96 unsigned
97 pgp_sub_packet_start(struct nettle_buffer *buffer);
98
99 int
100 pgp_put_sub_packet(struct nettle_buffer *buffer,
101                    unsigned type,
102                    unsigned length,
103                    const uint8_t *data);
104
105 void
106 pgp_sub_packet_end(struct nettle_buffer *buffer, unsigned start);
107
108 int
109 pgp_put_public_rsa_key(struct nettle_buffer *,
110                        const struct rsa_public_key *key,
111                        time_t timestamp);
112
113 int
114 pgp_put_rsa_sha1_signature(struct nettle_buffer *buffer,
115                            const struct rsa_private_key *key,
116                            const uint8_t *keyid,
117                            unsigned type,
118                            struct sha1_ctx *hash);
119
120 int
121 pgp_put_userid(struct nettle_buffer *buffer,
122                unsigned length,
123                const uint8_t *name);
124
125 uint32_t
126 pgp_crc24(unsigned length, const uint8_t *data);
127
128 int
129 pgp_armor(struct nettle_buffer *buffer,
130           const char *tag,
131           unsigned length,
132           const uint8_t *data);
133
134 /* Values that can be passed to pgp_put_header when the size of the
135  * length field, but not the length itself, is known. Also the minimum length
136  * for the given field size. */
137 enum pgp_lengths
138   {
139     PGP_LENGTH_ONE_OCTET = 0,
140     PGP_LENGTH_TWO_OCTETS = 192,
141     PGP_LENGTH_FOUR_OCTETS = 8384,
142   };
143
144 enum pgp_public_key_algorithm
145   {
146     PGP_RSA = 1,
147     PGP_RSA_ENCRYPT = 2,
148     PGP_RSA_SIGN = 3,
149     PGP_EL_GAMAL_ENCRYPT = 16,
150     PGP_DSA = 17,
151     PGP_EL_GAMAL = 20,
152   };
153
154 enum pgp_symmetric_algorithm
155   {
156     PGP_PLAINTEXT = 0,
157     PGP_IDEA = 1,
158     PGP_3DES = 2,
159     PGP_CAST5 = 3,
160     PGP_BLOWFISH = 4,
161     PGP_SAFER_SK = 5,
162     PGP_AES128 = 7,
163     PGP_AES192 = 8,
164     PGP_AES256 = 9,
165   };
166
167 enum pgp_compression_algorithm
168   {
169     PGP_UNCOMPRESSED = 0,
170     PGP_ZIP = 1,
171     PGP_ZLIB = 2,
172   };
173
174 enum pgp_hash_algorithm
175   {
176     PGP_MD5 = 1,
177     PGP_SHA1 = 2,
178     PGP_RIPEMD = 3,
179     PGP_MD2 = 5,
180     PGP_TIGER192 = 6,
181     PGP_HAVAL = 7,
182   };
183
184 enum pgp_tag
185   {
186     PGP_TAG_PUBLIC_SESSION_KEY = 1,
187     PGP_TAG_SIGNATURE = 2,
188     PGP_TAG_SYMMETRIC_SESSION_KEY = 3,
189     PGP_TAG_ONE_PASS_SIGNATURE = 4,
190     PGP_TAG_SECRET_KEY = 5,
191     PGP_TAG_PUBLIC_KEY = 6,
192     PGP_TAG_SECRET_SUBKEY = 7,
193     PGP_TAG_COMPRESSED = 8,
194     PGP_TAG_ENCRYPTED = 9,
195     PGP_TAG_MARKER = 10,
196     PGP_TAG_LITERAL = 11,
197     PGP_TAG_TRUST = 12,
198     PGP_TAG_USERID = 13,
199     PGP_TAG_PUBLIC_SUBKEY = 14,
200   };
201
202 enum pgp_signature_type
203   {
204     PGP_SIGN_BINARY = 0,
205     PGP_SIGN_TEXT = 1,
206     PGP_SIGN_STANDALONE = 2,
207     PGP_SIGN_CERTIFICATION = 0x10,
208     PGP_SIGN_CERTIFICATION_PERSONA = 0x11,
209     PGP_SIGN_CERTIFICATION_CASUAL = 0x12,
210     PGP_SIGN_CERTIFICATION_POSITIVE = 0x13,
211     PGP_SIGN_SUBKEY = 0x18,
212     PGP_SIGN_KEY = 0x1f,
213     PGP_SIGN_REVOCATION = 0x20,
214     PGP_SIGN_REVOCATION_SUBKEY = 0x28,
215     PGP_SIGN_REVOCATION_CERTIFICATE = 0x30,
216     PGP_SIGN_TIMESTAMP = 0x40,
217   };
218
219 enum pgp_subpacket_tag
220   {
221     PGP_SUBPACKET_CREATION_TIME = 2,
222     PGP_SUBPACKET_SIGNATURE_EXPIRATION_TIME = 3,
223     PGP_SUBPACKET_EXPORTABLE_CERTIFICATION = 4,
224     PGP_SUBPACKET_TRUST_SIGNATURE = 5,
225     PGP_SUBPACKET_REGULAR_EXPRESSION = 6,
226     PGP_SUBPACKET_REVOCABLE = 7,
227     PGP_SUBPACKET_KEY_EXPIRATION_TIME = 9,
228     PGP_SUBPACKET_PLACEHOLDER = 10 ,
229     PGP_SUBPACKET_PREFERRED_SYMMETRIC_ALGORITHMS = 11,
230     PGP_SUBPACKET_REVOCATION_KEY = 12,
231     PGP_SUBPACKET_ISSUER_KEY_ID = 16,
232     PGP_SUBPACKET_NOTATION_DATA = 20,
233     PGP_SUBPACKET_PREFERRED_HASH_ALGORITHMS = 21,
234     PGP_SUBPACKET_PREFERRED_COMPRESSION_ALGORITHMS = 22,
235     PGP_SUBPACKET_KEY_SERVER_PREFERENCES = 23,
236     PGP_SUBPACKET_PREFERRED_KEY_SERVER = 24,
237     PGP_SUBPACKET_PRIMARY_USER_ID = 25,
238     PGP_SUBPACKET_POLICY_URL = 26,
239     PGP_SUBPACKET_KEY_FLAGS = 27,
240     PGP_SUBPACKET_SIGNERS_USER_ID = 28,
241     PGP_SUBPACKET_REASON_FOR_REVOCATION = 29,
242   };
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif /* NETTLE_PGP_H_INCLUDED */