This commit is contained in:
purplerain 2023-05-02 22:23:09 +00:00
parent 01bad5edf2
commit f609457dcf
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
85 changed files with 1589 additions and 1491 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec_curve.c,v 1.39 2023/05/01 17:53:01 tb Exp $ */
/* $OpenBSD: ec_curve.c,v 1.41 2023/05/02 13:01:57 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
@ -3000,11 +3000,10 @@ static const struct ec_list_element {
static EC_GROUP *
ec_group_new_from_data(const struct ec_list_element *curve)
{
EC_GROUP *group = NULL;
EC_POINT *P = NULL;
EC_GROUP *group = NULL, *ret = NULL;
EC_POINT *generator = NULL;
BN_CTX *ctx = NULL;
BIGNUM *p, *a, *b, *x, *y, *order, *cofactor;
int ok = 0;
if ((ctx = BN_CTX_new()) == NULL) {
ECerror(ERR_R_MALLOC_FAILURE);
@ -3057,8 +3056,9 @@ ec_group_new_from_data(const struct ec_list_element *curve)
ECerror(ERR_R_EC_LIB);
goto err;
}
EC_GROUP_set_curve_name(group, curve->nid);
if ((P = EC_POINT_new(group)) == NULL) {
if ((generator = EC_POINT_new(group)) == NULL) {
ECerror(ERR_R_EC_LIB);
goto err;
}
@ -3070,7 +3070,7 @@ ec_group_new_from_data(const struct ec_list_element *curve)
ECerror(ERR_R_BN_LIB);
goto err;
}
if (!EC_POINT_set_affine_coordinates(group, P, x, y, ctx)) {
if (!EC_POINT_set_affine_coordinates(group, generator, x, y, ctx)) {
ECerror(ERR_R_EC_LIB);
goto err;
}
@ -3082,51 +3082,45 @@ ec_group_new_from_data(const struct ec_list_element *curve)
ECerror(ERR_R_BN_LIB);
goto err;
}
if (!EC_GROUP_set_generator(group, P, order, cofactor)) {
if (!EC_GROUP_set_generator(group, generator, order, cofactor)) {
ECerror(ERR_R_EC_LIB);
goto err;
}
if (curve->seed != NULL) {
if (!EC_GROUP_set_seed(group, curve->seed, curve->seed_len)) {
ECerror(ERR_R_EC_LIB);
goto err;
}
}
ok = 1;
ret = group;
group = NULL;
err:
if (!ok) {
EC_GROUP_free(group);
group = NULL;
}
EC_POINT_free(P);
EC_GROUP_free(group);
EC_POINT_free(generator);
BN_CTX_end(ctx);
BN_CTX_free(ctx);
return group;
return ret;
}
EC_GROUP *
EC_GROUP_new_by_curve_name(int nid)
{
size_t i;
EC_GROUP *ret = NULL;
if (nid <= 0)
return NULL;
for (i = 0; i < CURVE_LIST_LENGTH; i++) {
if (curve_list[i].nid == nid) {
ret = ec_group_new_from_data(&curve_list[i]);
break;
}
if (curve_list[i].nid == nid)
return ec_group_new_from_data(&curve_list[i]);
}
if (ret == NULL) {
ECerror(EC_R_UNKNOWN_GROUP);
return NULL;
}
EC_GROUP_set_curve_name(ret, nid);
return ret;
ECerror(EC_R_UNKNOWN_GROUP);
return NULL;
}
size_t

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: X509_NAME_get_index_by_NID.3,v 1.13 2022/07/02 17:09:09 jsing Exp $
.\" $OpenBSD: X509_NAME_get_index_by_NID.3,v 1.14 2023/05/02 14:13:05 beck Exp $
.\" OpenSSL aebb9aac Jul 19 09:27:53 2016 -0400
.\"
.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
@ -49,7 +49,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: July 2 2022 $
.Dd $Mdocdate: May 2 2023 $
.Dt X509_NAME_GET_INDEX_BY_NID 3
.Os
.Sh NAME
@ -136,22 +136,32 @@ run from 0 to
.Fn X509_NAME_get_text_by_NID
and
.Fn X509_NAME_get_text_by_OBJ
retrieve the "text" from the first entry in
retrieve the bytes encoded as UTF-8 from the first entry in
.Fa name
which matches
.Fa nid
or
.Fa obj .
At most
.Fa len
bytes will be written and the text written to
.Fa buf
will be NUL terminated.
If
.Fa buf
is
.Dv NULL ,
nothing is written, but the return value is calculated as usual.
If
.Fa buf
is not
.Dv NULL ,
no more than
.Fa len
bytes will be written and the text written to
.Fa buf
will be NUL terminated.
.Pp
Nothing is written and it is a failure if
.Fa len
is not large enough to hold the NUL byte terminated UTF-8 encoding of
the text, or if the UTF-8 encoding ot the text would contins a NUL
byte.
.Pp
All relevant
.Dv NID_*
@ -189,8 +199,8 @@ if the index is invalid.
.Fn X509_NAME_get_text_by_NID
and
.Fn X509_NAME_get_text_by_OBJ
return the length of the output string written, not counting the
terminating NUL, or -1 if no match is found.
return the length of the output UTF-8 string written, not counting the
terminating NUL, or -1 in the case of an error or no match being found.
.Pp
In some cases of failure of
.Fn X509_NAME_get_index_by_NID

View file

@ -1,4 +1,4 @@
/* $OpenBSD: pk7_mime.c,v 1.17 2023/04/26 14:25:58 tb Exp $ */
/* $OpenBSD: pk7_mime.c,v 1.19 2023/05/02 09:56:12 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
*/
@ -71,8 +71,7 @@ LCRYPTO_ALIAS(BIO_new_PKCS7);
int
i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
{
return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)p7, in, flags,
&PKCS7_it);
return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)p7, in, flags, &PKCS7_it);
}
LCRYPTO_ALIAS(i2d_PKCS7_bio_stream);
@ -87,16 +86,14 @@ LCRYPTO_ALIAS(PEM_write_bio_PKCS7_stream);
int
SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
{
STACK_OF(X509_ALGOR) *mdalgs;
int ctype_nid = OBJ_obj2nid(p7->type);
if (ctype_nid == NID_pkcs7_signed)
STACK_OF(X509_ALGOR) *mdalgs = NULL;
int ctype_nid;
if ((ctype_nid = OBJ_obj2nid(p7->type)) == NID_pkcs7_signed)
mdalgs = p7->d.sign->md_algs;
else
mdalgs = NULL;
flags ^= SMIME_OLDMIME;
return SMIME_write_ASN1(bio, (ASN1_VALUE *)p7, data, flags,
ctype_nid, NID_undef, mdalgs, &PKCS7_it);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: x509name.c,v 1.31 2023/02/16 08:38:17 tb Exp $ */
/* $OpenBSD: x509name.c,v 1.32 2023/05/02 14:13:05 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -66,6 +66,7 @@
#include <openssl/stack.h>
#include <openssl/x509.h>
#include "bytestring.h"
#include "x509_local.h"
int
@ -84,21 +85,37 @@ int
X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf,
int len)
{
int i;
unsigned char *text = NULL;
ASN1_STRING *data;
int i, text_len;
int ret = -1;
CBS cbs;
i = X509_NAME_get_index_by_OBJ(name, obj, -1);
if (i < 0)
return (-1);
goto err;
data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i));
i = (data->length > (len - 1)) ? (len - 1) : data->length;
if (buf == NULL)
return (data->length);
if (i >= 0) {
memcpy(buf, data->data, i);
buf[i] = '\0';
/*
* Fail if we cannot encode as UTF-8, or if the UTF-8 encoding of the
* string contains a 0 byte, because mortal callers seldom handle the
* length difference correctly
*/
if ((text_len = ASN1_STRING_to_UTF8(&text, data)) < 0)
goto err;
CBS_init(&cbs, text, text_len);
if (CBS_contains_zero_byte(&cbs))
goto err;
/* We still support the "pass NULL to find out how much" API */
if (buf != NULL) {
if (!CBS_write_bytes(&cbs, buf, len - 1, NULL))
goto err;
/* It must be a C string */
buf[text_len] = '\0';
}
return (i);
ret = text_len;
err:
free(text);
return (ret);
}
LCRYPTO_ALIAS(X509_NAME_get_text_by_OBJ);