Latest update.
This commit is contained in:
@@ -21,11 +21,11 @@
|
||||
# libfips.a Contains all things needed to support
|
||||
# FIPS implementations, such as code from
|
||||
# crypto/ and object files that contain
|
||||
# FIPS-specific code. FIPS_MODE is defined
|
||||
# FIPS-specific code. FIPS_MODULE is defined
|
||||
# for this library. The FIPS module uses
|
||||
# this.
|
||||
# libnonfips.a Corresponds to libfips.a, but built with
|
||||
# FIPS_MODE undefined. The default and legacy
|
||||
# FIPS_MODULE undefined. The default and legacy
|
||||
# providers use this.
|
||||
|
||||
SUBDIRS=common implementations
|
||||
@@ -50,7 +50,7 @@ INCLUDE[$LIBIMPLEMENTATIONS]=.. $COMMON_INCLUDES
|
||||
INCLUDE[$LIBLEGACY]=.. $COMMON_INCLUDES
|
||||
INCLUDE[$LIBNONFIPS]=$COMMON_INCLUDES
|
||||
INCLUDE[$LIBFIPS]=.. $COMMON_INCLUDES
|
||||
DEFINE[$LIBFIPS]=FIPS_MODE
|
||||
DEFINE[$LIBFIPS]=FIPS_MODULE
|
||||
|
||||
# Weak dependencies to provide library order information.
|
||||
# We make it weak so they aren't both used always; what is
|
||||
@@ -101,7 +101,7 @@ SUBDIRS=fips
|
||||
$FIPSGOAL=fips
|
||||
DEPEND[$FIPSGOAL]=$LIBIMPLEMENTATIONS $LIBFIPS
|
||||
INCLUDE[$FIPSGOAL]=../include
|
||||
DEFINE[$FIPSGOAL]=FIPS_MODE
|
||||
DEFINE[$FIPSGOAL]=FIPS_MODULE
|
||||
IF[{- defined $target{shared_defflag} -}]
|
||||
SOURCE[$FIPSGOAL]=fips.ld
|
||||
GENERATE[fips.ld]=../util/providers.num
|
||||
@@ -149,7 +149,7 @@ IF[{- !$disabled{legacy} -}]
|
||||
# Common things that are valid no matter what form the Legacy provider
|
||||
# takes.
|
||||
SOURCE[$LEGACYGOAL]=legacyprov.c
|
||||
INCLUDE[$LEGACYGOAL]=../include implementations/include
|
||||
INCLUDE[$LEGACYGOAL]=../include implementations/include common/include
|
||||
ENDIF
|
||||
|
||||
#
|
||||
|
||||
+108
-6
@@ -7,12 +7,15 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "prov/bio.h"
|
||||
|
||||
static OSSL_BIO_new_file_fn *c_bio_new_file = NULL;
|
||||
static OSSL_BIO_new_membuf_fn *c_bio_new_membuf = NULL;
|
||||
static OSSL_BIO_read_ex_fn *c_bio_read_ex = NULL;
|
||||
static OSSL_BIO_write_ex_fn *c_bio_write_ex = NULL;
|
||||
static OSSL_BIO_free_fn *c_bio_free = NULL;
|
||||
static OSSL_BIO_vprintf_fn *c_bio_vprintf = NULL;
|
||||
|
||||
@@ -32,6 +35,10 @@ int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns)
|
||||
if (c_bio_read_ex == NULL)
|
||||
c_bio_read_ex = OSSL_get_BIO_read_ex(fns);
|
||||
break;
|
||||
case OSSL_FUNC_BIO_WRITE_EX:
|
||||
if (c_bio_write_ex == NULL)
|
||||
c_bio_write_ex = OSSL_get_BIO_write_ex(fns);
|
||||
break;
|
||||
case OSSL_FUNC_BIO_FREE:
|
||||
if (c_bio_free == NULL)
|
||||
c_bio_free = OSSL_get_BIO_free(fns);
|
||||
@@ -46,21 +53,21 @@ int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns)
|
||||
return 1;
|
||||
}
|
||||
|
||||
BIO *ossl_prov_bio_new_file(const char *filename, const char *mode)
|
||||
OSSL_CORE_BIO *ossl_prov_bio_new_file(const char *filename, const char *mode)
|
||||
{
|
||||
if (c_bio_new_file == NULL)
|
||||
return NULL;
|
||||
return c_bio_new_file(filename, mode);
|
||||
}
|
||||
|
||||
BIO *ossl_prov_bio_new_membuf(const char *filename, int len)
|
||||
OSSL_CORE_BIO *ossl_prov_bio_new_membuf(const char *filename, int len)
|
||||
{
|
||||
if (c_bio_new_membuf == NULL)
|
||||
return NULL;
|
||||
return c_bio_new_membuf(filename, len);
|
||||
}
|
||||
|
||||
int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len,
|
||||
int ossl_prov_bio_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len,
|
||||
size_t *bytes_read)
|
||||
{
|
||||
if (c_bio_read_ex == NULL)
|
||||
@@ -68,21 +75,29 @@ int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len,
|
||||
return c_bio_read_ex(bio, data, data_len, bytes_read);
|
||||
}
|
||||
|
||||
int ossl_prov_bio_free(BIO *bio)
|
||||
int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len,
|
||||
size_t *written)
|
||||
{
|
||||
if (c_bio_write_ex == NULL)
|
||||
return 0;
|
||||
return c_bio_write_ex(bio, data, data_len, written);
|
||||
}
|
||||
|
||||
int ossl_prov_bio_free(OSSL_CORE_BIO *bio)
|
||||
{
|
||||
if (c_bio_free == NULL)
|
||||
return 0;
|
||||
return c_bio_free(bio);
|
||||
}
|
||||
|
||||
int ossl_prov_bio_vprintf(BIO *bio, const char *format, va_list ap)
|
||||
int ossl_prov_bio_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list ap)
|
||||
{
|
||||
if (c_bio_vprintf == NULL)
|
||||
return -1;
|
||||
return c_bio_vprintf(bio, format, ap);
|
||||
}
|
||||
|
||||
int ossl_prov_bio_printf(BIO *bio, const char *format, ...)
|
||||
int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
@@ -94,3 +109,90 @@ int ossl_prov_bio_printf(BIO *bio, const char *format, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODULE
|
||||
|
||||
/* No direct BIO support in the FIPS module */
|
||||
|
||||
static int bio_core_read_ex(BIO *bio, char *data, size_t data_len,
|
||||
size_t *bytes_read)
|
||||
{
|
||||
return ossl_prov_bio_read_ex(BIO_get_data(bio), data, data_len, bytes_read);
|
||||
}
|
||||
|
||||
static int bio_core_write_ex(BIO *bio, const char *data, size_t data_len,
|
||||
size_t *written)
|
||||
{
|
||||
return ossl_prov_bio_write_ex(BIO_get_data(bio), data, data_len, written);
|
||||
}
|
||||
|
||||
static long bio_core_ctrl(BIO *bio, int cmd, long num, void *ptr)
|
||||
{
|
||||
/* We don't support this */
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bio_core_gets(BIO *bio, char *buf, int size)
|
||||
{
|
||||
/* We don't support this */
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int bio_core_puts(BIO *bio, const char *str)
|
||||
{
|
||||
/* We don't support this */
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int bio_core_new(BIO *bio)
|
||||
{
|
||||
BIO_set_init(bio, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bio_core_free(BIO *bio)
|
||||
{
|
||||
BIO_set_init(bio, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
BIO_METHOD *bio_prov_init_bio_method(void)
|
||||
{
|
||||
BIO_METHOD *corebiometh = NULL;
|
||||
|
||||
corebiometh = BIO_meth_new(BIO_TYPE_CORE_TO_PROV, "BIO to Core filter");
|
||||
if (corebiometh == NULL
|
||||
|| !BIO_meth_set_write_ex(corebiometh, bio_core_write_ex)
|
||||
|| !BIO_meth_set_read_ex(corebiometh, bio_core_read_ex)
|
||||
|| !BIO_meth_set_puts(corebiometh, bio_core_puts)
|
||||
|| !BIO_meth_set_gets(corebiometh, bio_core_gets)
|
||||
|| !BIO_meth_set_ctrl(corebiometh, bio_core_ctrl)
|
||||
|| !BIO_meth_set_create(corebiometh, bio_core_new)
|
||||
|| !BIO_meth_set_destroy(corebiometh, bio_core_free)) {
|
||||
BIO_meth_free(corebiometh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return corebiometh;
|
||||
}
|
||||
|
||||
BIO *bio_new_from_core_bio(PROV_CTX *provctx, OSSL_CORE_BIO *corebio)
|
||||
{
|
||||
BIO *outbio;
|
||||
BIO_METHOD *corebiometh = PROV_CTX_get0_core_bio_method(provctx);
|
||||
|
||||
if (corebiometh == NULL)
|
||||
return NULL;
|
||||
|
||||
outbio = BIO_new(corebiometh);
|
||||
if (outbio != NULL)
|
||||
BIO_set_data(outbio, corebio);
|
||||
|
||||
return outbio;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
SUBDIRS=der
|
||||
|
||||
SOURCE[../libcommon.a]=provider_err.c bio_prov.c
|
||||
SOURCE[../libcommon.a]=provider_err.c bio_prov.c provider_ctx.c
|
||||
$FIPSCOMMON=provider_util.c
|
||||
SOURCE[../libnonfips.a]=$FIPSCOMMON nid_to_name.c
|
||||
SOURCE[../libfips.a]=$FIPSCOMMON
|
||||
@@ -0,0 +1,19 @@
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
||||
|
||||
id-sha256 OBJECT IDENTIFIER ::= { hashAlgs 1 }
|
||||
id-sha384 OBJECT IDENTIFIER ::= { hashAlgs 2 }
|
||||
id-sha512 OBJECT IDENTIFIER ::= { hashAlgs 3 }
|
||||
id-sha224 OBJECT IDENTIFIER ::= { hashAlgs 4 }
|
||||
id-sha512-224 OBJECT IDENTIFIER ::= { hashAlgs 5 }
|
||||
id-sha512-256 OBJECT IDENTIFIER ::= { hashAlgs 6 }
|
||||
id-sha3-224 OBJECT IDENTIFIER ::= { hashAlgs 7 }
|
||||
id-sha3-256 OBJECT IDENTIFIER ::= { hashAlgs 8 }
|
||||
id-sha3-384 OBJECT IDENTIFIER ::= { hashAlgs 9 }
|
||||
id-sha3-512 OBJECT IDENTIFIER ::= { hashAlgs 10 }
|
||||
id-shake128 OBJECT IDENTIFIER ::= { hashAlgs 11 }
|
||||
id-shake256 OBJECT IDENTIFIER ::= { hashAlgs 12 }
|
||||
id-shake128-len OBJECT IDENTIFIER ::= { hashAlgs 17 }
|
||||
id-shake256-len OBJECT IDENTIFIER ::= { hashAlgs 18 }
|
||||
id-KMACWithSHAKE128 OBJECT IDENTIFIER ::={hashAlgs 19}
|
||||
id-KMACWithSHAKE256 OBJECT IDENTIFIER ::={ hashAlgs 20}
|
||||
@@ -0,0 +1,8 @@
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
||||
|
||||
-- Copies of common OIDs used by other ASN.1 files.
|
||||
csor OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 }
|
||||
nistAlgorithms OBJECT IDENTIFIER ::= { csor nistAlgorithm(4) }
|
||||
hashAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 2 }
|
||||
sigAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 3 }
|
||||
@@ -80,9 +80,18 @@ id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 }
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
||||
|
||||
sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
|
||||
|
||||
id-rsassa-pkcs1-v1_5-with-sha3-224 OBJECT IDENTIFIER ::= { sigAlgs 13 }
|
||||
id-rsassa-pkcs1-v1_5-with-sha3-256 OBJECT IDENTIFIER ::= { sigAlgs 14 }
|
||||
id-rsassa-pkcs1-v1_5-with-sha3-384 OBJECT IDENTIFIER ::= { sigAlgs 15 }
|
||||
id-rsassa-pkcs1-v1_5-with-sha3-512 OBJECT IDENTIFIER ::= { sigAlgs 16 }
|
||||
|
||||
|
||||
-- -------------------------------------------------------------------
|
||||
-- These OID's exist in the codebase but may need to be deprecated at some point.
|
||||
-- mdc2 and md5_sha1 have been omitted as they do not look like valid entries.
|
||||
|
||||
md4WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 3 }
|
||||
|
||||
ripemd160WithRSAEncryption OBJECT IDENTIFIER ::= {
|
||||
iso(1) identified-organization(3) teletrust(36) algorithm(3) signatureAlgorithm(3) rsaSignature(1) 2
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
$FIPSABLE=der_rsa.c der_dsa.c der_ec.c
|
||||
$FIPSABLE=der_rsa.c der_dsa.c der_ec.c der_digests.c
|
||||
|
||||
SOURCE[../../libfips.a]=$FIPSABLE
|
||||
SOURCE[../../libnonfips.a]=$FIPSABLE
|
||||
@@ -6,7 +6,7 @@ SOURCE[../../libnonfips.a]=$FIPSABLE
|
||||
GENERATE[der_rsa.c]=der_rsa.c.in
|
||||
DEPEND[der_rsa.c]=oids_to_c.pm
|
||||
|
||||
DEPEND[der_rsa.o]=../include/prov/der_rsa.h
|
||||
DEPEND[der_rsa.o]=../include/prov/der_rsa.h ../include/prov/der_digests.h
|
||||
GENERATE[../include/prov/der_rsa.h]=der_rsa.h.in
|
||||
DEPEND[../include/prov/der_rsa.h]=oids_to_c.pm
|
||||
|
||||
@@ -23,3 +23,10 @@ DEPEND[der_ec.c]=oids_to_c.pm
|
||||
DEPEND[der_ec.o]=../include/prov/der_ec.h
|
||||
GENERATE[../include/prov/der_ec.h]=der_ec.h.in
|
||||
DEPEND[../include/prov/der_ec.h]=oids_to_c.pm
|
||||
|
||||
GENERATE[der_digests.c]=der_digests.c.in
|
||||
DEPEND[der_digests.c]=oids_to_c.pm
|
||||
|
||||
DEPEND[der_digests.o]=../include/prov/der_digests.h
|
||||
GENERATE[../include/prov/der_digests.h]=der_digests.h.in
|
||||
DEPEND[../include/prov/der_digests.h]=oids_to_c.pm
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "prov/der_digests.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1',
|
||||
'providers/common/der/DIGESTS.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_C });
|
||||
-}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/der.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1',
|
||||
'providers/common/der/DIGESTS.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_H });
|
||||
-}
|
||||
@@ -9,25 +9,381 @@
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "prov/der_rsa.h"
|
||||
#include "prov/der_digests.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/RSA.asn1',
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1',
|
||||
'providers/common/der/DIGESTS.asn1',
|
||||
'providers/common/der/RSA.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_C });
|
||||
-}
|
||||
|
||||
int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa)
|
||||
/* More complex pre-compiled sequences. TODO(3.0) refactor? */
|
||||
/*-
|
||||
* From https://tools.ietf.org/html/rfc8017#appendix-A.2.1
|
||||
*
|
||||
* OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
|
||||
* { OID id-sha1 PARAMETERS NULL }|
|
||||
* { OID id-sha224 PARAMETERS NULL }|
|
||||
* { OID id-sha256 PARAMETERS NULL }|
|
||||
* { OID id-sha384 PARAMETERS NULL }|
|
||||
* { OID id-sha512 PARAMETERS NULL }|
|
||||
* { OID id-sha512-224 PARAMETERS NULL }|
|
||||
* { OID id-sha512-256 PARAMETERS NULL },
|
||||
* ... -- Allows for future expansion --
|
||||
* }
|
||||
*/
|
||||
#define DER_V_NULL DER_P_NULL, 0
|
||||
#define DER_SZ_NULL 2
|
||||
|
||||
/*
|
||||
* The names for the hash function AlgorithmIdentifiers are borrowed and
|
||||
* expanded from https://tools.ietf.org/html/rfc4055#section-2.1
|
||||
*
|
||||
* sha1Identifier AlgorithmIdentifier ::= { id-sha1, NULL }
|
||||
* sha224Identifier AlgorithmIdentifier ::= { id-sha224, NULL }
|
||||
* sha256Identifier AlgorithmIdentifier ::= { id-sha256, NULL }
|
||||
* sha384Identifier AlgorithmIdentifier ::= { id-sha384, NULL }
|
||||
* sha512Identifier AlgorithmIdentifier ::= { id-sha512, NULL }
|
||||
*/
|
||||
/*
|
||||
* NOTE: Some of the arrays aren't used other than inside sizeof(), which
|
||||
* clang complains about (-Wno-unneeded-internal-declaration). To get
|
||||
* around that, we make them non-static, and declare them an extra time to
|
||||
* avoid compilers complaining about definitions without declarations.
|
||||
*/
|
||||
#if 0 /* Currently unused */
|
||||
#define DER_AID_V_sha1Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha1 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha1, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha1Identifier[];
|
||||
const unsigned char der_aid_sha1Identifier[] = {
|
||||
DER_AID_V_sha1Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha1Identifier sizeof(der_aid_sha1Identifier)
|
||||
#endif
|
||||
|
||||
#define DER_AID_V_sha224Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha224 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha224, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha224Identifier[];
|
||||
const unsigned char der_aid_sha224Identifier[] = {
|
||||
DER_AID_V_sha224Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha224Identifier sizeof(der_aid_sha224Identifier)
|
||||
|
||||
#define DER_AID_V_sha256Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha256 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha256, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha256Identifier[];
|
||||
const unsigned char der_aid_sha256Identifier[] = {
|
||||
DER_AID_V_sha256Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha256Identifier sizeof(der_aid_sha256Identifier)
|
||||
|
||||
#define DER_AID_V_sha384Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha384 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha384, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha384Identifier[];
|
||||
const unsigned char der_aid_sha384Identifier[] = {
|
||||
DER_AID_V_sha384Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha384Identifier sizeof(der_aid_sha384Identifier)
|
||||
|
||||
#define DER_AID_V_sha512Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha512 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha512, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha512Identifier[];
|
||||
const unsigned char der_aid_sha512Identifier[] = {
|
||||
DER_AID_V_sha512Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha512Identifier sizeof(der_aid_sha512Identifier)
|
||||
|
||||
#define DER_AID_V_sha512_224Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha512_224 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha512_224, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha512_224Identifier[];
|
||||
const unsigned char der_aid_sha512_224Identifier[] = {
|
||||
DER_AID_V_sha512_224Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha512_224Identifier sizeof(der_aid_sha512_224Identifier)
|
||||
|
||||
#define DER_AID_V_sha512_256Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_sha512_256 + DER_SZ_NULL, \
|
||||
DER_OID_V_id_sha512_256, \
|
||||
DER_V_NULL
|
||||
extern const unsigned char der_aid_sha512_256Identifier[];
|
||||
const unsigned char der_aid_sha512_256Identifier[] = {
|
||||
DER_AID_V_sha512_256Identifier
|
||||
};
|
||||
#define DER_AID_SZ_sha512_256Identifier sizeof(der_aid_sha512_256Identifier)
|
||||
|
||||
/*-
|
||||
* From https://tools.ietf.org/html/rfc8017#appendix-A.2.1
|
||||
*
|
||||
* HashAlgorithm ::= AlgorithmIdentifier {
|
||||
* {OAEP-PSSDigestAlgorithms}
|
||||
* }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
|
||||
* { OID id-mgf1 PARAMETERS HashAlgorithm },
|
||||
* ... -- Allows for future expansion --
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* The names for the MGF1 AlgorithmIdentifiers are borrowed and expanded
|
||||
* from https://tools.ietf.org/html/rfc4055#section-2.1
|
||||
*
|
||||
* mgf1SHA1Identifier AlgorithmIdentifier ::=
|
||||
* { id-mgf1, sha1Identifier }
|
||||
* mgf1SHA224Identifier AlgorithmIdentifier ::=
|
||||
* { id-mgf1, sha224Identifier }
|
||||
* mgf1SHA256Identifier AlgorithmIdentifier ::=
|
||||
* { id-mgf1, sha256Identifier }
|
||||
* mgf1SHA384Identifier AlgorithmIdentifier ::=
|
||||
* { id-mgf1, sha384Identifier }
|
||||
* mgf1SHA512Identifier AlgorithmIdentifier ::=
|
||||
* { id-mgf1, sha512Identifier }
|
||||
*/
|
||||
#if 0 /* Currently unused */
|
||||
#define DER_AID_V_mgf1SHA1Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha1Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha1Identifier
|
||||
static const unsigned char der_aid_mgf1SHA1Identifier[] = {
|
||||
DER_AID_V_mgf1SHA1Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA1Identifier sizeof(der_aid_mgf1SHA1Identifier)
|
||||
#endif
|
||||
|
||||
#define DER_AID_V_mgf1SHA224Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha224Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha224Identifier
|
||||
static const unsigned char der_aid_mgf1SHA224Identifier[] = {
|
||||
DER_AID_V_mgf1SHA224Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA224Identifier sizeof(der_aid_mgf1SHA224Identifier)
|
||||
|
||||
#define DER_AID_V_mgf1SHA256Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha256Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha256Identifier
|
||||
static const unsigned char der_aid_mgf1SHA256Identifier[] = {
|
||||
DER_AID_V_mgf1SHA256Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA256Identifier sizeof(der_aid_mgf1SHA256Identifier)
|
||||
|
||||
#define DER_AID_V_mgf1SHA384Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha384Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha384Identifier
|
||||
static const unsigned char der_aid_mgf1SHA384Identifier[] = {
|
||||
DER_AID_V_mgf1SHA384Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA384Identifier sizeof(der_aid_mgf1SHA384Identifier)
|
||||
|
||||
#define DER_AID_V_mgf1SHA512Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha512Identifier
|
||||
static const unsigned char der_aid_mgf1SHA512Identifier[] = {
|
||||
DER_AID_V_mgf1SHA512Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA512Identifier sizeof(der_aid_mgf1SHA512Identifier)
|
||||
|
||||
#define DER_AID_V_mgf1SHA512_224Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512_224Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha512_224Identifier
|
||||
static const unsigned char der_aid_mgf1SHA512_224Identifier[] = {
|
||||
DER_AID_V_mgf1SHA512_224Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA512_224Identifier sizeof(der_aid_mgf1SHA512_224Identifier)
|
||||
|
||||
#define DER_AID_V_mgf1SHA512_256Identifier \
|
||||
DER_P_SEQUENCE|DER_F_CONSTRUCTED, \
|
||||
DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512_256Identifier, \
|
||||
DER_OID_V_id_mgf1, \
|
||||
DER_AID_V_sha512_256Identifier
|
||||
static const unsigned char der_aid_mgf1SHA512_256Identifier[] = {
|
||||
DER_AID_V_mgf1SHA512_256Identifier
|
||||
};
|
||||
#define DER_AID_SZ_mgf1SHA512_256Identifier sizeof(der_aid_mgf1SHA512_256Identifier)
|
||||
|
||||
|
||||
#define MGF1_SHA_CASE(bits, var) \
|
||||
case NID_sha##bits: \
|
||||
var = der_aid_mgf1SHA##bits##Identifier; \
|
||||
var##_sz = sizeof(der_aid_mgf1SHA##bits##Identifier); \
|
||||
break;
|
||||
|
||||
/*-
|
||||
* The name is borrowed from https://tools.ietf.org/html/rfc8017#appendix-A.2.1
|
||||
*
|
||||
* MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }
|
||||
*/
|
||||
static int DER_w_MaskGenAlgorithm(WPACKET *pkt, int tag,
|
||||
const RSA_PSS_PARAMS_30 *pss)
|
||||
{
|
||||
if (pss != NULL && rsa_pss_params_30_maskgenalg(pss) == NID_mgf1) {
|
||||
int maskgenhashalg_nid = rsa_pss_params_30_maskgenhashalg(pss);
|
||||
const unsigned char *maskgenalg = NULL;
|
||||
size_t maskgenalg_sz = 0;
|
||||
|
||||
switch (maskgenhashalg_nid) {
|
||||
case NID_sha1:
|
||||
break;
|
||||
MGF1_SHA_CASE(224, maskgenalg);
|
||||
MGF1_SHA_CASE(256, maskgenalg);
|
||||
MGF1_SHA_CASE(384, maskgenalg);
|
||||
MGF1_SHA_CASE(512, maskgenalg);
|
||||
MGF1_SHA_CASE(512_224, maskgenalg);
|
||||
MGF1_SHA_CASE(512_256, maskgenalg);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If there is none (or it was the default), we write nothing */
|
||||
if (maskgenalg == NULL)
|
||||
return 1;
|
||||
|
||||
return DER_w_precompiled(pkt, tag, maskgenalg, maskgenalg_sz);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OAEP_PSS_MD_CASE(name, var) \
|
||||
case NID_##name: \
|
||||
var = der_oid_id_##name; \
|
||||
var##_sz = sizeof(der_oid_id_##name); \
|
||||
break;
|
||||
|
||||
int DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag, const RSA_PSS_PARAMS_30 *pss)
|
||||
{
|
||||
int hashalg_nid, default_hashalg_nid;
|
||||
int saltlen, default_saltlen;
|
||||
int trailerfield, default_trailerfield;
|
||||
const unsigned char *hashalg = NULL;
|
||||
size_t hashalg_sz = 0;
|
||||
|
||||
/*
|
||||
* For an unrestricted key, this function should not have been called;
|
||||
* the caller must be in control, because unrestricted keys are permitted
|
||||
* in some situations (when encoding the public key in a SubjectKeyInfo,
|
||||
* for example) while not in others, and this function doesn't know the
|
||||
* intent. Therefore, we assert that here, the PSS parameters must show
|
||||
* that the key is restricted.
|
||||
*/
|
||||
if (!ossl_assert(pss != NULL && !rsa_pss_params_30_is_unrestricted(pss)))
|
||||
return 0;
|
||||
|
||||
hashalg_nid = rsa_pss_params_30_hashalg(pss);
|
||||
saltlen = rsa_pss_params_30_saltlen(pss);
|
||||
trailerfield = rsa_pss_params_30_trailerfield(pss);
|
||||
|
||||
/* Getting default values */
|
||||
default_hashalg_nid = rsa_pss_params_30_hashalg(NULL);
|
||||
default_saltlen = rsa_pss_params_30_saltlen(NULL);
|
||||
default_trailerfield = rsa_pss_params_30_trailerfield(NULL);
|
||||
|
||||
/*
|
||||
* From https://tools.ietf.org/html/rfc8017#appendix-A.2.1:
|
||||
*
|
||||
* OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
|
||||
* { OID id-sha1 PARAMETERS NULL }|
|
||||
* { OID id-sha224 PARAMETERS NULL }|
|
||||
* { OID id-sha256 PARAMETERS NULL }|
|
||||
* { OID id-sha384 PARAMETERS NULL }|
|
||||
* { OID id-sha512 PARAMETERS NULL }|
|
||||
* { OID id-sha512-224 PARAMETERS NULL }|
|
||||
* { OID id-sha512-256 PARAMETERS NULL },
|
||||
* ... -- Allows for future expansion --
|
||||
* }
|
||||
*/
|
||||
switch (hashalg_nid) {
|
||||
OAEP_PSS_MD_CASE(sha1, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha224, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha256, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha384, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha512, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha512_224, hashalg);
|
||||
OAEP_PSS_MD_CASE(sha512_256, hashalg);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, der_oid_rsaEncryption,
|
||||
sizeof(der_oid_rsaEncryption))
|
||||
&& (trailerfield == default_trailerfield
|
||||
|| DER_w_ulong(pkt, 3, trailerfield))
|
||||
&& (saltlen == default_saltlen || DER_w_ulong(pkt, 2, saltlen))
|
||||
&& DER_w_MaskGenAlgorithm(pkt, 1, pss)
|
||||
&& (hashalg_nid == default_hashalg_nid
|
||||
|| DER_w_precompiled(pkt, 0, hashalg, hashalg_sz))
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
|
||||
/* Aliases so we can have a uniform MD_CASE */
|
||||
/* Aliases so we can have a uniform RSA_CASE */
|
||||
#define der_oid_rsassaPss der_oid_id_RSASSA_PSS
|
||||
|
||||
#define RSA_CASE(name, var) \
|
||||
var##_nid = NID_##name; \
|
||||
var##_oid = der_oid_##name; \
|
||||
var##_oid_sz = sizeof(der_oid_##name); \
|
||||
break;
|
||||
|
||||
int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa)
|
||||
{
|
||||
int rsa_nid = NID_undef;
|
||||
const unsigned char *rsa_oid = NULL;
|
||||
size_t rsa_oid_sz = 0;
|
||||
RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
RSA_CASE(rsaEncryption, rsa);
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
RSA_CASE(rsassaPss, rsa);
|
||||
}
|
||||
|
||||
if (rsa_oid == NULL)
|
||||
return 0;
|
||||
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
&& (rsa_nid != NID_rsassaPss
|
||||
|| rsa_pss_params_30_is_unrestricted(pss_params)
|
||||
|| DER_w_RSASSA_PSS_params(pkt, -1, pss_params))
|
||||
&& DER_w_precompiled(pkt, -1, rsa_oid, rsa_oid_sz)
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
|
||||
/* Aliases so we can have a uniform MD_with_RSA_CASE */
|
||||
#define der_oid_sha3_224WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_224
|
||||
#define der_oid_sha3_256WithRSAEncryption \
|
||||
@@ -37,10 +393,10 @@ int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa)
|
||||
#define der_oid_sha3_512WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_512
|
||||
|
||||
#define MD_CASE(name) \
|
||||
#define MD_with_RSA_CASE(name, var) \
|
||||
case NID_##name: \
|
||||
precompiled = der_oid_##name##WithRSAEncryption; \
|
||||
precompiled_sz = sizeof(der_oid_##name##WithRSAEncryption); \
|
||||
var = der_oid_##name##WithRSAEncryption; \
|
||||
var##_sz = sizeof(der_oid_##name##WithRSAEncryption); \
|
||||
break;
|
||||
|
||||
int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag,
|
||||
@@ -50,19 +406,24 @@ int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag,
|
||||
size_t precompiled_sz = 0;
|
||||
|
||||
switch (mdnid) {
|
||||
#ifndef FIPS_MODE
|
||||
MD_CASE(md2);
|
||||
MD_CASE(md5);
|
||||
#ifndef FIPS_MODULE
|
||||
MD_with_RSA_CASE(md2, precompiled);
|
||||
MD_with_RSA_CASE(md5, precompiled);
|
||||
MD_with_RSA_CASE(md4, precompiled);
|
||||
MD_with_RSA_CASE(ripemd160, precompiled);
|
||||
/* TODO(3.0) Decide what to do about mdc2 and md5_sha1 */
|
||||
#endif
|
||||
MD_CASE(sha1);
|
||||
MD_CASE(sha224);
|
||||
MD_CASE(sha256);
|
||||
MD_CASE(sha384);
|
||||
MD_CASE(sha512);
|
||||
MD_CASE(sha3_224);
|
||||
MD_CASE(sha3_256);
|
||||
MD_CASE(sha3_384);
|
||||
MD_CASE(sha3_512);
|
||||
MD_with_RSA_CASE(sha1, precompiled);
|
||||
MD_with_RSA_CASE(sha224, precompiled);
|
||||
MD_with_RSA_CASE(sha256, precompiled);
|
||||
MD_with_RSA_CASE(sha384, precompiled);
|
||||
MD_with_RSA_CASE(sha512, precompiled);
|
||||
MD_with_RSA_CASE(sha512_224, precompiled);
|
||||
MD_with_RSA_CASE(sha512_256, precompiled);
|
||||
MD_with_RSA_CASE(sha3_224, precompiled);
|
||||
MD_with_RSA_CASE(sha3_256, precompiled);
|
||||
MD_with_RSA_CASE(sha3_384, precompiled);
|
||||
MD_with_RSA_CASE(sha3_512, precompiled);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,20 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "crypto/rsa.h"
|
||||
#include "internal/der.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/RSA.asn1',
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1',
|
||||
'providers/common/der/DIGESTS.asn1',
|
||||
'providers/common/der/RSA.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_H });
|
||||
-}
|
||||
|
||||
int DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag,
|
||||
const RSA_PSS_PARAMS_30 *pss);
|
||||
int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa);
|
||||
int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag,
|
||||
RSA *rsa, int mdnid);
|
||||
@@ -10,13 +10,19 @@
|
||||
#include <stdarg.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/core.h>
|
||||
#include "prov/provider_ctx.h"
|
||||
|
||||
int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns);
|
||||
|
||||
BIO *ossl_prov_bio_new_file(const char *filename, const char *mode);
|
||||
BIO *ossl_prov_bio_new_membuf(const char *filename, int len);
|
||||
int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len,
|
||||
OSSL_CORE_BIO *ossl_prov_bio_new_file(const char *filename, const char *mode);
|
||||
OSSL_CORE_BIO *ossl_prov_bio_new_membuf(const char *filename, int len);
|
||||
int ossl_prov_bio_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len,
|
||||
size_t *bytes_read);
|
||||
int ossl_prov_bio_free(BIO *bio);
|
||||
int ossl_prov_bio_vprintf(BIO *bio, const char *format, va_list ap);
|
||||
int ossl_prov_bio_printf(BIO *bio, const char *format, ...);
|
||||
int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len,
|
||||
size_t *written);
|
||||
int ossl_prov_bio_free(OSSL_CORE_BIO *bio);
|
||||
int ossl_prov_bio_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list ap);
|
||||
int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...);
|
||||
|
||||
BIO_METHOD *bio_prov_init_bio_method(void);
|
||||
BIO *bio_new_from_core_bio(PROV_CTX *provctx, OSSL_CORE_BIO *corebio);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -7,8 +7,34 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#ifndef OSSL_PROV_PROVIDER_CTX_H
|
||||
# define OSSL_PROV_PROVIDER_CTX_H
|
||||
|
||||
# include <openssl/types.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/core.h>
|
||||
|
||||
typedef struct prov_ctx_st {
|
||||
const OSSL_CORE_HANDLE *handle;
|
||||
OPENSSL_CTX *libctx; /* For all provider modules */
|
||||
BIO_METHOD *corebiometh;
|
||||
} PROV_CTX;
|
||||
|
||||
/*
|
||||
* To be used anywhere the library context needs to be passed, such as to
|
||||
* fetching functions.
|
||||
*/
|
||||
#define PROV_LIBRARY_CONTEXT_OF(provctx) (provctx)
|
||||
# define PROV_LIBRARY_CONTEXT_OF(provctx) \
|
||||
PROV_CTX_get0_library_context((provctx))
|
||||
|
||||
PROV_CTX *PROV_CTX_new(void);
|
||||
void PROV_CTX_free(PROV_CTX *ctx);
|
||||
void PROV_CTX_set0_library_context(PROV_CTX *ctx, OPENSSL_CTX *libctx);
|
||||
void PROV_CTX_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle);
|
||||
void PROV_CTX_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh);
|
||||
OPENSSL_CTX *PROV_CTX_get0_library_context(PROV_CTX *ctx);
|
||||
const OSSL_CORE_HANDLE *PROV_CTX_get0_handle(PROV_CTX *ctx);
|
||||
BIO_METHOD *PROV_CTX_get0_core_bio_method(PROV_CTX *ctx);
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <openssl/provider.h>
|
||||
|
||||
const OSSL_PROVIDER *FIPS_get_provider(OPENSSL_CTX *ctx);
|
||||
const OSSL_CORE_HANDLE *FIPS_get_core_handle(OPENSSL_CTX *ctx);
|
||||
|
||||
const char *ossl_prov_util_nid_to_name(int nid);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#ifndef OPENSSL_PROVERR_H
|
||||
# define OPENSSL_PROVERR_H
|
||||
# pragma once
|
||||
|
||||
# include <openssl/opensslconf.h>
|
||||
# include <openssl/symhacks.h>
|
||||
@@ -89,6 +90,7 @@ int ERR_load_PROV_strings(void);
|
||||
# define PROV_R_INVALID_PSS_SALTLEN 169
|
||||
# define PROV_R_INVALID_SALT_LENGTH 112
|
||||
# define PROV_R_INVALID_SEED_LENGTH 154
|
||||
# define PROV_R_INVALID_SIGNATURE_SIZE 179
|
||||
# define PROV_R_INVALID_TAG 110
|
||||
# define PROV_R_INVALID_TAGLEN 118
|
||||
# define PROV_R_INVALID_X931_DIGEST 170
|
||||
@@ -110,6 +112,7 @@ int ERR_load_PROV_strings(void);
|
||||
# define PROV_R_NOT_XOF_OR_INVALID_LENGTH 113
|
||||
# define PROV_R_NO_KEY_SET 114
|
||||
# define PROV_R_NO_PARAMETERS_SET 177
|
||||
# define PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 178
|
||||
# define PROV_R_OUTPUT_BUFFER_TOO_SMALL 106
|
||||
# define PROV_R_PSS_SALTLEN_TOO_SMALL 172
|
||||
# define PROV_R_READ_KEY 159
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "prov/bio.h"
|
||||
|
||||
PROV_CTX *PROV_CTX_new(void)
|
||||
{
|
||||
return OPENSSL_zalloc(sizeof(PROV_CTX));
|
||||
}
|
||||
|
||||
void PROV_CTX_free(PROV_CTX *ctx)
|
||||
{
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
void PROV_CTX_set0_library_context(PROV_CTX *ctx, OPENSSL_CTX *libctx)
|
||||
{
|
||||
if (ctx != NULL)
|
||||
ctx->libctx = libctx;
|
||||
}
|
||||
|
||||
void PROV_CTX_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle)
|
||||
{
|
||||
if (ctx != NULL)
|
||||
ctx->handle = handle;
|
||||
}
|
||||
|
||||
void PROV_CTX_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh)
|
||||
{
|
||||
if (ctx != NULL)
|
||||
ctx->corebiometh = corebiometh;
|
||||
}
|
||||
|
||||
OPENSSL_CTX *PROV_CTX_get0_library_context(PROV_CTX *ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
return ctx->libctx;
|
||||
}
|
||||
|
||||
const OSSL_CORE_HANDLE *PROV_CTX_get0_handle(PROV_CTX *ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
return ctx->handle;
|
||||
}
|
||||
|
||||
BIO_METHOD *PROV_CTX_get0_core_bio_method(PROV_CTX *ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
return ctx->corebiometh;
|
||||
}
|
||||
@@ -75,6 +75,8 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
"invalid salt length"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_SEED_LENGTH),
|
||||
"invalid seed length"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_SIGNATURE_SIZE),
|
||||
"invalid signature size"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_TAG), "invalid tag"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_TAGLEN), "invalid taglen"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_X931_DIGEST),
|
||||
@@ -101,6 +103,8 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
"not xof or invalid length"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_NO_KEY_SET), "no key set"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_NO_PARAMETERS_SET), "no parameters set"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),
|
||||
"operation not supported for this keytype"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_OUTPUT_BUFFER_TOO_SMALL),
|
||||
"output buffer too small"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_PSS_SALTLEN_TOO_SMALL),
|
||||
|
||||
@@ -46,7 +46,7 @@ static int load_common(const OSSL_PARAM params[], const char **propquery,
|
||||
*engine = NULL;
|
||||
/* TODO legacy stuff, to be removed */
|
||||
/* Inside the FIPS module, we don't support legacy ciphers */
|
||||
#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE)
|
||||
#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE)
|
||||
p = OSSL_PARAM_locate_const(params, "engine");
|
||||
if (p != NULL) {
|
||||
if (p->data_type != OSSL_PARAM_UTF8_STRING)
|
||||
@@ -80,7 +80,7 @@ int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
|
||||
ERR_set_mark();
|
||||
pc->cipher = pc->alloc_cipher = EVP_CIPHER_fetch(ctx, p->data, propquery);
|
||||
/* TODO legacy stuff, to be removed */
|
||||
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy ciphers */
|
||||
#ifndef FIPS_MODULE /* Inside the FIPS module, we don't support legacy ciphers */
|
||||
if (pc->cipher == NULL)
|
||||
pc->cipher = EVP_get_cipherbyname(p->data);
|
||||
#endif
|
||||
@@ -140,7 +140,7 @@ int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
|
||||
ERR_set_mark();
|
||||
pd->md = pd->alloc_md = EVP_MD_fetch(ctx, p->data, propquery);
|
||||
/* TODO legacy stuff, to be removed */
|
||||
#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */
|
||||
#ifndef FIPS_MODULE /* Inside the FIPS module, we don't support legacy digests */
|
||||
if (pd->md == NULL)
|
||||
pd->md = EVP_get_digestbyname(p->data);
|
||||
#endif
|
||||
@@ -231,7 +231,7 @@ int ossl_prov_macctx_load_from_params(EVP_MAC_CTX **macctx,
|
||||
*mp++ = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_PROPERTIES,
|
||||
(char *)properties, 0);
|
||||
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
|
||||
if ((p = OSSL_PARAM_locate_const(params, "engine")) != NULL) {
|
||||
if (p->data_type != OSSL_PARAM_UTF8_STRING)
|
||||
return 0;
|
||||
|
||||
+50
-9
@@ -15,11 +15,20 @@
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_util.h"
|
||||
#include "internal/nelem.h"
|
||||
|
||||
/*
|
||||
* Forward declarations to ensure that interface functions are correctly
|
||||
* defined.
|
||||
*/
|
||||
static OSSL_provider_gettable_params_fn deflt_gettable_params;
|
||||
static OSSL_provider_get_params_fn deflt_get_params;
|
||||
static OSSL_provider_query_operation_fn deflt_query;
|
||||
|
||||
#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
|
||||
#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
|
||||
|
||||
@@ -35,12 +44,12 @@ static const OSSL_PARAM deflt_param_types[] = {
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *deflt_gettable_params(const OSSL_PROVIDER *prov)
|
||||
static const OSSL_PARAM *deflt_gettable_params(void *provctx)
|
||||
{
|
||||
return deflt_param_types;
|
||||
}
|
||||
|
||||
static int deflt_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
static int deflt_get_params(void *provctx, OSSL_PARAM params[])
|
||||
{
|
||||
OSSL_PARAM *p;
|
||||
|
||||
@@ -354,6 +363,7 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = {
|
||||
{ "DSA:dsaEncryption", "provider=default", dsa_keymgmt_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "provider=default", rsa_keymgmt_functions },
|
||||
{ "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions },
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions },
|
||||
{ "X25519", "provider=default", x25519_keymgmt_functions },
|
||||
@@ -382,6 +392,18 @@ static const OSSL_ALGORITHM deflt_serializer[] = {
|
||||
rsa_priv_pem_serializer_functions },
|
||||
{ "RSA", "provider=default,fips=yes,format=pem,type=public",
|
||||
rsa_pub_pem_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=text,type=private",
|
||||
rsa_priv_text_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=text,type=public",
|
||||
rsa_pub_text_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=der,type=private",
|
||||
rsa_priv_der_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=der,type=public",
|
||||
rsa_pub_der_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=pem,type=private",
|
||||
rsa_priv_pem_serializer_functions },
|
||||
{ "RSA-PSS", "provider=default,fips=yes,format=pem,type=public",
|
||||
rsa_pub_pem_serializer_functions },
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH", "provider=default,fips=yes,format=text,type=private",
|
||||
@@ -500,8 +522,7 @@ static const OSSL_ALGORITHM deflt_serializer[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov,
|
||||
int operation_id,
|
||||
static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id,
|
||||
int *no_cache)
|
||||
{
|
||||
*no_cache = 0;
|
||||
@@ -529,8 +550,15 @@ static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void deflt_teardown(void *provctx)
|
||||
{
|
||||
BIO_meth_free(PROV_CTX_get0_core_bio_method(provctx));
|
||||
PROV_CTX_free(provctx);
|
||||
}
|
||||
|
||||
/* Functions we provide to the core */
|
||||
static const OSSL_DISPATCH deflt_dispatch_table[] = {
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
|
||||
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
|
||||
@@ -539,12 +567,13 @@ static const OSSL_DISPATCH deflt_dispatch_table[] = {
|
||||
|
||||
OSSL_provider_init_fn ossl_default_provider_init;
|
||||
|
||||
int ossl_default_provider_init(const OSSL_PROVIDER *provider,
|
||||
int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
OSSL_core_get_library_context_fn *c_get_libctx = NULL;
|
||||
BIO_METHOD *corebiometh;
|
||||
|
||||
if (!ossl_prov_bio_from_dispatch(in))
|
||||
return 0;
|
||||
@@ -568,13 +597,25 @@ int ossl_default_provider_init(const OSSL_PROVIDER *provider,
|
||||
if (c_get_libctx == NULL)
|
||||
return 0;
|
||||
|
||||
*out = deflt_dispatch_table;
|
||||
|
||||
/*
|
||||
* We want to make sure that all calls from this provider that requires
|
||||
* a library context use the same context as the one used to call our
|
||||
* functions. We do that by passing it along as the provider context.
|
||||
* functions. We do that by passing it along in the provider context.
|
||||
*
|
||||
* This only works for built-in providers. Most providers should
|
||||
* create their own library context.
|
||||
*/
|
||||
*provctx = c_get_libctx(provider);
|
||||
if ((*provctx = PROV_CTX_new()) == NULL
|
||||
|| (corebiometh = bio_prov_init_bio_method()) == NULL) {
|
||||
PROV_CTX_free(*provctx);
|
||||
*provctx = NULL;
|
||||
return 0;
|
||||
}
|
||||
PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle));
|
||||
PROV_CTX_set0_handle(*provctx, handle);
|
||||
PROV_CTX_set0_core_bio_method(*provctx, corebiometh);
|
||||
|
||||
*out = deflt_dispatch_table;
|
||||
|
||||
return 1;
|
||||
}
|
||||
+83
-46
@@ -34,6 +34,15 @@
|
||||
#include "prov/provider_util.h"
|
||||
#include "self_test.h"
|
||||
|
||||
/*
|
||||
* Forward declarations to ensure that interface functions are correctly
|
||||
* defined.
|
||||
*/
|
||||
static OSSL_provider_teardown_fn fips_teardown;
|
||||
static OSSL_provider_gettable_params_fn fips_gettable_params;
|
||||
static OSSL_provider_get_params_fn fips_get_params;
|
||||
static OSSL_provider_query_operation_fn fips_query;
|
||||
|
||||
#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=fips,fips=yes", FUNC }, CHECK }
|
||||
#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
|
||||
|
||||
@@ -72,7 +81,7 @@ static OSSL_CRYPTO_secure_allocated_fn *c_CRYPTO_secure_allocated;
|
||||
static OSSL_BIO_vsnprintf_fn *c_BIO_vsnprintf;
|
||||
|
||||
typedef struct fips_global_st {
|
||||
const OSSL_PROVIDER *prov;
|
||||
const OSSL_CORE_HANDLE *handle;
|
||||
} FIPS_GLOBAL;
|
||||
|
||||
static void *fips_prov_ossl_ctx_new(OPENSSL_CTX *libctx)
|
||||
@@ -127,9 +136,8 @@ static OSSL_PARAM core_params[] =
|
||||
};
|
||||
|
||||
/* TODO(3.0): To be removed */
|
||||
static int dummy_evp_call(void *provctx)
|
||||
static int dummy_evp_call(OPENSSL_CTX *libctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
EVP_MD *sha256 = EVP_MD_fetch(libctx, "SHA256", NULL);
|
||||
EVP_KDF *kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_PBKDF2, NULL);
|
||||
@@ -208,12 +216,12 @@ static int dummy_evp_call(void *provctx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *fips_gettable_params(const OSSL_PROVIDER *prov)
|
||||
static const OSSL_PARAM *fips_gettable_params(void *provctx)
|
||||
{
|
||||
return fips_param_types;
|
||||
}
|
||||
|
||||
static int fips_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
static int fips_get_params(void *provctx, OSSL_PARAM params[])
|
||||
{
|
||||
OSSL_PARAM *p;
|
||||
|
||||
@@ -233,7 +241,7 @@ static int fips_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
/* FIPS specific version of the function of the same name in provlib.c */
|
||||
const char *ossl_prov_util_nid_to_name(int nid)
|
||||
{
|
||||
/* We don't have OBJ_nid2n() in FIPS_MODE so we have an explicit list */
|
||||
/* We don't have OBJ_nid2n() in FIPS_MODULE so we have an explicit list */
|
||||
|
||||
switch (nid) {
|
||||
/* Digests */
|
||||
@@ -469,6 +477,7 @@ static const OSSL_ALGORITHM fips_keymgmt[] = {
|
||||
{ "DSA", "provider=fips,fips=yes", dsa_keymgmt_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_keymgmt_functions },
|
||||
{ "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions },
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "EC:id-ecPublicKey", "provider=fips,fips=yes", ec_keymgmt_functions },
|
||||
{ "X25519", "provider=fips,fips=no", x25519_keymgmt_functions },
|
||||
@@ -479,9 +488,8 @@ static const OSSL_ALGORITHM fips_keymgmt[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov,
|
||||
int operation_id,
|
||||
int *no_cache)
|
||||
static const OSSL_ALGORITHM *fips_query(void *provctx, int operation_id,
|
||||
int *no_cache)
|
||||
{
|
||||
*no_cache = 0;
|
||||
switch (operation_id) {
|
||||
@@ -506,13 +514,24 @@ static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void fips_teardown(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX_free(PROV_LIBRARY_CONTEXT_OF(provctx));
|
||||
PROV_CTX_free(provctx);
|
||||
}
|
||||
|
||||
static void fips_intern_teardown(void *provctx)
|
||||
{
|
||||
/*
|
||||
* We know that the library context is the same as for the outer provider,
|
||||
* so no need to destroy it here.
|
||||
*/
|
||||
PROV_CTX_free(provctx);
|
||||
}
|
||||
|
||||
/* Functions we provide to the core */
|
||||
static const OSSL_DISPATCH fips_dispatch_table[] = {
|
||||
/*
|
||||
* To release our resources we just need to free the OPENSSL_CTX so we just
|
||||
* use OPENSSL_CTX_free directly as our teardown function
|
||||
*/
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))OPENSSL_CTX_free },
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_teardown },
|
||||
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))fips_gettable_params },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))fips_get_params },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
|
||||
@@ -521,18 +540,19 @@ static const OSSL_DISPATCH fips_dispatch_table[] = {
|
||||
|
||||
/* Functions we provide to ourself */
|
||||
static const OSSL_DISPATCH intern_dispatch_table[] = {
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_intern_teardown },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
FIPS_GLOBAL *fgbl;
|
||||
OPENSSL_CTX *ctx;
|
||||
OPENSSL_CTX *libctx = NULL;
|
||||
OSSL_self_test_cb_fn *stcbfn = NULL;
|
||||
OSSL_core_get_library_context_fn *c_get_libctx = NULL;
|
||||
|
||||
@@ -627,7 +647,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
}
|
||||
|
||||
if (stcbfn != NULL && c_get_libctx != NULL) {
|
||||
stcbfn(c_get_libctx(provider), &selftest_params.cb,
|
||||
stcbfn(c_get_libctx(handle), &selftest_params.cb,
|
||||
&selftest_params.cb_arg);
|
||||
}
|
||||
else {
|
||||
@@ -635,39 +655,47 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
selftest_params.cb_arg = NULL;
|
||||
}
|
||||
|
||||
if (!c_get_params(provider, core_params))
|
||||
if (!c_get_params(handle, core_params))
|
||||
return 0;
|
||||
|
||||
/* Create a context. */
|
||||
if ((ctx = OPENSSL_CTX_new()) == NULL)
|
||||
return 0;
|
||||
if ((fgbl = openssl_ctx_get_data(ctx, OPENSSL_CTX_FIPS_PROV_INDEX,
|
||||
&fips_prov_ossl_ctx_method)) == NULL) {
|
||||
OPENSSL_CTX_free(ctx);
|
||||
return 0;
|
||||
if ((*provctx = PROV_CTX_new()) == NULL
|
||||
|| (libctx = OPENSSL_CTX_new()) == NULL) {
|
||||
/*
|
||||
* We free libctx separately here and only here because it hasn't
|
||||
* been attached to *provctx. All other error paths below rely
|
||||
* solely on fips_teardown.
|
||||
*/
|
||||
OPENSSL_CTX_free(libctx);
|
||||
goto err;
|
||||
}
|
||||
PROV_CTX_set0_library_context(*provctx, libctx);
|
||||
PROV_CTX_set0_handle(*provctx, handle);
|
||||
|
||||
fgbl->prov = provider;
|
||||
if ((fgbl = openssl_ctx_get_data(libctx, OPENSSL_CTX_FIPS_PROV_INDEX,
|
||||
&fips_prov_ossl_ctx_method)) == NULL)
|
||||
goto err;
|
||||
|
||||
selftest_params.libctx = PROV_LIBRARY_CONTEXT_OF(ctx);
|
||||
if (!SELF_TEST_post(&selftest_params, 0)) {
|
||||
OPENSSL_CTX_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
fgbl->handle = handle;
|
||||
|
||||
selftest_params.libctx = libctx;
|
||||
if (!SELF_TEST_post(&selftest_params, 0))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* TODO(3.0): Remove me. This is just a dummy call to demonstrate making
|
||||
* EVP calls from within the FIPS module.
|
||||
*/
|
||||
if (!dummy_evp_call(ctx)) {
|
||||
OPENSSL_CTX_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
if (!dummy_evp_call(libctx))
|
||||
goto err;
|
||||
|
||||
*out = fips_dispatch_table;
|
||||
*provctx = ctx;
|
||||
|
||||
return 1;
|
||||
err:
|
||||
fips_teardown(*provctx);
|
||||
*provctx = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -678,7 +706,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
* that was used in the EVP call that initiated this recursive call.
|
||||
*/
|
||||
OSSL_provider_init_fn fips_intern_provider_init;
|
||||
int fips_intern_provider_init(const OSSL_PROVIDER *provider,
|
||||
int fips_intern_provider_init(const OSSL_CORE_HANDLE *handle,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
@@ -698,14 +726,15 @@ int fips_intern_provider_init(const OSSL_PROVIDER *provider,
|
||||
if (c_get_libctx == NULL)
|
||||
return 0;
|
||||
|
||||
*provctx = c_get_libctx(provider);
|
||||
|
||||
/*
|
||||
* Safety measure... we should get the library context that was
|
||||
* created up in OSSL_provider_init().
|
||||
*/
|
||||
if (*provctx == NULL)
|
||||
if ((*provctx = PROV_CTX_new()) == NULL)
|
||||
return 0;
|
||||
/*
|
||||
* Using the parent library context only works because we are a built-in
|
||||
* internal provider. This is not something that most providers would be
|
||||
* able to do.
|
||||
*/
|
||||
PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle));
|
||||
PROV_CTX_set0_handle(*provctx, handle);
|
||||
|
||||
*out = intern_dispatch_table;
|
||||
return 1;
|
||||
@@ -750,15 +779,23 @@ int ERR_pop_to_mark(void)
|
||||
return c_pop_error_to_mark(NULL);
|
||||
}
|
||||
|
||||
const OSSL_PROVIDER *FIPS_get_provider(OPENSSL_CTX *ctx)
|
||||
/*
|
||||
* This must take a library context, since it's called from the depths
|
||||
* of crypto/initthread.c code, where it's (correctly) assumed that the
|
||||
* passed caller argument is an OPENSSL_CTX pointer (since the same routine
|
||||
* is also called from other parts of libcrypto, which all pass around a
|
||||
* OPENSSL_CTX pointer)
|
||||
*/
|
||||
const OSSL_CORE_HANDLE *FIPS_get_core_handle(OPENSSL_CTX *libctx)
|
||||
{
|
||||
FIPS_GLOBAL *fgbl = openssl_ctx_get_data(ctx, OPENSSL_CTX_FIPS_PROV_INDEX,
|
||||
FIPS_GLOBAL *fgbl = openssl_ctx_get_data(libctx,
|
||||
OPENSSL_CTX_FIPS_PROV_INDEX,
|
||||
&fips_prov_ossl_ctx_method);
|
||||
|
||||
if (fgbl == NULL)
|
||||
return NULL;
|
||||
|
||||
return fgbl->prov;
|
||||
return fgbl->handle;
|
||||
}
|
||||
|
||||
void *CRYPTO_malloc(size_t num, const char *file, int line)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
@@ -130,7 +130,7 @@ DEP_FINI_ATTRIBUTE void cleanup(void)
|
||||
* the result matches the expected value.
|
||||
* Return 1 if verified, or 0 if it fails.
|
||||
*/
|
||||
static int verify_integrity(BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb,
|
||||
static int verify_integrity(OSSL_CORE_BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb,
|
||||
unsigned char *expected, size_t expected_len,
|
||||
OPENSSL_CTX *libctx, OSSL_SELF_TEST *ev,
|
||||
const char *event_type)
|
||||
@@ -188,7 +188,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test)
|
||||
int ok = 0;
|
||||
int kats_already_passed = 0;
|
||||
long checksum_len;
|
||||
BIO *bio_module = NULL, *bio_indicator = NULL;
|
||||
OSSL_CORE_BIO *bio_module = NULL, *bio_indicator = NULL;
|
||||
unsigned char *module_checksum = NULL;
|
||||
unsigned char *indicator_checksum = NULL;
|
||||
int loclstate;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -89,7 +89,16 @@ static int rsa_init(void *vprsactx, void *vrsa)
|
||||
return 0;
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
|
||||
switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
break;
|
||||
default:
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx,
|
||||
size_t nextblocks;
|
||||
size_t outlint = 0;
|
||||
|
||||
if (bufsz != 0)
|
||||
if (*bufsz != 0)
|
||||
nextblocks = fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl);
|
||||
else
|
||||
nextblocks = inl & ~(AES_BLOCK_SIZE-1);
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
#include "cipher_aes_xts.h"
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
const int allow_insecure_decrypt = 0;
|
||||
#else
|
||||
const int allow_insecure_decrypt = 1;
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
@@ -49,7 +49,7 @@ static void *cast5_dupctx(void *ctx)
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ecb, ECB, CAST5_FLAGS, 128, 64, 0, block)
|
||||
/* cast5128cbc_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cbc, CBC, CAST5_FLAGS, 128, 64, 64, block)
|
||||
/* cast564ofb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 64, 8, 64, stream)
|
||||
/* cast564cfb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 64, 8, 64, stream)
|
||||
/* cast5128ofb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 128, 8, 64, stream)
|
||||
/* cast5128cfb64_functions */
|
||||
IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 128, 8, 64, stream)
|
||||
@@ -65,7 +65,13 @@ static int cipher_hw_des_ecb_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
static int cipher_hw_des_cbc_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t len)
|
||||
{
|
||||
DES_key_schedule *key = &(((PROV_DES_CTX *)ctx)->dks.ks);
|
||||
PROV_DES_CTX *dctx = (PROV_DES_CTX *)ctx;
|
||||
DES_key_schedule *key = &(dctx->dks.ks);
|
||||
|
||||
if (dctx->dstream.cbc != NULL) {
|
||||
(*dctx->dstream.cbc) (in, out, len, key, ctx->iv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (len >= MAXCHUNK) {
|
||||
DES_ncbc_encrypt(in, out, MAXCHUNK, key, (DES_cblock *)ctx->iv,
|
||||
|
||||
@@ -458,7 +458,7 @@ int ecdh_plain_derive(void *vpecdhctx, unsigned char *secret,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
static ossl_inline
|
||||
int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
size_t *psecretlen, size_t outlen)
|
||||
@@ -498,7 +498,7 @@ int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
OPENSSL_secure_clear_free(stmp, stmplen);
|
||||
return ret;
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
|
||||
static
|
||||
int ecdh_derive(void *vpecdhctx, unsigned char *secret,
|
||||
@@ -509,11 +509,11 @@ int ecdh_derive(void *vpecdhctx, unsigned char *secret,
|
||||
switch (pecdhctx->kdf_type) {
|
||||
case PROV_ECDH_KDF_NONE:
|
||||
return ecdh_plain_derive(vpecdhctx, secret, psecretlen, outlen);
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
case PROV_ECDH_KDF_X9_63:
|
||||
return ecdh_X9_63_kdf_derive(vpecdhctx, secret, psecretlen, outlen);
|
||||
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ extern const OSSL_DISPATCH idea128cfb64_functions[];
|
||||
#ifndef OPENSSL_NO_CAST
|
||||
extern const OSSL_DISPATCH cast5128ecb_functions[];
|
||||
extern const OSSL_DISPATCH cast5128cbc_functions[];
|
||||
extern const OSSL_DISPATCH cast564ofb64_functions[];
|
||||
extern const OSSL_DISPATCH cast564cfb64_functions[];
|
||||
extern const OSSL_DISPATCH cast5128ofb64_functions[];
|
||||
extern const OSSL_DISPATCH cast5128cfb64_functions[];
|
||||
#endif /* OPENSSL_NO_CAST */
|
||||
#ifndef OPENSSL_NO_SEED
|
||||
extern const OSSL_DISPATCH seed128ecb_functions[];
|
||||
@@ -181,7 +181,7 @@ extern const OSSL_DISPATCH rc2128ofb128_functions[];
|
||||
#ifndef OPENSSL_NO_DES
|
||||
extern const OSSL_DISPATCH tdes_ede3_ecb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cbc_functions[];
|
||||
# ifndef FIPS_MODE
|
||||
# ifndef FIPS_MODULE
|
||||
extern const OSSL_DISPATCH tdes_ede3_ofb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cfb_functions[];
|
||||
extern const OSSL_DISPATCH tdes_ede3_cfb8_functions[];
|
||||
@@ -201,7 +201,7 @@ extern const OSSL_DISPATCH des_ofb64_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb64_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb1_functions[];
|
||||
extern const OSSL_DISPATCH des_cfb8_functions[];
|
||||
# endif /* FIPS_MODE */
|
||||
# endif /* FIPS_MODULE */
|
||||
#endif /* OPENSSL_NO_DES */
|
||||
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
@@ -257,6 +257,7 @@ extern const OSSL_DISPATCH kdf_krb5kdf_functions[];
|
||||
extern const OSSL_DISPATCH dh_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH dsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH rsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH rsapss_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x25519_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x448_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_keymgmt_functions[];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -13,8 +13,8 @@
|
||||
* For backwards compatibility reasons,
|
||||
* Extra checks are done by default in fips mode only.
|
||||
*/
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
const int kdf_pbkdf2_default_checks = 1;
|
||||
#else
|
||||
const int kdf_pbkdf2_default_checks = 0;
|
||||
#endif /* FIPS_MODE */
|
||||
#endif /* FIPS_MODULE */
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
|
||||
@@ -322,6 +322,8 @@ static int dh_validate_public(DH *dh)
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DH_get0_key(dh, &pub_key, NULL);
|
||||
if (pub_key == NULL)
|
||||
return 0;
|
||||
return DH_check_pub_key_ex(dh, pub_key);
|
||||
}
|
||||
|
||||
@@ -331,6 +333,8 @@ static int dh_validate_private(DH *dh)
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DH_get0_key(dh, NULL, &priv_key);
|
||||
if (priv_key == NULL)
|
||||
return 0;
|
||||
return dh_check_priv_key(dh, priv_key, &status);;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,6 +312,8 @@ static int dsa_validate_public(DSA *dsa)
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, &pub_key, NULL);
|
||||
if (pub_key == NULL)
|
||||
return 0;
|
||||
return dsa_check_pub_key(dsa, pub_key, &status);
|
||||
}
|
||||
|
||||
@@ -321,6 +323,8 @@ static int dsa_validate_private(DSA *dsa)
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, NULL, &priv_key);
|
||||
if (priv_key == NULL)
|
||||
return 0;
|
||||
return dsa_check_priv_key(dsa, priv_key, &status);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ static OSSL_OP_keymgmt_gen_init_fn ec_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_set_template_fn ec_gen_set_template;
|
||||
static OSSL_OP_keymgmt_gen_set_params_fn ec_gen_set_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn ec_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_get_params_fn ec_gen_get_params;
|
||||
static OSSL_OP_keymgmt_gen_gettable_params_fn ec_gen_gettable_params;
|
||||
static OSSL_OP_keymgmt_gen_fn ec_gen;
|
||||
static OSSL_OP_keymgmt_gen_cleanup_fn ec_gen_cleanup;
|
||||
static OSSL_OP_keymgmt_free_fn ec_freedata;
|
||||
@@ -679,39 +677,6 @@ static const OSSL_PARAM *ec_gen_settable_params(void *provctx)
|
||||
return settable;
|
||||
}
|
||||
|
||||
static int ec_gen_get_params(void *genctx, OSSL_PARAM params[])
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_NAME)) != NULL) {
|
||||
int nid = EC_GROUP_get_curve_name(gctx->gen_group);
|
||||
int ret = 0;
|
||||
const char *curve_name = ec_curve_nid2name(nid);
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_UTF8_STRING:
|
||||
ret = OSSL_PARAM_set_utf8_string(p, curve_name);
|
||||
break;
|
||||
case OSSL_PARAM_UTF8_PTR:
|
||||
ret = OSSL_PARAM_set_utf8_ptr(p, curve_name);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *ec_gen_gettable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM gettable[] = {
|
||||
{ OSSL_PKEY_PARAM_EC_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 },
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
return gettable;
|
||||
}
|
||||
|
||||
static int ec_gen_assign_group(EC_KEY *ec, EC_GROUP *group)
|
||||
{
|
||||
if (group == NULL) {
|
||||
@@ -767,9 +732,6 @@ const OSSL_DISPATCH ec_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))ec_gen_set_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
|
||||
(void (*)(void))ec_gen_settable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS, (void (*)(void))ec_gen_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS,
|
||||
(void (*)(void))ec_gen_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))ec_gen },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))ec_gen_cleanup },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ec_freedata },
|
||||
|
||||
@@ -47,6 +47,7 @@ static OSSL_OP_keymgmt_gettable_params_fn x448_gettable_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ed25519_gettable_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ed448_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn ecx_has;
|
||||
static OSSL_OP_keymgmt_match_fn ecx_match;
|
||||
static OSSL_OP_keymgmt_import_fn ecx_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn ecx_imexport_types;
|
||||
static OSSL_OP_keymgmt_export_fn ecx_export;
|
||||
@@ -68,22 +69,22 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx);
|
||||
|
||||
static void *x25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_X25519, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X25519, 0);
|
||||
}
|
||||
|
||||
static void *x448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_X448, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X448, 0);
|
||||
}
|
||||
|
||||
static void *ed25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED25519, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED25519, 0);
|
||||
}
|
||||
|
||||
static void *ed448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED448, 0);
|
||||
return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED448, 0);
|
||||
}
|
||||
|
||||
static int ecx_has(void *keydata, int selection)
|
||||
@@ -104,6 +105,36 @@ static int ecx_has(void *keydata, int selection)
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_match(const void *keydata1, const void *keydata2, int selection)
|
||||
{
|
||||
const ECX_KEY *key1 = keydata1;
|
||||
const ECX_KEY *key2 = keydata2;
|
||||
int ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && key1->type == key2->type;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
|
||||
if ((key1->privkey == NULL && key2->privkey != NULL)
|
||||
|| (key1->privkey != NULL && key2->privkey == NULL)
|
||||
|| key1->type != key2->type)
|
||||
ok = 0;
|
||||
else
|
||||
ok = ok && (key1->privkey == NULL /* implies key2->privkey == NULL */
|
||||
|| CRYPTO_memcmp(key1->privkey, key2->privkey,
|
||||
key1->keylen) == 0);
|
||||
}
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
|
||||
if (key1->haspubkey != key2->haspubkey
|
||||
|| key1->type != key2->type)
|
||||
ok = 0;
|
||||
else
|
||||
ok = ok && (key1->haspubkey == 0 /* implies key2->haspubkey == 0 */
|
||||
|| CRYPTO_memcmp(key1->pubkey, key2->pubkey,
|
||||
key1->keylen) == 0);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
@@ -113,12 +144,11 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
|
||||
return 0;
|
||||
|
||||
include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && ecx_key_fromdata(key, params, include_private);
|
||||
ok = ok && ecx_key_fromdata(key, params, include_private);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -162,10 +192,6 @@ static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
&& !key_to_params(key, tmpl, NULL))
|
||||
goto err;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
|
||||
&& !key_to_params(key, tmpl, NULL))
|
||||
goto err;
|
||||
|
||||
params = OSSL_PARAM_BLD_to_param(tmpl);
|
||||
if (params == NULL)
|
||||
goto err;
|
||||
@@ -326,7 +352,7 @@ static void *ecx_gen(struct ecx_gen_ctx *gctx)
|
||||
|
||||
if (gctx == NULL)
|
||||
return NULL;
|
||||
if ((key = ecx_key_new(gctx->type, 0)) == NULL) {
|
||||
if ((key = ecx_key_new(gctx->libctx, gctx->type, 0)) == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
@@ -425,6 +451,7 @@ static void ecx_gen_cleanup(void *genctx)
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))alg##_get_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))alg##_gettable_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has }, \
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))ecx_match }, \
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ecx_import }, \
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))ecx_imexport_types }, \
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))ecx_export }, \
|
||||
@@ -450,7 +477,7 @@ static void *s390x_ecx_keygen25519(struct ecx_gen_ctx *gctx)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X25519, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X25519, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
if (key == NULL) {
|
||||
@@ -490,7 +517,7 @@ static void *s390x_ecx_keygen448(struct ecx_gen_ctx *gctx)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X448, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X448, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
if (key == NULL) {
|
||||
@@ -533,7 +560,7 @@ static void *s390x_ecd_keygen25519(struct ecx_gen_ctx *gctx)
|
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
||||
};
|
||||
unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH];
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED25519, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED25519, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
unsigned int sz;
|
||||
EVP_MD *sha = NULL;
|
||||
@@ -595,7 +622,7 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx)
|
||||
0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00
|
||||
};
|
||||
unsigned char x_dst[57], buff[114];
|
||||
ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED448, 1);
|
||||
ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED448, 1);
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
EVP_MD_CTX *hashctx = NULL;
|
||||
EVP_MD *shake = NULL;
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
#include "internal/param_build_set.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn rsa_newdata;
|
||||
static OSSL_OP_keymgmt_new_fn rsapss_newdata;
|
||||
static OSSL_OP_keymgmt_gen_init_fn rsa_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_init_fn rsapss_gen_init;
|
||||
static OSSL_OP_keymgmt_gen_set_params_fn rsa_gen_set_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn rsa_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_settable_params_fn rsapss_gen_settable_params;
|
||||
static OSSL_OP_keymgmt_gen_fn rsa_gen;
|
||||
static OSSL_OP_keymgmt_gen_cleanup_fn rsa_gen_cleanup;
|
||||
static OSSL_OP_keymgmt_free_fn rsa_freedata;
|
||||
@@ -35,51 +38,53 @@ static OSSL_OP_keymgmt_import_fn rsa_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn rsa_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn rsa_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn rsa_export_types;
|
||||
static OSSL_OP_keymgmt_query_operation_name_fn rsapss_query_operation_name;
|
||||
|
||||
#define RSA_DEFAULT_MD "SHA256"
|
||||
#define RSA_POSSIBLE_SELECTIONS \
|
||||
#define RSA_PSS_DEFAULT_MD OSSL_DIGEST_NAME_SHA1
|
||||
#define RSA_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
|
||||
|
||||
DEFINE_STACK_OF(BIGNUM)
|
||||
DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM)
|
||||
|
||||
static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
|
||||
static int pss_params_fromdata(RSA_PSS_PARAMS_30 *pss_params,
|
||||
const OSSL_PARAM params[], int rsa_type,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL;
|
||||
STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null();
|
||||
if (!rsa_pss_params_30_fromdata(pss_params, params, libctx))
|
||||
return 0;
|
||||
|
||||
if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL)
|
||||
goto err;
|
||||
/* If not a PSS type RSA, sending us PSS parameters is wrong */
|
||||
if (rsa_type != RSA_FLAG_TYPE_RSASSAPSS
|
||||
&& !rsa_pss_params_30_is_unrestricted(pss_params))
|
||||
return 0;
|
||||
|
||||
RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d);
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_N, rsa_n)
|
||||
|| !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_E, rsa_e)
|
||||
|| !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_D, rsa_d)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_factor_names,
|
||||
factors)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_exp_names,
|
||||
exps)
|
||||
|| !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_coeff_names,
|
||||
coeffs))
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
sk_BIGNUM_const_free(exps);
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newdata(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
RSA *rsa = rsa_new_with_ctx(libctx);
|
||||
|
||||
return rsa_new_with_ctx(libctx);
|
||||
if (rsa != NULL) {
|
||||
RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa, RSA_FLAG_TYPE_RSA);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
static void *rsapss_newdata(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
RSA *rsa = rsa_new_with_ctx(libctx);
|
||||
|
||||
if (rsa != NULL) {
|
||||
RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
static void rsa_freedata(void *keydata)
|
||||
@@ -97,7 +102,8 @@ static int rsa_has(void *keydata, int selection)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && 0; /* This will change with PSS and OAEP */
|
||||
/* This will change with OAEP */
|
||||
ok = ok && (RSA_test_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS) != 0);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && (RSA_get0_e(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
@@ -126,13 +132,22 @@ static int rsa_match(const void *keydata1, const void *keydata2, int selection)
|
||||
static int rsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
int rsa_type;
|
||||
int ok = 1;
|
||||
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) == 0)
|
||||
return 0;
|
||||
|
||||
rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
|
||||
/* TODO(3.0) OAEP should bring on parameters as well */
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && pss_params_fromdata(rsa_get0_pss_params_30(rsa), params,
|
||||
rsa_type, rsa_get0_libctx(rsa));
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && rsa_fromdata(rsa, params);
|
||||
|
||||
@@ -143,6 +158,7 @@ static int rsa_export(void *keydata, int selection,
|
||||
OSSL_CALLBACK *param_callback, void *cbarg)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ok = 1;
|
||||
@@ -150,14 +166,17 @@ static int rsa_export(void *keydata, int selection,
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
/* TODO(3.0) OAEP should bring on parameters */
|
||||
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && (rsa_pss_params_30_is_unrestricted(pss_params)
|
||||
|| rsa_pss_params_30_todata(pss_params, NULL, tmpl, NULL));
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(rsa, tmpl, NULL);
|
||||
ok = ok && rsa_todata(rsa, tmpl, NULL);
|
||||
|
||||
if (!ok
|
||||
|| (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
|
||||
@@ -170,7 +189,7 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
#ifdef FIPS_MODULE
|
||||
/* In fips mode there are no multi-primes. */
|
||||
# define RSA_KEY_MP_TYPES() \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
|
||||
@@ -259,6 +278,8 @@ static const OSSL_PARAM *rsa_export_types(int selection)
|
||||
static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
RSA *rsa = key;
|
||||
const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
int rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK);
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL
|
||||
@@ -271,32 +292,36 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
&& !OSSL_PARAM_set_int(p, RSA_size(rsa)))
|
||||
return 0;
|
||||
|
||||
# if 0 /* TODO(3.0): PSS support pending */
|
||||
if ((p = OSSL_PARAM_locate(params,
|
||||
OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL
|
||||
&& RSA_get0_pss_params(rsa) != NULL) {
|
||||
const EVP_MD *md, *mgf1md;
|
||||
int min_saltlen;
|
||||
|
||||
if (!rsa_pss_get_param(RSA_get0_pss_params(rsa),
|
||||
&md, &mgf1md, &min_saltlen)) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md)))
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* For RSA-PSS keys, we ignore the default digest request
|
||||
* TODO(3.0) with RSA-OAEP keys, this may need to be amended
|
||||
*/
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
|
||||
/* TODO(3.0): PSS support pending */
|
||||
#if 0
|
||||
&& RSA_get0_pss_params(rsa) == NULL
|
||||
#endif
|
||||
) {
|
||||
&& rsa_type != RSA_FLAG_TYPE_RSASSAPSS) {
|
||||
if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
|
||||
return 0;
|
||||
}
|
||||
return key_to_params(rsa, NULL, params);
|
||||
|
||||
/*
|
||||
* For non-RSA-PSS keys, we ignore the mandatory digest request
|
||||
* TODO(3.0) with RSA-OAEP keys, this may need to be amended
|
||||
*/
|
||||
if ((p = OSSL_PARAM_locate(params,
|
||||
OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL
|
||||
&& rsa_type == RSA_FLAG_TYPE_RSASSAPSS) {
|
||||
const char *mdname = RSA_PSS_DEFAULT_MD;
|
||||
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
mdname =
|
||||
rsa_oaeppss_nid2name(rsa_pss_params_30_hashalg(pss_params));
|
||||
|
||||
if (mdname == NULL || !OSSL_PARAM_set_utf8_string(p, mdname))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (rsa_type != RSA_FLAG_TYPE_RSASSAPSS
|
||||
|| rsa_pss_params_30_todata(pss_params, NULL, NULL, params))
|
||||
&& rsa_todata(rsa, NULL, params);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM rsa_params[] = {
|
||||
@@ -337,10 +362,15 @@ static int rsa_validate(void *keydata, int selection)
|
||||
struct rsa_gen_ctx {
|
||||
OPENSSL_CTX *libctx;
|
||||
|
||||
int rsa_type;
|
||||
|
||||
size_t nbits;
|
||||
BIGNUM *pub_exp;
|
||||
size_t primes;
|
||||
|
||||
/* For PSS */
|
||||
RSA_PSS_PARAMS_30 pss_params;
|
||||
|
||||
/* For generation callback */
|
||||
OSSL_CALLBACK *cb;
|
||||
void *cbarg;
|
||||
@@ -357,7 +387,7 @@ static int rsa_gencb(int p, int n, BN_GENCB *cb)
|
||||
return gctx->cb(params, gctx->cbarg);
|
||||
}
|
||||
|
||||
static void *rsa_gen_init(void *provctx, int selection)
|
||||
static void *gen_init(void *provctx, int selection, int rsa_type)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
struct rsa_gen_ctx *gctx = NULL;
|
||||
@@ -370,15 +400,32 @@ static void *rsa_gen_init(void *provctx, int selection)
|
||||
if ((gctx->pub_exp = BN_new()) == NULL
|
||||
|| !BN_set_word(gctx->pub_exp, RSA_F4)) {
|
||||
BN_free(gctx->pub_exp);
|
||||
OPENSSL_free(gctx);
|
||||
gctx = NULL;
|
||||
} else {
|
||||
gctx->nbits = 2048;
|
||||
gctx->primes = RSA_DEFAULT_PRIME_NUM;
|
||||
}
|
||||
gctx->rsa_type = rsa_type;
|
||||
}
|
||||
return gctx;
|
||||
}
|
||||
|
||||
static void *rsa_gen_init(void *provctx, int selection)
|
||||
{
|
||||
return gen_init(provctx, selection, RSA_FLAG_TYPE_RSA);
|
||||
}
|
||||
|
||||
static void *rsapss_gen_init(void *provctx, int selection)
|
||||
{
|
||||
return gen_init(provctx, selection, RSA_FLAG_TYPE_RSASSAPSS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is common for all RSA sub-types, to detect possible
|
||||
* misuse, such as PSS parameters being passed when a plain RSA key
|
||||
* is generated.
|
||||
*/
|
||||
static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
@@ -393,15 +440,44 @@ static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E)) != NULL
|
||||
&& !OSSL_PARAM_get_BN(p, &gctx->pub_exp))
|
||||
return 0;
|
||||
/* Only attempt to get PSS parameters when generating an RSA-PSS key */
|
||||
if (gctx->rsa_type == RSA_FLAG_TYPE_RSASSAPSS
|
||||
&& !pss_params_fromdata(&gctx->pss_params, params, gctx->rsa_type,
|
||||
gctx->libctx))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define rsa_gen_basic \
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL), \
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0)
|
||||
|
||||
/*
|
||||
* The following must be kept in sync with rsa_pss_params_30_fromdata()
|
||||
* in crypto/rsa/rsa_backend.c
|
||||
*/
|
||||
#define rsa_gen_pss \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_DIGEST, NULL, 0), \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MASKGENFUNC, NULL, 0), \
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MGF1_DIGEST, NULL, 0), \
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, NULL)
|
||||
|
||||
static const OSSL_PARAM *rsa_gen_settable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM settable[] = {
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL),
|
||||
OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0),
|
||||
rsa_gen_basic,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
return settable;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *rsapss_gen_settable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM settable[] = {
|
||||
rsa_gen_basic,
|
||||
rsa_gen_pss,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
@@ -411,11 +487,28 @@ static const OSSL_PARAM *rsa_gen_settable_params(void *provctx)
|
||||
static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
RSA *rsa = NULL;
|
||||
RSA *rsa = NULL, *rsa_tmp = NULL;
|
||||
BN_GENCB *gencb = NULL;
|
||||
|
||||
switch (gctx->rsa_type) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
/* For plain RSA keys, PSS parameters must not be set */
|
||||
if (!rsa_pss_params_30_is_unrestricted(&gctx->pss_params))
|
||||
goto err;
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
/*
|
||||
* For plain RSA-PSS keys, PSS parameters may be set but don't have
|
||||
* to, so not check.
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
/* Unsupported RSA key sub-type... */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (gctx == NULL
|
||||
|| (rsa = rsa_new_with_ctx(gctx->libctx)) == NULL)
|
||||
|| (rsa_tmp = rsa_new_with_ctx(gctx->libctx)) == NULL)
|
||||
return NULL;
|
||||
|
||||
gctx->cb = osslcb;
|
||||
@@ -424,14 +517,23 @@ static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
if (gencb != NULL)
|
||||
BN_GENCB_set(gencb, rsa_gencb, genctx);
|
||||
|
||||
if (!RSA_generate_multi_prime_key(rsa, (int)gctx->nbits, (int)gctx->primes,
|
||||
gctx->pub_exp, gencb)) {
|
||||
RSA_free(rsa);
|
||||
rsa = NULL;
|
||||
}
|
||||
if (!RSA_generate_multi_prime_key(rsa_tmp,
|
||||
(int)gctx->nbits, (int)gctx->primes,
|
||||
gctx->pub_exp, gencb))
|
||||
goto err;
|
||||
|
||||
if (!rsa_pss_params_30_copy(rsa_get0_pss_params_30(rsa_tmp),
|
||||
&gctx->pss_params))
|
||||
goto err;
|
||||
|
||||
RSA_clear_flags(rsa_tmp, RSA_FLAG_TYPE_MASK);
|
||||
RSA_set_flags(rsa_tmp, gctx->rsa_type);
|
||||
|
||||
rsa = rsa_tmp;
|
||||
rsa_tmp = NULL;
|
||||
err:
|
||||
BN_GENCB_free(gencb);
|
||||
|
||||
RSA_free(rsa_tmp);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
@@ -446,6 +548,12 @@ static void rsa_gen_cleanup(void *genctx)
|
||||
OPENSSL_free(gctx);
|
||||
}
|
||||
|
||||
/* For any RSA key, we use the "RSA" algorithms regardless of sub-type. */
|
||||
static const char *rsapss_query_operation_name(int operation_id)
|
||||
{
|
||||
return "RSA";
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsa_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsa_gen_init },
|
||||
@@ -467,3 +575,25 @@ const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const OSSL_DISPATCH rsapss_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsapss_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsapss_gen_init },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))rsa_gen_set_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
|
||||
(void (*)(void))rsapss_gen_settable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))rsa_gen },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))rsa_gen_cleanup },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))rsa_freedata },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))rsa_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))rsa_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))rsa_has },
|
||||
{ OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))rsa_validate },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))rsa_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))rsa_export },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types },
|
||||
{ OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME,
|
||||
(void (*)(void))rsapss_query_operation_name },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -250,6 +250,8 @@ static int kmac_init(void *vmacctx)
|
||||
return 0;
|
||||
|
||||
block_len = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest));
|
||||
if (block_len < 0)
|
||||
return 0;
|
||||
|
||||
/* Set default custom string if it is not already set */
|
||||
if (kctx->custom_len == 0) {
|
||||
|
||||
@@ -10,7 +10,10 @@ $ECX_GOAL=../../libimplementations.a
|
||||
$EC_GOAL=../../libimplementations.a
|
||||
|
||||
SOURCE[$SERIALIZER_GOAL]=serializer_common.c
|
||||
|
||||
SOURCE[$RSA_GOAL]=serializer_rsa.c serializer_rsa_priv.c serializer_rsa_pub.c
|
||||
DEPEND[serializer_rsa.o]=../../common/include/prov/der_rsa.h
|
||||
|
||||
IF[{- !$disabled{"dh"} || !$disabled{"dsa"} -}]
|
||||
SOURCE[$FFC_GOAL]=serializer_ffc_params.c
|
||||
ENDIF
|
||||
|
||||
@@ -178,7 +178,7 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
}
|
||||
|
||||
if (BN_is_zero(bn))
|
||||
return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
return BIO_printf(out, "%s%s0\n", label, post_label_spc);
|
||||
|
||||
if (BN_num_bytes(bn) <= BN_BYTES) {
|
||||
BN_ULONG *words = bn_get_words(bn);
|
||||
@@ -186,10 +186,8 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
if (BN_is_negative(bn))
|
||||
neg = "-";
|
||||
|
||||
return ossl_prov_bio_printf(out,
|
||||
"%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0],
|
||||
neg, words[0]);
|
||||
return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n",
|
||||
label, post_label_spc, neg, words[0], neg, words[0]);
|
||||
}
|
||||
|
||||
hex_str = BN_bn2hex(bn);
|
||||
@@ -198,18 +196,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
++p;
|
||||
neg = " (Negative)";
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
if (BIO_printf(out, "%s%s\n", label, neg) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Keep track of how many bytes we have printed out so far */
|
||||
bytes = 0;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s", spaces) <= 0)
|
||||
if (BIO_printf(out, "%s", spaces) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Add a leading 00 if the top bit is set */
|
||||
if (*p >= '8') {
|
||||
if (ossl_prov_bio_printf(out, "%02x", 0) <= 0)
|
||||
if (BIO_printf(out, "%02x", 0) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
use_sep = 1;
|
||||
@@ -217,18 +215,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
while (*p != '\0') {
|
||||
/* Do a newline after every 15 hex bytes + add the space indent */
|
||||
if ((bytes % 15) == 0 && bytes > 0) {
|
||||
if (ossl_prov_bio_printf(out, ":\n%s", spaces) <= 0)
|
||||
if (BIO_printf(out, ":\n%s", spaces) <= 0)
|
||||
goto err;
|
||||
use_sep = 0; /* The first byte on the next line doesnt have a : */
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "%s%c%c", use_sep ? ":" : "",
|
||||
ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
|
||||
if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "",
|
||||
ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0)
|
||||
goto err;
|
||||
++bytes;
|
||||
p += 2;
|
||||
use_sep = 1;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (BIO_printf(out, "\n") <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
@@ -244,22 +242,22 @@ int ossl_prov_print_labeled_buf(BIO *out, const char *label,
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s\n", label) <= 0)
|
||||
if (BIO_printf(out, "%s\n", label) <= 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < buflen; i++) {
|
||||
if ((i % LABELED_BUF_PRINT_WIDTH) == 0) {
|
||||
if (i > 0 && ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (i > 0 && BIO_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
if (ossl_prov_bio_printf(out, " ") <= 0)
|
||||
if (BIO_printf(out, " ") <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%02x%s", buf[i],
|
||||
if (BIO_printf(out, "%02x%s", buf[i],
|
||||
(i == buflen - 1) ? "" : ":") <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (ossl_prov_bio_printf(out, "\n") <= 0)
|
||||
if (BIO_printf(out, "\n") <= 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -70,7 +70,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type)
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p))
|
||||
<= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_param_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dh_param_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -69,14 +71,23 @@ static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_der(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_DHparams_bio(out, dh);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
ret = i2d_DHparams_bio(out, dh);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -97,13 +108,23 @@ static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_pem(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_DHparams(out, dh);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_DHparams(out, dh);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_param_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -124,10 +145,19 @@ static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_param_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_param_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_params);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_priv_newctx;
|
||||
@@ -117,7 +118,8 @@ static int dh_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -138,11 +140,15 @@ static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_priv_der(void *vctx, void *dh, BIO *out,
|
||||
static int dh_priv_der(void *vctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -151,12 +157,14 @@ static int dh_priv_der(void *vctx, void *dh, BIO *out,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -177,11 +185,15 @@ static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pem_priv(void *vctx, void *dh, BIO *out,
|
||||
static int dh_pem_priv(void *vctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -190,6 +202,7 @@ static int dh_pem_priv(void *vctx, void *dh, BIO *out,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -206,7 +219,8 @@ static void dh_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dh_priv_ctx_st *ctx = vctx;
|
||||
@@ -227,10 +241,19 @@ static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_priv_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_priv_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dh_pub_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dh_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
@@ -69,17 +71,27 @@ static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_der(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_der(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
|
||||
@@ -99,17 +111,26 @@ static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_pem(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH,
|
||||
ossl_prov_prepare_dh_params,
|
||||
ossl_prov_dh_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new();
|
||||
OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free();
|
||||
@@ -129,10 +150,19 @@ static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_pub_print(void *ctx, void *dh, BIO *out,
|
||||
static int dh_pub_print(void *ctx, void *dh, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dh(out, dh, dh_print_pub);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dh(out, dh, dh_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -73,8 +73,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type)
|
||||
if (p == NULL)
|
||||
goto null_err;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
BN_num_bits(p)) <= 0)
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0)
|
||||
goto err;
|
||||
if (priv_key != NULL
|
||||
&& !ossl_prov_print_labeled_bignum(out, "priv:", priv_key))
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_param_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dsa_param_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -69,14 +71,24 @@ static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_der(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_DSAparams_bio(out, dsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = i2d_DSAparams_bio(out, dsa);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -97,13 +109,23 @@ static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_pem(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_DSAparams(out, dsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_DSAparams(out, dsa);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -124,10 +146,19 @@ static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_param_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_param_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, dsa_print_params);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, dsa_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_priv_newctx;
|
||||
@@ -117,7 +118,8 @@ static int dsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -138,22 +140,31 @@ static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_priv_der(void *vctx, void *dsa, BIO *out,
|
||||
static int dsa_priv_der(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -174,18 +185,26 @@ static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pem_priv(void *vctx, void *dsa, BIO *out,
|
||||
static int dsa_pem_priv(void *vctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -201,7 +220,7 @@ static void dsa_print_freectx(void *ctx)
|
||||
}
|
||||
|
||||
static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct dsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -222,10 +241,19 @@ static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_priv_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_priv_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, dsa_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, dsa_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn dsa_pub_newctx;
|
||||
@@ -48,7 +49,8 @@ static void dsa_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -69,7 +71,7 @@ static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
/*
|
||||
@@ -77,8 +79,13 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
* in crypto/dsa/dsa_ameth.c
|
||||
*/
|
||||
int save_parameters = 1;
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
return
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret =
|
||||
save_parameters
|
||||
? ossl_prov_write_pub_der_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_all_dsa_params,
|
||||
@@ -87,10 +94,14 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -111,15 +122,26 @@ static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_pem(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA,
|
||||
ossl_prov_prepare_dsa_params,
|
||||
ossl_prov_dsa_pub_to_der);
|
||||
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new();
|
||||
@@ -140,10 +162,19 @@ static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dsa_pub_print(void *ctx, void *dsa, BIO *out,
|
||||
static int dsa_pub_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_dsa(out, dsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -31,15 +31,13 @@ static int ossl_prov_print_ec_param(BIO *out, const EC_GROUP *group)
|
||||
if (curve_nid == NID_undef)
|
||||
return 0;
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: %s\n", "ASN1 OID",
|
||||
OBJ_nid2sn(curve_nid)) <= 0)
|
||||
if (BIO_printf(out, "%s: %s\n", "ASN1 OID", OBJ_nid2sn(curve_nid)) <= 0)
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0): Only named curves are currently supported */
|
||||
curve_name = EC_curve_nid2nist(curve_nid);
|
||||
return (curve_name == NULL
|
||||
|| ossl_prov_bio_printf(out, "%s: %s\n", "NIST CURVE",
|
||||
curve_name) > 0);
|
||||
|| BIO_printf(out, "%s: %s\n", "NIST CURVE", curve_name) > 0);
|
||||
}
|
||||
|
||||
int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
@@ -86,8 +84,8 @@ int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
if (BIO_printf(out, "%s: (%d bit)\n", type_label,
|
||||
EC_GROUP_order_bits(group)) <= 0)
|
||||
goto err;
|
||||
if (priv != NULL
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", priv, priv_len))
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_param_newctx;
|
||||
@@ -39,8 +40,9 @@ static void ec_param_freectx(void *vctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -62,15 +64,25 @@ static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -92,14 +104,24 @@ static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey));
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_param_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
OSSL_OP_keymgmt_free_fn *ec_free;
|
||||
@@ -121,10 +143,19 @@ static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_param_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_param_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_params);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_param_der_serializer_functions[] = {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_priv_newctx;
|
||||
@@ -111,8 +112,9 @@ static int ec_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -134,23 +136,32 @@ static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_der(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -172,18 +183,26 @@ static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pem_priv(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pem_priv(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
return ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -198,7 +217,8 @@ static void ec_print_freectx(void *ctx)
|
||||
{
|
||||
}
|
||||
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ec_priv_ctx_st *ctx = vctx;
|
||||
@@ -221,10 +241,19 @@ static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_priv_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_priv_print(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn ec_pub_newctx;
|
||||
@@ -41,7 +42,8 @@ static void ec_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -64,16 +66,26 @@ static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_der(void *ctx, void *eckey, BIO *out,
|
||||
static int ec_pub_der(void *ctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -96,15 +108,25 @@ static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_pem(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC,
|
||||
ossl_prov_prepare_ec_params,
|
||||
ossl_prov_ec_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *ec_new;
|
||||
@@ -127,10 +149,19 @@ static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ec_pub_print(void *vctx, void *eckey, BIO *out,
|
||||
static int ec_pub_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO *out = bio_new_from_core_bio(vctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_eckey(out, eckey, ec_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -86,7 +86,7 @@ int ossl_prov_print_ecx(BIO *out, ECX_KEY *ecxkey, enum ecx_print_type type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ossl_prov_bio_printf(out, "%s:\n", type_label) <= 0)
|
||||
if (BIO_printf(out, "%s:\n", type_label) <= 0)
|
||||
return 0;
|
||||
if (type == ecx_print_priv
|
||||
&& !ossl_prov_print_labeled_buf(out, "priv:", ecxkey->privkey,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_priv_newctx;
|
||||
@@ -134,7 +135,8 @@ static int ecx_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -157,13 +159,17 @@ static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
static int ecx_priv_der(void *vctx, void *vecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
ECX_KEY *ecxkey = vecxkey;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -173,12 +179,14 @@ static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -201,12 +209,16 @@ static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
@@ -216,11 +228,13 @@ static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -243,10 +257,20 @@ static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_priv_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_pub_newctx;
|
||||
@@ -76,7 +77,8 @@ static void ecx_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -99,19 +101,28 @@ static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_der(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -134,19 +145,27 @@ static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
return ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
@@ -169,10 +188,20 @@ static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out,
|
||||
static int ecx_pub_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
|
||||
|
||||
@@ -20,7 +20,7 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
|
||||
if (name == NULL)
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
if (BIO_printf(out, "GROUP: %s\n", name) <= 0)
|
||||
goto err;
|
||||
return 1;
|
||||
#else
|
||||
@@ -46,15 +46,15 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->gindex != -1) {
|
||||
if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
if (BIO_printf(out, "gindex: %d\n", ffc->gindex) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->pcounter != -1) {
|
||||
if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
if (BIO_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (ffc->h != 0) {
|
||||
if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
if (BIO_printf(out, "h: %d\n", ffc->h) <= 0)
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -82,6 +82,14 @@ int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid,
|
||||
int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder);
|
||||
int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder);
|
||||
|
||||
/*
|
||||
* ossl_prov_prepare_rsa_params() is designed to work with the ossl_prov_write_
|
||||
* functions, hence 'void *rsa' rather than 'RSA *rsa'.
|
||||
*/
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype);
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa);
|
||||
|
||||
int ossl_prov_print_labeled_bignum(BIO *out, const char *label,
|
||||
const BIGNUM *bn);
|
||||
int ossl_prov_print_labeled_buf(BIO *out, const char *label,
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/packet.h"
|
||||
#include "crypto/rsa.h" /* rsa_get0_all_params() */
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/der_rsa.h" /* DER_w_RSASSA_PSS_params() */
|
||||
#include "prov/implementations.h" /* rsa_keymgmt_functions */
|
||||
#include "serializer_local.h"
|
||||
|
||||
@@ -37,6 +39,7 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null();
|
||||
STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null();
|
||||
RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa);
|
||||
int ret = 0;
|
||||
|
||||
if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL)
|
||||
@@ -46,15 +49,14 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (priv && rsa_d != NULL) {
|
||||
if (ossl_prov_bio_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
if (BIO_printf(out, "Private-Key: (%d bit, %d primes)\n",
|
||||
BN_num_bits(rsa_n),
|
||||
sk_BIGNUM_const_num(factors)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "modulus:";
|
||||
exponent_label = "publicExponent:";
|
||||
} else {
|
||||
if (ossl_prov_bio_printf(out, "Public-Key: (%d bit)\n",
|
||||
BN_num_bits(rsa_n)) <= 0)
|
||||
if (BIO_printf(out, "Public-Key: (%d bit)\n", BN_num_bits(rsa_n)) <= 0)
|
||||
goto err;
|
||||
modulus_label = "Modulus:";
|
||||
exponent_label = "Exponent:";
|
||||
@@ -84,18 +86,18 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_value(coeffs, 0)))
|
||||
goto err;
|
||||
for (i = 2; i < sk_BIGNUM_const_num(factors); i++) {
|
||||
if (ossl_prov_bio_printf(out, "prime%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "prime%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(factors,
|
||||
i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "exponent%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(exps, i)))
|
||||
goto err;
|
||||
if (ossl_prov_bio_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
if (BIO_printf(out, "coefficient%d:", i + 1) <= 0)
|
||||
goto err;
|
||||
if (!ossl_prov_print_labeled_bignum(out, NULL,
|
||||
sk_BIGNUM_const_value(coeffs,
|
||||
@@ -103,6 +105,60 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "(INVALID PSS PARAMETERS)\n") <= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss_params)) {
|
||||
if (BIO_printf(out, "No PSS parameter restrictions\n") <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
int hashalg_nid = rsa_pss_params_30_hashalg(pss_params);
|
||||
int maskgenalg_nid = rsa_pss_params_30_maskgenalg(pss_params);
|
||||
int maskgenhashalg_nid =
|
||||
rsa_pss_params_30_maskgenhashalg(pss_params);
|
||||
int saltlen = rsa_pss_params_30_saltlen(pss_params);
|
||||
int trailerfield = rsa_pss_params_30_trailerfield(pss_params);
|
||||
|
||||
if (BIO_printf(out, "PSS parameter restrictions:\n") <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Hash Algorithm: %s%s\n",
|
||||
rsa_oaeppss_nid2name(hashalg_nid),
|
||||
(hashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Mask Algorithm: %s with %s%s\n",
|
||||
rsa_mgf_nid2name(maskgenalg_nid),
|
||||
rsa_oaeppss_nid2name(maskgenhashalg_nid),
|
||||
(maskgenalg_nid == NID_mgf1
|
||||
&& maskgenhashalg_nid == NID_sha1
|
||||
? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
if (BIO_printf(out, " Minimum Salt Length: %d%s\n",
|
||||
saltlen,
|
||||
(saltlen == 20 ? " (default)" : "")) <= 0)
|
||||
goto err;
|
||||
/*
|
||||
* TODO(3.0) Should we show the ASN.1 trailerField value, or
|
||||
* the actual trailerfield byte (i.e. 0xBC for 1)?
|
||||
* crypto/rsa/rsa_ameth.c isn't very clear on that, as it
|
||||
* does display 0xBC when the default applies, but the ASN.1
|
||||
* trailerField value otherwise...
|
||||
*/
|
||||
if (BIO_printf(out, " Trailer Field: 0x%x%s\n",
|
||||
trailerfield,
|
||||
(trailerfield == 1 ? " (default)" : ""))
|
||||
<= 0)
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
@@ -110,3 +166,90 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions to prepare RSA-PSS params for serialization. We would
|
||||
* have simply written the whole AlgorithmIdentifier, but existing libcrypto
|
||||
* functionality doesn't allow that.
|
||||
*/
|
||||
|
||||
int ossl_prov_prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS_30 *pss = rsa_get0_pss_params_30((RSA *)rsa);
|
||||
|
||||
*pstr = NULL;
|
||||
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
/* If plain RSA, the parameters shall be NULL */
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
if (rsa_pss_params_30_is_unrestricted(pss)) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
} else {
|
||||
ASN1_STRING *astr = NULL;
|
||||
WPACKET pkt;
|
||||
unsigned char *str = NULL;
|
||||
size_t str_sz = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
if (!WPACKET_init_null_der(&pkt))
|
||||
goto err;
|
||||
break;
|
||||
case 1:
|
||||
if ((str = OPENSSL_malloc(str_sz)) == NULL
|
||||
|| !WPACKET_init_der(&pkt, str, str_sz)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!DER_w_RSASSA_PSS_params(&pkt, -1, pss)
|
||||
|| !WPACKET_finish(&pkt))
|
||||
goto err;
|
||||
WPACKET_get_total_written(&pkt, &str_sz);
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
/*
|
||||
* If no PSS parameters are going to be written, there's no
|
||||
* point going for another iteration.
|
||||
* This saves us from getting |str| allocated just to have it
|
||||
* immediately de-allocated.
|
||||
*/
|
||||
if (str_sz == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((astr = ASN1_STRING_new()) == NULL)
|
||||
goto err;
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
ASN1_STRING_set0(astr, str, (int)str_sz);
|
||||
*pstr = astr;
|
||||
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_free(str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ossl_prov_rsa_type_to_evp(const RSA *rsa)
|
||||
{
|
||||
switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
return EVP_PKEY_RSA;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
return EVP_PKEY_RSA_PSS;
|
||||
}
|
||||
|
||||
/* Currently unsupported RSA key type */
|
||||
return EVP_PKEY_NONE;
|
||||
}
|
||||
@@ -15,9 +15,11 @@
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include "crypto/rsa.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn rsa_priv_newctx;
|
||||
@@ -43,34 +45,6 @@ struct rsa_priv_ctx_st {
|
||||
struct pkcs8_encrypt_ctx_st sc;
|
||||
};
|
||||
|
||||
/* Helper functions to prepare RSA-PSS params for serialization */
|
||||
|
||||
static int prepare_rsa_params(const void *rsa, int nid,
|
||||
void **pstr, int *pstrtype)
|
||||
{
|
||||
const RSA_PSS_PARAMS *pss = RSA_get0_pss_params(rsa);
|
||||
*pstr = NULL;
|
||||
|
||||
/* If RSA it's just NULL type */
|
||||
if (nid != EVP_PKEY_RSA_PSS) {
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
}
|
||||
/* If no PSS parameters we omit parameters entirely */
|
||||
if (pss == NULL) {
|
||||
*pstrtype = V_ASN1_UNDEF;
|
||||
return 1;
|
||||
}
|
||||
/* Encode PSS parameters */
|
||||
if (ASN1_item_pack((void *)pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS),
|
||||
(ASN1_STRING **)pstr)
|
||||
== NULL)
|
||||
return 0;
|
||||
|
||||
*pstrtype = V_ASN1_SEQUENCE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Private key : context */
|
||||
static void *rsa_priv_newctx(void *provctx)
|
||||
{
|
||||
@@ -140,7 +114,8 @@ static int rsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* Private key : DER */
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -161,25 +136,32 @@ static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_der(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_der(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Private key : PEM */
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -200,19 +182,25 @@ static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, BIO *out,
|
||||
static int rsa_pem_priv(void *vctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa, EVP_PKEY_RSA,
|
||||
prepare_rsa_params,
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPrivateKey,
|
||||
&ctx->sc);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -230,7 +218,7 @@ static void rsa_print_freectx(void *ctx)
|
||||
}
|
||||
|
||||
static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
BIO *out,
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
struct rsa_priv_ctx_st *ctx = vctx;
|
||||
@@ -251,10 +239,19 @@ static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[],
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_priv_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_priv_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 1);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_priv_der_serializer_functions[] = {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn rsa_pub_newctx;
|
||||
@@ -42,7 +43,8 @@ static void rsa_pub_freectx(void *ctx)
|
||||
}
|
||||
|
||||
/* Public key : DER */
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -63,14 +65,27 @@ static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_der(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_der(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return i2d_RSA_PUBKEY_bio(out, rsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_der_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Public key : PEM */
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -91,13 +106,26 @@ static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_pem(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return PEM_write_bio_RSA_PUBKEY(out, rsa);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_write_pub_pem_from_obj(out, rsa,
|
||||
ossl_prov_rsa_type_to_evp(rsa),
|
||||
ossl_prov_prepare_rsa_params,
|
||||
(i2d_of_void *)i2d_RSAPublicKey);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
|
||||
OSSL_CORE_BIO *out,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
|
||||
@@ -118,10 +146,19 @@ static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int rsa_pub_print(void *ctx, void *rsa, BIO *out,
|
||||
static int rsa_pub_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
|
||||
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
|
||||
{
|
||||
return ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO *out = bio_new_from_core_bio(ctx, cout);
|
||||
int ret;
|
||||
|
||||
if (out == NULL)
|
||||
return 0;
|
||||
|
||||
ret = ossl_prov_print_rsa(out, rsa, 0);
|
||||
BIO_free(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_pub_der_serializer_functions[] = {
|
||||
|
||||
@@ -63,6 +63,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params;
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
DSA *dsa;
|
||||
|
||||
/*
|
||||
@@ -131,7 +132,7 @@ static int dsa_get_md_nid(const EVP_MD *md)
|
||||
return mdnid;
|
||||
}
|
||||
|
||||
static void *dsa_newctx(void *provctx)
|
||||
static void *dsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
|
||||
|
||||
@@ -140,12 +141,20 @@ static void *dsa_newctx(void *provctx)
|
||||
|
||||
pdsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
pdsactx->flag_allow_md = 1;
|
||||
if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
|
||||
OPENSSL_free(pdsactx);
|
||||
pdsactx = NULL;
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
}
|
||||
return pdsactx;
|
||||
}
|
||||
|
||||
static int dsa_setup_md(PROV_DSA_CTX *ctx,
|
||||
const char *mdname, const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = dsa_get_md_nid(md);
|
||||
@@ -234,7 +243,7 @@ static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen,
|
||||
}
|
||||
|
||||
static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
|
||||
const char *props, void *vdsa)
|
||||
void *vdsa)
|
||||
{
|
||||
PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
|
||||
|
||||
@@ -242,7 +251,7 @@ static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
|
||||
if (!dsa_signature_init(vpdsactx, vdsa))
|
||||
return 0;
|
||||
|
||||
if (!dsa_setup_md(pdsactx, mdname, props))
|
||||
if (!dsa_setup_md(pdsactx, mdname, NULL))
|
||||
return 0;
|
||||
|
||||
pdsactx->mdctx = EVP_MD_CTX_new();
|
||||
|
||||
@@ -60,6 +60,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn ecdsa_settable_ctx_md_params;
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
EC_KEY *ec;
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
|
||||
@@ -90,7 +91,7 @@ typedef struct {
|
||||
BIGNUM *r;
|
||||
} PROV_ECDSA_CTX;
|
||||
|
||||
static void *ecdsa_newctx(void *provctx)
|
||||
static void *ecdsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECDSA_CTX));
|
||||
|
||||
@@ -98,6 +99,11 @@ static void *ecdsa_newctx(void *provctx)
|
||||
return NULL;
|
||||
|
||||
ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
|
||||
OPENSSL_free(ctx);
|
||||
ctx = NULL;
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -203,7 +209,7 @@ static void free_md(PROV_ECDSA_CTX *ctx)
|
||||
}
|
||||
|
||||
static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
|
||||
const char *props, void *ec)
|
||||
void *ec)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
int md_nid = NID_undef;
|
||||
@@ -214,7 +220,7 @@ static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
|
||||
if (!ecdsa_signature_init(vctx, ec))
|
||||
return 0;
|
||||
|
||||
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, props);
|
||||
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq);
|
||||
if ((md_nid = get_md_nid(ctx->md)) == NID_undef)
|
||||
goto error;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef struct {
|
||||
ECX_KEY *key;
|
||||
} PROV_EDDSA_CTX;
|
||||
|
||||
static void *eddsa_newctx(void *provctx)
|
||||
static void *eddsa_newctx(void *provctx, const char *propq_unused)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX));
|
||||
|
||||
@@ -51,7 +51,7 @@ static void *eddsa_newctx(void *provctx)
|
||||
}
|
||||
|
||||
static int eddsa_digest_signverify_init(void *vpeddsactx, const char *mdname,
|
||||
const char *props, void *vedkey)
|
||||
void *vedkey)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
ECX_KEY *edkey = (ECX_KEY *)vedkey;
|
||||
|
||||
@@ -31,16 +31,16 @@
|
||||
#include "prov/der_rsa.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn rsa_newctx;
|
||||
static OSSL_OP_signature_sign_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_verify_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_verify_recover_init_fn rsa_signature_init;
|
||||
static OSSL_OP_signature_sign_init_fn rsa_sign_init;
|
||||
static OSSL_OP_signature_verify_init_fn rsa_verify_init;
|
||||
static OSSL_OP_signature_verify_recover_init_fn rsa_verify_recover_init;
|
||||
static OSSL_OP_signature_sign_fn rsa_sign;
|
||||
static OSSL_OP_signature_verify_fn rsa_verify;
|
||||
static OSSL_OP_signature_verify_recover_fn rsa_verify_recover;
|
||||
static OSSL_OP_signature_digest_sign_init_fn rsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_sign_init_fn rsa_digest_sign_init;
|
||||
static OSSL_OP_signature_digest_sign_update_fn rsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_sign_final_fn rsa_digest_sign_final;
|
||||
static OSSL_OP_signature_digest_verify_init_fn rsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_verify_init_fn rsa_digest_verify_init;
|
||||
static OSSL_OP_signature_digest_verify_update_fn rsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_verify_final_fn rsa_digest_verify_final;
|
||||
static OSSL_OP_signature_freectx_fn rsa_freectx;
|
||||
@@ -73,7 +73,9 @@ static OSSL_ITEM padding_item[] = {
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
char *propq;
|
||||
RSA *rsa;
|
||||
int operation;
|
||||
|
||||
/*
|
||||
* Flag to determine if the hash function can be changed (1) or not (0)
|
||||
@@ -129,6 +131,8 @@ static int rsa_get_md_nid(const EVP_MD *md)
|
||||
{ NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
|
||||
{ NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
|
||||
{ NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
|
||||
{ NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 },
|
||||
{ NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 },
|
||||
{ NID_md5, OSSL_DIGEST_NAME_MD5 },
|
||||
{ NID_md5_sha1, OSSL_DIGEST_NAME_MD5_SHA1 },
|
||||
{ NID_md2, OSSL_DIGEST_NAME_MD2 },
|
||||
@@ -153,9 +157,6 @@ static int rsa_get_md_nid(const EVP_MD *md)
|
||||
}
|
||||
}
|
||||
|
||||
if (mdnid == NID_undef)
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
|
||||
|
||||
end:
|
||||
return mdnid;
|
||||
}
|
||||
@@ -177,44 +178,51 @@ static int rsa_check_padding(int mdnid, int padding)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newctx(void *provctx)
|
||||
static int rsa_check_parameters(EVP_MD *md, PROV_RSA_CTX *prsactx)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
|
||||
if (prsactx->pad_mode == RSA_PKCS1_PSS_PADDING) {
|
||||
int max_saltlen;
|
||||
|
||||
if (prsactx == NULL)
|
||||
/* See if minimum salt length exceeds maximum possible */
|
||||
max_saltlen = RSA_size(prsactx->rsa) - EVP_MD_size(md);
|
||||
if ((RSA_bits(prsactx->rsa) & 0x7) == 1)
|
||||
max_saltlen--;
|
||||
if (prsactx->min_saltlen > max_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *rsa_newctx(void *provctx, const char *propq)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = NULL;
|
||||
char *propq_copy = NULL;
|
||||
|
||||
if ((prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX))) == NULL
|
||||
|| (propq != NULL
|
||||
&& (propq_copy = OPENSSL_strdup(propq)) == NULL)) {
|
||||
OPENSSL_free(prsactx);
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
prsactx->flag_allow_md = 1;
|
||||
prsactx->propq = propq_copy;
|
||||
return prsactx;
|
||||
}
|
||||
|
||||
/* True if PSS parameters are restricted */
|
||||
#define rsa_pss_restricted(prsactx) (prsactx->min_saltlen != -1)
|
||||
|
||||
static int rsa_signature_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa))
|
||||
return 0;
|
||||
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
if (RSA_get0_pss_params(prsactx->rsa) != NULL)
|
||||
prsactx->pad_mode = RSA_PKCS1_PSS_PADDING;
|
||||
else
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
/* Maximum for sign, auto for verify */
|
||||
prsactx->saltlen = RSA_PSS_SALTLEN_AUTO;
|
||||
prsactx->min_saltlen = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = rsa_get_md_nid(md);
|
||||
@@ -222,7 +230,14 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
|
||||
if (md == NULL
|
||||
|| md_nid == NID_undef
|
||||
|| !rsa_check_padding(md_nid, ctx->pad_mode)) {
|
||||
|| !rsa_check_padding(md_nid, ctx->pad_mode)
|
||||
|| !rsa_check_parameters(md, ctx)) {
|
||||
if (md == NULL)
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"%s could not be fetched", mdname);
|
||||
if (md_nid == NID_undef)
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
|
||||
"digest=%s", mdname);
|
||||
EVP_MD_free(md);
|
||||
return 0;
|
||||
}
|
||||
@@ -256,18 +271,90 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
}
|
||||
|
||||
static int rsa_setup_mgf1_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
const char *props)
|
||||
const char *mdprops)
|
||||
{
|
||||
if (mdprops == NULL)
|
||||
mdprops = ctx->propq;
|
||||
|
||||
if (ctx->mgf1_mdname[0] != '\0')
|
||||
EVP_MD_free(ctx->mgf1_md);
|
||||
|
||||
if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, props)) == NULL)
|
||||
if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, mdprops)) == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"%s could not be fetched", mdname);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_strlcpy(ctx->mgf1_mdname, mdname, sizeof(ctx->mgf1_mdname));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_signature_init(void *vprsactx, void *vrsa, int operation)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa))
|
||||
return 0;
|
||||
|
||||
RSA_free(prsactx->rsa);
|
||||
prsactx->rsa = vrsa;
|
||||
prsactx->operation = operation;
|
||||
|
||||
/* Maximum for sign, auto for verify */
|
||||
prsactx->saltlen = RSA_PSS_SALTLEN_AUTO;
|
||||
prsactx->min_saltlen = -1;
|
||||
|
||||
switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
|
||||
case RSA_FLAG_TYPE_RSA:
|
||||
prsactx->pad_mode = RSA_PKCS1_PADDING;
|
||||
break;
|
||||
case RSA_FLAG_TYPE_RSASSAPSS:
|
||||
prsactx->pad_mode = RSA_PKCS1_PSS_PADDING;
|
||||
|
||||
{
|
||||
const RSA_PSS_PARAMS_30 *pss =
|
||||
rsa_get0_pss_params_30(prsactx->rsa);
|
||||
|
||||
if (!rsa_pss_params_30_is_unrestricted(pss)) {
|
||||
int md_nid = rsa_pss_params_30_hashalg(pss);
|
||||
int mgf1md_nid = rsa_pss_params_30_maskgenhashalg(pss);
|
||||
int min_saltlen = rsa_pss_params_30_saltlen(pss);
|
||||
const char *mdname, *mgf1mdname;
|
||||
|
||||
mdname = rsa_oaeppss_nid2name(md_nid);
|
||||
mgf1mdname = rsa_oaeppss_nid2name(mgf1md_nid);
|
||||
prsactx->min_saltlen = min_saltlen;
|
||||
|
||||
if (mdname == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"PSS restrictions lack hash algorithm");
|
||||
return 0;
|
||||
}
|
||||
if (mgf1mdname == NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
|
||||
"PSS restrictions lack MGF1 hash algorithm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(prsactx->mdname, mdname, sizeof(prsactx->mdname));
|
||||
strncpy(prsactx->mgf1_mdname, mgf1mdname,
|
||||
sizeof(prsactx->mgf1_mdname));
|
||||
prsactx->saltlen = min_saltlen;
|
||||
|
||||
return rsa_setup_md(prsactx, mdname, prsactx->propq)
|
||||
&& rsa_setup_mgf1_md(prsactx, mgf1mdname, prsactx->propq);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ERR_raise(ERR_LIB_RSA, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setup_tbuf(PROV_RSA_CTX *ctx)
|
||||
{
|
||||
if (ctx->tbuf != NULL)
|
||||
@@ -287,10 +374,16 @@ static void clean_tbuf(PROV_RSA_CTX *ctx)
|
||||
|
||||
static void free_tbuf(PROV_RSA_CTX *ctx)
|
||||
{
|
||||
OPENSSL_clear_free(ctx->tbuf, RSA_size(ctx->rsa));
|
||||
clean_tbuf(ctx);
|
||||
OPENSSL_free(ctx->tbuf);
|
||||
ctx->tbuf = NULL;
|
||||
}
|
||||
|
||||
static int rsa_sign_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_SIGN);
|
||||
}
|
||||
|
||||
static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize, const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
@@ -304,8 +397,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sigsize < (size_t)rsasize)
|
||||
if (sigsize < rsasize) {
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SIGNATURE_SIZE,
|
||||
"is %zu, should be at least %zu", sigsize, rsasize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mdsize != 0) {
|
||||
if (tbslen != mdsize) {
|
||||
@@ -313,7 +409,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
if (EVP_MD_is_a(prsactx->md, OSSL_DIGEST_NAME_MDC2)) {
|
||||
unsigned int sltmp;
|
||||
|
||||
@@ -336,7 +432,9 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
switch (prsactx->pad_mode) {
|
||||
case RSA_X931_PADDING:
|
||||
if ((size_t)RSA_size(prsactx->rsa) < tbslen + 1) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL,
|
||||
"RSA key size = %d, expected minimum = %d",
|
||||
RSA_size(prsactx->rsa), tbslen + 1);
|
||||
return 0;
|
||||
}
|
||||
if (!setup_tbuf(prsactx)) {
|
||||
@@ -370,14 +468,24 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"minimum salt length set to %d, "
|
||||
"but the digest only gives %d",
|
||||
prsactx->min_saltlen,
|
||||
EVP_MD_size(prsactx->md));
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (prsactx->saltlen >= 0
|
||||
&& prsactx->saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"minimum salt length set to %d, but the"
|
||||
"actual salt length is only set to %d",
|
||||
prsactx->min_saltlen,
|
||||
prsactx->saltlen);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -407,7 +515,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
prsactx->pad_mode);
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
#ifndef FIPS_MODULE
|
||||
end:
|
||||
#endif
|
||||
if (ret <= 0) {
|
||||
@@ -419,6 +527,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_verify_recover_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFYRECOVER);
|
||||
}
|
||||
|
||||
static int rsa_verify_recover(void *vprsactx,
|
||||
unsigned char *rout,
|
||||
size_t *routlen,
|
||||
@@ -459,7 +572,9 @@ static int rsa_verify_recover(void *vprsactx,
|
||||
|
||||
*routlen = ret;
|
||||
if (routsize < (size_t)ret) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
ERR_raise_data(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL,
|
||||
"buffer size is %d, should be %d",
|
||||
routsize, ret);
|
||||
return 0;
|
||||
}
|
||||
memcpy(rout, prsactx->tbuf, ret);
|
||||
@@ -496,6 +611,11 @@ static int rsa_verify_recover(void *vprsactx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rsa_verify_init(void *vprsactx, void *vrsa)
|
||||
{
|
||||
return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFY);
|
||||
}
|
||||
|
||||
static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
@@ -520,29 +640,6 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
int ret;
|
||||
size_t mdsize;
|
||||
|
||||
/* Check PSS restrictions */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_AUTO:
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN);
|
||||
return 0;
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (prsactx->saltlen >= 0
|
||||
&& prsactx->saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to check this for the RSA_verify_PKCS1_PSS_mgf1()
|
||||
* call
|
||||
@@ -596,18 +693,20 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen,
|
||||
}
|
||||
|
||||
static int rsa_digest_signverify_init(void *vprsactx, const char *mdname,
|
||||
const char *props, void *vrsa)
|
||||
void *vrsa, int operation)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
prsactx->flag_allow_md = 0;
|
||||
if (!rsa_signature_init(vprsactx, vrsa)
|
||||
|| !rsa_setup_md(prsactx, mdname, props))
|
||||
if (!rsa_signature_init(vprsactx, vrsa, operation)
|
||||
|| !rsa_setup_md(prsactx, mdname, NULL)) /* TODO RL */
|
||||
return 0;
|
||||
|
||||
prsactx->mdctx = EVP_MD_CTX_new();
|
||||
if (prsactx->mdctx == NULL)
|
||||
if (prsactx->mdctx == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!EVP_DigestInit_ex(prsactx->mdctx, prsactx->md, NULL))
|
||||
goto error;
|
||||
@@ -622,8 +721,9 @@ static int rsa_digest_signverify_init(void *vprsactx, const char *mdname,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data,
|
||||
size_t datalen)
|
||||
static int rsa_digest_signverify_update(void *vprsactx,
|
||||
const unsigned char *data,
|
||||
size_t datalen)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
|
||||
@@ -633,8 +733,15 @@ int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data,
|
||||
return EVP_DigestUpdate(prsactx->mdctx, data, datalen);
|
||||
}
|
||||
|
||||
int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize)
|
||||
static int rsa_digest_sign_init(void *vprsactx, const char *mdname,
|
||||
void *vrsa)
|
||||
{
|
||||
return rsa_digest_signverify_init(vprsactx, mdname, vrsa,
|
||||
EVP_PKEY_OP_SIGN);
|
||||
}
|
||||
|
||||
static int rsa_digest_sign_final(void *vprsactx, unsigned char *sig,
|
||||
size_t *siglen, size_t sigsize)
|
||||
{
|
||||
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
@@ -661,6 +768,12 @@ int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
return rsa_sign(vprsactx, sig, siglen, sigsize, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
static int rsa_digest_verify_init(void *vprsactx, const char *mdname,
|
||||
void *vrsa)
|
||||
{
|
||||
return rsa_digest_signverify_init(vprsactx, mdname, vrsa,
|
||||
EVP_PKEY_OP_VERIFY);
|
||||
}
|
||||
|
||||
int rsa_digest_verify_final(void *vprsactx, const unsigned char *sig,
|
||||
size_t siglen)
|
||||
@@ -695,6 +808,7 @@ static void rsa_freectx(void *vprsactx)
|
||||
EVP_MD_CTX_free(prsactx->mdctx);
|
||||
EVP_MD_free(prsactx->md);
|
||||
EVP_MD_free(prsactx->mgf1_md);
|
||||
OPENSSL_free(prsactx->propq);
|
||||
free_tbuf(prsactx);
|
||||
|
||||
OPENSSL_clear_free(prsactx, sizeof(prsactx));
|
||||
@@ -706,8 +820,10 @@ static void *rsa_dupctx(void *vprsactx)
|
||||
PROV_RSA_CTX *dstctx;
|
||||
|
||||
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
|
||||
if (dstctx == NULL)
|
||||
if (dstctx == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*dstctx = *srcctx;
|
||||
dstctx->rsa = NULL;
|
||||
@@ -858,11 +974,13 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
|
||||
return 0;
|
||||
if (propsp != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
|
||||
|
||||
if (propsp == NULL)
|
||||
pmdprops = NULL;
|
||||
else if (!OSSL_PARAM_get_utf8_string(propsp,
|
||||
&pmdprops, sizeof(mdprops)))
|
||||
return 0;
|
||||
|
||||
/* TODO(3.0) PSS check needs more work */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
/* TODO(3.0) figure out what to do for prsactx->md == NULL */
|
||||
if (prsactx->md == NULL || EVP_MD_is_a(prsactx->md, mdname))
|
||||
@@ -872,13 +990,14 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* non-PSS code follows */
|
||||
if (!rsa_setup_md(prsactx, mdname, mdprops))
|
||||
if (!rsa_setup_md(prsactx, mdname, pmdprops))
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PAD_MODE);
|
||||
if (p != NULL) {
|
||||
int pad_mode = 0;
|
||||
const char *err_extra_text = NULL;
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
|
||||
@@ -910,31 +1029,49 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
* OAEP padding is for asymmetric cipher only so is not compatible
|
||||
* with signature use.
|
||||
*/
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
"OAEP padding not allowed for signing / verifying");
|
||||
return 0;
|
||||
err_extra_text = "OAEP padding not allowed for signing / verifying";
|
||||
goto bad_pad;
|
||||
case RSA_PKCS1_PSS_PADDING:
|
||||
if (prsactx->mdname[0] == '\0')
|
||||
rsa_setup_md(prsactx, "SHA1", "");
|
||||
goto cont;
|
||||
case RSA_PKCS1_PADDING:
|
||||
case RSA_SSLV23_PADDING:
|
||||
case RSA_NO_PADDING:
|
||||
case RSA_X931_PADDING:
|
||||
if (RSA_get0_pss_params(prsactx->rsa) != NULL) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
"X.931 padding not allowed with RSA-PSS");
|
||||
if ((prsactx->operation
|
||||
& (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY)) == 0) {
|
||||
err_extra_text =
|
||||
"PSS padding only allowed for sign and verify operations";
|
||||
goto bad_pad;
|
||||
}
|
||||
if (prsactx->md == NULL
|
||||
&& !rsa_setup_md(prsactx, OSSL_DIGEST_NAME_SHA1, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
cont:
|
||||
if (!rsa_check_padding(prsactx->mdnid, pad_mode))
|
||||
return 0;
|
||||
break;
|
||||
case RSA_PKCS1_PADDING:
|
||||
err_extra_text = "PKCS#1 padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_SSLV23_PADDING:
|
||||
err_extra_text = "SSLv3 padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_NO_PADDING:
|
||||
err_extra_text = "No padding not allowed with RSA-PSS";
|
||||
goto cont;
|
||||
case RSA_X931_PADDING:
|
||||
err_extra_text = "X.931 padding not allowed with RSA-PSS";
|
||||
cont:
|
||||
if (RSA_test_flags(prsactx->rsa,
|
||||
RSA_FLAG_TYPE_MASK) == RSA_FLAG_TYPE_RSA)
|
||||
break;
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
bad_pad:
|
||||
if (err_extra_text == NULL)
|
||||
ERR_raise(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
|
||||
else
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE,
|
||||
err_extra_text);
|
||||
return 0;
|
||||
}
|
||||
if (!rsa_check_padding(prsactx->mdnid, pad_mode))
|
||||
return 0;
|
||||
prsactx->pad_mode = pad_mode;
|
||||
}
|
||||
|
||||
@@ -978,6 +1115,37 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
switch (prsactx->saltlen) {
|
||||
case RSA_PSS_SALTLEN_AUTO:
|
||||
if (prsactx->operation == EVP_PKEY_OP_VERIFY) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case RSA_PSS_SALTLEN_DIGEST:
|
||||
if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"Should be more than %d, but would be "
|
||||
"set to match digest size (%d)",
|
||||
prsactx->min_saltlen,
|
||||
EVP_MD_size(prsactx->md));
|
||||
return 0;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
if (saltlen >= 0 && saltlen < prsactx->min_saltlen) {
|
||||
ERR_raise_data(ERR_LIB_PROV,
|
||||
PROV_R_PSS_SALTLEN_TOO_SMALL,
|
||||
"Should be more than %d, "
|
||||
"but would be set to %d",
|
||||
prsactx->min_saltlen, saltlen);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prsactx->saltlen = saltlen;
|
||||
}
|
||||
|
||||
@@ -991,8 +1159,11 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
|
||||
return 0;
|
||||
if (propsp != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
|
||||
|
||||
if (propsp == NULL)
|
||||
pmdprops = NULL;
|
||||
else if (!OSSL_PARAM_get_utf8_string(propsp,
|
||||
&pmdprops, sizeof(mdprops)))
|
||||
return 0;
|
||||
|
||||
if (prsactx->pad_mode != RSA_PKCS1_PSS_PADDING) {
|
||||
@@ -1000,9 +1171,8 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO(3.0) PSS check needs more work */
|
||||
if (rsa_pss_restricted(prsactx)) {
|
||||
/* TODO(3.0) figure out what to do for prsactx->md == NULL */
|
||||
/* TODO(3.0) figure out what to do for prsactx->mgf1_md == NULL */
|
||||
if (prsactx->mgf1_md == NULL
|
||||
|| EVP_MD_is_a(prsactx->mgf1_md, mdname))
|
||||
return 1;
|
||||
@@ -1011,7 +1181,7 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
|
||||
}
|
||||
|
||||
/* non-PSS code follows */
|
||||
if (!rsa_setup_mgf1_md(prsactx, mdname, mdprops))
|
||||
if (!rsa_setup_mgf1_md(prsactx, mdname, pmdprops))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1081,20 +1251,22 @@ static const OSSL_PARAM *rsa_settable_ctx_md_params(void *vprsactx)
|
||||
|
||||
const OSSL_DISPATCH rsa_signature_functions[] = {
|
||||
{ OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))rsa_newctx },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_sign_init },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))rsa_sign },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_verify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))rsa_verify },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT, (void (*)(void))rsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER, (void (*)(void))rsa_verify_recover },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT,
|
||||
(void (*)(void))rsa_verify_recover_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_RECOVER,
|
||||
(void (*)(void))rsa_verify_recover },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
|
||||
(void (*)(void))rsa_digest_signverify_init },
|
||||
(void (*)(void))rsa_digest_sign_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
|
||||
(void (*)(void))rsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
|
||||
(void (*)(void))rsa_digest_sign_final },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
|
||||
(void (*)(void))rsa_digest_signverify_init },
|
||||
(void (*)(void))rsa_digest_verify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
|
||||
(void (*)(void))rsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
|
||||
|
||||
+38
-18
@@ -13,8 +13,17 @@
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "prov/implementations.h"
|
||||
|
||||
/*
|
||||
* Forward declarations to ensure that interface functions are correctly
|
||||
* defined.
|
||||
*/
|
||||
static OSSL_provider_gettable_params_fn legacy_gettable_params;
|
||||
static OSSL_provider_get_params_fn legacy_get_params;
|
||||
static OSSL_provider_query_operation_fn legacy_query;
|
||||
|
||||
#define ALG(NAMES, FUNC) { NAMES, "provider=legacy", FUNC }
|
||||
|
||||
#ifdef STATIC_LEGACY
|
||||
@@ -27,19 +36,19 @@ static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
|
||||
static OSSL_core_get_params_fn *c_get_params = NULL;
|
||||
|
||||
/* Parameters we provide to the core */
|
||||
static const OSSL_ITEM legacy_param_types[] = {
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
|
||||
{ 0, NULL }
|
||||
static const OSSL_PARAM legacy_param_types[] = {
|
||||
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
|
||||
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
|
||||
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static const OSSL_ITEM *legacy_gettable_params(const OSSL_PROVIDER *prov)
|
||||
static const OSSL_PARAM *legacy_gettable_params(void *provctx)
|
||||
{
|
||||
return legacy_param_types;
|
||||
}
|
||||
|
||||
static int legacy_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
static int legacy_get_params(void *provctx, OSSL_PARAM params[])
|
||||
{
|
||||
OSSL_PARAM *p;
|
||||
|
||||
@@ -79,8 +88,8 @@ static const OSSL_ALGORITHM legacy_ciphers[] = {
|
||||
#ifndef OPENSSL_NO_CAST
|
||||
ALG("CAST5-ECB", cast5128ecb_functions),
|
||||
ALG("CAST5-CBC:CAST-CBC:CAST", cast5128cbc_functions),
|
||||
ALG("CAST5-OFB", cast564ofb64_functions),
|
||||
ALG("CAST5-CFB", cast564cfb64_functions),
|
||||
ALG("CAST5-OFB", cast5128ofb64_functions),
|
||||
ALG("CAST5-CFB", cast5128cfb64_functions),
|
||||
#endif /* OPENSSL_NO_CAST */
|
||||
#ifndef OPENSSL_NO_BF
|
||||
ALG("BF-ECB", blowfish128ecb_functions),
|
||||
@@ -133,8 +142,7 @@ static const OSSL_ALGORITHM legacy_ciphers[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov,
|
||||
int operation_id,
|
||||
static const OSSL_ALGORITHM *legacy_query(void *provctx, int operation_id,
|
||||
int *no_cache)
|
||||
{
|
||||
*no_cache = 0;
|
||||
@@ -147,20 +155,28 @@ static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void legacy_teardown(void *provctx)
|
||||
{
|
||||
OPENSSL_CTX_free(PROV_LIBRARY_CONTEXT_OF(provctx));
|
||||
PROV_CTX_free(provctx);
|
||||
}
|
||||
|
||||
/* Functions we provide to the core */
|
||||
static const OSSL_DISPATCH legacy_dispatch_table[] = {
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))legacy_teardown },
|
||||
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
OSSL_core_get_library_context_fn *c_get_libctx = NULL;
|
||||
OPENSSL_CTX *libctx = NULL;
|
||||
|
||||
for (; in->function_id != 0; in++) {
|
||||
switch (in->function_id) {
|
||||
@@ -182,13 +198,17 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
if (c_get_libctx == NULL)
|
||||
return 0;
|
||||
|
||||
if ((*provctx = PROV_CTX_new()) == NULL
|
||||
|| (libctx = OPENSSL_CTX_new()) == NULL) {
|
||||
OPENSSL_CTX_free(libctx);
|
||||
legacy_teardown(*provctx);
|
||||
*provctx = NULL;
|
||||
return 0;
|
||||
}
|
||||
PROV_CTX_set0_library_context(*provctx, libctx);
|
||||
PROV_CTX_set0_handle(*provctx, handle);
|
||||
|
||||
*out = legacy_dispatch_table;
|
||||
|
||||
/*
|
||||
* We want to make sure that all calls from this provider that requires
|
||||
* a library context use the same context as the one used to call our
|
||||
* functions. We do that by passing it along as the provider context.
|
||||
*/
|
||||
*provctx = c_get_libctx(provider);
|
||||
return 1;
|
||||
}
|
||||
+3
-33
@@ -17,10 +17,6 @@
|
||||
|
||||
OSSL_provider_init_fn ossl_null_provider_init;
|
||||
|
||||
/* Functions provided by the core */
|
||||
static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
|
||||
static OSSL_core_get_params_fn *c_get_params = NULL;
|
||||
|
||||
/* Parameters we provide to the core */
|
||||
static const OSSL_ITEM null_param_types[] = {
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
|
||||
@@ -67,40 +63,14 @@ static const OSSL_DISPATCH null_dispatch_table[] = {
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
int ossl_null_provider_init(const OSSL_PROVIDER *provider,
|
||||
int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
OSSL_core_get_library_context_fn *c_get_libctx = NULL;
|
||||
|
||||
for (; in->function_id != 0; in++) {
|
||||
switch (in->function_id) {
|
||||
case OSSL_FUNC_CORE_GETTABLE_PARAMS:
|
||||
c_gettable_params = OSSL_get_core_gettable_params(in);
|
||||
break;
|
||||
case OSSL_FUNC_CORE_GET_PARAMS:
|
||||
c_get_params = OSSL_get_core_get_params(in);
|
||||
break;
|
||||
case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
|
||||
c_get_libctx = OSSL_get_core_get_library_context(in);
|
||||
break;
|
||||
/* Just ignore anything we don't understand */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (c_get_libctx == NULL)
|
||||
return 0;
|
||||
|
||||
*out = null_dispatch_table;
|
||||
|
||||
/*
|
||||
* We want to make sure that all calls from this provider that requires
|
||||
* a library context use the same context as the one used to call our
|
||||
* functions. We do that by passing it along as the provider context.
|
||||
*/
|
||||
*provctx = c_get_libctx(provider);
|
||||
/* Could be anything - we don't use it */
|
||||
*provctx = (void *)handle;
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user