Codebase list pgpdump / c4c591b
Updated pgpdump to include gnupg-2.3.3 ECC curves, newer hashes and algorithm names Added definition for public algrothims 18, 19, and 22 Added definitions and code for GnuPG-2.3.3 supported ECC keys Added minor definitions/code for AEAD Added definitions for newer SHA3-256 and SHA3-512 algorithms galaxiesFarApart 2 years ago
7 changed file(s) with 294 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
5353 multi_precision_integer("RSA e");
5454 }
5555
56 /* added: 2021-11-11
57 * Reference: draft-ietf-openpgp-crypto-refresh-04 (10/2021);section 9.2 ECC Curves for OpenPGP
58 * https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-04.html
59 * Note (2021-11-25): actual ECC curve hex OID padded to 10 to match incoming oid array length
60 * so that memcmp will work properly (compare two values of the same size)
61 */
62 private unsigned char BrainPool256r1_OID[10]={0x2B,0x24,0x3,0x3,0x2,0x8,0x1,0x1,0x7,0};
63 private unsigned char NIST_P256_OID[10]={0x2A,0x86,0x48,0xCE,0x3D,0x3,0x1,0x7,0,0};
64 private unsigned char NIST_P384_OID[10]={0x2B,0x81,0x04,0x00,0x22,0,0,0,0,0};
65 private unsigned char NIST_P521_OID[10]={0x2B,0x81,0x04,0x00,0x23,0,0,0,0,0};
66 private unsigned char Ed25519_OID[10]={0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0F,0x01,0};
67 private unsigned char Ed448_OID[10]={0x2B,0x65,0x71,0,0,0,0,0,0,0};
68 private unsigned char Curve25519_OID[10]={0x2B,0x06,0x01,0x04,0x01,0x97,0x55,0x01,0x05,0x01};
69 private unsigned char X448_OID[10]={0x2B,0x65,0x6F,0,0,0,0,0,0,0};
70
71 private unsigned char oid_input_HEX[10]={0,0,0,0,0,0,0,0,0,0};
72 #define oid_input_HEX_size sizeof(oid_input_HEX)
73 private size_t oidLEN;
74 private int FoundECC=NO;
75 private int jj;
76
77 private struct {
78 const unsigned char *oidhex;
79 const char *name;
80 const char *oidstring;
81 const int expectedBits;
82 } ELLIP_CURVES[] = {
83 {NIST_P256_OID,"NIST P-256","0x2A 86 48 CE 3D 03 01 07",515},
84 {NIST_P384_OID,"NIST P-384","0x2B 81 04 00 22",771},
85 {NIST_P521_OID,"NIST P-521","0x2B 81 04 00 23",1059},
86 {Ed25519_OID,"Ed25519","0x2B 06 01 04 01 DA 47 0F 01",263},
87 {Ed448_OID,"Ed448","0x2B 65 71",463},
88 {Curve25519_OID,"Curve25519","0x2B 06 01 04 01 97 55 01 05 01",263},
89 {X448_OID,"X448","0x2B 65 6F",445},
90 {BrainPool256r1_OID,"brainpoolP256r1","0x2B 24 03 03 02 08 01 01 07",515}
91 };
92 #define ELLIP_CURVES_NUM 8
93
94 /* end 2021-11-11 */
95
96
5697 private void
5798 new_Public_Key_Packet(int len)
5899 {
78119 multi_precision_integer("DSA g");
79120 multi_precision_integer("DSA y");
80121 break;
122 case 18:/*ECDH*/
123 oidLEN = Getc();
124 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
125 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
126 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
127 FoundECC=YES;
128 break;
129 }
130 }
131 if(FoundECC){
132 printf("\tElliptic Curve - ");
133 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
134 }
135 else{
136 printf("\tunknown(elliptic curve - ");
137 for(jj=0;jj<oidLEN;jj++){
138 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
139 }
140 puts(")");
141 }
142 multi_precision_integer("ECDH Q");
143 /* note - what follows is most of what the "draft-ietf-openpgp-crypto-refresh-04"
144 * specifies for "13.5 EC DH Algorithm (ECDH)" minus the following:
145 * a) 'one-octet public key algorithm ID defined in Section 9.1'
146 * b) '20 octets representing the UTF-8 encoding of the string "Anonymous Sender"'
147 * c) '20 octets representing a recipient encryption subkey or a primary key fingerprint'
148 * The end result is consonant with GnuPG-2.3.3 "list-packets" output in fields/bytes,
149 * though gpg-2.3.3 displays "pkey[2]" [32 bits]" where the supposed KDF parameters exist.
150 */
151 unsigned int KDFparmsSize,KDFbits,KDFhashID,KDFsymAlgoID;
152 KDFparmsSize=Getc();/*don't display*/
153 KDFbits=(KDFparmsSize + 1)*8;
154 Getc();/*bypass supposed KDF constant */
155 KDFhashID=Getc();
156 KDFsymAlgoID=Getc();
157 printf("\tECDH KDF params(%d bits) - ...\n",KDFbits);
158 printf("\t\t%s ","KDFhashID: ");
159 hash_algs(KDFhashID);
160 printf("\t\t%s ","KDFsymAlgoID: ");
161 sym_algs(KDFsymAlgoID);
162 break;
163 case 19:/*ECDSA*/
164 oidLEN = Getc();
165 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
166 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
167 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
168 FoundECC=YES;
169 break;
170 }
171 }
172 if(FoundECC){
173 printf("\tElliptic Curve - ");
174 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
175 }
176 else{
177 printf("\tunknown(elliptic curve - ");
178 for(jj=0;jj<oidLEN;jj++){
179 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
180 }
181 puts(")");
182 }
183 multi_precision_integer("ECDSA Q");
184 break;
185 case 22:/*EdDSA*/
186 oidLEN = Getc();
187 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
188 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
189 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
190 FoundECC=YES;
191 break;
192 }
193 }
194 if(FoundECC){
195 printf("\tElliptic Curve - ");
196 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
197 }
198 else{
199 printf("\tunknown(elliptic curve - ");
200 for(jj=0;jj<oidLEN;jj++){
201 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
202 }
203 puts(")");
204 }
205 multi_precision_integer("EdDSA Q");
206 break;
81207 default:
82208 printf("\tUnknown public key(pub %d)\n", PUBLIC);
83209 skip(len - 5);
134260 break;
135261 }
136262 }
263
264 /*
265 * 2021-11-29: added cases 18,19,22 (copied from Public key)
266 */
137267
138268 private void
139269 plain_Secret_Key(int len)
168298 case 17:
169299 multi_precision_integer("DSA x");
170300 break;
301 case 18:/*ECDH*/
302 oidLEN = Getc();
303 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
304 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
305 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
306 FoundECC=YES;
307 break;
308 }
309 }
310 if(FoundECC){
311 printf("\tElliptic Curve - ");
312 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
313 }
314 else{
315 printf("\tunknown(elliptic curve - ");
316 for(jj=0;jj<oidLEN;jj++){
317 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
318 }
319 puts(")");
320 }
321 multi_precision_integer("ECDH Q");
322 /* note - what follows is most of what the "draft-ietf-openpgp-crypto-refresh-04"
323 * specifies for "13.5 EC DH Algorithm (ECDH)" minus the following:
324 * a) 'one-octet public key algorithm ID defined in Section 9.1'
325 * b) '20 octets representing the UTF-8 encoding of the string "Anonymous Sender"'
326 * c) '20 octets representing a recipient encryption subkey or a primary key fingerprint'
327 * The end result is consonant with GnuPG-2.3.3 "list-packets" output in fields/bytes,
328 * though gpg-2.3.3 displays "pkey[2]" [32 bits]" where the supposed KDF parameters exist.
329 */
330 unsigned int KDFparmsSize,KDFbits,KDFhashID,KDFsymAlgoID;
331 KDFparmsSize=Getc();/*don't display*/
332 KDFbits=(KDFparmsSize + 1)*8;
333 Getc();/*bypass supposed KDF constant */
334 KDFhashID=Getc();
335 KDFsymAlgoID=Getc();
336 printf("\tECDH KDF params(%d bits) - ...\n",KDFbits);
337 printf("\t\t%s ","KDFhashID: ");
338 hash_algs(KDFhashID);
339 printf("\t\t%s ","KDFsymAlgoID: ");
340 sym_algs(KDFsymAlgoID);
341 break;
342 case 19:/*ECDSA*/
343 oidLEN = Getc();
344 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
345 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
346 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
347 FoundECC=YES;
348 break;
349 }
350 }
351 if(FoundECC){
352 printf("\tElliptic Curve - ");
353 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
354 }
355 else{
356 printf("\tunknown(elliptic curve - ");
357 for(jj=0;jj<oidLEN;jj++){
358 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
359 }
360 puts(")");
361 }
362 multi_precision_integer("ECDSA Q");
363 break;
364 case 22:/*EdDSA*/
365 oidLEN = Getc();
366 for(jj=0;jj<oidLEN;jj++){oid_input_HEX[jj]=Getc();}
367 for(jj=0;jj<ELLIP_CURVES_NUM;jj++){
368 if(memcmp(ELLIP_CURVES[jj].oidhex,oid_input_HEX,oid_input_HEX_size) == 0){
369 FoundECC=YES;
370 break;
371 }
372 }
373 if(FoundECC){
374 printf("\tElliptic Curve - ");
375 printf("%s (%s)\n",ELLIP_CURVES[jj].name,ELLIP_CURVES[jj].oidstring);
376 }
377 else{
378 printf("\tunknown(elliptic curve - ");
379 for(jj=0;jj<oidLEN;jj++){
380 printf("%02hhu,%02x ",oid_input_HEX[jj],oid_input_HEX[jj]);
381 }
382 puts(")");
383 }
384 multi_precision_integer("EdDSA Q");
385 break;
386
171387 default:
172388 printf("\tUnknown secret key(pub %d)\n", PUBLIC);
173389 skip(len - 2);
184400 }
185401 }
186402
403 /*
404 * 2021-11-29: Added cases 18,19,20
405 */
187406 private void
188407 encrypted_Secret_Key(int len, int sha1)
189408 {
220439 case 17:
221440 printf("\tEncrypted DSA x\n");
222441 break;
442 case 18:
443 printf("\tEncrypted ECDH x\n");
444 break;
445 case 19:
446 printf("\tEncrypted ECDSA x\n");
447 break;
448 case 22:
449 printf("\tEncrypted EdDSA x\n");
450 break;
223451 default:
224452 printf("\tUnknown encrypted key(pub %d)\n", PUBLIC);
225453 break;
194194 "signature target(sub 31)",
195195 "embedded signature(sub 32)",
196196 "issuer fingerprint(sub 33)",
197 "preferred_aead_algorithms(sub 34)",
197198 };
198199 #define SIGSUB_NUM (sizeof(SIGSUB) / sizeof(string))
199200
233234 signature_target,
234235 embedded_signature,
235236 issuer_fingerprint,
237 preferred_aead_algorithms,
236238 };
237239
238240 private string
1313 int pflag;
1414 int uflag;
1515
16 private string pgpdump_version = "0.33, Copyright (C) 1998-2017 Kazu Yamamoto";
16 private string pgpdump_version = "0.34, Copyright (C) 1998-2017 Kazu Yamamoto";
1717 private string prog;
1818
1919 private string getprog(void);
8181 public int iv_len(unsigned int);
8282 public void comp_algs(unsigned int);
8383 public void hash_algs(unsigned int);
84 public void aead_algs(unsigned int);
8485 public void key_id(void);
8586 public void fingerprint(void);
8687 public void time4(string);
137138 public void key_expiration_time(int);
138139 public void additional_decryption_key(int);
139140 public void preferred_symmetric_algorithms(int);
141 public void preferred_aead_algorithms(int);
140142 public void revocation_key(int);
141143 public void issuer_key_ID(int);
142144 public void notation_data(int);
1616 dump(2);
1717 printf("\n");
1818 }
19
19 /*
20 * (2021-11-25) Added code for signatures #18, #19, and #22
21 * Reference: https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-04.html
22 */
2023 private void
2124 signature_multi_precision_integer(int pub, int len)
2225 {
3740 multi_precision_integer("DSA s");
3841 printf("\t\t-> hash(DSA q bits)\n");
3942 break;
43 case 18:
44 multi_precision_integer("ECDH G");
45 break;
46 case 19:
47 multi_precision_integer("ECDSA r");
48 multi_precision_integer("ECDSA s");
49 break;
50 case 22:
51 multi_precision_integer("EdDSA R");
52 multi_precision_integer("EdDSA s");
53 break;
4054 default:
4155 printf("\tUnknown signature(pub %d)\n", pub);
4256 skip(len);
95109 printf("Third-Party Confirmation signature(0x50).");
96110 break;
97111 default:
98 printf("unknown(0x%02x)", type);
112 printf("unknown(%02x)", type);
99113 break;
100114 }
101115 printf("\n");
9595 for (i = 0; i < len; i++) {
9696 printf("\t");
9797 sym_algs(Getc());
98 }
99 }
100
101
102 public void
103 preferred_aead_algorithms(int len)
104 {
105 int i;
106 for (i = 0; i < len; i++) {
107 printf("\t");
108 aead_algs(Getc());
98109 }
99110 }
100111
3131 private time_t key_creation_time = 0;
3232 private time_t sig_creation_time = 0;
3333
34 /*
35 * 2021-11-02, "pub 18" description updated
36 * Reference: RFC 6637 (June 2012)
37 */
3438 private string
3539 PUB_ALGS[] = {
3640 "unknown(pub 0)",
5155 "unknown(pub 15)",
5256 "ElGamal Encrypt-Only(pub 16)",
5357 "DSA Digital Signature Algorithm(pub 17)",
54 "Reserved for Elliptic Curve(pub 18)",
58 "ECDH Elliptic Curve Diffie-Hellman Algorithm(pub 18)",
5559 "ECDSA Elliptic Curve Digital Signature Algorithm(pub 19)",
5660 "Reserved formerly ElGamal Encrypt or Sign(pub 20)",
5761 "Reserved for Diffie-Hellman (pub 21)",
5862 "EdDSA Edwards-curve Digital Signature Algorithm(pub 22)",
63 "Reserved - AEDH",
64 "Reserved - AEDSA",
5965 };
6066 #define PUB_ALGS_NUM (sizeof(PUB_ALGS) / sizeof(string))
6167
153159 printf("\n");
154160 }
155161
162 /*
163 * Added: 2021-11-28
164 * Reference: https://datatracker.ietf.org/doc/html/draft-ietf-openpgp-rfc4880bis-10#section-9.6
165 * Section "9.6. AEAD Algorithms"
166 */
167 private string
168 AEAD_ALGS[] = {
169 "unknown(aead 0)",
170 "EAX(aead 1)",
171 "OCB(aead 2)",
172 };
173 #define AEAD_ALGS_NUM (sizeof(AEAD_ALGS) / sizeof(string))
174
175 public void
176 aead_algs(unsigned int type)
177 {
178 printf("\tAEAD alg - ");
179 if (type < AEAD_ALGS_NUM)
180 printf("%s", AEAD_ALGS[type]);
181 else
182 printf("unknown(aead %d)", type);
183 printf("\n");
184 }
185
156186 private string
157187 HASH_ALGS[] = {
158188 "unknown(hash 0)",
167197 "SHA384(hash 9)",
168198 "SHA512(hash 10)",
169199 "SHA224(hash 11)",
200 "SHA3-256(hash 12)",
201 "Reserved(hash 13)",
202 "SHA3-512(hash 14)",
170203 };
171204 #define HASH_ALGS_NUM (sizeof(HASH_ALGS) / sizeof(string))
172205