/src/gnupg/common/openpgpdefs.h
Line | Count | Source |
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 | 0 | { |
63 | 0 | switch (type) |
64 | 0 | { |
65 | 0 | case PKT_PUBKEY_ENC: return "PUBKEY_ENC"; |
66 | 0 | case PKT_SIGNATURE: return "SIGNATURE"; |
67 | 0 | case PKT_SYMKEY_ENC: return "SYMKEY_ENC"; |
68 | 0 | case PKT_ONEPASS_SIG: return "ONEPASS_SIG"; |
69 | 0 | case PKT_SECRET_KEY: return "SECRET_KEY"; |
70 | 0 | case PKT_PUBLIC_KEY: return "PUBLIC_KEY"; |
71 | 0 | case PKT_SECRET_SUBKEY: return "SECRET_SUBKEY"; |
72 | 0 | case PKT_COMPRESSED: return "COMPRESSED"; |
73 | 0 | case PKT_ENCRYPTED: return "ENCRYPTED"; |
74 | 0 | case PKT_MARKER: return "MARKER"; |
75 | 0 | case PKT_PLAINTEXT: return "PLAINTEXT"; |
76 | 0 | case PKT_RING_TRUST: return "RING_TRUST"; |
77 | 0 | case PKT_USER_ID: return "USER_ID"; |
78 | 0 | case PKT_PUBLIC_SUBKEY: return "PUBLIC_SUBKEY"; |
79 | 0 | case PKT_OLD_COMMENT: return "OLD_COMMENT"; |
80 | 0 | case PKT_ATTRIBUTE: return "ATTRIBUTE"; |
81 | 0 | case PKT_ENCRYPTED_MDC: return "ENCRYPTED_MDC"; |
82 | 0 | case PKT_MDC: return "MDC"; |
83 | 0 | case PKT_COMMENT: return "COMMENT"; |
84 | 0 | case PKT_GPG_CONTROL: return "GPG_CONTROL"; |
85 | 0 | default: return "unknown packet type"; |
86 | 0 | } |
87 | 0 | } Unexecuted instantiation: fuzzer_stubs.c:pkttype_str Unexecuted instantiation: fuzz_list.c:pkttype_str Unexecuted instantiation: mainproc.c:pkttype_str Unexecuted instantiation: trustdb.c:pkttype_str Unexecuted instantiation: decrypt-data.c:pkttype_str Unexecuted instantiation: pubkey-enc.c:pkttype_str Unexecuted instantiation: keyserver.c:pkttype_str Unexecuted instantiation: photoid.c:pkttype_str Unexecuted instantiation: pkclist.c:pkttype_str Unexecuted instantiation: trust.c:pkttype_str Unexecuted instantiation: export.c:pkttype_str Unexecuted instantiation: cpr.c:pkttype_str Unexecuted instantiation: skclist.c:pkttype_str Unexecuted instantiation: key-clean.c:pkttype_str Unexecuted instantiation: tdbio.c:pkttype_str Unexecuted instantiation: passphrase.c:pkttype_str Unexecuted instantiation: verify.c:pkttype_str Unexecuted instantiation: sig-check.c:pkttype_str Unexecuted instantiation: misc.c:pkttype_str Unexecuted instantiation: build-packet.c:pkttype_str Unexecuted instantiation: progress.c:pkttype_str Unexecuted instantiation: plaintext.c:pkttype_str Unexecuted instantiation: armor.c:pkttype_str Unexecuted instantiation: call-dirmngr.c:pkttype_str Unexecuted instantiation: getkey.c:pkttype_str Unexecuted instantiation: seskey.c:pkttype_str Unexecuted instantiation: expand-group.c:pkttype_str Unexecuted instantiation: call-agent.c:pkttype_str Unexecuted instantiation: call-keyboxd.c:pkttype_str Unexecuted instantiation: keyid.c:pkttype_str Unexecuted instantiation: tdbdump.c:pkttype_str Unexecuted instantiation: server.c:pkttype_str Unexecuted instantiation: keydb.c:pkttype_str Unexecuted instantiation: ecdh.c:pkttype_str Unexecuted instantiation: kbnode.c:pkttype_str Unexecuted instantiation: pkglue.c:pkttype_str Unexecuted instantiation: import.c:pkttype_str Unexecuted instantiation: key-check.c:pkttype_str Unexecuted instantiation: free-packet.c:pkttype_str Unexecuted instantiation: keylist.c:pkttype_str Unexecuted instantiation: helptext.c:pkttype_str Unexecuted instantiation: parse-packet.c:pkttype_str Unexecuted instantiation: decrypt.c:pkttype_str Unexecuted instantiation: compress.c:pkttype_str Unexecuted instantiation: openfile.c:pkttype_str Unexecuted instantiation: keyring.c:pkttype_str Unexecuted instantiation: textfilter.c:pkttype_str Unexecuted instantiation: keyedit.c:pkttype_str Unexecuted instantiation: objcache.c:pkttype_str Unexecuted instantiation: encrypt.c:pkttype_str Unexecuted instantiation: sign.c:pkttype_str Unexecuted instantiation: cipher-cfb.c:pkttype_str Unexecuted instantiation: cipher-aead.c:pkttype_str Unexecuted instantiation: keygen.c:pkttype_str Unexecuted instantiation: revoke.c:pkttype_str Unexecuted instantiation: keybox-openpgp.c:pkttype_str Unexecuted instantiation: sexputil.c:pkttype_str Unexecuted instantiation: openpgp-oid.c:pkttype_str Unexecuted instantiation: openpgp-s2k.c:pkttype_str Unexecuted instantiation: compliance.c:pkttype_str |
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_META_HASH = 40, /* Literal Data Meta Hash. */ |
126 | | SIGSUBPKT_TRUST_ALIAS = 41, /* Trust Alias. */ |
127 | | |
128 | | SIGSUBPKT_FLAG_CRITICAL = 128 |
129 | | } |
130 | | sigsubpkttype_t; |
131 | | |
132 | | |
133 | | typedef enum |
134 | | { |
135 | | CIPHER_ALGO_NONE = 0, |
136 | | CIPHER_ALGO_IDEA = 1, |
137 | | CIPHER_ALGO_3DES = 2, |
138 | | CIPHER_ALGO_CAST5 = 3, |
139 | | CIPHER_ALGO_BLOWFISH = 4, /* 128 bit */ |
140 | | /* 5 & 6 are reserved */ |
141 | | CIPHER_ALGO_AES = 7, |
142 | | CIPHER_ALGO_AES192 = 8, |
143 | | CIPHER_ALGO_AES256 = 9, |
144 | | CIPHER_ALGO_TWOFISH = 10, /* 256 bit */ |
145 | | CIPHER_ALGO_CAMELLIA128 = 11, |
146 | | CIPHER_ALGO_CAMELLIA192 = 12, |
147 | | CIPHER_ALGO_CAMELLIA256 = 13, |
148 | | CIPHER_ALGO_PRIVATE10 = 110 |
149 | | } |
150 | | cipher_algo_t; |
151 | | |
152 | | |
153 | | /* Note that we encode the AEAD algo in a 3 bit field at some places. */ |
154 | | typedef enum |
155 | | { |
156 | | AEAD_ALGO_NONE = 0, |
157 | | AEAD_ALGO_EAX = 1, |
158 | | AEAD_ALGO_OCB = 2 |
159 | | } |
160 | | aead_algo_t; |
161 | | |
162 | | |
163 | | typedef enum |
164 | | { |
165 | | PUBKEY_ALGO_RSA = 1, |
166 | | PUBKEY_ALGO_RSA_E = 2, /* RSA encrypt only (legacy). */ |
167 | | PUBKEY_ALGO_RSA_S = 3, /* RSA sign only (legacy). */ |
168 | | PUBKEY_ALGO_KYBER = 8, /* Kyber (FIPS-203 final) */ |
169 | | PUBKEY_ALGO_ELGAMAL_E = 16, /* Elgamal encrypt only. */ |
170 | | PUBKEY_ALGO_DSA = 17, |
171 | | PUBKEY_ALGO_ECDH = 18, /* RFC-6637 */ |
172 | | PUBKEY_ALGO_ECDSA = 19, /* RFC-6637 */ |
173 | | PUBKEY_ALGO_ELGAMAL = 20, /* Elgamal encrypt+sign (legacy). */ |
174 | | /* 21 reserved by OpenPGP. */ |
175 | | PUBKEY_ALGO_EDDSA = 22, /* EdDSA. */ |
176 | | /* 29 (was fips203.ipd.2023-08-24 in 1.5.0) */ |
177 | | PUBKEY_ALGO_DIL3_25519 = 35, /* Dilithium3 + Ed25519 (aka ML-DSA-65) */ |
178 | | PUBKEY_ALGO_DIL5_448 = 36, /* Dilithium5 + Ed448 (aka ML-DSA-87) */ |
179 | | PUBKEY_ALGO_SPHINX_SHA2 = 41, /* SPHINX+-simple-SHA2 (aka SLH-DSA-SHA2) */ |
180 | | PUBKEY_ALGO_PRIVATE10 = 110 |
181 | | } |
182 | | pubkey_algo_t; |
183 | | |
184 | | |
185 | | typedef enum |
186 | | { |
187 | | DIGEST_ALGO_MD5 = 1, |
188 | | DIGEST_ALGO_SHA1 = 2, |
189 | | DIGEST_ALGO_RMD160 = 3, |
190 | | /* 4, 5, 6, and 7 are reserved. */ |
191 | | DIGEST_ALGO_SHA256 = 8, |
192 | | DIGEST_ALGO_SHA384 = 9, |
193 | | DIGEST_ALGO_SHA512 = 10, |
194 | | DIGEST_ALGO_SHA224 = 11, |
195 | | DIGEST_ALGO_PRIVATE10 = 110 |
196 | | } |
197 | | digest_algo_t; |
198 | | |
199 | | |
200 | | typedef enum |
201 | | { |
202 | | COMPRESS_ALGO_NONE = 0, |
203 | | COMPRESS_ALGO_ZIP = 1, |
204 | | COMPRESS_ALGO_ZLIB = 2, |
205 | | COMPRESS_ALGO_BZIP2 = 3, |
206 | | COMPRESS_ALGO_PRIVATE10 = 110 |
207 | | } |
208 | | compress_algo_t; |
209 | | |
210 | | /* Limits to be used for static arrays. */ |
211 | | #define OPENPGP_MAX_NPKEY 5 /* Maximum number of public key parameters. */ |
212 | 0 | #define OPENPGP_MAX_NSKEY 7 /* Maximum number of secret key parameters. */ |
213 | | #define OPENPGP_MAX_NSIG 2 /* Maximum number of signature parameters. */ |
214 | 13.5k | #define OPENPGP_MAX_NENC 4 /* Maximum number of encryption parameters. */ |
215 | | |
216 | | |
217 | | /* Decode an rfc4880 encoded S2K count. */ |
218 | 0 | #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6)) |
219 | | |
220 | | |
221 | | /*-- openpgp-s2k.c --*/ |
222 | | unsigned char encode_s2k_iterations (int iterations); |
223 | | |
224 | | /*-- openpgp-fpr.c --*/ |
225 | | gpg_error_t compute_openpgp_fpr (int keyversion, int pgpalgo, |
226 | | unsigned long timestamp, |
227 | | gcry_buffer_t *iov, int iovcnt, |
228 | | unsigned char *result, |
229 | | unsigned int *r_resultlen); |
230 | | gpg_error_t compute_openpgp_fpr_rsa (int keyversion, |
231 | | unsigned long timestamp, |
232 | | const unsigned char *m, unsigned int mlen, |
233 | | const unsigned char *e, unsigned int elen, |
234 | | unsigned char *result, |
235 | | unsigned int *r_resultlen); |
236 | | gpg_error_t compute_openpgp_fpr_ecc (int keyversion, |
237 | | unsigned long timestamp, |
238 | | const char *curvename, int for_encryption, |
239 | | const unsigned char *q, unsigned int qlen, |
240 | | const unsigned char *kdf, |
241 | | unsigned int kdflen, |
242 | | unsigned char *result, |
243 | | unsigned int *r_resultlen); |
244 | | |
245 | | /*-- openpgp-oid.c --*/ |
246 | | pubkey_algo_t map_gcry_pk_to_openpgp (enum gcry_pk_algos algo); |
247 | | enum gcry_pk_algos map_openpgp_pk_to_gcry (pubkey_algo_t algo); |
248 | | |
249 | | |
250 | | |
251 | | #endif /*GNUPG_COMMON_OPENPGPDEFS_H*/ |