diff options
-rw-r--r-- | lib/libcrypto/Makefile | 4 | ||||
-rw-r--r-- | lib/libcrypto/asn1/asn1_item.c | 49 | ||||
-rw-r--r-- | lib/libcrypto/asn1/asn_pack.c | 109 |
3 files changed, 50 insertions, 112 deletions
diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile index dd5caec2197..ad5f4f5876c 100644 --- a/lib/libcrypto/Makefile +++ b/lib/libcrypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.62 2021/12/25 12:19:16 jsing Exp $ +# $OpenBSD: Makefile,v 1.63 2021/12/25 12:21:36 jsing Exp $ LIB= crypto LIBREBUILD=y @@ -64,7 +64,7 @@ SRCS+= tasn_prn.c ameth_lib.c SRCS+= n_pkey.c SRCS+= x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c SRCS+= asn1_gen.c asn1_par.c asn1_old_lib.c asn1_err.c a_strnid.c -SRCS+= asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c +SRCS+= p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c SRCS+= a_time_tm.c asn1_item.c asn1_old.c asn1_types.c asn1_lib.c # bf/ diff --git a/lib/libcrypto/asn1/asn1_item.c b/lib/libcrypto/asn1/asn1_item.c index 8db1713b298..d2819dbb965 100644 --- a/lib/libcrypto/asn1/asn1_item.c +++ b/lib/libcrypto/asn1/asn1_item.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_item.c,v 1.1 2021/12/25 12:00:22 jsing Exp $ */ +/* $OpenBSD: asn1_item.c,v 1.2 2021/12/25 12:21:36 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -167,6 +167,53 @@ ASN1_item_dup(const ASN1_ITEM *it, void *x) return (ret); } +/* Pack an ASN1 object into an ASN1_STRING. */ +ASN1_STRING * +ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) +{ + ASN1_STRING *octmp; + + if (!oct || !*oct) { + if (!(octmp = ASN1_STRING_new ())) { + ASN1error(ERR_R_MALLOC_FAILURE); + return NULL; + } + } else + octmp = *oct; + + free(octmp->data); + octmp->data = NULL; + + if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { + ASN1error(ASN1_R_ENCODE_ERROR); + goto err; + } + if (!octmp->data) { + ASN1error(ERR_R_MALLOC_FAILURE); + goto err; + } + if (oct) + *oct = octmp; + return octmp; +err: + if (!oct || octmp != *oct) + ASN1_STRING_free(octmp); + return NULL; +} + +/* Extract an ASN1 object from an ASN1_STRING. */ +void * +ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) +{ + const unsigned char *p; + void *ret; + + p = oct->data; + if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) + ASN1error(ASN1_R_DECODE_ERROR); + return ret; +} + int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) diff --git a/lib/libcrypto/asn1/asn_pack.c b/lib/libcrypto/asn1/asn_pack.c deleted file mode 100644 index 090beff0f0e..00000000000 --- a/lib/libcrypto/asn1/asn_pack.c +++ /dev/null @@ -1,109 +0,0 @@ -/* $OpenBSD: asn_pack.c,v 1.18 2018/10/24 17:57:22 jsing Exp $ */ -/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL - * project 1999. - */ -/* ==================================================================== - * Copyright (c) 1999 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -#include <stdio.h> - -#include <openssl/asn1.h> -#include <openssl/err.h> - -/* Pack an ASN1 object into an ASN1_STRING. */ -ASN1_STRING * -ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) -{ - ASN1_STRING *octmp; - - if (!oct || !*oct) { - if (!(octmp = ASN1_STRING_new ())) { - ASN1error(ERR_R_MALLOC_FAILURE); - return NULL; - } - } else - octmp = *oct; - - free(octmp->data); - octmp->data = NULL; - - if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { - ASN1error(ASN1_R_ENCODE_ERROR); - goto err; - } - if (!octmp->data) { - ASN1error(ERR_R_MALLOC_FAILURE); - goto err; - } - if (oct) - *oct = octmp; - return octmp; -err: - if (!oct || octmp != *oct) - ASN1_STRING_free(octmp); - return NULL; -} - -/* Extract an ASN1 object from an ASN1_STRING. */ -void * -ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) -{ - const unsigned char *p; - void *ret; - - p = oct->data; - if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) - ASN1error(ASN1_R_DECODE_ERROR); - return ret; -} |