Bump to 2.4.3
[platform/upstream/gpg2.git] / common / openpgpdefs.h
1 /* openpgpdefs.h - Constants from the OpenPGP standard (rfc2440)
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3  *               2006 Free Software Foundation, Inc.
4  * Copyright (C) 2014 Werner Koch
5  *
6  * This file is free software; you can redistribute it and/or modify
7  * it under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * This file is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, see <https://www.gnu.org/licenses/>.
28  */
29
30 #ifndef GNUPG_COMMON_OPENPGPDEFS_H
31 #define GNUPG_COMMON_OPENPGPDEFS_H
32
33 typedef enum
34   {
35     PKT_NONE          = 0,
36     PKT_PUBKEY_ENC    = 1,  /* Public key encrypted packet. */
37     PKT_SIGNATURE     = 2,  /* Secret key encrypted packet. */
38     PKT_SYMKEY_ENC    = 3,  /* Session key packet. */
39     PKT_ONEPASS_SIG   = 4,  /* One pass sig packet. */
40     PKT_SECRET_KEY    = 5,  /* Secret key. */
41     PKT_PUBLIC_KEY    = 6,  /* Public key. */
42     PKT_SECRET_SUBKEY = 7,  /* Secret subkey. */
43     PKT_COMPRESSED    = 8,  /* Compressed data packet. */
44     PKT_ENCRYPTED     = 9,  /* Conventional encrypted data. */
45     PKT_MARKER        = 10, /* Marker packet. */
46     PKT_PLAINTEXT     = 11, /* Literal data packet. */
47     PKT_RING_TRUST    = 12, /* Keyring trust packet. */
48     PKT_USER_ID       = 13, /* User id packet. */
49     PKT_PUBLIC_SUBKEY = 14, /* Public subkey. */
50     PKT_OLD_COMMENT   = 16, /* Comment packet from an OpenPGP draft. */
51     PKT_ATTRIBUTE     = 17, /* PGP's attribute packet. */
52     PKT_ENCRYPTED_MDC = 18, /* Integrity protected encrypted data. */
53     PKT_MDC           = 19, /* Manipulation detection code packet. */
54     PKT_ENCRYPTED_AEAD= 20, /* AEAD encrypted data packet. */
55     PKT_COMMENT       = 61, /* new comment packet (GnuPG specific). */
56     PKT_GPG_CONTROL   = 63  /* internal control packet (GnuPG specific). */
57   }
58 pkttype_t;
59
60 static inline const char *
61 pkttype_str (pkttype_t type)
62 {
63   switch (type)
64     {
65     case PKT_PUBKEY_ENC: return "PUBKEY_ENC";
66     case PKT_SIGNATURE: return "SIGNATURE";
67     case PKT_SYMKEY_ENC: return "SYMKEY_ENC";
68     case PKT_ONEPASS_SIG: return "ONEPASS_SIG";
69     case PKT_SECRET_KEY: return "SECRET_KEY";
70     case PKT_PUBLIC_KEY: return "PUBLIC_KEY";
71     case PKT_SECRET_SUBKEY: return "SECRET_SUBKEY";
72     case PKT_COMPRESSED: return "COMPRESSED";
73     case PKT_ENCRYPTED: return "ENCRYPTED";
74     case PKT_MARKER: return "MARKER";
75     case PKT_PLAINTEXT: return "PLAINTEXT";
76     case PKT_RING_TRUST: return "RING_TRUST";
77     case PKT_USER_ID: return "USER_ID";
78     case PKT_PUBLIC_SUBKEY: return "PUBLIC_SUBKEY";
79     case PKT_OLD_COMMENT: return "OLD_COMMENT";
80     case PKT_ATTRIBUTE: return "ATTRIBUTE";
81     case PKT_ENCRYPTED_MDC: return "ENCRYPTED_MDC";
82     case PKT_MDC: return "MDC";
83     case PKT_COMMENT: return "COMMENT";
84     case PKT_GPG_CONTROL: return "GPG_CONTROL";
85     default: return "unknown packet type";
86     }
87 }
88
89 typedef enum
90   {
91     SIGSUBPKT_TEST_CRITICAL = -3,
92     SIGSUBPKT_LIST_UNHASHED = -2,
93     SIGSUBPKT_LIST_HASHED   = -1,
94     SIGSUBPKT_NONE          =  0,
95     SIGSUBPKT_SIG_CREATED   =  2, /* Signature creation time. */
96     SIGSUBPKT_SIG_EXPIRE    =  3, /* Signature expiration time. */
97     SIGSUBPKT_EXPORTABLE    =  4, /* Exportable. */
98     SIGSUBPKT_TRUST         =  5, /* Trust signature. */
99     SIGSUBPKT_REGEXP        =  6, /* Regular expression. */
100     SIGSUBPKT_REVOCABLE     =  7, /* Revocable. */
101     SIGSUBPKT_KEY_EXPIRE    =  9, /* Key expiration time. */
102     SIGSUBPKT_ARR           = 10, /* Additional recipient request. */
103     SIGSUBPKT_PREF_SYM      = 11, /* Preferred symmetric algorithms. */
104     SIGSUBPKT_REV_KEY       = 12, /* Revocation key. */
105     SIGSUBPKT_ISSUER        = 16, /* Issuer key ID. */
106     SIGSUBPKT_NOTATION      = 20, /* Notation data. */
107     SIGSUBPKT_PREF_HASH     = 21, /* Preferred hash algorithms. */
108     SIGSUBPKT_PREF_COMPR    = 22, /* Preferred compression algorithms. */
109     SIGSUBPKT_KS_FLAGS      = 23, /* Key server preferences. */
110     SIGSUBPKT_PREF_KS       = 24, /* Preferred keyserver. */
111     SIGSUBPKT_PRIMARY_UID   = 25, /* Primary user id. */
112     SIGSUBPKT_POLICY        = 26, /* Policy URL. */
113     SIGSUBPKT_KEY_FLAGS     = 27, /* Key flags. */
114     SIGSUBPKT_SIGNERS_UID   = 28, /* Signer's user id. */
115     SIGSUBPKT_REVOC_REASON  = 29, /* Reason for revocation. */
116     SIGSUBPKT_FEATURES      = 30, /* Feature flags. */
117
118     SIGSUBPKT_SIGNATURE     = 32, /* Embedded signature. */
119     SIGSUBPKT_ISSUER_FPR    = 33, /* Issuer fingerprint. */
120     SIGSUBPKT_PREF_AEAD     = 34, /* Preferred AEAD algorithms. */
121
122     SIGSUBPKT_ATTST_SIGS    = 37, /* Attested Certifications.  */
123     SIGSUBPKT_KEY_BLOCK     = 38, /* Entire key used.          */
124
125     SIGSUBPKT_FLAG_CRITICAL = 128
126   }
127 sigsubpkttype_t;
128
129
130 typedef enum
131   {
132     CIPHER_ALGO_NONE        =  0,
133     CIPHER_ALGO_IDEA        =  1,
134     CIPHER_ALGO_3DES        =  2,
135     CIPHER_ALGO_CAST5       =  3,
136     CIPHER_ALGO_BLOWFISH    =  4, /* 128 bit */
137     /* 5 & 6 are reserved */
138     CIPHER_ALGO_AES         =  7,
139     CIPHER_ALGO_AES192      =  8,
140     CIPHER_ALGO_AES256      =  9,
141     CIPHER_ALGO_TWOFISH     = 10, /* 256 bit */
142     CIPHER_ALGO_CAMELLIA128 = 11,
143     CIPHER_ALGO_CAMELLIA192 = 12,
144     CIPHER_ALGO_CAMELLIA256 = 13,
145     CIPHER_ALGO_PRIVATE10   = 110
146   }
147 cipher_algo_t;
148
149
150 /* Note that we encode the AEAD algo in a 3 bit field at some places.  */
151 typedef enum
152   {
153     AEAD_ALGO_NONE          =  0,
154     AEAD_ALGO_EAX           =  1,
155     AEAD_ALGO_OCB           =  2
156   }
157 aead_algo_t;
158
159
160 typedef enum
161   {
162     PUBKEY_ALGO_RSA         =  1,
163     PUBKEY_ALGO_RSA_E       =  2, /* RSA encrypt only (legacy). */
164     PUBKEY_ALGO_RSA_S       =  3, /* RSA sign only (legacy).    */
165     PUBKEY_ALGO_ELGAMAL_E   = 16, /* Elgamal encrypt only.      */
166     PUBKEY_ALGO_DSA         = 17,
167     PUBKEY_ALGO_ECDH        = 18, /* RFC-6637  */
168     PUBKEY_ALGO_ECDSA       = 19, /* RFC-6637  */
169     PUBKEY_ALGO_ELGAMAL     = 20, /* Elgamal encrypt+sign (legacy).  */
170     /*                        21     reserved by OpenPGP.            */
171     PUBKEY_ALGO_EDDSA       = 22, /* EdDSA (not yet assigned).       */
172     PUBKEY_ALGO_PRIVATE10   = 110
173   }
174 pubkey_algo_t;
175
176
177 typedef enum
178   {
179     DIGEST_ALGO_MD5         =  1,
180     DIGEST_ALGO_SHA1        =  2,
181     DIGEST_ALGO_RMD160      =  3,
182     /* 4, 5, 6, and 7 are reserved. */
183     DIGEST_ALGO_SHA256      =  8,
184     DIGEST_ALGO_SHA384      =  9,
185     DIGEST_ALGO_SHA512      = 10,
186     DIGEST_ALGO_SHA224      = 11,
187     DIGEST_ALGO_PRIVATE10   = 110
188   }
189 digest_algo_t;
190
191
192 typedef enum
193   {
194     COMPRESS_ALGO_NONE      =  0,
195     COMPRESS_ALGO_ZIP       =  1,
196     COMPRESS_ALGO_ZLIB      =  2,
197     COMPRESS_ALGO_BZIP2     =  3,
198     COMPRESS_ALGO_PRIVATE10 = 110
199   }
200 compress_algo_t;
201
202 /* Limits to be used for static arrays.  */
203 #define OPENPGP_MAX_NPKEY  5  /* Maximum number of public key parameters. */
204 #define OPENPGP_MAX_NSKEY  7  /* Maximum number of secret key parameters. */
205 #define OPENPGP_MAX_NSIG   2  /* Maximum number of signature parameters.  */
206 #define OPENPGP_MAX_NENC   2  /* Maximum number of encryption parameters. */
207
208
209 /* Decode an rfc4880 encoded S2K count.  */
210 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
211
212
213 /*-- openpgp-s2k.c --*/
214 unsigned char encode_s2k_iterations (int iterations);
215
216 /*-- openpgp-fpr.c --*/
217 gpg_error_t compute_openpgp_fpr (int keyversion, int pgpalgo,
218                                  unsigned long timestamp,
219                                  gcry_buffer_t *iov, int iovcnt,
220                                  unsigned char *result,
221                                  unsigned int *r_resultlen);
222 gpg_error_t compute_openpgp_fpr_rsa (int keyversion,
223                                      unsigned long timestamp,
224                                      const unsigned char *m, unsigned int mlen,
225                                      const unsigned char *e, unsigned int elen,
226                                      unsigned char *result,
227                                      unsigned int *r_resultlen);
228 gpg_error_t compute_openpgp_fpr_ecc (int keyversion,
229                                      unsigned long timestamp,
230                                      const char *curvename, int for_encryption,
231                                      const unsigned char *q, unsigned int qlen,
232                                      const unsigned char *kdf,
233                                      unsigned int kdflen,
234                                      unsigned char *result,
235                                      unsigned int *r_resultlen);
236
237 /*-- openpgp-oid.c --*/
238 pubkey_algo_t map_gcry_pk_to_openpgp (enum gcry_pk_algos algo);
239 enum gcry_pk_algos map_openpgp_pk_to_gcry (pubkey_algo_t algo);
240
241
242
243 #endif /*GNUPG_COMMON_OPENPGPDEFS_H*/