Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-pkcs1.c
blobe0963a77e89797b26ce26d02bead3e54b41ec3d4
1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
3 /* packet-pkcs1.c */
4 /* asn2wrs.py -b -q -L -p pkcs1 -c ./pkcs1.cnf -s ./packet-pkcs1-template -D . -O ../.. PKIXAlgs-2009.asn */
6 /* packet-pkcs1.c
7 * Routines for PKCS#1/RFC2313 packet dissection
8 * Ronnie Sahlberg 2004
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
19 #include <epan/packet.h>
20 #include <epan/oids.h>
21 #include <epan/asn1.h>
22 #include <wsutil/array.h>
24 #include "packet-ber.h"
25 #include "packet-pkcs1.h"
26 #include "packet-x509af.h"
28 #define PNAME "PKCS#1"
29 #define PSNAME "PKCS-1"
30 #define PFNAME "pkcs-1"
32 void proto_register_pkcs1(void);
33 void proto_reg_handoff_pkcs1(void);
35 /* Initialize the protocol and registered fields */
36 static int proto_pkcs1;
37 static int hf_pkcs1_DSA_Params_PDU; /* DSA_Params */
38 static int hf_pkcs1_DomainParameters_PDU; /* DomainParameters */
39 static int hf_pkcs1_KEA_Params_Id_PDU; /* KEA_Params_Id */
40 static int hf_pkcs1_HashAlgorithm_PDU; /* HashAlgorithm */
41 static int hf_pkcs1_RSASSA_PSS_params_PDU; /* RSASSA_PSS_params */
42 static int hf_pkcs1_ECParameters_PDU; /* ECParameters */
43 static int hf_pkcs1_Prime_p_PDU; /* Prime_p */
44 static int hf_pkcs1_modulus; /* INTEGER */
45 static int hf_pkcs1_publicExponent; /* INTEGER */
46 static int hf_pkcs1_digestAlgorithm; /* DigestAlgorithmIdentifier */
47 static int hf_pkcs1_digest; /* Digest */
48 static int hf_pkcs1_p; /* INTEGER */
49 static int hf_pkcs1_q; /* INTEGER */
50 static int hf_pkcs1_g; /* INTEGER */
51 static int hf_pkcs1_j; /* INTEGER */
52 static int hf_pkcs1_validationParams; /* ValidationParams */
53 static int hf_pkcs1_seed; /* BIT_STRING */
54 static int hf_pkcs1_pgenCounter; /* INTEGER */
55 static int hf_pkcs1_hashAlgorithm; /* HashAlgorithm */
56 static int hf_pkcs1_maskGenAlgorithm; /* MaskGenAlgorithm */
57 static int hf_pkcs1_saltLength; /* INTEGER */
58 static int hf_pkcs1_trailerField; /* INTEGER */
59 static int hf_pkcs1_specifiedCurve; /* SpecifiedECDomain */
60 static int hf_pkcs1_namedCurve; /* OBJECT_IDENTIFIER */
61 static int hf_pkcs1_version; /* ECPVer */
62 static int hf_pkcs1_fieldID; /* FieldID */
63 static int hf_pkcs1_curve; /* Curve */
64 static int hf_pkcs1_base; /* ECPoint */
65 static int hf_pkcs1_order; /* INTEGER */
66 static int hf_pkcs1_cofactor; /* INTEGER */
67 static int hf_pkcs1_fieldType; /* T_fieldType */
68 static int hf_pkcs1_parameters; /* T_parameters */
69 static int hf_pkcs1_a; /* FieldElement */
70 static int hf_pkcs1_b; /* FieldElement */
71 static int hf_pkcs1_r; /* INTEGER */
72 static int hf_pkcs1_s; /* INTEGER */
74 /* Initialize the subtree pointers */
75 static int ett_pkcs1_RSAPublicKey;
76 static int ett_pkcs1_DigestInfo;
77 static int ett_pkcs1_DSA_Params;
78 static int ett_pkcs1_DomainParameters;
79 static int ett_pkcs1_ValidationParams;
80 static int ett_pkcs1_RSASSA_PSS_params;
81 static int ett_pkcs1_ECParameters;
82 static int ett_pkcs1_SpecifiedECDomain;
83 static int ett_pkcs1_FieldID;
84 static int ett_pkcs1_Curve;
85 static int ett_pkcs1_DSA_Sig_Value;
86 static int ett_pkcs1_ECDSA_Sig_Value;
90 static int
91 dissect_pkcs1_INTEGER(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
92 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
93 NULL);
95 return offset;
99 static const ber_sequence_t RSAPublicKey_sequence[] = {
100 { &hf_pkcs1_modulus , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
101 { &hf_pkcs1_publicExponent, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
102 { NULL, 0, 0, 0, NULL }
106 dissect_pkcs1_RSAPublicKey(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
107 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
108 RSAPublicKey_sequence, hf_index, ett_pkcs1_RSAPublicKey);
110 return offset;
115 static int
116 dissect_pkcs1_DigestAlgorithmIdentifier(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
117 offset = dissect_x509af_AlgorithmIdentifier(implicit_tag, tvb, offset, actx, tree, hf_index);
119 return offset;
124 static int
125 dissect_pkcs1_Digest(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
126 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
127 NULL);
129 return offset;
133 static const ber_sequence_t DigestInfo_sequence[] = {
134 { &hf_pkcs1_digestAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs1_DigestAlgorithmIdentifier },
135 { &hf_pkcs1_digest , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs1_Digest },
136 { NULL, 0, 0, 0, NULL }
140 dissect_pkcs1_DigestInfo(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
141 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
142 DigestInfo_sequence, hf_index, ett_pkcs1_DigestInfo);
144 return offset;
148 static const ber_sequence_t DSA_Params_sequence[] = {
149 { &hf_pkcs1_p , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
150 { &hf_pkcs1_q , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
151 { &hf_pkcs1_g , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
152 { NULL, 0, 0, 0, NULL }
155 static int
156 dissect_pkcs1_DSA_Params(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
157 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
158 DSA_Params_sequence, hf_index, ett_pkcs1_DSA_Params);
160 return offset;
166 static int
167 dissect_pkcs1_BIT_STRING(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
168 offset = dissect_ber_bitstring(implicit_tag, actx, tree, tvb, offset,
169 NULL, 0, hf_index, -1,
170 NULL);
172 return offset;
176 static const ber_sequence_t ValidationParams_sequence[] = {
177 { &hf_pkcs1_seed , BER_CLASS_UNI, BER_UNI_TAG_BITSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs1_BIT_STRING },
178 { &hf_pkcs1_pgenCounter , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
179 { NULL, 0, 0, 0, NULL }
182 static int
183 dissect_pkcs1_ValidationParams(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
184 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
185 ValidationParams_sequence, hf_index, ett_pkcs1_ValidationParams);
187 return offset;
191 static const ber_sequence_t DomainParameters_sequence[] = {
192 { &hf_pkcs1_p , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
193 { &hf_pkcs1_g , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
194 { &hf_pkcs1_q , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
195 { &hf_pkcs1_j , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
196 { &hf_pkcs1_validationParams, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs1_ValidationParams },
197 { NULL, 0, 0, 0, NULL }
200 static int
201 dissect_pkcs1_DomainParameters(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
202 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
203 DomainParameters_sequence, hf_index, ett_pkcs1_DomainParameters);
205 return offset;
211 static int
212 dissect_pkcs1_KEA_Params_Id(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
213 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
214 NULL);
216 return offset;
221 static int
222 dissect_pkcs1_HashAlgorithm(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
223 offset = dissect_x509af_AlgorithmIdentifier(implicit_tag, tvb, offset, actx, tree, hf_index);
225 return offset;
230 static int
231 dissect_pkcs1_MaskGenAlgorithm(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
232 offset = dissect_x509af_AlgorithmIdentifier(implicit_tag, tvb, offset, actx, tree, hf_index);
234 return offset;
238 static const ber_sequence_t RSASSA_PSS_params_sequence[] = {
239 { &hf_pkcs1_hashAlgorithm , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_pkcs1_HashAlgorithm },
240 { &hf_pkcs1_maskGenAlgorithm, BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL, dissect_pkcs1_MaskGenAlgorithm },
241 { &hf_pkcs1_saltLength , BER_CLASS_CON, 2, BER_FLAGS_OPTIONAL, dissect_pkcs1_INTEGER },
242 { &hf_pkcs1_trailerField , BER_CLASS_CON, 3, BER_FLAGS_OPTIONAL, dissect_pkcs1_INTEGER },
243 { NULL, 0, 0, 0, NULL }
246 static int
247 dissect_pkcs1_RSASSA_PSS_params(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
248 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
249 RSASSA_PSS_params_sequence, hf_index, ett_pkcs1_RSASSA_PSS_params);
251 return offset;
256 static int
257 dissect_pkcs1_ECPoint(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
258 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
259 NULL);
261 return offset;
265 static const value_string pkcs1_ECPVer_vals[] = {
266 { 1, "ecpVer1" },
267 { 0, NULL }
271 static int
272 dissect_pkcs1_ECPVer(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
273 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
274 NULL);
276 return offset;
281 static int
282 dissect_pkcs1_T_fieldType(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
283 offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &actx->external.direct_reference);
285 return offset;
290 static int
291 dissect_pkcs1_T_parameters(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
292 offset = call_ber_oid_callback(actx->external.direct_reference, tvb, offset, actx->pinfo, tree, NULL);
295 return offset;
299 static const ber_sequence_t FieldID_sequence[] = {
300 { &hf_pkcs1_fieldType , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs1_T_fieldType },
301 { &hf_pkcs1_parameters , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_pkcs1_T_parameters },
302 { NULL, 0, 0, 0, NULL }
305 static int
306 dissect_pkcs1_FieldID(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
307 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
308 FieldID_sequence, hf_index, ett_pkcs1_FieldID);
310 return offset;
315 static int
316 dissect_pkcs1_FieldElement(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
317 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
318 NULL);
320 return offset;
324 static const ber_sequence_t Curve_sequence[] = {
325 { &hf_pkcs1_a , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs1_FieldElement },
326 { &hf_pkcs1_b , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs1_FieldElement },
327 { &hf_pkcs1_seed , BER_CLASS_UNI, BER_UNI_TAG_BITSTRING, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs1_BIT_STRING },
328 { NULL, 0, 0, 0, NULL }
331 static int
332 dissect_pkcs1_Curve(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
333 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
334 Curve_sequence, hf_index, ett_pkcs1_Curve);
336 return offset;
340 static const ber_sequence_t SpecifiedECDomain_sequence[] = {
341 { &hf_pkcs1_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_ECPVer },
342 { &hf_pkcs1_fieldID , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs1_FieldID },
343 { &hf_pkcs1_curve , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs1_Curve },
344 { &hf_pkcs1_base , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs1_ECPoint },
345 { &hf_pkcs1_order , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
346 { &hf_pkcs1_cofactor , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_pkcs1_INTEGER },
347 { NULL, 0, 0, 0, NULL }
350 static int
351 dissect_pkcs1_SpecifiedECDomain(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
352 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
353 SpecifiedECDomain_sequence, hf_index, ett_pkcs1_SpecifiedECDomain);
355 return offset;
360 static int
361 dissect_pkcs1_OBJECT_IDENTIFIER(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
362 offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
364 return offset;
368 static const value_string pkcs1_ECParameters_vals[] = {
369 { 0, "specifiedCurve" },
370 { 1, "namedCurve" },
371 { 0, NULL }
374 static const ber_choice_t ECParameters_choice[] = {
375 { 0, &hf_pkcs1_specifiedCurve, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs1_SpecifiedECDomain },
376 { 1, &hf_pkcs1_namedCurve , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs1_OBJECT_IDENTIFIER },
377 { 0, NULL, 0, 0, 0, NULL }
380 static int
381 dissect_pkcs1_ECParameters(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
382 offset = dissect_ber_choice(actx, tree, tvb, offset,
383 ECParameters_choice, hf_index, ett_pkcs1_ECParameters,
384 NULL);
386 return offset;
391 static int
392 dissect_pkcs1_Prime_p(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
393 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
394 NULL);
396 return offset;
401 /*--- PDUs ---*/
403 static int dissect_DSA_Params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
404 int offset = 0;
405 asn1_ctx_t asn1_ctx;
406 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
407 offset = dissect_pkcs1_DSA_Params(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_DSA_Params_PDU);
408 return offset;
410 static int dissect_DomainParameters_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
411 int offset = 0;
412 asn1_ctx_t asn1_ctx;
413 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
414 offset = dissect_pkcs1_DomainParameters(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_DomainParameters_PDU);
415 return offset;
417 static int dissect_KEA_Params_Id_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
418 int offset = 0;
419 asn1_ctx_t asn1_ctx;
420 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
421 offset = dissect_pkcs1_KEA_Params_Id(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_KEA_Params_Id_PDU);
422 return offset;
424 static int dissect_HashAlgorithm_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
425 int offset = 0;
426 asn1_ctx_t asn1_ctx;
427 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
428 offset = dissect_pkcs1_HashAlgorithm(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_HashAlgorithm_PDU);
429 return offset;
431 static int dissect_RSASSA_PSS_params_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
432 int offset = 0;
433 asn1_ctx_t asn1_ctx;
434 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
435 offset = dissect_pkcs1_RSASSA_PSS_params(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_RSASSA_PSS_params_PDU);
436 return offset;
438 static int dissect_ECParameters_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
439 int offset = 0;
440 asn1_ctx_t asn1_ctx;
441 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
442 offset = dissect_pkcs1_ECParameters(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_ECParameters_PDU);
443 return offset;
445 static int dissect_Prime_p_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
446 int offset = 0;
447 asn1_ctx_t asn1_ctx;
448 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
449 offset = dissect_pkcs1_Prime_p(false, tvb, offset, &asn1_ctx, tree, hf_pkcs1_Prime_p_PDU);
450 return offset;
454 /*--- proto_register_pkcs1 ----------------------------------------------*/
455 void proto_register_pkcs1(void) {
457 /* List of fields */
458 static hf_register_info hf[] = {
459 { &hf_pkcs1_DSA_Params_PDU,
460 { "DSA-Params", "pkcs1.DSA_Params_element",
461 FT_NONE, BASE_NONE, NULL, 0,
462 NULL, HFILL }},
463 { &hf_pkcs1_DomainParameters_PDU,
464 { "DomainParameters", "pkcs1.DomainParameters_element",
465 FT_NONE, BASE_NONE, NULL, 0,
466 NULL, HFILL }},
467 { &hf_pkcs1_KEA_Params_Id_PDU,
468 { "KEA-Params-Id", "pkcs1.KEA_Params_Id",
469 FT_BYTES, BASE_NONE, NULL, 0,
470 NULL, HFILL }},
471 { &hf_pkcs1_HashAlgorithm_PDU,
472 { "HashAlgorithm", "pkcs1.HashAlgorithm_element",
473 FT_NONE, BASE_NONE, NULL, 0,
474 NULL, HFILL }},
475 { &hf_pkcs1_RSASSA_PSS_params_PDU,
476 { "RSASSA-PSS-params", "pkcs1.RSASSA_PSS_params_element",
477 FT_NONE, BASE_NONE, NULL, 0,
478 NULL, HFILL }},
479 { &hf_pkcs1_ECParameters_PDU,
480 { "ECParameters", "pkcs1.ECParameters",
481 FT_UINT32, BASE_DEC, VALS(pkcs1_ECParameters_vals), 0,
482 NULL, HFILL }},
483 { &hf_pkcs1_Prime_p_PDU,
484 { "Prime-p", "pkcs1.Prime_p",
485 FT_INT32, BASE_DEC, NULL, 0,
486 NULL, HFILL }},
487 { &hf_pkcs1_modulus,
488 { "modulus", "pkcs1.modulus",
489 FT_BYTES, BASE_NONE, NULL, 0,
490 "INTEGER", HFILL }},
491 { &hf_pkcs1_publicExponent,
492 { "publicExponent", "pkcs1.publicExponent",
493 FT_INT32, BASE_DEC, NULL, 0,
494 "INTEGER", HFILL }},
495 { &hf_pkcs1_digestAlgorithm,
496 { "digestAlgorithm", "pkcs1.digestAlgorithm_element",
497 FT_NONE, BASE_NONE, NULL, 0,
498 "DigestAlgorithmIdentifier", HFILL }},
499 { &hf_pkcs1_digest,
500 { "digest", "pkcs1.digest",
501 FT_BYTES, BASE_NONE, NULL, 0,
502 NULL, HFILL }},
503 { &hf_pkcs1_p,
504 { "p", "pkcs1.p",
505 FT_INT32, BASE_DEC, NULL, 0,
506 "INTEGER", HFILL }},
507 { &hf_pkcs1_q,
508 { "q", "pkcs1.q",
509 FT_INT32, BASE_DEC, NULL, 0,
510 "INTEGER", HFILL }},
511 { &hf_pkcs1_g,
512 { "g", "pkcs1.g",
513 FT_INT32, BASE_DEC, NULL, 0,
514 "INTEGER", HFILL }},
515 { &hf_pkcs1_j,
516 { "j", "pkcs1.j",
517 FT_INT32, BASE_DEC, NULL, 0,
518 "INTEGER", HFILL }},
519 { &hf_pkcs1_validationParams,
520 { "validationParams", "pkcs1.validationParams_element",
521 FT_NONE, BASE_NONE, NULL, 0,
522 NULL, HFILL }},
523 { &hf_pkcs1_seed,
524 { "seed", "pkcs1.seed",
525 FT_BYTES, BASE_NONE, NULL, 0,
526 "BIT_STRING", HFILL }},
527 { &hf_pkcs1_pgenCounter,
528 { "pgenCounter", "pkcs1.pgenCounter",
529 FT_INT32, BASE_DEC, NULL, 0,
530 "INTEGER", HFILL }},
531 { &hf_pkcs1_hashAlgorithm,
532 { "hashAlgorithm", "pkcs1.hashAlgorithm_element",
533 FT_NONE, BASE_NONE, NULL, 0,
534 NULL, HFILL }},
535 { &hf_pkcs1_maskGenAlgorithm,
536 { "maskGenAlgorithm", "pkcs1.maskGenAlgorithm_element",
537 FT_NONE, BASE_NONE, NULL, 0,
538 NULL, HFILL }},
539 { &hf_pkcs1_saltLength,
540 { "saltLength", "pkcs1.saltLength",
541 FT_INT32, BASE_DEC, NULL, 0,
542 "INTEGER", HFILL }},
543 { &hf_pkcs1_trailerField,
544 { "trailerField", "pkcs1.trailerField",
545 FT_INT32, BASE_DEC, NULL, 0,
546 "INTEGER", HFILL }},
547 { &hf_pkcs1_specifiedCurve,
548 { "specifiedCurve", "pkcs1.specifiedCurve_element",
549 FT_NONE, BASE_NONE, NULL, 0,
550 "SpecifiedECDomain", HFILL }},
551 { &hf_pkcs1_namedCurve,
552 { "namedCurve", "pkcs1.namedCurve",
553 FT_OID, BASE_NONE, NULL, 0,
554 "OBJECT_IDENTIFIER", HFILL }},
555 { &hf_pkcs1_version,
556 { "version", "pkcs1.version",
557 FT_INT32, BASE_DEC, VALS(pkcs1_ECPVer_vals), 0,
558 "ECPVer", HFILL }},
559 { &hf_pkcs1_fieldID,
560 { "fieldID", "pkcs1.fieldID_element",
561 FT_NONE, BASE_NONE, NULL, 0,
562 NULL, HFILL }},
563 { &hf_pkcs1_curve,
564 { "curve", "pkcs1.curve_element",
565 FT_NONE, BASE_NONE, NULL, 0,
566 NULL, HFILL }},
567 { &hf_pkcs1_base,
568 { "base", "pkcs1.base",
569 FT_BYTES, BASE_NONE, NULL, 0,
570 "ECPoint", HFILL }},
571 { &hf_pkcs1_order,
572 { "order", "pkcs1.order",
573 FT_INT32, BASE_DEC, NULL, 0,
574 "INTEGER", HFILL }},
575 { &hf_pkcs1_cofactor,
576 { "cofactor", "pkcs1.cofactor",
577 FT_INT32, BASE_DEC, NULL, 0,
578 "INTEGER", HFILL }},
579 { &hf_pkcs1_fieldType,
580 { "fieldType", "pkcs1.fieldType",
581 FT_OID, BASE_NONE, NULL, 0,
582 NULL, HFILL }},
583 { &hf_pkcs1_parameters,
584 { "parameters", "pkcs1.parameters_element",
585 FT_NONE, BASE_NONE, NULL, 0,
586 NULL, HFILL }},
587 { &hf_pkcs1_a,
588 { "a", "pkcs1.a",
589 FT_BYTES, BASE_NONE, NULL, 0,
590 "FieldElement", HFILL }},
591 { &hf_pkcs1_b,
592 { "b", "pkcs1.b",
593 FT_BYTES, BASE_NONE, NULL, 0,
594 "FieldElement", HFILL }},
595 { &hf_pkcs1_r,
596 { "r", "pkcs1.r",
597 FT_INT32, BASE_DEC, NULL, 0,
598 "INTEGER", HFILL }},
599 { &hf_pkcs1_s,
600 { "s", "pkcs1.s",
601 FT_INT32, BASE_DEC, NULL, 0,
602 "INTEGER", HFILL }},
605 /* List of subtrees */
606 static int *ett[] = {
607 &ett_pkcs1_RSAPublicKey,
608 &ett_pkcs1_DigestInfo,
609 &ett_pkcs1_DSA_Params,
610 &ett_pkcs1_DomainParameters,
611 &ett_pkcs1_ValidationParams,
612 &ett_pkcs1_RSASSA_PSS_params,
613 &ett_pkcs1_ECParameters,
614 &ett_pkcs1_SpecifiedECDomain,
615 &ett_pkcs1_FieldID,
616 &ett_pkcs1_Curve,
617 &ett_pkcs1_DSA_Sig_Value,
618 &ett_pkcs1_ECDSA_Sig_Value,
621 /* Register protocol */
622 proto_pkcs1 = proto_register_protocol(PNAME, PSNAME, PFNAME);
624 /* Register fields and subtrees */
625 proto_register_field_array(proto_pkcs1, hf, array_length(hf));
626 proto_register_subtree_array(ett, array_length(ett));
631 /*--- proto_reg_handoff_pkcs1 -------------------------------------------*/
632 void proto_reg_handoff_pkcs1(void) {
633 register_ber_oid_dissector("1.2.840.10040.4.1", dissect_DSA_Params_PDU, proto_pkcs1, "id-dsa");
634 register_ber_oid_dissector("1.2.840.10046.2.1", dissect_DomainParameters_PDU, proto_pkcs1, "dhpublicnumber");
635 register_ber_oid_dissector("2.16.840.1.101.2.1.1.22", dissect_KEA_Params_Id_PDU, proto_pkcs1, "id-keyExchangeAlgorithm");
636 register_ber_oid_dissector("1.2.840.10045.2.1", dissect_ECParameters_PDU, proto_pkcs1, "id-ecPublicKey");
637 register_ber_oid_dissector("1.3.132.1.12", dissect_ECParameters_PDU, proto_pkcs1, "id-ecDH");
638 register_ber_oid_dissector("1.2.840.10045.2.13", dissect_ECParameters_PDU, proto_pkcs1, "id-ecMQV");
639 register_ber_oid_dissector("1.2.840.113549.1.1.10", dissect_RSASSA_PSS_params_PDU, proto_pkcs1, "id-RSASSA-PSS");
640 register_ber_oid_dissector("1.2.840.113549.1.1.8", dissect_HashAlgorithm_PDU, proto_pkcs1, "id-mgf1");
641 register_ber_oid_dissector("1.2.840.10045.1.1", dissect_Prime_p_PDU, proto_pkcs1, "prime-field");
644 register_ber_oid_dissector("1.2.840.113549.2.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "md2");
645 register_ber_oid_dissector("1.2.840.113549.2.4", dissect_ber_oid_NULL_callback, proto_pkcs1, "md4");
646 register_ber_oid_dissector("1.2.840.113549.2.5", dissect_ber_oid_NULL_callback, proto_pkcs1, "md5");
648 register_ber_oid_dissector("1.2.840.113549.1.1.1", dissect_ber_oid_NULL_callback, proto_pkcs1, "rsaEncryption");
649 register_ber_oid_dissector("1.2.840.113549.1.1.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "md2WithRSAEncryption");
650 register_ber_oid_dissector("1.2.840.113549.1.1.3", dissect_ber_oid_NULL_callback, proto_pkcs1, "md4WithRSAEncryption");
651 register_ber_oid_dissector("1.2.840.113549.1.1.4", dissect_ber_oid_NULL_callback, proto_pkcs1, "md5WithRSAEncryption");
654 /* these two are not from RFC2313 but pulled in from
655 http://www.alvestrand.no/objectid/1.2.840.113549.1.1.html
657 register_ber_oid_dissector("1.2.840.113549.1.1.5", dissect_ber_oid_NULL_callback, proto_pkcs1, "sha1WithRSAEncryption");
658 register_ber_oid_dissector("1.2.840.113549.1.1.6", dissect_ber_oid_NULL_callback, proto_pkcs1, "rsaOAEPEncryptionSET");
660 /* these sha2 algorithms are from RFC3447 */
661 register_ber_oid_dissector("1.2.840.113549.1.1.11", dissect_ber_oid_NULL_callback, proto_pkcs1, "sha256WithRSAEncryption");
662 register_ber_oid_dissector("1.2.840.113549.1.1.12", dissect_ber_oid_NULL_callback, proto_pkcs1, "sha384WithRSAEncryption");
663 register_ber_oid_dissector("1.2.840.113549.1.1.13", dissect_ber_oid_NULL_callback, proto_pkcs1, "sha512WithRSAEncryption");
664 register_ber_oid_dissector("1.2.840.113549.1.1.14", dissect_ber_oid_NULL_callback, proto_pkcs1, "sha224WithRSAEncryption");
666 /* ECDSA SHA-1 algorithm from RFC 3279 */
667 register_ber_oid_dissector("1.2.840.10045.4.1", dissect_ber_oid_NULL_callback, proto_pkcs1, "ecdsa-with-SHA1");
669 /* SM2-with-SM3 from GM/T 0006 Cryptographic application identifier criterion specification */
670 register_ber_oid_dissector("1.2.156.10197.1.501", dissect_ber_oid_NULL_callback, proto_pkcs1, "SM2-with-SM3");
672 /* ECDSA SHA2 algorithms from X9.62, RFC5480, RFC 5758, RFC 5912 */
673 register_ber_oid_dissector("1.2.840.10045.4.3.1", dissect_ber_oid_NULL_callback, proto_pkcs1, "ecdsa-with-SHA224");
674 register_ber_oid_dissector("1.2.840.10045.4.3.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "ecdsa-with-SHA256");
675 register_ber_oid_dissector("1.2.840.10045.4.3.3", dissect_ber_oid_NULL_callback, proto_pkcs1, "ecdsa-with-SHA384");
676 register_ber_oid_dissector("1.2.840.10045.4.3.4", dissect_ber_oid_NULL_callback, proto_pkcs1, "ecdsa-with-SHA512");
678 /* DSA SHA2 algorithms from FIPS186-3, RFC5480, RFC 5758, RFC 5912 */
679 register_ber_oid_dissector("2.16.840.1.101.3.4.3.1", dissect_ber_oid_NULL_callback, proto_pkcs1, "id-dsa-with-sha224");
680 register_ber_oid_dissector("2.16.840.1.101.3.4.3.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "id-dsa-with-sha256");
682 oid_add_from_string("secp192r1","1.2.840.10045.3.1.1");
683 oid_add_from_string("sect163k1","1.3.132.0.1");
684 oid_add_from_string("sect163r2","1.3.132.0.15");
685 oid_add_from_string("secp224r1","1.3.132.0.33");
686 oid_add_from_string("sect233k1","1.3.132.0.26");
687 oid_add_from_string("sect233r1","1.3.132.0.27");
688 oid_add_from_string("secp256r1","1.2.840.10045.3.1.7");
689 oid_add_from_string("sect283k1","1.3.132.0.16");
690 oid_add_from_string("sect283r1","1.3.132.0.17");
691 oid_add_from_string("secp384r1","1.3.132.0.34");
692 oid_add_from_string("sect409k1","1.3.132.0.36");
693 oid_add_from_string("sect409r1","1.3.132.0.37");
694 oid_add_from_string("secp521r1","1.3.132.0.35");
695 oid_add_from_string("sect571k1","1.3.132.0.38");
696 oid_add_from_string("sect571r1","1.3.132.0.39");
698 /* SM2 from GM/T 0006 Cryptographic application identifier criterion specification */
699 oid_add_from_string("sm2","1.2.156.10197.1.301");
701 /* sha2 family, see RFC3447 and http://www.oid-info.com/get/2.16.840.1.101.3.4.2 */
702 oid_add_from_string("sha256", "2.16.840.1.101.3.4.2.1");
703 oid_add_from_string("sha384", "2.16.840.1.101.3.4.2.2");
704 oid_add_from_string("sha512", "2.16.840.1.101.3.4.2.3");
705 oid_add_from_string("sha224", "2.16.840.1.101.3.4.2.4");
707 /* SM3 from GM/T 0006 Cryptographic application identifier criterion specification */
708 oid_add_from_string("sm3","1.2.156.10197.1.401");
710 /* PQC digital signature algorithms from OQS-OpenSSL,
711 see https://github.com/open-quantum-safe/openssl/blob/OQS-OpenSSL_1_1_1-stable/oqs-template/oqs-sig-info.md */
712 oid_add_from_string("dilithium2", "1.3.6.1.4.1.2.267.7.4.4");
713 oid_add_from_string("p256_dilithium2", "1.3.9999.2.7.1");
714 oid_add_from_string("rsa3072_dilithium2", "1.3.9999.2.7.2");
715 oid_add_from_string("dilithium3", "1.3.6.1.4.1.2.267.7.6.5");
716 oid_add_from_string("p384_dilithium3", "1.3.9999.2.7.3");
717 oid_add_from_string("dilithium5", "1.3.6.1.4.1.2.267.7.8.7");
718 oid_add_from_string("p521_dilithium5", "1.3.9999.2.7.4");
719 oid_add_from_string("dilithium2_aes", "1.3.6.1.4.1.2.267.11.4.4");
720 oid_add_from_string("p256_dilithium2_aes", "1.3.9999.2.11.1");
721 oid_add_from_string("rsa3072_dilithium2_aes", "1.3.9999.2.11.2");
722 oid_add_from_string("dilithium3_aes", "1.3.6.1.4.1.2.267.11.6.5");
723 oid_add_from_string("p384_dilithium3_aes", "1.3.9999.2.11.3");
724 oid_add_from_string("dilithium5_aes", "1.3.6.1.4.1.2.267.11.8.7");
725 oid_add_from_string("p521_dilithium5_aes", "1.3.9999.2.11.4");
726 oid_add_from_string("falcon512", "1.3.9999.3.1");
727 oid_add_from_string("p256_falcon512", "1.3.9999.3.2");
728 oid_add_from_string("rsa3072_falcon512", "1.3.9999.3.3");
729 oid_add_from_string("falcon1024", "1.3.9999.3.4");
730 oid_add_from_string("p521_falcon1024", "1.3.9999.3.5");
731 oid_add_from_string("picnicl1full", "1.3.6.1.4.1.311.89.2.1.7");
732 oid_add_from_string("p256_picnicl1full", "1.3.6.1.4.1.311.89.2.1.8");
733 oid_add_from_string("rsa3072_picnicl1full", "1.3.6.1.4.1.311.89.2.1.9");
734 oid_add_from_string("picnic3l1", "1.3.6.1.4.1.311.89.2.1.21");
735 oid_add_from_string("p256_picnic3l1", "1.3.6.1.4.1.311.89.2.1.22");
736 oid_add_from_string("rsa3072_picnic3l1", "1.3.6.1.4.1.311.89.2.1.23");
737 oid_add_from_string("rainbowIclassic", "1.3.9999.5.1.1.1");
738 oid_add_from_string("p256_rainbowIclassic", "1.3.9999.5.1.2.1");
739 oid_add_from_string("rsa3072_rainbowIclassic", "1.3.9999.5.1.3.1");
740 oid_add_from_string("rainbowVclassic", "1.3.9999.5.3.1.1");
741 oid_add_from_string("p521_rainbowVclassic", "1.3.9999.5.3.2.1");
742 oid_add_from_string("sphincsharaka128frobust", "1.3.9999.6.1.1");
743 oid_add_from_string("p256_sphincsharaka128frobust", "1.3.9999.6.1.2");
744 oid_add_from_string("rsa3072_sphincsharaka128frobust", "1.3.9999.6.1.3");
745 oid_add_from_string("sphincssha256128frobust", "1.3.9999.6.4.1");
746 oid_add_from_string("p256_sphincssha256128frobust", "1.3.9999.6.4.2");
747 oid_add_from_string("rsa3072_sphincssha256128frobust", "1.3.9999.6.4.3");
748 oid_add_from_string("sphincsshake256128frobust", "1.3.9999.6.7.1");
749 oid_add_from_string("p256_sphincsshake256128frobust", "1.3.9999.6.7.2");
750 oid_add_from_string("rsa3072_sphincsshake256128frobust", "1.3.9999.6.7.3");