summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-01-14 08:29:06 +0000
committertb <>2022-01-14 08:29:06 +0000
commit82f4ff947f0f70daa31c164267dbb748f7c3c7ee (patch)
treebf869887a478042f2d395ff26cb94929bc51b5e8 /src
parent96b331528b7ab48983a3d8cb43fcf82cd8f322c3 (diff)
downloadopenbsd-82f4ff947f0f70daa31c164267dbb748f7c3c7ee.tar.gz
openbsd-82f4ff947f0f70daa31c164267dbb748f7c3c7ee.tar.bz2
openbsd-82f4ff947f0f70daa31c164267dbb748f7c3c7ee.zip
Simplify DSAPublicKey_it
This was obtained by porting the OpenSSL commit below and then using expand_crypto_asn1.go to unroll the new ASN.1 macros - actually the ones from 987157f6f63 which fixed the omission of dsa_cb() in the first commit. ok inoguchi jsing commit ea6b07b54c1f8fc2275a121cdda071e2df7bd6c1 Author: Dr. Stephen Henson <steve@openssl.org> Date: Thu Mar 26 14:35:49 2015 +0000 Simplify DSA public key handling. DSA public keys could exist in two forms: a single Integer type or a SEQUENCE containing the parameters and public key with a field called "write_params" deciding which form to use. These forms are non standard and were only used by functions containing "DSAPublicKey" in the name. Simplify code to only use the parameter form and encode the public key component directly in the DSA public key method. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/dsa/dsa_ameth.c12
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c61
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c5
-rw-r--r--src/lib/libcrypto/dsa/dsa_locl.h3
4 files changed, 25 insertions, 56 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c
index 3c7644d251..5fff2890a2 100644
--- a/src/lib/libcrypto/dsa/dsa_ameth.c
+++ b/src/lib/libcrypto/dsa/dsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_ameth.c,v 1.30 2022/01/07 09:35:36 tb Exp $ */ 1/* $OpenBSD: dsa_ameth.c,v 1.31 2022/01/14 08:29:06 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -133,6 +133,7 @@ static int
133dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) 133dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
134{ 134{
135 DSA *dsa; 135 DSA *dsa;
136 ASN1_INTEGER *pubint = NULL;
136 void *pval = NULL; 137 void *pval = NULL;
137 int ptype; 138 int ptype;
138 unsigned char *penc = NULL; 139 unsigned char *penc = NULL;
@@ -158,9 +159,14 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
158 } else 159 } else
159 ptype = V_ASN1_UNDEF; 160 ptype = V_ASN1_UNDEF;
160 161
161 dsa->write_params = 0;
162 162
163 penclen = i2d_DSAPublicKey(dsa, &penc); 163 if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) {
164 DSAerror(ERR_R_MALLOC_FAILURE);
165 goto err;
166 }
167
168 penclen = i2d_ASN1_INTEGER(pubint, &penc);
169 ASN1_INTEGER_free(pubint);
164 170
165 if (penclen <= 0) { 171 if (penclen <= 0) {
166 DSAerror(ERR_R_MALLOC_FAILURE); 172 DSAerror(ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 3bf044665f..daa970e316 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_asn1.c,v 1.23 2022/01/07 09:35:36 tb Exp $ */ 1/* $OpenBSD: dsa_asn1.c,v 1.24 2022/01/14 08:29:06 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -329,14 +329,15 @@ i2d_DSAparams_fp(FILE *fp, DSA *a)
329 return ASN1_item_i2d_fp(&DSAparams_it, fp, a); 329 return ASN1_item_i2d_fp(&DSAparams_it, fp, a);
330} 330}
331 331
332/* 332static const ASN1_AUX DSAPublicKey_aux = {
333 * DSA public key is a bit trickier... its effectively a CHOICE type 333 .app_data = NULL,
334 * decided by a field called write_params which can either write out 334 .flags = 0,
335 * just the public key as an INTEGER or the parameters and public key 335 .ref_offset = 0,
336 * in a SEQUENCE 336 .ref_lock = 0,
337 */ 337 .asn1_cb = dsa_cb,
338 338 .enc_offset = 0,
339static const ASN1_TEMPLATE dsa_pub_internal_seq_tt[] = { 339};
340static const ASN1_TEMPLATE DSAPublicKey_seq_tt[] = {
340 { 341 {
341 .flags = 0, 342 .flags = 0,
342 .tag = 0, 343 .tag = 0,
@@ -367,52 +368,16 @@ static const ASN1_TEMPLATE dsa_pub_internal_seq_tt[] = {
367 }, 368 },
368}; 369};
369 370
370const ASN1_ITEM dsa_pub_internal_it = { 371const ASN1_ITEM DSAPublicKey_it = {
371 .itype = ASN1_ITYPE_SEQUENCE, 372 .itype = ASN1_ITYPE_SEQUENCE,
372 .utype = V_ASN1_SEQUENCE, 373 .utype = V_ASN1_SEQUENCE,
373 .templates = dsa_pub_internal_seq_tt, 374 .templates = DSAPublicKey_seq_tt,
374 .tcount = sizeof(dsa_pub_internal_seq_tt) / sizeof(ASN1_TEMPLATE), 375 .tcount = sizeof(DSAPublicKey_seq_tt) / sizeof(ASN1_TEMPLATE),
375 .funcs = NULL,
376 .size = sizeof(DSA),
377 .sname = "DSA",
378};
379
380static const ASN1_AUX DSAPublicKey_aux = {
381 .app_data = NULL,
382 .flags = 0,
383 .ref_offset = 0,
384 .ref_lock = 0,
385 .asn1_cb = dsa_cb,
386 .enc_offset = 0,
387};
388static const ASN1_TEMPLATE DSAPublicKey_ch_tt[] = {
389 {
390 .flags = 0,
391 .tag = 0,
392 .offset = offsetof(DSA, pub_key),
393 .field_name = "pub_key",
394 .item = &BIGNUM_it,
395 },
396 {
397 .flags = 0 | ASN1_TFLG_COMBINE,
398 .tag = 0,
399 .offset = 0,
400 .field_name = NULL,
401 .item = &dsa_pub_internal_it,
402 },
403};
404
405const ASN1_ITEM DSAPublicKey_it = {
406 .itype = ASN1_ITYPE_CHOICE,
407 .utype = offsetof(DSA, write_params),
408 .templates = DSAPublicKey_ch_tt,
409 .tcount = sizeof(DSAPublicKey_ch_tt) / sizeof(ASN1_TEMPLATE),
410 .funcs = &DSAPublicKey_aux, 376 .funcs = &DSAPublicKey_aux,
411 .size = sizeof(DSA), 377 .size = sizeof(DSA),
412 .sname = "DSA", 378 .sname = "DSA",
413}; 379};
414 380
415
416DSA * 381DSA *
417d2i_DSAPublicKey(DSA **a, const unsigned char **in, long len) 382d2i_DSAPublicKey(DSA **a, const unsigned char **in, long len)
418{ 383{
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 7a7986b1f7..1369c6f745 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_lib.c,v 1.33 2022/01/07 09:35:36 tb Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.34 2022/01/14 08:29:06 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -154,7 +154,6 @@ DSA_new_method(ENGINE *engine)
154 154
155 ret->pad = 0; 155 ret->pad = 0;
156 ret->version = 0; 156 ret->version = 0;
157 ret->write_params = 1;
158 ret->p = NULL; 157 ret->p = NULL;
159 ret->q = NULL; 158 ret->q = NULL;
160 ret->g = NULL; 159 ret->g = NULL;
@@ -177,7 +176,7 @@ DSA_new_method(ENGINE *engine)
177 free(ret); 176 free(ret);
178 ret = NULL; 177 ret = NULL;
179 } 178 }
180 179
181 return ret; 180 return ret;
182} 181}
183 182
diff --git a/src/lib/libcrypto/dsa/dsa_locl.h b/src/lib/libcrypto/dsa/dsa_locl.h
index 29a3901dc7..299c67a6b9 100644
--- a/src/lib/libcrypto/dsa/dsa_locl.h
+++ b/src/lib/libcrypto/dsa/dsa_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_locl.h,v 1.4 2022/01/14 08:27:23 tb Exp $ */ 1/* $OpenBSD: dsa_locl.h,v 1.5 2022/01/14 08:29:06 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -90,7 +90,6 @@ struct dsa_st {
90 * a DSA is passed instead of of a EVP_PKEY */ 90 * a DSA is passed instead of of a EVP_PKEY */
91 int pad; 91 int pad;
92 long version; 92 long version;
93 int write_params;
94 BIGNUM *p; 93 BIGNUM *p;
95 BIGNUM *q; /* == 20 */ 94 BIGNUM *q; /* == 20 */
96 BIGNUM *g; 95 BIGNUM *g;