Latest update.
This commit is contained in:
+11
-1
@@ -47,7 +47,7 @@ $COMMON_INCLUDES=../crypto ../include implementations/include common/include
|
||||
|
||||
INCLUDE[$LIBCOMMON]=$COMMON_INCLUDES
|
||||
INCLUDE[$LIBIMPLEMENTATIONS]=.. $COMMON_INCLUDES
|
||||
INCLUDE[$LIBLEGACY]=$COMMON_INCLUDES
|
||||
INCLUDE[$LIBLEGACY]=.. $COMMON_INCLUDES
|
||||
INCLUDE[$LIBNONFIPS]=$COMMON_INCLUDES
|
||||
INCLUDE[$LIBFIPS]=.. $COMMON_INCLUDES
|
||||
DEFINE[$LIBFIPS]=FIPS_MODE
|
||||
@@ -151,3 +151,13 @@ IF[{- !$disabled{legacy} -}]
|
||||
SOURCE[$LEGACYGOAL]=legacyprov.c
|
||||
INCLUDE[$LEGACYGOAL]=../include implementations/include
|
||||
ENDIF
|
||||
|
||||
#
|
||||
# Null provider stuff
|
||||
#
|
||||
# Because the null provider is built in, it means that libcrypto must
|
||||
# include all the object files that are needed.
|
||||
$NULLGOAL=../libcrypto
|
||||
SOURCE[$NULLGOAL]=nullprov.c
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
SUBDIRS=der
|
||||
|
||||
SOURCE[../libcommon.a]=provider_err.c bio_prov.c
|
||||
$FIPSCOMMON=provider_util.c
|
||||
SOURCE[../libnonfips.a]=$FIPSCOMMON nid_to_name.c
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from RFC 3279, 3 ASN.1 Module
|
||||
-- (https://www.rfc-editor.org/rfc/rfc3279.html#section-3)
|
||||
|
||||
-- OID for DSA public key
|
||||
|
||||
id-dsa OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) x9-57(10040) x9algorithm(4) 1 }
|
||||
|
||||
-- OID for DSA signature generated with SHA-1 hash
|
||||
|
||||
id-dsa-with-sha1 OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) x9-57 (10040) x9algorithm(4) 3 }
|
||||
|
||||
|
||||
-- -------------------------------------------------------------------
|
||||
-- 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-dsa-with-sha224 OBJECT IDENTIFIER ::= { sigAlgs 1 }
|
||||
id-dsa-with-sha256 OBJECT IDENTIFIER ::= { sigAlgs 2 }
|
||||
id-dsa-with-sha384 OBJECT IDENTIFIER ::= { sigAlgs 3 }
|
||||
id-dsa-with-sha512 OBJECT IDENTIFIER ::= { sigAlgs 4 }
|
||||
|
||||
id-dsa-with-sha3-224 OBJECT IDENTIFIER ::= { sigAlgs 5 }
|
||||
id-dsa-with-sha3-256 OBJECT IDENTIFIER ::= { sigAlgs 6 }
|
||||
id-dsa-with-sha3-384 OBJECT IDENTIFIER ::= { sigAlgs 7 }
|
||||
id-dsa-with-sha3-512 OBJECT IDENTIFIER ::= { sigAlgs 8 }
|
||||
@@ -0,0 +1,83 @@
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from RFC 3279, 3 ASN.1 Module
|
||||
-- (https://www.rfc-editor.org/rfc/rfc3279.html#section-3)
|
||||
|
||||
ansi-X9-62 OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) 10045 }
|
||||
|
||||
-- Arc for ECDSA signature OIDS
|
||||
|
||||
id-ecSigType OBJECT IDENTIFIER ::= { ansi-X9-62 signatures(4) }
|
||||
|
||||
-- OID for ECDSA signatures with SHA-1
|
||||
|
||||
ecdsa-with-SHA1 OBJECT IDENTIFIER ::= { id-ecSigType 1 }
|
||||
|
||||
id-publicKeyType OBJECT IDENTIFIER ::= { ansi-X9-62 keyType(2) }
|
||||
|
||||
id-ecPublicKey OBJECT IDENTIFIER ::= { id-publicKeyType 1 }
|
||||
|
||||
-- Named Elliptic Curves in ANSI X9.62.
|
||||
|
||||
ellipticCurve OBJECT IDENTIFIER ::= { ansi-X9-62 curves(3) }
|
||||
|
||||
c-TwoCurve OBJECT IDENTIFIER ::= {
|
||||
ellipticCurve characteristicTwo(0) }
|
||||
|
||||
c2pnb163v1 OBJECT IDENTIFIER ::= { c-TwoCurve 1 }
|
||||
c2pnb163v2 OBJECT IDENTIFIER ::= { c-TwoCurve 2 }
|
||||
c2pnb163v3 OBJECT IDENTIFIER ::= { c-TwoCurve 3 }
|
||||
c2pnb176w1 OBJECT IDENTIFIER ::= { c-TwoCurve 4 }
|
||||
c2tnb191v1 OBJECT IDENTIFIER ::= { c-TwoCurve 5 }
|
||||
c2tnb191v2 OBJECT IDENTIFIER ::= { c-TwoCurve 6 }
|
||||
c2tnb191v3 OBJECT IDENTIFIER ::= { c-TwoCurve 7 }
|
||||
c2onb191v4 OBJECT IDENTIFIER ::= { c-TwoCurve 8 }
|
||||
c2onb191v5 OBJECT IDENTIFIER ::= { c-TwoCurve 9 }
|
||||
c2pnb208w1 OBJECT IDENTIFIER ::= { c-TwoCurve 10 }
|
||||
c2tnb239v1 OBJECT IDENTIFIER ::= { c-TwoCurve 11 }
|
||||
c2tnb239v2 OBJECT IDENTIFIER ::= { c-TwoCurve 12 }
|
||||
c2tnb239v3 OBJECT IDENTIFIER ::= { c-TwoCurve 13 }
|
||||
c2onb239v4 OBJECT IDENTIFIER ::= { c-TwoCurve 14 }
|
||||
c2onb239v5 OBJECT IDENTIFIER ::= { c-TwoCurve 15 }
|
||||
c2pnb272w1 OBJECT IDENTIFIER ::= { c-TwoCurve 16 }
|
||||
c2pnb304w1 OBJECT IDENTIFIER ::= { c-TwoCurve 17 }
|
||||
c2tnb359v1 OBJECT IDENTIFIER ::= { c-TwoCurve 18 }
|
||||
c2pnb368w1 OBJECT IDENTIFIER ::= { c-TwoCurve 19 }
|
||||
c2tnb431r1 OBJECT IDENTIFIER ::= { c-TwoCurve 20 }
|
||||
|
||||
primeCurve OBJECT IDENTIFIER ::= { ellipticCurve prime(1) }
|
||||
|
||||
prime192v1 OBJECT IDENTIFIER ::= { primeCurve 1 }
|
||||
prime192v2 OBJECT IDENTIFIER ::= { primeCurve 2 }
|
||||
prime192v3 OBJECT IDENTIFIER ::= { primeCurve 3 }
|
||||
prime239v1 OBJECT IDENTIFIER ::= { primeCurve 4 }
|
||||
prime239v2 OBJECT IDENTIFIER ::= { primeCurve 5 }
|
||||
prime239v3 OBJECT IDENTIFIER ::= { primeCurve 6 }
|
||||
prime256v1 OBJECT IDENTIFIER ::= { primeCurve 7 }
|
||||
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from RFC 5758, 3.2. ECDSA Signature Algorithm
|
||||
-- (https://www.rfc-editor.org/rfc/rfc5758.html#section-3.2)
|
||||
|
||||
ecdsa-with-SHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
|
||||
us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 1 }
|
||||
|
||||
ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
|
||||
us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 }
|
||||
|
||||
ecdsa-with-SHA384 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
|
||||
us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 3 }
|
||||
|
||||
ecdsa-with-SHA512 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
|
||||
us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 4 }
|
||||
|
||||
-- -------------------------------------------------------------------
|
||||
-- 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-ecdsa-with-sha3-224 OBJECT IDENTIFIER ::= { sigAlgs 9 }
|
||||
id-ecdsa-with-sha3-256 OBJECT IDENTIFIER ::= { sigAlgs 10 }
|
||||
id-ecdsa-with-sha3-384 OBJECT IDENTIFIER ::= { sigAlgs 11 }
|
||||
id-ecdsa-with-sha3-512 OBJECT IDENTIFIER ::= { sigAlgs 12 }
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
-- -------------------------------------------------------------------
|
||||
-- Taken from RFC 8017, Appendix C
|
||||
-- (https://www.rfc-editor.org/rfc/rfc8017.html#appendix-C)
|
||||
|
||||
-- ============================
|
||||
-- Basic object identifiers
|
||||
-- ============================
|
||||
|
||||
-- The DER encoding of this in hexadecimal is:
|
||||
-- (0x)06 08
|
||||
-- 2A 86 48 86 F7 0D 01 01
|
||||
--
|
||||
pkcs-1 OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1
|
||||
}
|
||||
|
||||
--
|
||||
-- When rsaEncryption is used in an AlgorithmIdentifier,
|
||||
-- the parameters MUST be present and MUST be NULL.
|
||||
--
|
||||
rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
|
||||
|
||||
--
|
||||
-- When id-RSAES-OAEP is used in an AlgorithmIdentifier, the
|
||||
-- parameters MUST be present and MUST be RSAES-OAEP-params.
|
||||
--
|
||||
id-RSAES-OAEP OBJECT IDENTIFIER ::= { pkcs-1 7 }
|
||||
|
||||
--
|
||||
-- When id-pSpecified is used in an AlgorithmIdentifier, the
|
||||
-- parameters MUST be an OCTET STRING.
|
||||
--
|
||||
id-pSpecified OBJECT IDENTIFIER ::= { pkcs-1 9 }
|
||||
|
||||
--
|
||||
-- When id-RSASSA-PSS is used in an AlgorithmIdentifier, the
|
||||
-- parameters MUST be present and MUST be RSASSA-PSS-params.
|
||||
--
|
||||
id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 }
|
||||
|
||||
--
|
||||
-- When the following OIDs are used in an AlgorithmIdentifier,
|
||||
-- the parameters MUST be present and MUST be NULL.
|
||||
--
|
||||
md2WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 2 }
|
||||
md5WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 }
|
||||
sha1WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 5 }
|
||||
sha224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 14 }
|
||||
sha256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 11 }
|
||||
sha384WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 12 }
|
||||
sha512WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 13 }
|
||||
sha512-224WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 15 }
|
||||
sha512-256WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 16 }
|
||||
|
||||
--
|
||||
-- This OID really belongs in a module with the secsig OIDs.
|
||||
--
|
||||
id-sha1 OBJECT IDENTIFIER ::= {
|
||||
iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2)
|
||||
26
|
||||
}
|
||||
|
||||
--
|
||||
-- OIDs for MD2 and MD5, allowed only in EMSA-PKCS1-v1_5.
|
||||
--
|
||||
id-md2 OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2
|
||||
}
|
||||
|
||||
id-md5 OBJECT IDENTIFIER ::= {
|
||||
iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5
|
||||
}
|
||||
|
||||
--
|
||||
-- When id-mgf1 is used in an AlgorithmIdentifier, the parameters
|
||||
-- MUST be present and MUST be a HashAlgorithm, for example, sha1.
|
||||
--
|
||||
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 }
|
||||
@@ -0,0 +1,25 @@
|
||||
$FIPSABLE=der_rsa.c der_dsa.c der_ec.c
|
||||
|
||||
SOURCE[../../libfips.a]=$FIPSABLE
|
||||
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
|
||||
GENERATE[../include/prov/der_rsa.h]=der_rsa.h.in
|
||||
DEPEND[../include/prov/der_rsa.h]=oids_to_c.pm
|
||||
|
||||
GENERATE[der_dsa.c]=der_dsa.c.in
|
||||
DEPEND[der_dsa.c]=oids_to_c.pm
|
||||
|
||||
DEPEND[der_dsa.o]=../include/prov/der_dsa.h
|
||||
GENERATE[../include/prov/der_dsa.h]=der_dsa.h.in
|
||||
DEPEND[../include/prov/der_dsa.h]=oids_to_c.pm
|
||||
|
||||
GENERATE[der_ec.c]=der_ec.c.in
|
||||
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
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "prov/der_dsa.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/DSA.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_C });
|
||||
-}
|
||||
|
||||
int DER_w_algorithmIdentifier_DSA(WPACKET *pkt, int tag, DSA *dsa)
|
||||
{
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, der_oid_id_dsa, sizeof(der_oid_id_dsa))
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
|
||||
#define MD_CASE(name) \
|
||||
case NID_##name: \
|
||||
precompiled = der_oid_id_dsa_with_##name; \
|
||||
precompiled_sz = sizeof(der_oid_id_dsa_with_##name); \
|
||||
break;
|
||||
|
||||
int DER_w_algorithmIdentifier_DSA_with(WPACKET *pkt, int tag,
|
||||
DSA *dsa, int mdnid)
|
||||
{
|
||||
const unsigned char *precompiled = NULL;
|
||||
size_t precompiled_sz = 0;
|
||||
|
||||
switch (mdnid) {
|
||||
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);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/DSA.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_H });
|
||||
-}
|
||||
|
||||
int DER_w_algorithmIdentifier_DSA(WPACKET *pkt, int tag, DSA *dsa);
|
||||
int DER_w_algorithmIdentifier_DSA_with(WPACKET *pkt, int tag,
|
||||
DSA *dsa, int mdnid);
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "prov/der_ec.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('providers/common/der/EC.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_C });
|
||||
-}
|
||||
|
||||
int DER_w_algorithmIdentifier_EC(WPACKET *pkt, int cont, EC_KEY *ec)
|
||||
{
|
||||
return DER_w_begin_sequence(pkt, cont)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, der_oid_id_ecPublicKey,
|
||||
sizeof(der_oid_id_ecPublicKey))
|
||||
&& DER_w_end_sequence(pkt, cont);
|
||||
}
|
||||
|
||||
/* Aliases so we can have a uniform MD_CASE */
|
||||
#define der_oid_id_ecdsa_with_sha1 der_oid_ecdsa_with_SHA1
|
||||
#define der_oid_id_ecdsa_with_sha224 der_oid_ecdsa_with_SHA224
|
||||
#define der_oid_id_ecdsa_with_sha256 der_oid_ecdsa_with_SHA256
|
||||
#define der_oid_id_ecdsa_with_sha384 der_oid_ecdsa_with_SHA384
|
||||
#define der_oid_id_ecdsa_with_sha512 der_oid_ecdsa_with_SHA512
|
||||
|
||||
#define MD_CASE(name) \
|
||||
case NID_##name: \
|
||||
precompiled = der_oid_id_ecdsa_with_##name; \
|
||||
precompiled_sz = sizeof(der_oid_id_ecdsa_with_##name); \
|
||||
break;
|
||||
|
||||
int DER_w_algorithmIdentifier_ECDSA_with(WPACKET *pkt, int cont,
|
||||
EC_KEY *ec, int mdnid)
|
||||
{
|
||||
const unsigned char *precompiled = NULL;
|
||||
size_t precompiled_sz = 0;
|
||||
|
||||
switch (mdnid) {
|
||||
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);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DER_w_begin_sequence(pkt, cont)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
|
||||
&& DER_w_end_sequence(pkt, cont);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/EC.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_H });
|
||||
-}
|
||||
|
||||
int DER_w_algorithmIdentifier_EC(WPACKET *pkt, int cont, EC_KEY *ec);
|
||||
int DER_w_algorithmIdentifier_ECDSA_with(WPACKET *pkt, int cont,
|
||||
EC_KEY *ec, int mdnid);
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "prov/der_rsa.h"
|
||||
|
||||
/* Well known OIDs precompiled */
|
||||
{-
|
||||
$OUT = oids_to_c::process_leaves('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)
|
||||
{
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, der_oid_rsaEncryption,
|
||||
sizeof(der_oid_rsaEncryption))
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
|
||||
/* Aliases so we can have a uniform MD_CASE */
|
||||
#define der_oid_sha3_224WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_224
|
||||
#define der_oid_sha3_256WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_256
|
||||
#define der_oid_sha3_384WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_384
|
||||
#define der_oid_sha3_512WithRSAEncryption \
|
||||
der_oid_id_rsassa_pkcs1_v1_5_with_sha3_512
|
||||
|
||||
#define MD_CASE(name) \
|
||||
case NID_##name: \
|
||||
precompiled = der_oid_##name##WithRSAEncryption; \
|
||||
precompiled_sz = sizeof(der_oid_##name##WithRSAEncryption); \
|
||||
break;
|
||||
|
||||
int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag,
|
||||
RSA *rsa, int mdnid)
|
||||
{
|
||||
const unsigned char *precompiled = NULL;
|
||||
size_t precompiled_sz = 0;
|
||||
|
||||
switch (mdnid) {
|
||||
#ifndef FIPS_MODE
|
||||
MD_CASE(md2);
|
||||
MD_CASE(md5);
|
||||
#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);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DER_w_begin_sequence(pkt, tag)
|
||||
/* No parameters (yet?) */
|
||||
&& DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
|
||||
&& DER_w_end_sequence(pkt, tag);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/RSA.asn1',
|
||||
{ dir => $config{sourcedir},
|
||||
filter => \&oids_to_c::filter_to_H });
|
||||
-}
|
||||
|
||||
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);
|
||||
@@ -0,0 +1,111 @@
|
||||
#! /usr/bin/env perl
|
||||
# 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
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
package oids_to_c;
|
||||
|
||||
use Carp;
|
||||
use File::Spec;
|
||||
use OpenSSL::OID;
|
||||
|
||||
my $OID_name_re = qr/([a-z](?:[-_A-Za-z0-9]*[A-Za-z0-9])?)/;
|
||||
my $OID_value_re = qr/(\{.*?\})/s;
|
||||
my $OID_def_re = qr/
|
||||
${OID_name_re} \s+ OBJECT \s+ IDENTIFIER \s*
|
||||
::=
|
||||
\s* ${OID_value_re}
|
||||
/x;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
sub filter_to_H {
|
||||
my ($name, $comment) = @{ shift() };
|
||||
my @oid_nums = @_;
|
||||
|
||||
(my $C_name = $name) =~ s|-|_|g;
|
||||
my $C_bytes_size = 2 + scalar @_;
|
||||
|
||||
return <<"_____";
|
||||
extern const unsigned char der_oid_${C_name}[$C_bytes_size];
|
||||
_____
|
||||
}
|
||||
|
||||
sub filter_to_C {
|
||||
my ($name, $comment) = @{ shift() };
|
||||
my @oid_nums = @_;
|
||||
my $oid_size = scalar @oid_nums;
|
||||
|
||||
croak "Unsupported OID size (>127 bytes)" if $oid_size > 127;
|
||||
|
||||
(my $C_comment = $comment) =~ s|^| * |msg;
|
||||
$C_comment = "\n/*\n${C_comment}\n */" if $C_comment ne '';
|
||||
(my $C_name = $name) =~ s|-|_|g;
|
||||
my $C_bytes_size = 2 + $oid_size;
|
||||
my $C_bytes = join(', ', map { sprintf("0x%02X", $_) } @oid_nums );
|
||||
|
||||
return <<"_____";
|
||||
$C_comment
|
||||
#define DER_OID_V_${C_name} DER_P_OBJECT, $oid_size, ${C_bytes}
|
||||
#define DER_OID_SZ_${C_name} ${C_bytes_size}
|
||||
const unsigned char der_oid_${C_name}[DER_OID_SZ_${C_name}] = {
|
||||
DER_OID_V_${C_name}
|
||||
};
|
||||
_____
|
||||
}
|
||||
|
||||
sub _process {
|
||||
my %opts = %{ pop @_ } if ref $_[$#_] eq 'HASH';
|
||||
|
||||
# To maintain input order
|
||||
my @OID_names = ();
|
||||
|
||||
foreach my $file (@_) {
|
||||
my $input = File::Spec->catfile($opts{dir}, $file);
|
||||
open my $fh, $input or die "Reading $input: $!\n";
|
||||
|
||||
my $text = join('',
|
||||
map {
|
||||
s|--.*(\R)$|$1|;
|
||||
$_;
|
||||
} <$fh>);
|
||||
# print STDERR "-----BEGIN DEBUG-----\n";
|
||||
# print STDERR $text;
|
||||
# print STDERR "-----END DEBUG-----\n";
|
||||
use re 'debugcolor';
|
||||
while ($text =~ m/${OID_def_re}/sg) {
|
||||
my $comment = $&;
|
||||
my $name = $1;
|
||||
my $value = $2;
|
||||
|
||||
# print STDERR "-----BEGIN DEBUG $name-----\n";
|
||||
# print STDERR $value,"\n";
|
||||
# print STDERR "-----END DEBUG $name-----\n";
|
||||
register_oid($name, $value);
|
||||
push @OID_names, [ $name, $comment ];
|
||||
}
|
||||
}
|
||||
|
||||
return @OID_names;
|
||||
}
|
||||
|
||||
sub process_leaves {
|
||||
my %opts = %{ $_[$#_] } if ref $_[$#_] eq 'HASH';
|
||||
my @OID_names = _process @_;
|
||||
|
||||
my $text = '';
|
||||
my %leaves = map { $_ => 1 } registered_oid_leaves;
|
||||
foreach (grep { defined $leaves{$_->[0]} } @OID_names) {
|
||||
my $lines = $opts{filter}->($_, encode_oid($_->[0]));
|
||||
$text .= $lines;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -64,10 +64,12 @@ int ERR_load_PROV_strings(void);
|
||||
# define PROV_R_FAILED_TO_GENERATE_KEY 121
|
||||
# define PROV_R_FAILED_TO_GET_PARAMETER 103
|
||||
# define PROV_R_FAILED_TO_SET_PARAMETER 104
|
||||
# define PROV_R_FAILED_TO_SIGN 175
|
||||
# define PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 165
|
||||
# define PROV_R_INAVLID_UKM_LENGTH 146
|
||||
# define PROV_R_INVALID_AAD 108
|
||||
# define PROV_R_INVALID_CONSTANT_LENGTH 157
|
||||
# define PROV_R_INVALID_CURVE 176
|
||||
# define PROV_R_INVALID_CUSTOM_LENGTH 111
|
||||
# define PROV_R_INVALID_DATA 115
|
||||
# define PROV_R_INVALID_DIGEST 122
|
||||
@@ -107,6 +109,7 @@ int ERR_load_PROV_strings(void);
|
||||
# define PROV_R_NOT_SUPPORTED 136
|
||||
# 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_OUTPUT_BUFFER_TOO_SMALL 106
|
||||
# define PROV_R_PSS_SALTLEN_TOO_SMALL 172
|
||||
# define PROV_R_READ_KEY 159
|
||||
|
||||
@@ -39,6 +39,7 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
"failed to get parameter"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_FAILED_TO_SET_PARAMETER),
|
||||
"failed to set parameter"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_FAILED_TO_SIGN), "failed to sign"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE),
|
||||
"illegal or unsupported padding mode"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INAVLID_UKM_LENGTH),
|
||||
@@ -46,6 +47,7 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_AAD), "invalid aad"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_CONSTANT_LENGTH),
|
||||
"invalid constant length"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_CURVE), "invalid curve"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_CUSTOM_LENGTH),
|
||||
"invalid custom length"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_DATA), "invalid data"},
|
||||
@@ -98,6 +100,7 @@ static const ERR_STRING_DATA PROV_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_NOT_XOF_OR_INVALID_LENGTH),
|
||||
"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_OUTPUT_BUFFER_TOO_SMALL),
|
||||
"output buffer too small"},
|
||||
{ERR_PACK(ERR_LIB_PROV, 0, PROV_R_PSS_SALTLEN_TOO_SMALL),
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/err.h>
|
||||
#include "prov/provider_util.h"
|
||||
|
||||
void ossl_prov_cipher_reset(PROV_CIPHER *pc)
|
||||
@@ -76,12 +77,17 @@ int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
|
||||
return 0;
|
||||
|
||||
EVP_CIPHER_free(pc->alloc_cipher);
|
||||
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 */
|
||||
if (pc->cipher == NULL)
|
||||
pc->cipher = EVP_get_cipherbyname(p->data);
|
||||
#endif
|
||||
if (pc->cipher != NULL)
|
||||
ERR_pop_to_mark();
|
||||
else
|
||||
ERR_clear_last_mark();
|
||||
return pc->cipher != NULL;
|
||||
}
|
||||
|
||||
@@ -131,12 +137,17 @@ int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
|
||||
return 0;
|
||||
|
||||
EVP_MD_free(pd->alloc_md);
|
||||
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 */
|
||||
if (pd->md == NULL)
|
||||
pd->md = EVP_get_digestbyname(p->data);
|
||||
#endif
|
||||
if (pd->md != NULL)
|
||||
ERR_pop_to_mark();
|
||||
else
|
||||
ERR_clear_last_mark();
|
||||
return pd->md != NULL;
|
||||
}
|
||||
|
||||
|
||||
+35
-54
@@ -254,43 +254,12 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
|
||||
ALG("DES-EDE3-CFB", tdes_ede3_cfb_functions),
|
||||
ALG("DES-EDE3-CFB8", tdes_ede3_cfb8_functions),
|
||||
ALG("DES-EDE3-CFB1", tdes_ede3_cfb1_functions),
|
||||
ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions),
|
||||
ALG("DES-EDE-ECB:DES-EDE", tdes_ede2_ecb_functions),
|
||||
ALG("DES-EDE-CBC", tdes_ede2_cbc_functions),
|
||||
ALG("DES-EDE-OFB", tdes_ede2_ofb_functions),
|
||||
ALG("DES-EDE-CFB", tdes_ede2_cfb_functions),
|
||||
ALG("DESX-CBC:DESX", tdes_desx_cbc_functions),
|
||||
ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions),
|
||||
ALG("DES-ECB", des_ecb_functions),
|
||||
ALG("DES-CBC:DES", des_cbc_functions),
|
||||
ALG("DES-OFB", des_ofb64_functions),
|
||||
ALG("DES-CFB", des_cfb64_functions),
|
||||
ALG("DES-CFB1", des_cfb1_functions),
|
||||
ALG("DES-CFB8", des_cfb8_functions),
|
||||
#endif /* OPENSSL_NO_DES */
|
||||
#ifndef OPENSSL_NO_BF
|
||||
ALG("BF-ECB", blowfish128ecb_functions),
|
||||
ALG("BF-CBC:BF:BLOWFISH", blowfish128cbc_functions),
|
||||
ALG("BF-OFB", blowfish64ofb64_functions),
|
||||
ALG("BF-CFB", blowfish64cfb64_functions),
|
||||
#endif /* OPENSSL_NO_BF */
|
||||
#ifndef OPENSSL_NO_IDEA
|
||||
ALG("IDEA-ECB", idea128ecb_functions),
|
||||
ALG("IDEA-CBC:IDEA", idea128cbc_functions),
|
||||
ALG("IDEA-OFB:IDEA-OFB64", idea128ofb64_functions),
|
||||
ALG("IDEA-CFB:IDEA-CFB64", idea128cfb64_functions),
|
||||
#endif /* OPENSSL_NO_IDEA */
|
||||
#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),
|
||||
#endif /* OPENSSL_NO_CAST */
|
||||
#ifndef OPENSSL_NO_SEED
|
||||
ALG("SEED-ECB", seed128ecb_functions),
|
||||
ALG("SEED-CBC:SEED", seed128cbc_functions),
|
||||
ALG("SEED-OFB:SEED-OFB128", seed128ofb128_functions),
|
||||
ALG("SEED-CFB:SEED-CFB128", seed128cfb128_functions),
|
||||
#endif /* OPENSSL_NO_SEED */
|
||||
#ifndef OPENSSL_NO_SM4
|
||||
ALG("SM4-ECB", sm4128ecb_functions),
|
||||
ALG("SM4-CBC:SM4", sm4128cbc_functions),
|
||||
@@ -298,27 +267,6 @@ static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
|
||||
ALG("SM4-OFB:SM4-OFB128", sm4128ofb128_functions),
|
||||
ALG("SM4-CFB:SM4-CFB128", sm4128cfb128_functions),
|
||||
#endif /* OPENSSL_NO_SM4 */
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
ALG("RC4", rc4128_functions),
|
||||
ALG("RC4-40", rc440_functions),
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
ALG("RC4-HMAC-MD5", rc4_hmac_md5_functions),
|
||||
# endif /* OPENSSL_NO_MD5 */
|
||||
#endif /* OPENSSL_NO_RC4 */
|
||||
#ifndef OPENSSL_NO_RC5
|
||||
ALG("RC5-ECB", rc5128ecb_functions),
|
||||
ALG("RC5-CBC", rc5128cbc_functions),
|
||||
ALG("RC5-OFB", rc5128ofb64_functions),
|
||||
ALG("RC5-CFB", rc5128cfb64_functions),
|
||||
#endif /* OPENSSL_NO_RC5 */
|
||||
#ifndef OPENSSL_NO_RC2
|
||||
ALG("RC2-ECB", rc2128ecb_functions),
|
||||
ALG("RC2-CBC", rc2128cbc_functions),
|
||||
ALG("RC2-40-CBC", rc240cbc_functions),
|
||||
ALG("RC2-64-CBC", rc264cbc_functions),
|
||||
ALG("RC2-CFB", rc2128cfb128_functions),
|
||||
ALG("RC2-OFB", rc2128ofb128_functions),
|
||||
#endif /* OPENSSL_NO_RC2 */
|
||||
#ifndef OPENSSL_NO_CHACHA
|
||||
ALG("ChaCha20", chacha20_functions),
|
||||
# ifndef OPENSSL_NO_POLY1305
|
||||
@@ -373,7 +321,7 @@ static const OSSL_ALGORITHM deflt_keyexch[] = {
|
||||
{ "DH:dhKeyAgreement", "provider=default", dh_keyexch_functions },
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "ECDH:id-ecPublicKey", "provider=default", ecdh_keyexch_functions },
|
||||
{ "ECDH", "provider=default", ecdh_keyexch_functions },
|
||||
{ "X25519", "provider=default", x25519_keyexch_functions },
|
||||
{ "X448", "provider=default", x448_keyexch_functions },
|
||||
#endif
|
||||
@@ -385,6 +333,11 @@ static const OSSL_ALGORITHM deflt_signature[] = {
|
||||
{ "DSA:dsaEncryption", "provider=default", dsa_signature_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "provider=default", rsa_signature_functions },
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "ED25519:Ed25519", "provider=default", ed25519_signature_functions },
|
||||
{ "ED448:Ed448", "provider=default", ed448_signature_functions },
|
||||
{ "ECDSA", "provider=default", ecdsa_signature_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -405,6 +358,8 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = {
|
||||
{ "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions },
|
||||
{ "X25519", "provider=default", x25519_keymgmt_functions },
|
||||
{ "X448", "provider=default", x448_keymgmt_functions },
|
||||
{ "ED25519", "provider=default", ed25519_keymgmt_functions },
|
||||
{ "ED448", "provider=default", ed448_keymgmt_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
@@ -497,6 +452,32 @@ static const OSSL_ALGORITHM deflt_serializer[] = {
|
||||
{ "X448", "provider=default,format=pem,type=public",
|
||||
x448_pub_pem_serializer_functions },
|
||||
|
||||
{ "ED25519", "provider=default,fips=yes,format=text,type=private",
|
||||
ed25519_priv_print_serializer_functions },
|
||||
{ "ED25519", "provider=default,fips=yes,format=text,type=public",
|
||||
ed25519_pub_print_serializer_functions },
|
||||
{ "ED25519", "provider=default,fips=yes,format=der,type=private",
|
||||
ed25519_priv_der_serializer_functions },
|
||||
{ "ED25519", "provider=default,fips=yes,format=der,type=public",
|
||||
ed25519_pub_der_serializer_functions },
|
||||
{ "ED25519", "provider=default,fips=yes,format=pem,type=private",
|
||||
ed25519_priv_pem_serializer_functions },
|
||||
{ "ED25519", "provider=default,fips=yes,format=pem,type=public",
|
||||
ed25519_pub_pem_serializer_functions },
|
||||
|
||||
{ "ED448", "provider=default,format=text,type=private",
|
||||
ed448_priv_print_serializer_functions },
|
||||
{ "ED448", "provider=default,format=text,type=public",
|
||||
ed448_pub_print_serializer_functions },
|
||||
{ "ED448", "provider=default,format=der,type=private",
|
||||
ed448_priv_der_serializer_functions },
|
||||
{ "ED448", "provider=default,format=der,type=public",
|
||||
ed448_pub_der_serializer_functions },
|
||||
{ "ED448", "provider=default,format=pem,type=private",
|
||||
ed448_priv_pem_serializer_functions },
|
||||
{ "ED448", "provider=default,format=pem,type=public",
|
||||
ed448_pub_pem_serializer_functions },
|
||||
|
||||
{ "EC", "provider=default,fips=yes,format=text,type=private",
|
||||
ec_priv_text_serializer_functions },
|
||||
{ "EC", "provider=default,fips=yes,format=text,type=public",
|
||||
|
||||
+26
-352
@@ -26,7 +26,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/property.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "openssl/param_build.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
@@ -69,6 +69,7 @@ static OSSL_CRYPTO_secure_zalloc_fn *c_CRYPTO_secure_zalloc;
|
||||
static OSSL_CRYPTO_secure_free_fn *c_CRYPTO_secure_free;
|
||||
static OSSL_CRYPTO_secure_clear_free_fn *c_CRYPTO_secure_clear_free;
|
||||
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;
|
||||
@@ -125,347 +126,6 @@ static OSSL_PARAM core_params[] =
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
/*
|
||||
* Convert a string into a bignumber.
|
||||
* The array of hex_data is used to get around compilers that dont like
|
||||
* strings longer than 509 bytes,
|
||||
*/
|
||||
#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA)
|
||||
static int hextobn(const char *hex_data[], BIGNUM **bn)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, slen;
|
||||
char *str = NULL;
|
||||
|
||||
/* Get the total length of the strings */
|
||||
for (slen = 0, i = 0; hex_data[i] != NULL; ++i)
|
||||
slen += strlen(hex_data[i]);
|
||||
|
||||
/* Add 1 for the string terminator */
|
||||
str = OPENSSL_zalloc(slen + 1);
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
/* join the strings together into 1 buffer */
|
||||
for (i = 0; hex_data[i] != NULL; ++i)
|
||||
strcat(str, hex_data[i]);
|
||||
|
||||
if (BN_hex2bn(bn, str) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_free(str);
|
||||
return ret;
|
||||
}
|
||||
#endif /* !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) */
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
static int hextobin(const char *hex_data[], unsigned char **out, size_t *len)
|
||||
{
|
||||
int ret = 0, sz;
|
||||
BIGNUM *bn = NULL;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
if (!hextobn(hex_data, &bn))
|
||||
return 0;
|
||||
sz = BN_num_bytes(bn);
|
||||
buf = OPENSSL_zalloc(sz);
|
||||
if (buf == NULL)
|
||||
goto err;
|
||||
if (BN_bn2binpad(bn, buf, sz) <= 0)
|
||||
goto err;
|
||||
|
||||
*out = buf;
|
||||
*len = sz;
|
||||
buf = NULL; /* Set to NULL so it is not freed */
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_free(buf);
|
||||
BN_free(bn);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
static int dsa_key_signature_test(OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
BIGNUM *pub = NULL, *priv = NULL;
|
||||
OSSL_PARAM *params = NULL, *params_sig = NULL;
|
||||
OSSL_PARAM_BLD bld;
|
||||
EVP_PKEY_CTX *sctx = NULL, *kctx = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
unsigned char sig[64];
|
||||
size_t siglen;
|
||||
|
||||
static const unsigned char dgst[SHA256_DIGEST_LENGTH] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
/* dsa 2048 */
|
||||
static const char *dsa_p_hex[] = {
|
||||
"a29b8872ce8b8423b7d5d21d4b02f57e03e9e6b8a258dc16611ba098ab543415"
|
||||
"e415f156997a3ee236658fa093260de3ad422e05e046f9ec29161a375f0eb4ef"
|
||||
"fcef58285c5d39ed425d7a62ca12896c4a92cb1946f2952a48133f07da364d1b"
|
||||
"df6b0f7139983e693c80059b0eacd1479ba9f2857754ede75f112b07ebbf3534",
|
||||
"8bbf3e01e02f2d473de39453f99dd2367541caca3ba01166343d7b5b58a37bd1"
|
||||
"b7521db2f13b86707132fe09f4cd09dc1618fa3401ebf9cc7b19fa94aa472088"
|
||||
"133d6cb2d35c1179c8c8ff368758d507d9f9a17d46c110fe3144ce9b022b42e4"
|
||||
"19eb4f5388613bfc3e26241a432e8706bc58ef76117278deab6cf692618291b7",
|
||||
NULL
|
||||
};
|
||||
static const char *dsa_q_hex[] = {
|
||||
"a3bfd9ab7884794e383450d5891dc18b65157bdcfcdac51518902867",
|
||||
NULL
|
||||
};
|
||||
static const char *dsa_g_hex[] = {
|
||||
"6819278869c7fd3d2d7b77f77e8150d9ad433bea3ba85efc80415aa3545f78f7"
|
||||
"2296f06cb19ceda06c94b0551cfe6e6f863e31d1de6eed7dab8b0c9df231e084"
|
||||
"34d1184f91d033696bb382f8455e9888f5d31d4784ec40120246f4bea61794bb"
|
||||
"a5866f09746463bdf8e9e108cd9529c3d0f6df80316e2e70aaeb1b26cdb8ad97",
|
||||
"bc3d287e0b8d616c42e65b87db20deb7005bc416747a6470147a68a7820388eb"
|
||||
"f44d52e0628af9cf1b7166d03465f35acc31b6110c43dabc7c5d591e671eaf7c"
|
||||
"252c1c145336a1a4ddf13244d55e835680cab2533b82df2efe55ec18c1e6cd00"
|
||||
"7bb089758bb17c2cbe14441bd093ae66e5976d53733f4fa3269701d31d23d467",
|
||||
NULL
|
||||
};
|
||||
static const char *dsa_pub_hex[] = {
|
||||
"a012b3b170b307227957b7ca2061a816ac7a2b3d9ae995a5119c385b603bf6f6"
|
||||
"c5de4dc5ecb5dfa4a41c68662eb25b638b7e2620ba898d07da6c4991e76cc0ec"
|
||||
"d1ad3421077067e47c18f58a92a72ad43199ecb7bd84e7d3afb9019f0e9dd0fb"
|
||||
"aa487300b13081e33c902876436f7b03c345528481d362815e24fe59dac5ac34",
|
||||
"660d4c8a76cb99a7c7de93eb956cd6bc88e58d901034944a094b01803a43c672"
|
||||
"b9688c0e01d8f4fc91c62a3f88021f7bd6a651b1a88f43aa4ef27653d12bf8b7"
|
||||
"099fdf6b461082f8e939107bfd2f7210087d326c375200f1f51e7e74a3413190"
|
||||
"1bcd0863521ff8d676c48581868736c5e51b16a4e39215ea0b17c4735974c516",
|
||||
NULL
|
||||
};
|
||||
static const char *dsa_priv_hex[] = {
|
||||
"6ccaeef6d73b4e80f11c17b8e9627c036635bac39423505e407e5cb7",
|
||||
NULL
|
||||
};
|
||||
|
||||
if (!hextobn(dsa_p_hex, &p)
|
||||
|| !hextobn(dsa_q_hex, &q)
|
||||
|| !hextobn(dsa_g_hex, &g)
|
||||
|| !hextobn(dsa_pub_hex, &pub)
|
||||
|| !hextobn(dsa_priv_hex, &priv))
|
||||
goto err;
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_PUB_KEY, pub)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_PRIV_KEY, priv))
|
||||
goto err;
|
||||
params = ossl_param_bld_to_param(&bld);
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DSA key into */
|
||||
kctx = EVP_PKEY_CTX_new_from_name(libctx, SN_dsa, "");
|
||||
if (kctx == NULL || params == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kctx) <= 0
|
||||
|| EVP_PKEY_fromdata(kctx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to use for the signing operation */
|
||||
sctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (sctx == NULL
|
||||
|| EVP_PKEY_sign_init(sctx) <= 0)
|
||||
goto err;
|
||||
|
||||
/* set signature parameters */
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_utf8_string(&bld, OSSL_SIGNATURE_PARAM_DIGEST,
|
||||
SN_sha256,strlen(SN_sha256) + 1))
|
||||
goto err;
|
||||
params_sig = ossl_param_bld_to_param(&bld);
|
||||
if (EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_sign(sctx, sig, &siglen, dgst, sizeof(dgst)) <= 0
|
||||
|| EVP_PKEY_verify_init(sctx) <= 0
|
||||
|| EVP_PKEY_verify(sctx, sig, siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
ossl_param_bld_free(params);
|
||||
ossl_param_bld_free(params_sig);
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
BN_free(pub);
|
||||
BN_free(priv);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(sctx);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_DSA */
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
static int dh_key_exchange_test(OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
BIGNUM *pub = NULL, *priv = NULL, *pub_peer = NULL;
|
||||
unsigned char *kat_secret = NULL;
|
||||
EVP_PKEY_CTX *kactx = NULL, *dctx = NULL;
|
||||
EVP_PKEY *pkey = NULL, *peerkey = NULL;
|
||||
OSSL_PARAM *params = NULL;
|
||||
OSSL_PARAM *params_peer = NULL;
|
||||
unsigned char secret[256];
|
||||
size_t secret_len, kat_secret_len = 0;
|
||||
OSSL_PARAM_BLD bld;
|
||||
|
||||
/* DH KAT */
|
||||
static const char *dh_p_hex[] = {
|
||||
"dcca1511b2313225f52116e1542789e001f0425bccc7f366f7406407f1c9fa8b"
|
||||
"e610f1778bb170be39dbb76f85bf24ce6880adb7629f7c6d015e61d43fa3ee4d"
|
||||
"e185f2cfd041ffde9d418407e15138bb021daeb35f762d1782acc658d32bd4b0"
|
||||
"232c927dd38fa097b3d1859fa8acafb98f066608fc644ec7ddb6f08599f92ac1",
|
||||
"b59825da8432077def695646063c20823c9507ab6f0176d4730d990dbbe6361c"
|
||||
"d8b2b94d3d2f329b82099bd661f42950f403df3ede62a33188b02798ba823f44"
|
||||
"b946fe9df677a0c5a1238eaa97b70f80da8cac88e092b1127060ffbf45579994"
|
||||
"011dc2faa5e7f6c76245e1cc312231c17d1ca6b19007ef0db99f9cb60e1d5f69",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_q_hex[] = {
|
||||
"898b226717ef039e603e82e5c7afe48374ac5f625c54f1ea11acb57d",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_g_hex[] = {
|
||||
"5ef7b88f2df60139351dfbfe1266805fdf356cdfd13a4da0050c7ede"
|
||||
"246df59f6abf96ade5f2b28ffe88d6bce7f7894a3d535fc82126ddd4"
|
||||
"24872e16b838df8c51e9016f889c7c203e98a8b631f9c72563d38a49"
|
||||
"589a0753d358e783318cefd9677c7b2dbb77d6dce2a1963795ca64b9",
|
||||
"2d1c9aac6d0e8d431de5e50060dff78689c9eca1c1248c16ed09c7ad",
|
||||
"412a17406d2b525aa1cabb237b9734ec7b8ce3fae02f29c5efed30d6"
|
||||
"9187da109c2c9fe2aadbb0c22af54c616655000c431c6b4a379763b0"
|
||||
"a91658efc84e8b06358c8b4f213710fd10172cf39b830c2dd84a0c8a"
|
||||
"b82516ecab995fa4215e023e4ecf8074c39d6c88b70d1ee4e96fdc20",
|
||||
"ea115c32",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_priv_hex[] = {
|
||||
"1433e0b5a917b60a3023f2f8aa2c2d70d2968aba9aeac81540b8fce6",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_pub_hex[] = {
|
||||
"95dd338d29e5710492b918317b72a36936e1951a2ee5a5591699c048"
|
||||
"6d0d4f9bdd6d5a3f6b98890c62b37652d36e712111e68a7355372506"
|
||||
"99efe330537391fbc2c548bc5ac3e5b23386c3eef5eb43c099d70a52"
|
||||
"02687e83964248fca91f40908e8fb3319315f6d2606d7f7cd52cc6e7",
|
||||
"c5843afb22519cf0f0f9d3a0a4e8c88899efede7364351fb6a363ee7"
|
||||
"17e5445adab4c931a6483997b87dad83677e4d1d3a7775e0f6d00fdf"
|
||||
"73c7ad801e665a0e5a796d0a0380a19fa182efc8a04f5e4db90d1a86"
|
||||
"37f95db16436bdc8f3fc096c4ff7f234be8fef479ac4b0dc4b77263e",
|
||||
"07d9959de0f1bf3f0ae3d9d50e4b89c99e3ea1217343dd8c6581acc4"
|
||||
"959c91d3",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_peer_pub_hex[] = {
|
||||
"1fc1da341d1a846a96b7be24340f877dd010aa0356d5ad58aae9c7b0"
|
||||
"8f749a32235110b5d88eb5dbfa978d27ecc530f02d3114005b64b1c0"
|
||||
"e024cb8ae21698bca9e60d42808622f181c56e1de7a96e6efee9d665"
|
||||
"67e91b977042c7e3d0448f05fb77f522b9bfc8d33cc3c31ed3b31f0f",
|
||||
"ecb6db4f6ea311e77afdbcd47aee1bb150f216873578fb96468e8f9f"
|
||||
"3de8efbfce75624b1df05322a34f1463e839e8984c4ad0a96e1ac842"
|
||||
"e5318cc23c062a8ca171b8d575980dde7fc56f1536523820d43192bf"
|
||||
"d51e8e228978aca5b94472f339caeb9931b42be301268bc99789c9b2",
|
||||
"5571c3c0e4cb3f007f1a511cbb53c8519cdd1302abca6c0f34f96739"
|
||||
"f17ff48b",
|
||||
NULL
|
||||
};
|
||||
static const char *dh_secret_exptd_hex[] = {
|
||||
"08ff33bb2ecff49a7d4a7912aeb1bb6ab511641b4a76770c8cc1bcc2"
|
||||
"33343dfe700d11813d2c9ed23b211ca9e8786921edca283c68b16153"
|
||||
"fa01e91ab82c90ddab4a95816770a98710e14c92ab83b6e46e1e426e"
|
||||
"e852430d6187daa3720a6bcd73235c6b0f941f3364f50420551a4bfe",
|
||||
"afe2bc438505a59a4a40daca7a895a73db575c74c13a23ad8832957d"
|
||||
"582d38f0a6165fb0d7e9b8799e42fd3220e332e98185a0c9429757b2"
|
||||
"d0d02c17dbaa1ff6ed93d7e73e241eaed90caf394d2bc6570f18c81f"
|
||||
"2be5d01a2ca99ff142b5d963f9f500325e7556f95849b3ffc7479486",
|
||||
"be1d4596a3106bd5cb4f61c57ec5f100fb7a0c82a10b82526a97d1d9"
|
||||
"7d98eaf6",
|
||||
NULL
|
||||
};
|
||||
|
||||
if (!hextobn(dh_p_hex, &p)
|
||||
|| !hextobn(dh_q_hex, &q)
|
||||
|| !hextobn(dh_g_hex, &g)
|
||||
|| !hextobn(dh_pub_hex, &pub)
|
||||
|| !hextobn(dh_priv_hex, &priv)
|
||||
|| !hextobn(dh_peer_pub_hex, &pub_peer)
|
||||
|| !hextobin(dh_secret_exptd_hex, &kat_secret, &kat_secret_len))
|
||||
goto err;
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_PUB_KEY, pub)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_PRIV_KEY, priv))
|
||||
goto err;
|
||||
params = ossl_param_bld_to_param(&bld);
|
||||
|
||||
ossl_param_bld_init(&bld);
|
||||
if (!ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_FFC_G, g)
|
||||
|| !ossl_param_bld_push_BN(&bld, OSSL_PKEY_PARAM_PUB_KEY, pub_peer))
|
||||
goto err;
|
||||
|
||||
params_peer = ossl_param_bld_to_param(&bld);
|
||||
if (params == NULL || params_peer == NULL)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DH keys into */
|
||||
kactx = EVP_PKEY_CTX_new_from_name(libctx, "DH", "");
|
||||
if (kactx == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &peerkey, params_peer) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to perform key derivation */
|
||||
dctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (dctx == NULL)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_derive_init(dctx) <= 0
|
||||
|| EVP_PKEY_derive_set_peer(dctx, peerkey) <= 0
|
||||
|| EVP_PKEY_derive(dctx, secret, &secret_len) <= 0)
|
||||
goto err;
|
||||
|
||||
if (secret_len != kat_secret_len
|
||||
|| memcmp(secret, kat_secret, secret_len) != 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
ossl_param_bld_free(params_peer);
|
||||
ossl_param_bld_free(params);
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
BN_free(pub);
|
||||
BN_free(priv);
|
||||
BN_free(pub_peer);
|
||||
OPENSSL_free(kat_secret);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_free(peerkey);
|
||||
EVP_PKEY_CTX_free(kactx);
|
||||
EVP_PKEY_CTX_free(dctx);
|
||||
return ret;
|
||||
}
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
|
||||
/* TODO(3.0): To be removed */
|
||||
static int dummy_evp_call(void *provctx)
|
||||
{
|
||||
@@ -533,16 +193,6 @@ static int dummy_evp_call(void *provctx)
|
||||
goto err;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
if (!dsa_key_signature_test(libctx))
|
||||
goto err;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
if (!dh_key_exchange_test(libctx))
|
||||
goto err;
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_end(bnctx);
|
||||
@@ -794,6 +444,9 @@ static const OSSL_ALGORITHM fips_kdfs[] = {
|
||||
static const OSSL_ALGORITHM fips_keyexch[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{ "DH:dhKeyAgreement", "provider=fips,fips=yes", dh_keyexch_functions },
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "ECDH", "provider=fips,fips=yes", ecdh_keyexch_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
@@ -801,6 +454,10 @@ static const OSSL_ALGORITHM fips_keyexch[] = {
|
||||
static const OSSL_ALGORITHM fips_signature[] = {
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{ "DSA:dsaEncryption", "provider=fips,fips=yes", dsa_signature_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_signature_functions },
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "ECDSA", "provider=fips,fips=yes", ecdsa_signature_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
@@ -818,6 +475,9 @@ static const OSSL_ALGORITHM fips_keymgmt[] = {
|
||||
{ "DSA", "provider=fips,fips=yes", dsa_keymgmt_functions },
|
||||
#endif
|
||||
{ "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_keymgmt_functions },
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{ "EC:id-ecPublicKey", "provider=fips,fips=yes", ec_keymgmt_functions },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -955,6 +615,9 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
case OSSL_FUNC_BIO_FREE:
|
||||
selftest_params.bio_free_cb = OSSL_get_BIO_free(in);
|
||||
break;
|
||||
case OSSL_FUNC_BIO_VSNPRINTF:
|
||||
c_BIO_vsnprintf = OSSL_get_BIO_vsnprintf(in);
|
||||
break;
|
||||
case OSSL_FUNC_SELF_TEST_CB: {
|
||||
stcbfn = OSSL_get_self_test_cb(in);
|
||||
break;
|
||||
@@ -1155,3 +818,14 @@ int CRYPTO_secure_allocated(const void *ptr)
|
||||
{
|
||||
return c_CRYPTO_secure_allocated(ptr);
|
||||
}
|
||||
|
||||
int BIO_snprintf(char *buf, size_t n, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
va_start(args, format);
|
||||
ret = c_BIO_vsnprintf(buf, n, format, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
@@ -7,6 +7,26 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* Macros to build Self test data */
|
||||
#define ITM(x) x, sizeof(x)
|
||||
#define ITM_STR(x) x, (sizeof(x) - 1)
|
||||
|
||||
#define ST_KAT_PARAM_END() { "", 0, NULL, 0 }
|
||||
#define ST_KAT_PARAM_BIGNUM(name, data) \
|
||||
{ name, OSSL_PARAM_UNSIGNED_INTEGER, ITM(data) }
|
||||
#define ST_KAT_PARAM_OCTET(name, data) \
|
||||
{ name, OSSL_PARAM_OCTET_STRING, ITM(data) }
|
||||
#define ST_KAT_PARAM_UTF8STRING(name, data) \
|
||||
{ name, OSSL_PARAM_UTF8_STRING, ITM_STR(data) }
|
||||
|
||||
/* used to store raw parameters for keys and algorithms */
|
||||
typedef struct st_kat_param_st {
|
||||
const char *name; /* an OSSL_PARAM name */
|
||||
size_t type; /* the type associated with the data */
|
||||
const void *data; /* unsigned char [], or char [] depending on the type */
|
||||
size_t data_len; /* the length of the data */
|
||||
} ST_KAT_PARAM;
|
||||
|
||||
typedef struct st_kat_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
@@ -29,15 +49,10 @@ typedef struct st_kat_cipher_st {
|
||||
size_t tag_len;
|
||||
} ST_KAT_CIPHER;
|
||||
|
||||
typedef struct st_kat_nvp_st {
|
||||
const char *name;
|
||||
const char *value;
|
||||
} ST_KAT_NVP;
|
||||
|
||||
typedef struct st_kat_kdf_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
const ST_KAT_NVP *ctrls;
|
||||
const ST_KAT_PARAM *params;
|
||||
const unsigned char *expected;
|
||||
size_t expected_len;
|
||||
} ST_KAT_KDF;
|
||||
@@ -64,9 +79,26 @@ typedef struct st_kat_drbg_st {
|
||||
size_t expectedlen;
|
||||
} ST_KAT_DRBG;
|
||||
|
||||
/* Macros to build Self test data */
|
||||
#define ITM(x) x, sizeof(x)
|
||||
#define ITM_STR(x) x, sizeof(x) - 1
|
||||
typedef struct st_kat_kas_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
|
||||
const ST_KAT_PARAM *key_group;
|
||||
const ST_KAT_PARAM *key_host_data;
|
||||
const ST_KAT_PARAM *key_peer_data;
|
||||
|
||||
const unsigned char *expected;
|
||||
size_t expected_len;
|
||||
} ST_KAT_KAS;
|
||||
|
||||
typedef struct st_kat_sign_st {
|
||||
const char *desc;
|
||||
const char *algorithm;
|
||||
const char *mdalgorithm;
|
||||
const ST_KAT_PARAM *key;
|
||||
const unsigned char *sig_expected; /* Set to NULL if this value changes */
|
||||
size_t sig_expected_len;
|
||||
} ST_KAT_SIGN;
|
||||
|
||||
/*- DIGEST TEST DATA */
|
||||
static const unsigned char sha1_pt[] = "abc";
|
||||
@@ -118,11 +150,11 @@ static const ST_KAT_DIGEST st_kat_digest_tests[] =
|
||||
|
||||
/* DES3 test data */
|
||||
static const unsigned char des_ede3_cbc_pt[] = {
|
||||
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11,
|
||||
0x73, 0x93, 0x17, 0x2A, 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
|
||||
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
|
||||
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
|
||||
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
|
||||
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51
|
||||
};
|
||||
|
||||
static const unsigned char des_ede3_cbc_key[] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
|
||||
@@ -132,34 +164,38 @@ static const unsigned char des_ede3_cbc_iv[] = {
|
||||
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17
|
||||
};
|
||||
static const unsigned char des_ede3_cbc_ct[] = {
|
||||
0x20, 0x79, 0xC3, 0xD5, 0x3A, 0xA7, 0x63, 0xE1, 0x93, 0xB7, 0x9E, 0x25,
|
||||
0x69, 0xAB, 0x52, 0x62, 0x51, 0x65, 0x70, 0x48, 0x1F, 0x25, 0xB5, 0x0F,
|
||||
0x20, 0x79, 0xC3, 0xD5, 0x3A, 0xA7, 0x63, 0xE1,
|
||||
0x93, 0xB7, 0x9E, 0x25, 0x69, 0xAB, 0x52, 0x62,
|
||||
0x51, 0x65, 0x70, 0x48, 0x1F, 0x25, 0xB5, 0x0F,
|
||||
0x73, 0xC0, 0xBD, 0xA8, 0x5C, 0x8E, 0x0D, 0xA7
|
||||
};
|
||||
|
||||
/* AES-256 GCM test data */
|
||||
static const unsigned char aes_256_gcm_key[] = {
|
||||
0x92,0xe1,0x1d,0xcd,0xaa,0x86,0x6f,0x5c,0xe7,0x90,0xfd,0x24,
|
||||
0x50,0x1f,0x92,0x50,0x9a,0xac,0xf4,0xcb,0x8b,0x13,0x39,0xd5,
|
||||
0x0c,0x9c,0x12,0x40,0x93,0x5d,0xd0,0x8b
|
||||
0x92, 0xe1, 0x1d, 0xcd, 0xaa, 0x86, 0x6f, 0x5c,
|
||||
0xe7, 0x90, 0xfd, 0x24, 0x50, 0x1f, 0x92, 0x50,
|
||||
0x9a, 0xac, 0xf4, 0xcb, 0x8b, 0x13, 0x39, 0xd5,
|
||||
0x0c, 0x9c, 0x12, 0x40, 0x93, 0x5d, 0xd0, 0x8b
|
||||
};
|
||||
static const unsigned char aes_256_gcm_iv[] = {
|
||||
0xac,0x93,0xa1,0xa6,0x14,0x52,0x99,0xbd,0xe9,0x02,0xf2,0x1a
|
||||
0xac, 0x93, 0xa1, 0xa6, 0x14, 0x52, 0x99, 0xbd,
|
||||
0xe9, 0x02, 0xf2, 0x1a
|
||||
};
|
||||
static const unsigned char aes_256_gcm_pt[] = {
|
||||
0x2d,0x71,0xbc,0xfa,0x91,0x4e,0x4a,0xc0,0x45,0xb2,0xaa,0x60,
|
||||
0x95,0x5f,0xad,0x24
|
||||
0x2d, 0x71, 0xbc, 0xfa, 0x91, 0x4e, 0x4a, 0xc0,
|
||||
0x45, 0xb2, 0xaa, 0x60, 0x95, 0x5f, 0xad, 0x24
|
||||
};
|
||||
static const unsigned char aes_256_gcm_aad[] = {
|
||||
0x1e,0x08,0x89,0x01,0x6f,0x67,0x60,0x1c,0x8e,0xbe,0xa4,0x94,
|
||||
0x3b,0xc2,0x3a,0xd6
|
||||
0x1e, 0x08, 0x89, 0x01, 0x6f, 0x67, 0x60, 0x1c,
|
||||
0x8e, 0xbe, 0xa4, 0x94, 0x3b, 0xc2, 0x3a, 0xd6
|
||||
};
|
||||
static const unsigned char aes_256_gcm_ct[] = {
|
||||
0x89,0x95,0xae,0x2e,0x6d,0xf3,0xdb,0xf9,0x6f,0xac,0x7b,0x71,
|
||||
0x37,0xba,0xe6,0x7f
|
||||
0x89, 0x95, 0xae, 0x2e, 0x6d, 0xf3, 0xdb, 0xf9,
|
||||
0x6f, 0xac, 0x7b, 0x71, 0x37, 0xba, 0xe6, 0x7f
|
||||
};
|
||||
static const unsigned char aes_256_gcm_tag[] = {
|
||||
0xec,0xa5,0xaa,0x77,0xd5,0x1d,0x4a,0x0a,0x14,0xd9,0xc5,0x1e,
|
||||
0x1d,0xa4,0x74,0xab
|
||||
0xec, 0xa5, 0xaa, 0x77, 0xd5, 0x1d, 0x4a, 0x0a,
|
||||
0x14, 0xd9, 0xc5, 0x1e, 0x1d, 0xa4, 0x74, 0xab
|
||||
};
|
||||
|
||||
static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
@@ -189,27 +225,65 @@ static const ST_KAT_CIPHER st_kat_cipher_tests[] = {
|
||||
}
|
||||
};
|
||||
|
||||
/*- KDF TEST DATA */
|
||||
static const char hkdf_digest[] = "SHA256";
|
||||
static const unsigned char hkdf_secret[] = { 's', 'e', 'c', 'r', 'e', 't' };
|
||||
static const unsigned char hkdf_salt[] = { 's', 'a', 'l', 't' };
|
||||
static const unsigned char hkdf_info[] = { 'l', 'a', 'b', 'e', 'l' };
|
||||
|
||||
static const ST_KAT_NVP hkdf_ctrl[] =
|
||||
{
|
||||
{ "digest", "SHA256" },
|
||||
{ "key", "secret" },
|
||||
{ "salt", "salt" },
|
||||
{ "info", "label" },
|
||||
{ NULL, NULL }
|
||||
static const ST_KAT_PARAM hkdf_params[] = {
|
||||
ST_KAT_PARAM_UTF8STRING(OSSL_KDF_PARAM_DIGEST, hkdf_digest),
|
||||
ST_KAT_PARAM_OCTET(OSSL_KDF_PARAM_KEY, hkdf_secret),
|
||||
ST_KAT_PARAM_OCTET(OSSL_KDF_PARAM_SALT, hkdf_salt),
|
||||
ST_KAT_PARAM_OCTET(OSSL_KDF_PARAM_INFO, hkdf_info),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
static const unsigned char hkdf_expected[] = {
|
||||
0x2a, 0xc4, 0x36, 0x9f, 0x52, 0x59, 0x96, 0xf8, 0xde, 0x13
|
||||
0x2a, 0xc4, 0x36, 0x9f, 0x52, 0x59, 0x96, 0xf8,
|
||||
0xde, 0x13
|
||||
};
|
||||
|
||||
static const char sskdf_digest[] = "SHA224";
|
||||
static const unsigned char sskdf_secret[] = {
|
||||
0x6d, 0xbd, 0xc2, 0x3f, 0x04, 0x54, 0x88, 0xe4,
|
||||
0x06, 0x27, 0x57, 0xb0, 0x6b, 0x9e, 0xba, 0xe1,
|
||||
0x83, 0xfc, 0x5a, 0x59, 0x46, 0xd8, 0x0d, 0xb9,
|
||||
0x3f, 0xec, 0x6f, 0x62, 0xec, 0x07, 0xe3, 0x72,
|
||||
0x7f, 0x01, 0x26, 0xae, 0xd1, 0x2c, 0xe4, 0xb2,
|
||||
0x62, 0xf4, 0x7d, 0x48, 0xd5, 0x42, 0x87, 0xf8,
|
||||
0x1d, 0x47, 0x4c, 0x7c, 0x3b, 0x18, 0x50, 0xe9
|
||||
};
|
||||
static const unsigned char sskdf_otherinfo[] = {
|
||||
0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0x43, 0x41, 0x56,
|
||||
0x53, 0x69, 0x64, 0x3c, 0x83, 0x2e, 0x98, 0x49,
|
||||
0xdc, 0xdb, 0xa7, 0x1e, 0x9a, 0x31, 0x39, 0xe6,
|
||||
0x06, 0xe0, 0x95, 0xde, 0x3c, 0x26, 0x4a, 0x66,
|
||||
0xe9, 0x8a, 0x16, 0x58, 0x54, 0xcd, 0x07, 0x98,
|
||||
0x9b, 0x1e, 0xe0, 0xec, 0x3f, 0x8d, 0xbe
|
||||
};
|
||||
static const unsigned char sskdf_expected[] = {
|
||||
0xa4, 0x62, 0xde, 0x16, 0xa8, 0x9d, 0xe8, 0x46,
|
||||
0x6e, 0xf5, 0x46, 0x0b, 0x47, 0xb8
|
||||
};
|
||||
static const ST_KAT_PARAM sskdf_params[] = {
|
||||
ST_KAT_PARAM_UTF8STRING(OSSL_KDF_PARAM_DIGEST, sskdf_digest),
|
||||
ST_KAT_PARAM_OCTET(OSSL_KDF_PARAM_KEY, sskdf_secret),
|
||||
ST_KAT_PARAM_OCTET(OSSL_KDF_PARAM_INFO, sskdf_otherinfo),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
static const ST_KAT_KDF st_kat_kdf_tests[] =
|
||||
{
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_KDF_HKDF,
|
||||
"HKDF",
|
||||
hkdf_ctrl,
|
||||
OSSL_KDF_NAME_HKDF,
|
||||
hkdf_params,
|
||||
ITM(hkdf_expected)
|
||||
},
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_KDF_SSKDF,
|
||||
OSSL_KDF_NAME_SSKDF,
|
||||
sskdf_params,
|
||||
ITM(sskdf_expected)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -422,3 +496,691 @@ static const ST_KAT_DRBG st_kat_drbg_tests[] =
|
||||
ITM(drbg_hmac_sha1_pr_expected)
|
||||
}
|
||||
};
|
||||
|
||||
/* KEY EXCHANGE TEST DATA */
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
/* DH KAT */
|
||||
static const unsigned char dh_p[] = {
|
||||
0xdc, 0xca, 0x15, 0x11, 0xb2, 0x31, 0x32, 0x25,
|
||||
0xf5, 0x21, 0x16, 0xe1, 0x54, 0x27, 0x89, 0xe0,
|
||||
0x01, 0xf0, 0x42, 0x5b, 0xcc, 0xc7, 0xf3, 0x66,
|
||||
0xf7, 0x40, 0x64, 0x07, 0xf1, 0xc9, 0xfa, 0x8b,
|
||||
0xe6, 0x10, 0xf1, 0x77, 0x8b, 0xb1, 0x70, 0xbe,
|
||||
0x39, 0xdb, 0xb7, 0x6f, 0x85, 0xbf, 0x24, 0xce,
|
||||
0x68, 0x80, 0xad, 0xb7, 0x62, 0x9f, 0x7c, 0x6d,
|
||||
0x01, 0x5e, 0x61, 0xd4, 0x3f, 0xa3, 0xee, 0x4d,
|
||||
0xe1, 0x85, 0xf2, 0xcf, 0xd0, 0x41, 0xff, 0xde,
|
||||
0x9d, 0x41, 0x84, 0x07, 0xe1, 0x51, 0x38, 0xbb,
|
||||
0x02, 0x1d, 0xae, 0xb3, 0x5f, 0x76, 0x2d, 0x17,
|
||||
0x82, 0xac, 0xc6, 0x58, 0xd3, 0x2b, 0xd4, 0xb0,
|
||||
0x23, 0x2c, 0x92, 0x7d, 0xd3, 0x8f, 0xa0, 0x97,
|
||||
0xb3, 0xd1, 0x85, 0x9f, 0xa8, 0xac, 0xaf, 0xb9,
|
||||
0x8f, 0x06, 0x66, 0x08, 0xfc, 0x64, 0x4e, 0xc7,
|
||||
0xdd, 0xb6, 0xf0, 0x85, 0x99, 0xf9, 0x2a, 0xc1,
|
||||
0xb5, 0x98, 0x25, 0xda, 0x84, 0x32, 0x07, 0x7d,
|
||||
0xef, 0x69, 0x56, 0x46, 0x06, 0x3c, 0x20, 0x82,
|
||||
0x3c, 0x95, 0x07, 0xab, 0x6f, 0x01, 0x76, 0xd4,
|
||||
0x73, 0x0d, 0x99, 0x0d, 0xbb, 0xe6, 0x36, 0x1c,
|
||||
0xd8, 0xb2, 0xb9, 0x4d, 0x3d, 0x2f, 0x32, 0x9b,
|
||||
0x82, 0x09, 0x9b, 0xd6, 0x61, 0xf4, 0x29, 0x50,
|
||||
0xf4, 0x03, 0xdf, 0x3e, 0xde, 0x62, 0xa3, 0x31,
|
||||
0x88, 0xb0, 0x27, 0x98, 0xba, 0x82, 0x3f, 0x44,
|
||||
0xb9, 0x46, 0xfe, 0x9d, 0xf6, 0x77, 0xa0, 0xc5,
|
||||
0xa1, 0x23, 0x8e, 0xaa, 0x97, 0xb7, 0x0f, 0x80,
|
||||
0xda, 0x8c, 0xac, 0x88, 0xe0, 0x92, 0xb1, 0x12,
|
||||
0x70, 0x60, 0xff, 0xbf, 0x45, 0x57, 0x99, 0x94,
|
||||
0x01, 0x1d, 0xc2, 0xfa, 0xa5, 0xe7, 0xf6, 0xc7,
|
||||
0x62, 0x45, 0xe1, 0xcc, 0x31, 0x22, 0x31, 0xc1,
|
||||
0x7d, 0x1c, 0xa6, 0xb1, 0x90, 0x07, 0xef, 0x0d,
|
||||
0xb9, 0x9f, 0x9c, 0xb6, 0x0e, 0x1d, 0x5f, 0x69
|
||||
};
|
||||
static const unsigned char dh_q[] = {
|
||||
0x89, 0x8b, 0x22, 0x67, 0x17, 0xef, 0x03, 0x9e,
|
||||
0x60, 0x3e, 0x82, 0xe5, 0xc7, 0xaf, 0xe4, 0x83,
|
||||
0x74, 0xac, 0x5f, 0x62, 0x5c, 0x54, 0xf1, 0xea,
|
||||
0x11, 0xac, 0xb5, 0x7d
|
||||
};
|
||||
static const unsigned char dh_g[] = {
|
||||
0x5e, 0xf7, 0xb8, 0x8f, 0x2d, 0xf6, 0x01, 0x39,
|
||||
0x35, 0x1d, 0xfb, 0xfe, 0x12, 0x66, 0x80, 0x5f,
|
||||
0xdf, 0x35, 0x6c, 0xdf, 0xd1, 0x3a, 0x4d, 0xa0,
|
||||
0x05, 0x0c, 0x7e, 0xde, 0x24, 0x6d, 0xf5, 0x9f,
|
||||
0x6a, 0xbf, 0x96, 0xad, 0xe5, 0xf2, 0xb2, 0x8f,
|
||||
0xfe, 0x88, 0xd6, 0xbc, 0xe7, 0xf7, 0x89, 0x4a,
|
||||
0x3d, 0x53, 0x5f, 0xc8, 0x21, 0x26, 0xdd, 0xd4,
|
||||
0x24, 0x87, 0x2e, 0x16, 0xb8, 0x38, 0xdf, 0x8c,
|
||||
0x51, 0xe9, 0x01, 0x6f, 0x88, 0x9c, 0x7c, 0x20,
|
||||
0x3e, 0x98, 0xa8, 0xb6, 0x31, 0xf9, 0xc7, 0x25,
|
||||
0x63, 0xd3, 0x8a, 0x49, 0x58, 0x9a, 0x07, 0x53,
|
||||
0xd3, 0x58, 0xe7, 0x83, 0x31, 0x8c, 0xef, 0xd9,
|
||||
0x67, 0x7c, 0x7b, 0x2d, 0xbb, 0x77, 0xd6, 0xdc,
|
||||
0xe2, 0xa1, 0x96, 0x37, 0x95, 0xca, 0x64, 0xb9,
|
||||
0x2d, 0x1c, 0x9a, 0xac, 0x6d, 0x0e, 0x8d, 0x43,
|
||||
0x1d, 0xe5, 0xe5, 0x00, 0x60, 0xdf, 0xf7, 0x86,
|
||||
0x89, 0xc9, 0xec, 0xa1, 0xc1, 0x24, 0x8c, 0x16,
|
||||
0xed, 0x09, 0xc7, 0xad, 0x41, 0x2a, 0x17, 0x40,
|
||||
0x6d, 0x2b, 0x52, 0x5a, 0xa1, 0xca, 0xbb, 0x23,
|
||||
0x7b, 0x97, 0x34, 0xec, 0x7b, 0x8c, 0xe3, 0xfa,
|
||||
0xe0, 0x2f, 0x29, 0xc5, 0xef, 0xed, 0x30, 0xd6,
|
||||
0x91, 0x87, 0xda, 0x10, 0x9c, 0x2c, 0x9f, 0xe2,
|
||||
0xaa, 0xdb, 0xb0, 0xc2, 0x2a, 0xf5, 0x4c, 0x61,
|
||||
0x66, 0x55, 0x00, 0x0c, 0x43, 0x1c, 0x6b, 0x4a,
|
||||
0x37, 0x97, 0x63, 0xb0, 0xa9, 0x16, 0x58, 0xef,
|
||||
0xc8, 0x4e, 0x8b, 0x06, 0x35, 0x8c, 0x8b, 0x4f,
|
||||
0x21, 0x37, 0x10, 0xfd, 0x10, 0x17, 0x2c, 0xf3,
|
||||
0x9b, 0x83, 0x0c, 0x2d, 0xd8, 0x4a, 0x0c, 0x8a,
|
||||
0xb8, 0x25, 0x16, 0xec, 0xab, 0x99, 0x5f, 0xa4,
|
||||
0x21, 0x5e, 0x02, 0x3e, 0x4e, 0xcf, 0x80, 0x74,
|
||||
0xc3, 0x9d, 0x6c, 0x88, 0xb7, 0x0d, 0x1e, 0xe4,
|
||||
0xe9, 0x6f, 0xdc, 0x20, 0xea, 0x11, 0x5c, 0x32
|
||||
};
|
||||
static const unsigned char dh_priv[] = {
|
||||
0x14, 0x33, 0xe0, 0xb5, 0xa9, 0x17, 0xb6, 0x0a,
|
||||
0x30, 0x23, 0xf2, 0xf8, 0xaa, 0x2c, 0x2d, 0x70,
|
||||
0xd2, 0x96, 0x8a, 0xba, 0x9a, 0xea, 0xc8, 0x15,
|
||||
0x40, 0xb8, 0xfc, 0xe6
|
||||
};
|
||||
static const unsigned char dh_pub[] = {
|
||||
0x95, 0xdd, 0x33, 0x8d, 0x29, 0xe5, 0x71, 0x04,
|
||||
0x92, 0xb9, 0x18, 0x31, 0x7b, 0x72, 0xa3, 0x69,
|
||||
0x36, 0xe1, 0x95, 0x1a, 0x2e, 0xe5, 0xa5, 0x59,
|
||||
0x16, 0x99, 0xc0, 0x48, 0x6d, 0x0d, 0x4f, 0x9b,
|
||||
0xdd, 0x6d, 0x5a, 0x3f, 0x6b, 0x98, 0x89, 0x0c,
|
||||
0x62, 0xb3, 0x76, 0x52, 0xd3, 0x6e, 0x71, 0x21,
|
||||
0x11, 0xe6, 0x8a, 0x73, 0x55, 0x37, 0x25, 0x06,
|
||||
0x99, 0xef, 0xe3, 0x30, 0x53, 0x73, 0x91, 0xfb,
|
||||
0xc2, 0xc5, 0x48, 0xbc, 0x5a, 0xc3, 0xe5, 0xb2,
|
||||
0x33, 0x86, 0xc3, 0xee, 0xf5, 0xeb, 0x43, 0xc0,
|
||||
0x99, 0xd7, 0x0a, 0x52, 0x02, 0x68, 0x7e, 0x83,
|
||||
0x96, 0x42, 0x48, 0xfc, 0xa9, 0x1f, 0x40, 0x90,
|
||||
0x8e, 0x8f, 0xb3, 0x31, 0x93, 0x15, 0xf6, 0xd2,
|
||||
0x60, 0x6d, 0x7f, 0x7c, 0xd5, 0x2c, 0xc6, 0xe7,
|
||||
0xc5, 0x84, 0x3a, 0xfb, 0x22, 0x51, 0x9c, 0xf0,
|
||||
0xf0, 0xf9, 0xd3, 0xa0, 0xa4, 0xe8, 0xc8, 0x88,
|
||||
0x99, 0xef, 0xed, 0xe7, 0x36, 0x43, 0x51, 0xfb,
|
||||
0x6a, 0x36, 0x3e, 0xe7, 0x17, 0xe5, 0x44, 0x5a,
|
||||
0xda, 0xb4, 0xc9, 0x31, 0xa6, 0x48, 0x39, 0x97,
|
||||
0xb8, 0x7d, 0xad, 0x83, 0x67, 0x7e, 0x4d, 0x1d,
|
||||
0x3a, 0x77, 0x75, 0xe0, 0xf6, 0xd0, 0x0f, 0xdf,
|
||||
0x73, 0xc7, 0xad, 0x80, 0x1e, 0x66, 0x5a, 0x0e,
|
||||
0x5a, 0x79, 0x6d, 0x0a, 0x03, 0x80, 0xa1, 0x9f,
|
||||
0xa1, 0x82, 0xef, 0xc8, 0xa0, 0x4f, 0x5e, 0x4d,
|
||||
0xb9, 0x0d, 0x1a, 0x86, 0x37, 0xf9, 0x5d, 0xb1,
|
||||
0x64, 0x36, 0xbd, 0xc8, 0xf3, 0xfc, 0x09, 0x6c,
|
||||
0x4f, 0xf7, 0xf2, 0x34, 0xbe, 0x8f, 0xef, 0x47,
|
||||
0x9a, 0xc4, 0xb0, 0xdc, 0x4b, 0x77, 0x26, 0x3e,
|
||||
0x07, 0xd9, 0x95, 0x9d, 0xe0, 0xf1, 0xbf, 0x3f,
|
||||
0x0a, 0xe3, 0xd9, 0xd5, 0x0e, 0x4b, 0x89, 0xc9,
|
||||
0x9e, 0x3e, 0xa1, 0x21, 0x73, 0x43, 0xdd, 0x8c,
|
||||
0x65, 0x81, 0xac, 0xc4, 0x95, 0x9c, 0x91, 0xd3
|
||||
};
|
||||
static const unsigned char dh_peer_pub[] = {
|
||||
0x1f, 0xc1, 0xda, 0x34, 0x1d, 0x1a, 0x84, 0x6a,
|
||||
0x96, 0xb7, 0xbe, 0x24, 0x34, 0x0f, 0x87, 0x7d,
|
||||
0xd0, 0x10, 0xaa, 0x03, 0x56, 0xd5, 0xad, 0x58,
|
||||
0xaa, 0xe9, 0xc7, 0xb0, 0x8f, 0x74, 0x9a, 0x32,
|
||||
0x23, 0x51, 0x10, 0xb5, 0xd8, 0x8e, 0xb5, 0xdb,
|
||||
0xfa, 0x97, 0x8d, 0x27, 0xec, 0xc5, 0x30, 0xf0,
|
||||
0x2d, 0x31, 0x14, 0x00, 0x5b, 0x64, 0xb1, 0xc0,
|
||||
0xe0, 0x24, 0xcb, 0x8a, 0xe2, 0x16, 0x98, 0xbc,
|
||||
0xa9, 0xe6, 0x0d, 0x42, 0x80, 0x86, 0x22, 0xf1,
|
||||
0x81, 0xc5, 0x6e, 0x1d, 0xe7, 0xa9, 0x6e, 0x6e,
|
||||
0xfe, 0xe9, 0xd6, 0x65, 0x67, 0xe9, 0x1b, 0x97,
|
||||
0x70, 0x42, 0xc7, 0xe3, 0xd0, 0x44, 0x8f, 0x05,
|
||||
0xfb, 0x77, 0xf5, 0x22, 0xb9, 0xbf, 0xc8, 0xd3,
|
||||
0x3c, 0xc3, 0xc3, 0x1e, 0xd3, 0xb3, 0x1f, 0x0f,
|
||||
0xec, 0xb6, 0xdb, 0x4f, 0x6e, 0xa3, 0x11, 0xe7,
|
||||
0x7a, 0xfd, 0xbc, 0xd4, 0x7a, 0xee, 0x1b, 0xb1,
|
||||
0x50, 0xf2, 0x16, 0x87, 0x35, 0x78, 0xfb, 0x96,
|
||||
0x46, 0x8e, 0x8f, 0x9f, 0x3d, 0xe8, 0xef, 0xbf,
|
||||
0xce, 0x75, 0x62, 0x4b, 0x1d, 0xf0, 0x53, 0x22,
|
||||
0xa3, 0x4f, 0x14, 0x63, 0xe8, 0x39, 0xe8, 0x98,
|
||||
0x4c, 0x4a, 0xd0, 0xa9, 0x6e, 0x1a, 0xc8, 0x42,
|
||||
0xe5, 0x31, 0x8c, 0xc2, 0x3c, 0x06, 0x2a, 0x8c,
|
||||
0xa1, 0x71, 0xb8, 0xd5, 0x75, 0x98, 0x0d, 0xde,
|
||||
0x7f, 0xc5, 0x6f, 0x15, 0x36, 0x52, 0x38, 0x20,
|
||||
0xd4, 0x31, 0x92, 0xbf, 0xd5, 0x1e, 0x8e, 0x22,
|
||||
0x89, 0x78, 0xac, 0xa5, 0xb9, 0x44, 0x72, 0xf3,
|
||||
0x39, 0xca, 0xeb, 0x99, 0x31, 0xb4, 0x2b, 0xe3,
|
||||
0x01, 0x26, 0x8b, 0xc9, 0x97, 0x89, 0xc9, 0xb2,
|
||||
0x55, 0x71, 0xc3, 0xc0, 0xe4, 0xcb, 0x3f, 0x00,
|
||||
0x7f, 0x1a, 0x51, 0x1c, 0xbb, 0x53, 0xc8, 0x51,
|
||||
0x9c, 0xdd, 0x13, 0x02, 0xab, 0xca, 0x6c, 0x0f,
|
||||
0x34, 0xf9, 0x67, 0x39, 0xf1, 0x7f, 0xf4, 0x8b
|
||||
};
|
||||
|
||||
static const unsigned char dh_secret_expected[] = {
|
||||
0x08, 0xff, 0x33, 0xbb, 0x2e, 0xcf, 0xf4, 0x9a,
|
||||
0x7d, 0x4a, 0x79, 0x12, 0xae, 0xb1, 0xbb, 0x6a,
|
||||
0xb5, 0x11, 0x64, 0x1b, 0x4a, 0x76, 0x77, 0x0c,
|
||||
0x8c, 0xc1, 0xbc, 0xc2, 0x33, 0x34, 0x3d, 0xfe,
|
||||
0x70, 0x0d, 0x11, 0x81, 0x3d, 0x2c, 0x9e, 0xd2,
|
||||
0x3b, 0x21, 0x1c, 0xa9, 0xe8, 0x78, 0x69, 0x21,
|
||||
0xed, 0xca, 0x28, 0x3c, 0x68, 0xb1, 0x61, 0x53,
|
||||
0xfa, 0x01, 0xe9, 0x1a, 0xb8, 0x2c, 0x90, 0xdd,
|
||||
0xab, 0x4a, 0x95, 0x81, 0x67, 0x70, 0xa9, 0x87,
|
||||
0x10, 0xe1, 0x4c, 0x92, 0xab, 0x83, 0xb6, 0xe4,
|
||||
0x6e, 0x1e, 0x42, 0x6e, 0xe8, 0x52, 0x43, 0x0d,
|
||||
0x61, 0x87, 0xda, 0xa3, 0x72, 0x0a, 0x6b, 0xcd,
|
||||
0x73, 0x23, 0x5c, 0x6b, 0x0f, 0x94, 0x1f, 0x33,
|
||||
0x64, 0xf5, 0x04, 0x20, 0x55, 0x1a, 0x4b, 0xfe,
|
||||
0xaf, 0xe2, 0xbc, 0x43, 0x85, 0x05, 0xa5, 0x9a,
|
||||
0x4a, 0x40, 0xda, 0xca, 0x7a, 0x89, 0x5a, 0x73,
|
||||
0xdb, 0x57, 0x5c, 0x74, 0xc1, 0x3a, 0x23, 0xad,
|
||||
0x88, 0x32, 0x95, 0x7d, 0x58, 0x2d, 0x38, 0xf0,
|
||||
0xa6, 0x16, 0x5f, 0xb0, 0xd7, 0xe9, 0xb8, 0x79,
|
||||
0x9e, 0x42, 0xfd, 0x32, 0x20, 0xe3, 0x32, 0xe9,
|
||||
0x81, 0x85, 0xa0, 0xc9, 0x42, 0x97, 0x57, 0xb2,
|
||||
0xd0, 0xd0, 0x2c, 0x17, 0xdb, 0xaa, 0x1f, 0xf6,
|
||||
0xed, 0x93, 0xd7, 0xe7, 0x3e, 0x24, 0x1e, 0xae,
|
||||
0xd9, 0x0c, 0xaf, 0x39, 0x4d, 0x2b, 0xc6, 0x57,
|
||||
0x0f, 0x18, 0xc8, 0x1f, 0x2b, 0xe5, 0xd0, 0x1a,
|
||||
0x2c, 0xa9, 0x9f, 0xf1, 0x42, 0xb5, 0xd9, 0x63,
|
||||
0xf9, 0xf5, 0x00, 0x32, 0x5e, 0x75, 0x56, 0xf9,
|
||||
0x58, 0x49, 0xb3, 0xff, 0xc7, 0x47, 0x94, 0x86,
|
||||
0xbe, 0x1d, 0x45, 0x96, 0xa3, 0x10, 0x6b, 0xd5,
|
||||
0xcb, 0x4f, 0x61, 0xc5, 0x7e, 0xc5, 0xf1, 0x00,
|
||||
0xfb, 0x7a, 0x0c, 0x82, 0xa1, 0x0b, 0x82, 0x52,
|
||||
0x6a, 0x97, 0xd1, 0xd9, 0x7d, 0x98, 0xea, 0xf6
|
||||
};
|
||||
|
||||
static const ST_KAT_PARAM dh_group[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_P, dh_p),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_Q, dh_q),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_G, dh_g),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
/* The host's private key */
|
||||
static const ST_KAT_PARAM dh_host_key[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PUB_KEY, dh_pub),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PRIV_KEY, dh_priv),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
/* The peer's public key */
|
||||
static const ST_KAT_PARAM dh_peer_key[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PUB_KEY, dh_peer_pub),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
static const char ecdh_curve_name[] = "prime256v1";
|
||||
static const unsigned char ecdh_privd[] = {
|
||||
0x33, 0xd0, 0x43, 0x83, 0xa9, 0x89, 0x56, 0x03,
|
||||
0xd2, 0xd7, 0xfe, 0x6b, 0x01, 0x6f, 0xe4, 0x59,
|
||||
0xcc, 0x0d, 0x9a, 0x24, 0x6c, 0x86, 0x1b, 0x2e,
|
||||
0xdc, 0x4b, 0x4d, 0x35, 0x43, 0xe1, 0x1b, 0xad
|
||||
};
|
||||
static const unsigned char ecdh_pub[] = {
|
||||
0x04,
|
||||
0x1b, 0x93, 0x67, 0x55, 0x1c, 0x55, 0x9f, 0x63,
|
||||
0xd1, 0x22, 0xa4, 0xd8, 0xd1, 0x0a, 0x60, 0x6d,
|
||||
0x02, 0xa5, 0x77, 0x57, 0xc8, 0xa3, 0x47, 0x73,
|
||||
0x3a, 0x6a, 0x08, 0x28, 0x39, 0xbd, 0xc9, 0xd2,
|
||||
0x80, 0xec, 0xe9, 0xa7, 0x08, 0x29, 0x71, 0x2f,
|
||||
0xc9, 0x56, 0x82, 0xee, 0x9a, 0x85, 0x0f, 0x6d,
|
||||
0x7f, 0x59, 0x5f, 0x8c, 0xd1, 0x96, 0x0b, 0xdf,
|
||||
0x29, 0x3e, 0x49, 0x07, 0x88, 0x3f, 0x9a, 0x29
|
||||
};
|
||||
static const unsigned char ecdh_peer_pub[] = {
|
||||
0x04,
|
||||
0x1f, 0x72, 0xbd, 0x2a, 0x3e, 0xeb, 0x6c, 0x76,
|
||||
0xe5, 0x5d, 0x69, 0x75, 0x24, 0xbf, 0x2f, 0x5b,
|
||||
0x96, 0xb2, 0x91, 0x62, 0x06, 0x35, 0xcc, 0xb2,
|
||||
0x4b, 0x31, 0x1b, 0x0c, 0x6f, 0x06, 0x9f, 0x86,
|
||||
0xcf, 0xc8, 0xac, 0xd5, 0x4f, 0x4d, 0x77, 0xf3,
|
||||
0x70, 0x4a, 0x8f, 0x04, 0x9a, 0xb1, 0x03, 0xc7,
|
||||
0xeb, 0xd5, 0x94, 0x78, 0x61, 0xab, 0x78, 0x0c,
|
||||
0x4a, 0x2d, 0x6b, 0xf3, 0x2f, 0x2e, 0x4a, 0xbc
|
||||
};
|
||||
|
||||
static const ST_KAT_PARAM ecdh_group[] = {
|
||||
ST_KAT_PARAM_UTF8STRING(OSSL_PKEY_PARAM_EC_NAME, ecdh_curve_name),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
static const ST_KAT_PARAM ecdh_host_key[] = {
|
||||
ST_KAT_PARAM_OCTET(OSSL_PKEY_PARAM_PUB_KEY, ecdh_pub),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PRIV_KEY, ecdh_privd),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
static const ST_KAT_PARAM ecdh_peer_key[] = {
|
||||
ST_KAT_PARAM_OCTET(OSSL_PKEY_PARAM_PUB_KEY, ecdh_peer_pub),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
static const unsigned char ecdh_secret_expected[] = {
|
||||
0x45, 0x2a, 0x2f, 0x0d, 0x24, 0xe6, 0x8d, 0xd0,
|
||||
0xda, 0x59, 0x7b, 0x0c, 0xec, 0x9b, 0x4c, 0x38,
|
||||
0x41, 0xdd, 0xce, 0xb3, 0xcc, 0xf1, 0x90, 0x8e,
|
||||
0x30, 0xdb, 0x5b, 0x5f, 0x97, 0xea, 0xe0, 0xc2
|
||||
};
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
|
||||
static const ST_KAT_KAS st_kat_kas_tests[] =
|
||||
{
|
||||
#ifndef OPENSSL_NO_DH
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_KA_DH,
|
||||
"DH",
|
||||
dh_group,
|
||||
dh_host_key,
|
||||
dh_peer_key,
|
||||
ITM(dh_secret_expected)
|
||||
},
|
||||
#endif /* OPENSSL_NO_DH */
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_KA_ECDH,
|
||||
"EC",
|
||||
ecdh_group,
|
||||
ecdh_host_key,
|
||||
ecdh_peer_key,
|
||||
ITM(ecdh_secret_expected)
|
||||
},
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
};
|
||||
|
||||
#if !defined(OPENSSL_NO_RSA)
|
||||
/* RSA key data */
|
||||
static const unsigned char rsa_n[] = {
|
||||
0xDB, 0x10, 0x1A, 0xC2, 0xA3, 0xF1, 0xDC, 0xFF,
|
||||
0x13, 0x6B, 0xED, 0x44, 0xDF, 0xF0, 0x02, 0x6D,
|
||||
0x13, 0xC7, 0x88, 0xDA, 0x70, 0x6B, 0x54, 0xF1,
|
||||
0xE8, 0x27, 0xDC, 0xC3, 0x0F, 0x99, 0x6A, 0xFA,
|
||||
0xC6, 0x67, 0xFF, 0x1D, 0x1E, 0x3C, 0x1D, 0xC1,
|
||||
0xB5, 0x5F, 0x6C, 0xC0, 0xB2, 0x07, 0x3A, 0x6D,
|
||||
0x41, 0xE4, 0x25, 0x99, 0xAC, 0xFC, 0xD2, 0x0F,
|
||||
0x02, 0xD3, 0xD1, 0x54, 0x06, 0x1A, 0x51, 0x77,
|
||||
0xBD, 0xB6, 0xBF, 0xEA, 0xA7, 0x5C, 0x06, 0xA9,
|
||||
0x5D, 0x69, 0x84, 0x45, 0xD7, 0xF5, 0x05, 0xBA,
|
||||
0x47, 0xF0, 0x1B, 0xD7, 0x2B, 0x24, 0xEC, 0xCB,
|
||||
0x9B, 0x1B, 0x10, 0x8D, 0x81, 0xA0, 0xBE, 0xB1,
|
||||
0x8C, 0x33, 0xE4, 0x36, 0xB8, 0x43, 0xEB, 0x19,
|
||||
0x2A, 0x81, 0x8D, 0xDE, 0x81, 0x0A, 0x99, 0x48,
|
||||
0xB6, 0xF6, 0xBC, 0xCD, 0x49, 0x34, 0x3A, 0x8F,
|
||||
0x26, 0x94, 0xE3, 0x28, 0x82, 0x1A, 0x7C, 0x8F,
|
||||
0x59, 0x9F, 0x45, 0xE8, 0x5D, 0x1A, 0x45, 0x76,
|
||||
0x04, 0x56, 0x05, 0xA1, 0xD0, 0x1B, 0x8C, 0x77,
|
||||
0x6D, 0xAF, 0x53, 0xFA, 0x71, 0xE2, 0x67, 0xE0,
|
||||
0x9A, 0xFE, 0x03, 0xA9, 0x85, 0xD2, 0xC9, 0xAA,
|
||||
0xBA, 0x2A, 0xBC, 0xF4, 0xA0, 0x08, 0xF5, 0x13,
|
||||
0x98, 0x13, 0x5D, 0xF0, 0xD9, 0x33, 0x34, 0x2A,
|
||||
0x61, 0xC3, 0x89, 0x55, 0xF0, 0xAE, 0x1A, 0x9C,
|
||||
0x22, 0xEE, 0x19, 0x05, 0x8D, 0x32, 0xFE, 0xEC,
|
||||
0x9C, 0x84, 0xBA, 0xB7, 0xF9, 0x6C, 0x3A, 0x4F,
|
||||
0x07, 0xFC, 0x45, 0xEB, 0x12, 0xE5, 0x7B, 0xFD,
|
||||
0x55, 0xE6, 0x29, 0x69, 0xD1, 0xC2, 0xE8, 0xB9,
|
||||
0x78, 0x59, 0xF6, 0x79, 0x10, 0xC6, 0x4E, 0xEB,
|
||||
0x6A, 0x5E, 0xB9, 0x9A, 0xC7, 0xC4, 0x5B, 0x63,
|
||||
0xDA, 0xA3, 0x3F, 0x5E, 0x92, 0x7A, 0x81, 0x5E,
|
||||
0xD6, 0xB0, 0xE2, 0x62, 0x8F, 0x74, 0x26, 0xC2,
|
||||
0x0C, 0xD3, 0x9A, 0x17, 0x47, 0xE6, 0x8E, 0xAB
|
||||
};
|
||||
static const unsigned char rsa_e[] = { 0x01, 0x00, 0x01 };
|
||||
static const unsigned char rsa_d[] = {
|
||||
0x52, 0x41, 0xF4, 0xDA, 0x7B, 0xB7, 0x59, 0x55,
|
||||
0xCA, 0xD4, 0x2F, 0x0F, 0x3A, 0xCB, 0xA4, 0x0D,
|
||||
0x93, 0x6C, 0xCC, 0x9D, 0xC1, 0xB2, 0xFB, 0xFD,
|
||||
0xAE, 0x40, 0x31, 0xAC, 0x69, 0x52, 0x21, 0x92,
|
||||
0xB3, 0x27, 0xDF, 0xEA, 0xEE, 0x2C, 0x82, 0xBB,
|
||||
0xF7, 0x40, 0x32, 0xD5, 0x14, 0xC4, 0x94, 0x12,
|
||||
0xEC, 0xB8, 0x1F, 0xCA, 0x59, 0xE3, 0xC1, 0x78,
|
||||
0xF3, 0x85, 0xD8, 0x47, 0xA5, 0xD7, 0x02, 0x1A,
|
||||
0x65, 0x79, 0x97, 0x0D, 0x24, 0xF4, 0xF0, 0x67,
|
||||
0x6E, 0x75, 0x2D, 0xBF, 0x10, 0x3D, 0xA8, 0x7D,
|
||||
0xEF, 0x7F, 0x60, 0xE4, 0xE6, 0x05, 0x82, 0x89,
|
||||
0x5D, 0xDF, 0xC6, 0xD2, 0x6C, 0x07, 0x91, 0x33,
|
||||
0x98, 0x42, 0xF0, 0x02, 0x00, 0x25, 0x38, 0xC5,
|
||||
0x85, 0x69, 0x8A, 0x7D, 0x2F, 0x95, 0x6C, 0x43,
|
||||
0x9A, 0xB8, 0x81, 0xE2, 0xD0, 0x07, 0x35, 0xAA,
|
||||
0x05, 0x41, 0xC9, 0x1E, 0xAF, 0xE4, 0x04, 0x3B,
|
||||
0x19, 0xB8, 0x73, 0xA2, 0xAC, 0x4B, 0x1E, 0x66,
|
||||
0x48, 0xD8, 0x72, 0x1F, 0xAC, 0xF6, 0xCB, 0xBC,
|
||||
0x90, 0x09, 0xCA, 0xEC, 0x0C, 0xDC, 0xF9, 0x2C,
|
||||
0xD7, 0xEB, 0xAE, 0xA3, 0xA4, 0x47, 0xD7, 0x33,
|
||||
0x2F, 0x8A, 0xCA, 0xBC, 0x5E, 0xF0, 0x77, 0xE4,
|
||||
0x97, 0x98, 0x97, 0xC7, 0x10, 0x91, 0x7D, 0x2A,
|
||||
0xA6, 0xFF, 0x46, 0x83, 0x97, 0xDE, 0xE9, 0xE2,
|
||||
0x17, 0x03, 0x06, 0x14, 0xE2, 0xD7, 0xB1, 0x1D,
|
||||
0x77, 0xAF, 0x51, 0x27, 0x5B, 0x5E, 0x69, 0xB8,
|
||||
0x81, 0xE6, 0x11, 0xC5, 0x43, 0x23, 0x81, 0x04,
|
||||
0x62, 0xFF, 0xE9, 0x46, 0xB8, 0xD8, 0x44, 0xDB,
|
||||
0xA5, 0xCC, 0x31, 0x54, 0x34, 0xCE, 0x3E, 0x82,
|
||||
0xD6, 0xBF, 0x7A, 0x0B, 0x64, 0x21, 0x6D, 0x88,
|
||||
0x7E, 0x5B, 0x45, 0x12, 0x1E, 0x63, 0x8D, 0x49,
|
||||
0xA7, 0x1D, 0xD9, 0x1E, 0x06, 0xCD, 0xE8, 0xBA,
|
||||
0x2C, 0x8C, 0x69, 0x32, 0xEA, 0xBE, 0x60, 0x71
|
||||
};
|
||||
static const unsigned char rsa_p[] = {
|
||||
0xFA, 0xAC, 0xE1, 0x37, 0x5E, 0x32, 0x11, 0x34,
|
||||
0xC6, 0x72, 0x58, 0x2D, 0x91, 0x06, 0x3E, 0x77,
|
||||
0xE7, 0x11, 0x21, 0xCD, 0x4A, 0xF8, 0xA4, 0x3F,
|
||||
0x0F, 0xEF, 0x31, 0xE3, 0xF3, 0x55, 0xA0, 0xB9,
|
||||
0xAC, 0xB6, 0xCB, 0xBB, 0x41, 0xD0, 0x32, 0x81,
|
||||
0x9A, 0x8F, 0x7A, 0x99, 0x30, 0x77, 0x6C, 0x68,
|
||||
0x27, 0xE2, 0x96, 0xB5, 0x72, 0xC9, 0xC3, 0xD4,
|
||||
0x42, 0xAA, 0xAA, 0xCA, 0x95, 0x8F, 0xFF, 0xC9,
|
||||
0x9B, 0x52, 0x34, 0x30, 0x1D, 0xCF, 0xFE, 0xCF,
|
||||
0x3C, 0x56, 0x68, 0x6E, 0xEF, 0xE7, 0x6C, 0xD7,
|
||||
0xFB, 0x99, 0xF5, 0x4A, 0xA5, 0x21, 0x1F, 0x2B,
|
||||
0xEA, 0x93, 0xE8, 0x98, 0x26, 0xC4, 0x6E, 0x42,
|
||||
0x21, 0x5E, 0xA0, 0xA1, 0x2A, 0x58, 0x35, 0xBB,
|
||||
0x10, 0xE7, 0xBA, 0x27, 0x0A, 0x3B, 0xB3, 0xAF,
|
||||
0xE2, 0x75, 0x36, 0x04, 0xAC, 0x56, 0xA0, 0xAB,
|
||||
0x52, 0xDE, 0xCE, 0xDD, 0x2C, 0x28, 0x77, 0x03
|
||||
};
|
||||
static const unsigned char rsa_q[] = {
|
||||
0xDF, 0xB7, 0x52, 0xB6, 0xD7, 0xC0, 0xE2, 0x96,
|
||||
0xE7, 0xC9, 0xFE, 0x5D, 0x71, 0x5A, 0xC4, 0x40,
|
||||
0x96, 0x2F, 0xE5, 0x87, 0xEA, 0xF3, 0xA5, 0x77,
|
||||
0x11, 0x67, 0x3C, 0x8D, 0x56, 0x08, 0xA7, 0xB5,
|
||||
0x67, 0xFA, 0x37, 0xA8, 0xB8, 0xCF, 0x61, 0xE8,
|
||||
0x63, 0xD8, 0x38, 0x06, 0x21, 0x2B, 0x92, 0x09,
|
||||
0xA6, 0x39, 0x3A, 0xEA, 0xA8, 0xB4, 0x45, 0x4B,
|
||||
0x36, 0x10, 0x4C, 0xE4, 0x00, 0x66, 0x71, 0x65,
|
||||
0xF8, 0x0B, 0x94, 0x59, 0x4F, 0x8C, 0xFD, 0xD5,
|
||||
0x34, 0xA2, 0xE7, 0x62, 0x84, 0x0A, 0xA7, 0xBB,
|
||||
0xDB, 0xD9, 0x8A, 0xCD, 0x05, 0xE1, 0xCC, 0x57,
|
||||
0x7B, 0xF1, 0xF1, 0x1F, 0x11, 0x9D, 0xBA, 0x3E,
|
||||
0x45, 0x18, 0x99, 0x1B, 0x41, 0x64, 0x43, 0xEE,
|
||||
0x97, 0x5D, 0x77, 0x13, 0x5B, 0x74, 0x69, 0x73,
|
||||
0x87, 0x95, 0x05, 0x07, 0xBE, 0x45, 0x07, 0x17,
|
||||
0x7E, 0x4A, 0x69, 0x22, 0xF3, 0xDB, 0x05, 0x39
|
||||
};
|
||||
static const unsigned char rsa_dp[] = {
|
||||
0x5E, 0xD8, 0xDC, 0xDA, 0x53, 0x44, 0xC4, 0x67,
|
||||
0xE0, 0x92, 0x51, 0x34, 0xE4, 0x83, 0xA5, 0x4D,
|
||||
0x3E, 0xDB, 0xA7, 0x9B, 0x82, 0xBB, 0x73, 0x81,
|
||||
0xFC, 0xE8, 0x77, 0x4B, 0x15, 0xBE, 0x17, 0x73,
|
||||
0x49, 0x9B, 0x5C, 0x98, 0xBC, 0xBD, 0x26, 0xEF,
|
||||
0x0C, 0xE9, 0x2E, 0xED, 0x19, 0x7E, 0x86, 0x41,
|
||||
0x1E, 0x9E, 0x48, 0x81, 0xDD, 0x2D, 0xE4, 0x6F,
|
||||
0xC2, 0xCD, 0xCA, 0x93, 0x9E, 0x65, 0x7E, 0xD5,
|
||||
0xEC, 0x73, 0xFD, 0x15, 0x1B, 0xA2, 0xA0, 0x7A,
|
||||
0x0F, 0x0D, 0x6E, 0xB4, 0x53, 0x07, 0x90, 0x92,
|
||||
0x64, 0x3B, 0x8B, 0xA9, 0x33, 0xB3, 0xC5, 0x94,
|
||||
0x9B, 0x4C, 0x5D, 0x9C, 0x7C, 0x46, 0xA4, 0xA5,
|
||||
0x56, 0xF4, 0xF3, 0xF8, 0x27, 0x0A, 0x7B, 0x42,
|
||||
0x0D, 0x92, 0x70, 0x47, 0xE7, 0x42, 0x51, 0xA9,
|
||||
0xC2, 0x18, 0xB1, 0x58, 0xB1, 0x50, 0x91, 0xB8,
|
||||
0x61, 0x41, 0xB6, 0xA9, 0xCE, 0xD4, 0x7C, 0xBB
|
||||
};
|
||||
static const unsigned char rsa_dq[] = {
|
||||
0x54, 0x09, 0x1F, 0x0F, 0x03, 0xD8, 0xB6, 0xC5,
|
||||
0x0C, 0xE8, 0xB9, 0x9E, 0x0C, 0x38, 0x96, 0x43,
|
||||
0xD4, 0xA6, 0xC5, 0x47, 0xDB, 0x20, 0x0E, 0xE5,
|
||||
0xBD, 0x29, 0xD4, 0x7B, 0x1A, 0xF8, 0x41, 0x57,
|
||||
0x49, 0x69, 0x9A, 0x82, 0xCC, 0x79, 0x4A, 0x43,
|
||||
0xEB, 0x4D, 0x8B, 0x2D, 0xF2, 0x43, 0xD5, 0xA5,
|
||||
0xBE, 0x44, 0xFD, 0x36, 0xAC, 0x8C, 0x9B, 0x02,
|
||||
0xF7, 0x9A, 0x03, 0xE8, 0x19, 0xA6, 0x61, 0xAE,
|
||||
0x76, 0x10, 0x93, 0x77, 0x41, 0x04, 0xAB, 0x4C,
|
||||
0xED, 0x6A, 0xCC, 0x14, 0x1B, 0x99, 0x8D, 0x0C,
|
||||
0x6A, 0x37, 0x3B, 0x86, 0x6C, 0x51, 0x37, 0x5B,
|
||||
0x1D, 0x79, 0xF2, 0xA3, 0x43, 0x10, 0xC6, 0xA7,
|
||||
0x21, 0x79, 0x6D, 0xF9, 0xE9, 0x04, 0x6A, 0xE8,
|
||||
0x32, 0xFF, 0xAE, 0xFD, 0x1C, 0x7B, 0x8C, 0x29,
|
||||
0x13, 0xA3, 0x0C, 0xB2, 0xAD, 0xEC, 0x6C, 0x0F,
|
||||
0x8D, 0x27, 0x12, 0x7B, 0x48, 0xB2, 0xDB, 0x31
|
||||
};
|
||||
static const unsigned char rsa_qInv[] = {
|
||||
0x8D, 0x1B, 0x05, 0xCA, 0x24, 0x1F, 0x0C, 0x53,
|
||||
0x19, 0x52, 0x74, 0x63, 0x21, 0xFA, 0x78, 0x46,
|
||||
0x79, 0xAF, 0x5C, 0xDE, 0x30, 0xA4, 0x6C, 0x20,
|
||||
0x38, 0xE6, 0x97, 0x39, 0xB8, 0x7A, 0x70, 0x0D,
|
||||
0x8B, 0x6C, 0x6D, 0x13, 0x74, 0xD5, 0x1C, 0xDE,
|
||||
0xA9, 0xF4, 0x60, 0x37, 0xFE, 0x68, 0x77, 0x5E,
|
||||
0x0B, 0x4E, 0x5E, 0x03, 0x31, 0x30, 0xDF, 0xD6,
|
||||
0xAE, 0x85, 0xD0, 0x81, 0xBB, 0x61, 0xC7, 0xB1,
|
||||
0x04, 0x5A, 0xC4, 0x6D, 0x56, 0x1C, 0xD9, 0x64,
|
||||
0xE7, 0x85, 0x7F, 0x88, 0x91, 0xC9, 0x60, 0x28,
|
||||
0x05, 0xE2, 0xC6, 0x24, 0x8F, 0xDD, 0x61, 0x64,
|
||||
0xD8, 0x09, 0xDE, 0x7E, 0xD3, 0x4A, 0x61, 0x1A,
|
||||
0xD3, 0x73, 0x58, 0x4B, 0xD8, 0xA0, 0x54, 0x25,
|
||||
0x48, 0x83, 0x6F, 0x82, 0x6C, 0xAF, 0x36, 0x51,
|
||||
0x2A, 0x5D, 0x14, 0x2F, 0x41, 0x25, 0x00, 0xDD,
|
||||
0xF8, 0xF3, 0x95, 0xFE, 0x31, 0x25, 0x50, 0x12
|
||||
};
|
||||
|
||||
static const ST_KAT_PARAM rsa_key[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_N, rsa_n),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_E, rsa_e),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_D, rsa_d),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_FACTOR, rsa_p),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_FACTOR, rsa_q),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_EXPONENT, rsa_dp),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_EXPONENT, rsa_dq),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_COEFFICIENT, rsa_qInv),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
|
||||
static const unsigned char rsa_expected_sig[256] = {
|
||||
0xad, 0xbe, 0x2a, 0xaf, 0x16, 0x85, 0xc5, 0x00,
|
||||
0x91, 0x3e, 0xd0, 0x49, 0xfb, 0x3a, 0x81, 0xb9,
|
||||
0x6c, 0x28, 0xbc, 0xbf, 0xea, 0x96, 0x5f, 0xe4,
|
||||
0x9f, 0x99, 0xf7, 0x18, 0x8c, 0xec, 0x60, 0x28,
|
||||
0xeb, 0x29, 0x02, 0x49, 0xfc, 0xda, 0xd7, 0x78,
|
||||
0x68, 0xf8, 0xe1, 0xe9, 0x4d, 0x20, 0x6d, 0x32,
|
||||
0xa6, 0xde, 0xfc, 0xe4, 0xda, 0xcc, 0x6c, 0x75,
|
||||
0x36, 0x6b, 0xff, 0x5a, 0xac, 0x01, 0xa8, 0xc2,
|
||||
0xa9, 0xe6, 0x8b, 0x18, 0x3e, 0xec, 0xea, 0x4c,
|
||||
0x4a, 0x9e, 0x00, 0x09, 0xd1, 0x8a, 0x69, 0x1b,
|
||||
0x8b, 0xd9, 0xad, 0x37, 0xe5, 0x7c, 0xff, 0x7d,
|
||||
0x59, 0x56, 0x3e, 0xa0, 0xc6, 0x32, 0xd8, 0x35,
|
||||
0x2f, 0xff, 0xfb, 0x05, 0x02, 0xcd, 0xd7, 0x19,
|
||||
0xb9, 0x00, 0x86, 0x2a, 0xcf, 0xaa, 0x78, 0x16,
|
||||
0x4b, 0xf1, 0xa7, 0x59, 0xef, 0x7d, 0xe8, 0x74,
|
||||
0x23, 0x5c, 0xb2, 0xd4, 0x8a, 0x99, 0xa5, 0xbc,
|
||||
0xfa, 0x63, 0xd8, 0xf7, 0xbd, 0xc6, 0x00, 0x13,
|
||||
0x06, 0x02, 0x9a, 0xd4, 0xa7, 0xb4, 0x3d, 0x61,
|
||||
0xab, 0xf1, 0xc2, 0x95, 0x59, 0x9b, 0x3d, 0x67,
|
||||
0x1f, 0xde, 0x57, 0xb6, 0xb6, 0x9f, 0xb0, 0x87,
|
||||
0xd6, 0x51, 0xd5, 0x3e, 0x00, 0xe2, 0xc9, 0xa0,
|
||||
0x03, 0x66, 0xbc, 0x01, 0xb3, 0x8e, 0xfa, 0xf1,
|
||||
0x15, 0xeb, 0x26, 0xf1, 0x5d, 0x81, 0x90, 0xb4,
|
||||
0x1c, 0x00, 0x7c, 0x83, 0x4a, 0xa5, 0xde, 0x64,
|
||||
0xae, 0xea, 0x6c, 0x43, 0xc3, 0x20, 0x77, 0x77,
|
||||
0x42, 0x12, 0x24, 0xf5, 0xe3, 0x70, 0xdd, 0x59,
|
||||
0x48, 0x9c, 0xef, 0xd4, 0x8a, 0x3c, 0x29, 0x6a,
|
||||
0x0c, 0x9c, 0xf2, 0x13, 0xa4, 0x1c, 0x2f, 0x49,
|
||||
0xcd, 0xb4, 0xaa, 0x28, 0x40, 0x34, 0xc6, 0x75,
|
||||
0xba, 0x30, 0xe6, 0xd8, 0x5b, 0x2f, 0x08, 0xd0,
|
||||
0x29, 0xa5, 0x39, 0xfb, 0x6e, 0x3b, 0x0f, 0x52,
|
||||
0x2c, 0x68, 0xf0, 0x37, 0xa9, 0xd2, 0x56, 0xd6
|
||||
};
|
||||
|
||||
#endif /* OPENSSL_NO_RSA */
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
/* ECDSA key data */
|
||||
static const char ecd_curve_name[] = "secp224r1";
|
||||
static const unsigned char ecd_priv[] = {
|
||||
0x98, 0x1f, 0xb5, 0xf1, 0xfc, 0x87, 0x1d, 0x7d,
|
||||
0xde, 0x1e, 0x01, 0x64, 0x09, 0x9b, 0xe7, 0x1b,
|
||||
0x9f, 0xad, 0x63, 0xdd, 0x33, 0x01, 0xd1, 0x50,
|
||||
0x80, 0x93, 0x50, 0x30
|
||||
};
|
||||
static const unsigned char ecd_pub[] = {
|
||||
0x04, 0x95, 0x47, 0x99, 0x44, 0x29, 0x8f, 0x51,
|
||||
0x39, 0xe2, 0x53, 0xec, 0x79, 0xb0, 0x4d, 0xde,
|
||||
0x87, 0x1a, 0x76, 0x54, 0xd5, 0x96, 0xb8, 0x7a,
|
||||
0x6d, 0xf4, 0x1c, 0x2c, 0x87, 0x91, 0x5f, 0xd5,
|
||||
0x31, 0xdd, 0x24, 0xe5, 0x78, 0xd9, 0x08, 0x24,
|
||||
0x8a, 0x49, 0x99, 0xec, 0x55, 0xf2, 0x82, 0xb3,
|
||||
0xc4, 0xb7, 0x33, 0x68, 0xe4, 0x24, 0xa9, 0x12,
|
||||
0x82
|
||||
};
|
||||
|
||||
static const ST_KAT_PARAM ecdsa_key[] = {
|
||||
ST_KAT_PARAM_UTF8STRING(OSSL_PKEY_PARAM_EC_NAME, ecd_curve_name),
|
||||
ST_KAT_PARAM_OCTET(OSSL_PKEY_PARAM_PUB_KEY, ecd_pub),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PRIV_KEY, ecd_priv),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
/* dsa 2048 */
|
||||
static const unsigned char dsa_p[] = {
|
||||
0xa2, 0x9b, 0x88, 0x72, 0xce, 0x8b, 0x84, 0x23,
|
||||
0xb7, 0xd5, 0xd2, 0x1d, 0x4b, 0x02, 0xf5, 0x7e,
|
||||
0x03, 0xe9, 0xe6, 0xb8, 0xa2, 0x58, 0xdc, 0x16,
|
||||
0x61, 0x1b, 0xa0, 0x98, 0xab, 0x54, 0x34, 0x15,
|
||||
0xe4, 0x15, 0xf1, 0x56, 0x99, 0x7a, 0x3e, 0xe2,
|
||||
0x36, 0x65, 0x8f, 0xa0, 0x93, 0x26, 0x0d, 0xe3,
|
||||
0xad, 0x42, 0x2e, 0x05, 0xe0, 0x46, 0xf9, 0xec,
|
||||
0x29, 0x16, 0x1a, 0x37, 0x5f, 0x0e, 0xb4, 0xef,
|
||||
0xfc, 0xef, 0x58, 0x28, 0x5c, 0x5d, 0x39, 0xed,
|
||||
0x42, 0x5d, 0x7a, 0x62, 0xca, 0x12, 0x89, 0x6c,
|
||||
0x4a, 0x92, 0xcb, 0x19, 0x46, 0xf2, 0x95, 0x2a,
|
||||
0x48, 0x13, 0x3f, 0x07, 0xda, 0x36, 0x4d, 0x1b,
|
||||
0xdf, 0x6b, 0x0f, 0x71, 0x39, 0x98, 0x3e, 0x69,
|
||||
0x3c, 0x80, 0x05, 0x9b, 0x0e, 0xac, 0xd1, 0x47,
|
||||
0x9b, 0xa9, 0xf2, 0x85, 0x77, 0x54, 0xed, 0xe7,
|
||||
0x5f, 0x11, 0x2b, 0x07, 0xeb, 0xbf, 0x35, 0x34,
|
||||
0x8b, 0xbf, 0x3e, 0x01, 0xe0, 0x2f, 0x2d, 0x47,
|
||||
0x3d, 0xe3, 0x94, 0x53, 0xf9, 0x9d, 0xd2, 0x36,
|
||||
0x75, 0x41, 0xca, 0xca, 0x3b, 0xa0, 0x11, 0x66,
|
||||
0x34, 0x3d, 0x7b, 0x5b, 0x58, 0xa3, 0x7b, 0xd1,
|
||||
0xb7, 0x52, 0x1d, 0xb2, 0xf1, 0x3b, 0x86, 0x70,
|
||||
0x71, 0x32, 0xfe, 0x09, 0xf4, 0xcd, 0x09, 0xdc,
|
||||
0x16, 0x18, 0xfa, 0x34, 0x01, 0xeb, 0xf9, 0xcc,
|
||||
0x7b, 0x19, 0xfa, 0x94, 0xaa, 0x47, 0x20, 0x88,
|
||||
0x13, 0x3d, 0x6c, 0xb2, 0xd3, 0x5c, 0x11, 0x79,
|
||||
0xc8, 0xc8, 0xff, 0x36, 0x87, 0x58, 0xd5, 0x07,
|
||||
0xd9, 0xf9, 0xa1, 0x7d, 0x46, 0xc1, 0x10, 0xfe,
|
||||
0x31, 0x44, 0xce, 0x9b, 0x02, 0x2b, 0x42, 0xe4,
|
||||
0x19, 0xeb, 0x4f, 0x53, 0x88, 0x61, 0x3b, 0xfc,
|
||||
0x3e, 0x26, 0x24, 0x1a, 0x43, 0x2e, 0x87, 0x06,
|
||||
0xbc, 0x58, 0xef, 0x76, 0x11, 0x72, 0x78, 0xde,
|
||||
0xab, 0x6c, 0xf6, 0x92, 0x61, 0x82, 0x91, 0xb7
|
||||
};
|
||||
static const unsigned char dsa_q[] = {
|
||||
0xa3, 0xbf, 0xd9, 0xab, 0x78, 0x84, 0x79, 0x4e,
|
||||
0x38, 0x34, 0x50, 0xd5, 0x89, 0x1d, 0xc1, 0x8b,
|
||||
0x65, 0x15, 0x7b, 0xdc, 0xfc, 0xda, 0xc5, 0x15,
|
||||
0x18, 0x90, 0x28, 0x67
|
||||
};
|
||||
static const unsigned char dsa_g[] = {
|
||||
0x68, 0x19, 0x27, 0x88, 0x69, 0xc7, 0xfd, 0x3d,
|
||||
0x2d, 0x7b, 0x77, 0xf7, 0x7e, 0x81, 0x50, 0xd9,
|
||||
0xad, 0x43, 0x3b, 0xea, 0x3b, 0xa8, 0x5e, 0xfc,
|
||||
0x80, 0x41, 0x5a, 0xa3, 0x54, 0x5f, 0x78, 0xf7,
|
||||
0x22, 0x96, 0xf0, 0x6c, 0xb1, 0x9c, 0xed, 0xa0,
|
||||
0x6c, 0x94, 0xb0, 0x55, 0x1c, 0xfe, 0x6e, 0x6f,
|
||||
0x86, 0x3e, 0x31, 0xd1, 0xde, 0x6e, 0xed, 0x7d,
|
||||
0xab, 0x8b, 0x0c, 0x9d, 0xf2, 0x31, 0xe0, 0x84,
|
||||
0x34, 0xd1, 0x18, 0x4f, 0x91, 0xd0, 0x33, 0x69,
|
||||
0x6b, 0xb3, 0x82, 0xf8, 0x45, 0x5e, 0x98, 0x88,
|
||||
0xf5, 0xd3, 0x1d, 0x47, 0x84, 0xec, 0x40, 0x12,
|
||||
0x02, 0x46, 0xf4, 0xbe, 0xa6, 0x17, 0x94, 0xbb,
|
||||
0xa5, 0x86, 0x6f, 0x09, 0x74, 0x64, 0x63, 0xbd,
|
||||
0xf8, 0xe9, 0xe1, 0x08, 0xcd, 0x95, 0x29, 0xc3,
|
||||
0xd0, 0xf6, 0xdf, 0x80, 0x31, 0x6e, 0x2e, 0x70,
|
||||
0xaa, 0xeb, 0x1b, 0x26, 0xcd, 0xb8, 0xad, 0x97,
|
||||
0xbc, 0x3d, 0x28, 0x7e, 0x0b, 0x8d, 0x61, 0x6c,
|
||||
0x42, 0xe6, 0x5b, 0x87, 0xdb, 0x20, 0xde, 0xb7,
|
||||
0x00, 0x5b, 0xc4, 0x16, 0x74, 0x7a, 0x64, 0x70,
|
||||
0x14, 0x7a, 0x68, 0xa7, 0x82, 0x03, 0x88, 0xeb,
|
||||
0xf4, 0x4d, 0x52, 0xe0, 0x62, 0x8a, 0xf9, 0xcf,
|
||||
0x1b, 0x71, 0x66, 0xd0, 0x34, 0x65, 0xf3, 0x5a,
|
||||
0xcc, 0x31, 0xb6, 0x11, 0x0c, 0x43, 0xda, 0xbc,
|
||||
0x7c, 0x5d, 0x59, 0x1e, 0x67, 0x1e, 0xaf, 0x7c,
|
||||
0x25, 0x2c, 0x1c, 0x14, 0x53, 0x36, 0xa1, 0xa4,
|
||||
0xdd, 0xf1, 0x32, 0x44, 0xd5, 0x5e, 0x83, 0x56,
|
||||
0x80, 0xca, 0xb2, 0x53, 0x3b, 0x82, 0xdf, 0x2e,
|
||||
0xfe, 0x55, 0xec, 0x18, 0xc1, 0xe6, 0xcd, 0x00,
|
||||
0x7b, 0xb0, 0x89, 0x75, 0x8b, 0xb1, 0x7c, 0x2c,
|
||||
0xbe, 0x14, 0x44, 0x1b, 0xd0, 0x93, 0xae, 0x66,
|
||||
0xe5, 0x97, 0x6d, 0x53, 0x73, 0x3f, 0x4f, 0xa3,
|
||||
0x26, 0x97, 0x01, 0xd3, 0x1d, 0x23, 0xd4, 0x67
|
||||
};
|
||||
static const unsigned char dsa_pub[] = {
|
||||
0xa0, 0x12, 0xb3, 0xb1, 0x70, 0xb3, 0x07, 0x22,
|
||||
0x79, 0x57, 0xb7, 0xca, 0x20, 0x61, 0xa8, 0x16,
|
||||
0xac, 0x7a, 0x2b, 0x3d, 0x9a, 0xe9, 0x95, 0xa5,
|
||||
0x11, 0x9c, 0x38, 0x5b, 0x60, 0x3b, 0xf6, 0xf6,
|
||||
0xc5, 0xde, 0x4d, 0xc5, 0xec, 0xb5, 0xdf, 0xa4,
|
||||
0xa4, 0x1c, 0x68, 0x66, 0x2e, 0xb2, 0x5b, 0x63,
|
||||
0x8b, 0x7e, 0x26, 0x20, 0xba, 0x89, 0x8d, 0x07,
|
||||
0xda, 0x6c, 0x49, 0x91, 0xe7, 0x6c, 0xc0, 0xec,
|
||||
0xd1, 0xad, 0x34, 0x21, 0x07, 0x70, 0x67, 0xe4,
|
||||
0x7c, 0x18, 0xf5, 0x8a, 0x92, 0xa7, 0x2a, 0xd4,
|
||||
0x31, 0x99, 0xec, 0xb7, 0xbd, 0x84, 0xe7, 0xd3,
|
||||
0xaf, 0xb9, 0x01, 0x9f, 0x0e, 0x9d, 0xd0, 0xfb,
|
||||
0xaa, 0x48, 0x73, 0x00, 0xb1, 0x30, 0x81, 0xe3,
|
||||
0x3c, 0x90, 0x28, 0x76, 0x43, 0x6f, 0x7b, 0x03,
|
||||
0xc3, 0x45, 0x52, 0x84, 0x81, 0xd3, 0x62, 0x81,
|
||||
0x5e, 0x24, 0xfe, 0x59, 0xda, 0xc5, 0xac, 0x34,
|
||||
0x66, 0x0d, 0x4c, 0x8a, 0x76, 0xcb, 0x99, 0xa7,
|
||||
0xc7, 0xde, 0x93, 0xeb, 0x95, 0x6c, 0xd6, 0xbc,
|
||||
0x88, 0xe5, 0x8d, 0x90, 0x10, 0x34, 0x94, 0x4a,
|
||||
0x09, 0x4b, 0x01, 0x80, 0x3a, 0x43, 0xc6, 0x72,
|
||||
0xb9, 0x68, 0x8c, 0x0e, 0x01, 0xd8, 0xf4, 0xfc,
|
||||
0x91, 0xc6, 0x2a, 0x3f, 0x88, 0x02, 0x1f, 0x7b,
|
||||
0xd6, 0xa6, 0x51, 0xb1, 0xa8, 0x8f, 0x43, 0xaa,
|
||||
0x4e, 0xf2, 0x76, 0x53, 0xd1, 0x2b, 0xf8, 0xb7,
|
||||
0x09, 0x9f, 0xdf, 0x6b, 0x46, 0x10, 0x82, 0xf8,
|
||||
0xe9, 0x39, 0x10, 0x7b, 0xfd, 0x2f, 0x72, 0x10,
|
||||
0x08, 0x7d, 0x32, 0x6c, 0x37, 0x52, 0x00, 0xf1,
|
||||
0xf5, 0x1e, 0x7e, 0x74, 0xa3, 0x41, 0x31, 0x90,
|
||||
0x1b, 0xcd, 0x08, 0x63, 0x52, 0x1f, 0xf8, 0xd6,
|
||||
0x76, 0xc4, 0x85, 0x81, 0x86, 0x87, 0x36, 0xc5,
|
||||
0xe5, 0x1b, 0x16, 0xa4, 0xe3, 0x92, 0x15, 0xea,
|
||||
0x0b, 0x17, 0xc4, 0x73, 0x59, 0x74, 0xc5, 0x16
|
||||
};
|
||||
static const unsigned char dsa_priv[] = {
|
||||
0x6c, 0xca, 0xee, 0xf6, 0xd7, 0x3b, 0x4e, 0x80,
|
||||
0xf1, 0x1c, 0x17, 0xb8, 0xe9, 0x62, 0x7c, 0x03,
|
||||
0x66, 0x35, 0xba, 0xc3, 0x94, 0x23, 0x50, 0x5e,
|
||||
0x40, 0x7e, 0x5c, 0xb7
|
||||
};
|
||||
|
||||
static const ST_KAT_PARAM dsa_key[] = {
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_P, dsa_p),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_Q, dsa_q),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_FFC_G, dsa_g),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PUB_KEY, dsa_pub),
|
||||
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_PRIV_KEY, dsa_priv),
|
||||
ST_KAT_PARAM_END()
|
||||
};
|
||||
#endif /* OPENSSL_NO_DSA */
|
||||
|
||||
static const ST_KAT_SIGN st_kat_sign_tests[] = {
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_RSA,
|
||||
"RSA",
|
||||
"SHA-256",
|
||||
rsa_key,
|
||||
ITM(rsa_expected_sig)
|
||||
},
|
||||
#endif /* OPENSSL_NO_RSA */
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_ECDSA,
|
||||
"EC",
|
||||
"SHA-256",
|
||||
ecdsa_key,
|
||||
/*
|
||||
* The ECDSA signature changes each time due to it using a random k.
|
||||
* So there is no expected KAT for this case.
|
||||
*/
|
||||
},
|
||||
#endif /* OPENSSL_NO_EC */
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
{
|
||||
OSSL_SELF_TEST_DESC_SIGN_DSA,
|
||||
"DSA",
|
||||
"SHA-256",
|
||||
dsa_key,
|
||||
/*
|
||||
* The DSA signature changes each time due to it using a random k.
|
||||
* So there is no expected KAT for this case.
|
||||
*/
|
||||
},
|
||||
#endif /* OPENSSL_NO_DSA */
|
||||
};
|
||||
+251
-23
@@ -11,6 +11,8 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/rand_drbg.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/param_build.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "self_test.h"
|
||||
@@ -46,10 +48,9 @@ static int self_test_digest(const ST_KAT_DIGEST *t, OSSL_SELF_TEST *st,
|
||||
goto err;
|
||||
ok = 1;
|
||||
err:
|
||||
OSSL_SELF_TEST_onend(st, ok);
|
||||
EVP_MD_free(md);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
|
||||
OSSL_SELF_TEST_onend(st, ok);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -142,39 +143,79 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int add_params(OSSL_PARAM_BLD *bld, const ST_KAT_PARAM *params,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
int ret = 0;
|
||||
const ST_KAT_PARAM *p;
|
||||
|
||||
if (params == NULL)
|
||||
return 1;
|
||||
for (p = params; p->data != NULL; ++p)
|
||||
{
|
||||
switch (p->type) {
|
||||
case OSSL_PARAM_UNSIGNED_INTEGER: {
|
||||
BIGNUM *bn = BN_CTX_get(ctx);
|
||||
|
||||
if (bn == NULL
|
||||
|| (BN_bin2bn(p->data, p->data_len, bn) == NULL)
|
||||
|| !OSSL_PARAM_BLD_push_BN(bld, p->name, bn))
|
||||
goto err;
|
||||
break;
|
||||
}
|
||||
case OSSL_PARAM_UTF8_STRING: {
|
||||
if (!OSSL_PARAM_BLD_push_utf8_string(bld, p->name, p->data, 0))
|
||||
goto err;
|
||||
break;
|
||||
}
|
||||
case OSSL_PARAM_OCTET_STRING: {
|
||||
if (!OSSL_PARAM_BLD_push_octet_string(bld, p->name, p->data,
|
||||
p->data_len))
|
||||
goto err;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_kdf(const ST_KAT_KDF *t, OSSL_SELF_TEST *st,
|
||||
OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, numparams;
|
||||
unsigned char out[64];
|
||||
EVP_KDF *kdf = NULL;
|
||||
EVP_KDF_CTX *ctx = NULL;
|
||||
OSSL_PARAM params[16];
|
||||
const OSSL_PARAM *settables = NULL;
|
||||
BN_CTX *bnctx = NULL;
|
||||
OSSL_PARAM *params = NULL;
|
||||
OSSL_PARAM_BLD *bld = NULL;
|
||||
|
||||
numparams = OSSL_NELEM(params);
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_KDF, t->desc);
|
||||
|
||||
/* Zeroize the params array to avoid mem leaks on error */
|
||||
for (i = 0; i < numparams; ++i)
|
||||
params[i] = OSSL_PARAM_construct_end();
|
||||
bld = OSSL_PARAM_BLD_new();
|
||||
if (bld == NULL)
|
||||
goto err;
|
||||
|
||||
kdf = EVP_KDF_fetch(libctx, t->algorithm, "");
|
||||
if (kdf == NULL)
|
||||
goto err;
|
||||
|
||||
ctx = EVP_KDF_CTX_new(kdf);
|
||||
if (ctx == NULL)
|
||||
goto err;
|
||||
|
||||
settables = EVP_KDF_settable_ctx_params(kdf);
|
||||
for (i = 0; t->ctrls[i].name != NULL; ++i) {
|
||||
if (!ossl_assert(i < (numparams - 1)))
|
||||
goto err;
|
||||
if (!OSSL_PARAM_allocate_from_text(¶ms[i], settables,
|
||||
t->ctrls[i].name,
|
||||
t->ctrls[i].value,
|
||||
strlen(t->ctrls[i].value), NULL))
|
||||
goto err;
|
||||
}
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
if (!add_params(bld, t->params, bnctx))
|
||||
goto err;
|
||||
params = OSSL_PARAM_BLD_to_param(bld);
|
||||
if (params == NULL)
|
||||
goto err;
|
||||
if (!EVP_KDF_CTX_set_params(ctx, params))
|
||||
goto err;
|
||||
|
||||
@@ -190,10 +231,11 @@ static int self_test_kdf(const ST_KAT_KDF *t, OSSL_SELF_TEST *st,
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
for (i = 0; params[i].key != NULL; ++i)
|
||||
OPENSSL_free(params[i].data);
|
||||
EVP_KDF_free(kdf);
|
||||
EVP_KDF_CTX_free(ctx);
|
||||
BN_CTX_free(bnctx);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
OSSL_PARAM_BLD_free(bld);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -300,6 +342,168 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int self_test_ka(const ST_KAT_KAS *t,
|
||||
OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY_CTX *kactx = NULL, *dctx = NULL;
|
||||
EVP_PKEY *pkey = NULL, *peerkey = NULL;
|
||||
OSSL_PARAM *params = NULL;
|
||||
OSSL_PARAM *params_peer = NULL;
|
||||
unsigned char secret[256];
|
||||
size_t secret_len;
|
||||
OSSL_PARAM_BLD *bld = NULL;
|
||||
BN_CTX *bnctx = NULL;
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_KA, t->desc);
|
||||
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
|
||||
bld = OSSL_PARAM_BLD_new();
|
||||
if (bld == NULL)
|
||||
goto err;
|
||||
|
||||
if (!add_params(bld, t->key_group, bnctx)
|
||||
|| !add_params(bld, t->key_host_data, bnctx))
|
||||
goto err;
|
||||
params = OSSL_PARAM_BLD_to_param(bld);
|
||||
|
||||
if (!add_params(bld, t->key_group, bnctx)
|
||||
|| !add_params(bld, t->key_peer_data, bnctx))
|
||||
goto err;
|
||||
|
||||
params_peer = OSSL_PARAM_BLD_to_param(bld);
|
||||
if (params == NULL || params_peer == NULL)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DH keys into */
|
||||
kactx = EVP_PKEY_CTX_new_from_name(libctx, t->algorithm, "");
|
||||
if (kactx == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kactx) <= 0
|
||||
|| EVP_PKEY_fromdata(kactx, &peerkey, params_peer) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to perform key derivation */
|
||||
dctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (dctx == NULL)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_derive_init(dctx) <= 0
|
||||
|| EVP_PKEY_derive_set_peer(dctx, peerkey) <= 0
|
||||
|| EVP_PKEY_derive(dctx, secret, &secret_len) <= 0)
|
||||
goto err;
|
||||
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, secret);
|
||||
|
||||
if (secret_len != t->expected_len
|
||||
|| memcmp(secret, t->expected, t->expected_len) != 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_free(bnctx);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_free(peerkey);
|
||||
EVP_PKEY_CTX_free(kactx);
|
||||
EVP_PKEY_CTX_free(dctx);
|
||||
OSSL_PARAM_BLD_free_params(params_peer);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
OSSL_PARAM_BLD_free(bld);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_sign(const ST_KAT_SIGN *t,
|
||||
OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int ret = 0;
|
||||
OSSL_PARAM *params = NULL, *params_sig = NULL;
|
||||
OSSL_PARAM_BLD *bld = NULL;
|
||||
EVP_PKEY_CTX *sctx = NULL, *kctx = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
unsigned char sig[256];
|
||||
BN_CTX *bnctx = NULL;
|
||||
size_t siglen = 0;
|
||||
static const unsigned char dgst[] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
|
||||
OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_KAT_SIGNATURE, t->desc);
|
||||
|
||||
bnctx = BN_CTX_new_ex(libctx);
|
||||
if (bnctx == NULL)
|
||||
goto err;
|
||||
|
||||
bld = OSSL_PARAM_BLD_new();
|
||||
if (bld == NULL)
|
||||
goto err;
|
||||
|
||||
if (!add_params(bld, t->key, bnctx))
|
||||
goto err;
|
||||
params = OSSL_PARAM_BLD_to_param(bld);
|
||||
|
||||
/* Create a EVP_PKEY_CTX to load the DSA key into */
|
||||
kctx = EVP_PKEY_CTX_new_from_name(libctx, t->algorithm, "");
|
||||
if (kctx == NULL || params == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_key_fromdata_init(kctx) <= 0
|
||||
|| EVP_PKEY_fromdata(kctx, &pkey, params) <= 0)
|
||||
goto err;
|
||||
|
||||
/* Create a EVP_PKEY_CTX to use for the signing operation */
|
||||
sctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, NULL);
|
||||
if (sctx == NULL
|
||||
|| EVP_PKEY_sign_init(sctx) <= 0)
|
||||
goto err;
|
||||
|
||||
/* set signature parameters */
|
||||
if (!OSSL_PARAM_BLD_push_utf8_string(bld, OSSL_SIGNATURE_PARAM_DIGEST,
|
||||
t->mdalgorithm,
|
||||
strlen(t->mdalgorithm) + 1))
|
||||
goto err;
|
||||
params_sig = OSSL_PARAM_BLD_to_param(bld);
|
||||
if (EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
|
||||
if (EVP_PKEY_sign(sctx, sig, &siglen, dgst, sizeof(dgst)) <= 0
|
||||
|| EVP_PKEY_verify_init(sctx) <= 0
|
||||
|| EVP_PKEY_CTX_set_params(sctx, params_sig) <= 0)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Used by RSA, for other key types where the signature changes, we
|
||||
* can only use the verify.
|
||||
*/
|
||||
if (t->sig_expected != NULL
|
||||
&& (siglen != t->sig_expected_len
|
||||
|| memcmp(sig, t->sig_expected, t->sig_expected_len) != 0))
|
||||
goto err;
|
||||
|
||||
OSSL_SELF_TEST_oncorrupt_byte(st, sig);
|
||||
if (EVP_PKEY_verify(sctx, sig, siglen, dgst, sizeof(dgst)) <= 0)
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_free(bnctx);
|
||||
EVP_PKEY_free(pkey);
|
||||
EVP_PKEY_CTX_free(kctx);
|
||||
EVP_PKEY_CTX_free(sctx);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
OSSL_PARAM_BLD_free_params(params_sig);
|
||||
OSSL_PARAM_BLD_free(bld);
|
||||
OSSL_SELF_TEST_onend(st, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a data driven list of KAT's for digest algorithms.
|
||||
* All tests are run regardless of if they fail or not.
|
||||
@@ -349,12 +553,32 @@ static int self_test_drbgs(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_kas(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_kas_tests); ++i) {
|
||||
if (!self_test_ka(&st_kat_kas_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int self_test_signatures(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
int i, ret = 1;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(st_kat_sign_tests); ++i) {
|
||||
if (!self_test_sign(&st_kat_sign_tests[i], st, libctx))
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Run the algorithm KAT's.
|
||||
* Return 1 is successful, otherwise return 0.
|
||||
* This runs all the tests regardless of if any fail.
|
||||
*
|
||||
* TODO(3.0) Add self tests for KA, Sign/Verify when they become available
|
||||
*/
|
||||
int SELF_TEST_kats(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
{
|
||||
@@ -364,10 +588,14 @@ int SELF_TEST_kats(OSSL_SELF_TEST *st, OPENSSL_CTX *libctx)
|
||||
ret = 0;
|
||||
if (!self_test_ciphers(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_signatures(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_kdfs(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_drbgs(st, libctx))
|
||||
ret = 0;
|
||||
if (!self_test_kas(st, libctx))
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -219,7 +219,8 @@ static int rsa_decrypt(void *vprsactx, unsigned char *out, size_t *outlen,
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_BAD_TLS_CLIENT_VERSION);
|
||||
return 0;
|
||||
}
|
||||
ret = rsa_padding_check_PKCS1_type_2_TLS(out, outsize,
|
||||
ret = rsa_padding_check_PKCS1_type_2_TLS(prsactx->libctx, out,
|
||||
outsize,
|
||||
tbuf, len,
|
||||
prsactx->client_version,
|
||||
prsactx->alt_version);
|
||||
|
||||
@@ -11,17 +11,17 @@ $NULL_GOAL=../../libimplementations.a
|
||||
$AES_GOAL=../../libimplementations.a
|
||||
$TDES_1_GOAL=../../libimplementations.a
|
||||
$TDES_2_GOAL=../../libimplementations.a
|
||||
$DES_GOAL=../../libimplementations.a
|
||||
$ARIA_GOAL=../../libimplementations.a
|
||||
$CAMELLIA_GOAL=../../libimplementations.a
|
||||
$BLOWFISH_GOAL=../../libimplementations.a
|
||||
$IDEA_GOAL=../../libimplementations.a
|
||||
$CAST5_GOAL=../../libimplementations.a
|
||||
$SEED_GOAL=../../libimplementations.a
|
||||
$DES_GOAL=../../liblegacy.a
|
||||
$BLOWFISH_GOAL=../../liblegacy.a
|
||||
$IDEA_GOAL=../../liblegacy.a
|
||||
$CAST5_GOAL=../../liblegacy.a
|
||||
$RC2_GOAL=../../liblegacy.a
|
||||
$RC4_GOAL=../../liblegacy.a
|
||||
$RC5_GOAL=../../liblegacy.a
|
||||
$SEED_GOAL=../../liblegacy.a
|
||||
$SM4_GOAL=../../libimplementations.a
|
||||
$RC4_GOAL=../../libimplementations.a
|
||||
$RC5_GOAL=../../libimplementations.a
|
||||
$RC2_GOAL=../../libimplementations.a
|
||||
$CHACHA_GOAL=../../libimplementations.a
|
||||
$CHACHAPOLY_GOAL=../../libimplementations.a
|
||||
$SIV_GOAL=../../libimplementations.a
|
||||
@@ -33,7 +33,7 @@ SOURCE[$COMMON_GOAL]=\
|
||||
ciphercommon_ccm.c ciphercommon_ccm_hw.c
|
||||
|
||||
IF[{- !$disabled{des} -}]
|
||||
SOURCE[$TDES_1_GOAL]=cipher_tdes.c cipher_tdes_hw.c
|
||||
SOURCE[$TDES_1_GOAL]=cipher_tdes.c cipher_tdes_common.c cipher_tdes_hw.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[$NULL_GOAL]=\
|
||||
@@ -63,7 +63,7 @@ IF[{- !$disabled{des} -}]
|
||||
cipher_tdes_default.c cipher_tdes_default_hw.c \
|
||||
cipher_tdes_wrap.c cipher_tdes_wrap_hw.c
|
||||
SOURCE[$DES_GOAL]=\
|
||||
cipher_desx.c cipher_desx_hw.c \
|
||||
cipher_desx.c cipher_desx_hw.c cipher_tdes_common.c\
|
||||
cipher_des.c cipher_des_hw.c
|
||||
ENDIF
|
||||
|
||||
|
||||
@@ -150,9 +150,14 @@ static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx,
|
||||
size_t outsize, const unsigned char *in,
|
||||
size_t inl, OSSL_ocb_cipher_fn ciph)
|
||||
{
|
||||
size_t nextblocks = fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl);
|
||||
size_t nextblocks;
|
||||
size_t outlint = 0;
|
||||
|
||||
if (bufsz != 0)
|
||||
nextblocks = fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl);
|
||||
else
|
||||
nextblocks = inl & ~(AES_BLOCK_SIZE-1);
|
||||
|
||||
if (*bufsz == AES_BLOCK_SIZE) {
|
||||
if (outsize < AES_BLOCK_SIZE) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
@@ -179,7 +184,7 @@ static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx,
|
||||
in += nextblocks;
|
||||
inl -= nextblocks;
|
||||
}
|
||||
if (!trailingdata(buf, bufsz, AES_BLOCK_SIZE, &in, &inl)) {
|
||||
if (inl != 0 && !trailingdata(buf, bufsz, AES_BLOCK_SIZE, &in, &inl)) {
|
||||
/* PROVerr already called */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,20 @@ static void *des_newctx(void *provctx, size_t kbits, size_t blkbits,
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void *des_dupctx(void *ctx)
|
||||
{
|
||||
PROV_DES_CTX *in = (PROV_DES_CTX *)ctx;
|
||||
PROV_DES_CTX *ret = OPENSSL_malloc(sizeof(*ret));
|
||||
|
||||
if (ret == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
in->base.hw->copyctx(&ret->base, &in->base);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void des_freectx(void *vctx)
|
||||
{
|
||||
PROV_DES_CTX *ctx = (PROV_DES_CTX *)vctx;
|
||||
@@ -137,6 +151,7 @@ const OSSL_DISPATCH des_##lcmode##_functions[] = { \
|
||||
{ OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
|
||||
{ OSSL_FUNC_CIPHER_NEWCTX, \
|
||||
(void (*)(void))des_##lcmode##_newctx }, \
|
||||
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))des_dupctx }, \
|
||||
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))des_freectx }, \
|
||||
{ OSSL_FUNC_CIPHER_GET_PARAMS, \
|
||||
(void (*)(void))des_##lcmode##_get_params }, \
|
||||
|
||||
@@ -38,6 +38,16 @@ static int cipher_hw_des_initkey(PROV_CIPHER_CTX *ctx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cipher_hw_des_copyctx(PROV_CIPHER_CTX *dst,
|
||||
const PROV_CIPHER_CTX *src)
|
||||
{
|
||||
PROV_DES_CTX *sctx = (PROV_DES_CTX *)src;
|
||||
PROV_DES_CTX *dctx = (PROV_DES_CTX *)dst;
|
||||
|
||||
*dctx = *sctx;
|
||||
dst->ks = &dctx->dks.ks;
|
||||
}
|
||||
|
||||
static int cipher_hw_des_ecb_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t len)
|
||||
{
|
||||
@@ -164,7 +174,8 @@ static int cipher_hw_des_cfb8_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
#define PROV_CIPHER_HW_des_mode(mode) \
|
||||
static const PROV_CIPHER_HW des_##mode = { \
|
||||
cipher_hw_des_initkey, \
|
||||
cipher_hw_des_##mode##_cipher \
|
||||
cipher_hw_des_##mode##_cipher, \
|
||||
cipher_hw_des_copyctx \
|
||||
}; \
|
||||
const PROV_CIPHER_HW *PROV_CIPHER_HW_des_##mode(void) \
|
||||
{ \
|
||||
|
||||
@@ -37,6 +37,16 @@ static int cipher_hw_desx_cbc_initkey(PROV_CIPHER_CTX *ctx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cipher_hw_desx_copyctx(PROV_CIPHER_CTX *dst,
|
||||
const PROV_CIPHER_CTX *src)
|
||||
{
|
||||
PROV_TDES_CTX *sctx = (PROV_TDES_CTX *)src;
|
||||
PROV_TDES_CTX *dctx = (PROV_TDES_CTX *)dst;
|
||||
|
||||
*dctx = *sctx;
|
||||
dst->ks = &dctx->tks.ks;
|
||||
}
|
||||
|
||||
static int cipher_hw_desx_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inl)
|
||||
{
|
||||
@@ -60,7 +70,8 @@ static int cipher_hw_desx_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
static const PROV_CIPHER_HW desx_cbc =
|
||||
{
|
||||
cipher_hw_desx_cbc_initkey,
|
||||
cipher_hw_desx_cbc
|
||||
cipher_hw_desx_cbc,
|
||||
cipher_hw_desx_copyctx
|
||||
};
|
||||
const PROV_CIPHER_HW *PROV_CIPHER_HW_tdes_desx_cbc(void)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
@@ -19,101 +19,10 @@
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
|
||||
void *tdes_newctx(void *provctx, int mode, size_t kbits, size_t blkbits,
|
||||
size_t ivbits, uint64_t flags, const PROV_CIPHER_HW *hw)
|
||||
{
|
||||
PROV_TDES_CTX *tctx = OPENSSL_zalloc(sizeof(*tctx));
|
||||
|
||||
if (tctx != NULL)
|
||||
cipher_generic_initkey(tctx, kbits, blkbits, ivbits, mode, flags, hw,
|
||||
provctx);
|
||||
return tctx;
|
||||
}
|
||||
|
||||
void tdes_freectx(void *vctx)
|
||||
{
|
||||
PROV_TDES_CTX *ctx = (PROV_TDES_CTX *)vctx;
|
||||
|
||||
OPENSSL_clear_free(ctx, sizeof(*ctx));
|
||||
}
|
||||
|
||||
static int tdes_init(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen, int enc)
|
||||
{
|
||||
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
||||
|
||||
ctx->enc = enc;
|
||||
|
||||
if (iv != NULL) {
|
||||
if (!cipher_generic_initiv(ctx, iv, ivlen))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (key != NULL) {
|
||||
if (keylen != ctx->keylen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEYLEN);
|
||||
return 0;
|
||||
}
|
||||
return ctx->hw->init(ctx, key, ctx->keylen);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tdes_einit(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen)
|
||||
{
|
||||
return tdes_init(vctx, key, keylen, iv, ivlen, 1);
|
||||
}
|
||||
|
||||
int tdes_dinit(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen)
|
||||
{
|
||||
return tdes_init(vctx, key, keylen, iv, ivlen, 0);
|
||||
}
|
||||
|
||||
static int tdes_generatekey(PROV_CIPHER_CTX *ctx, void *ptr)
|
||||
{
|
||||
|
||||
DES_cblock *deskey = ptr;
|
||||
size_t kl = ctx->keylen;
|
||||
|
||||
if (kl == 0 || RAND_priv_bytes_ex(ctx->libctx, ptr, kl) <= 0)
|
||||
return 0;
|
||||
DES_set_odd_parity(deskey);
|
||||
if (kl >= 16)
|
||||
DES_set_odd_parity(deskey + 1);
|
||||
if (kl >= 24) {
|
||||
DES_set_odd_parity(deskey + 2);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(tdes)
|
||||
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_RANDOM_KEY, NULL, 0),
|
||||
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(tdes)
|
||||
|
||||
int tdes_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||
{
|
||||
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if (!cipher_generic_get_ctx_params(vctx, params))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_RANDOM_KEY);
|
||||
if (p != NULL && !tdes_generatekey(ctx, p->data)) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GENERATE_KEY);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO(3.0) - ECB mode does not use an IV - but existing test code is setting
|
||||
* an IV. Fixing this could potentially make applications break.
|
||||
*/
|
||||
|
||||
/* tdes_ede3_ecb_functions */
|
||||
IMPLEMENT_tdes_cipher(ede3, EDE3, ecb, ECB, TDES_FLAGS, 64*3, 64, 64, block);
|
||||
/* tdes_ede3_cbc_functions */
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef struct prov_tdes_ctx_st {
|
||||
|
||||
} PROV_TDES_CTX;
|
||||
|
||||
#define IMPLEMENT_tdes_cipher(type, UCTYPE, lcmode, UCMODE, flags, \
|
||||
#define IMPLEMENT_tdes_cipher(type, UCTYPE, lcmode, UCMODE, flags, \
|
||||
kbits, blkbits, ivbits, block) \
|
||||
static OSSL_OP_cipher_newctx_fn tdes_##type##_##lcmode##_newctx; \
|
||||
static void *tdes_##type##_##lcmode##_newctx(void *provctx) \
|
||||
@@ -53,6 +53,7 @@ const OSSL_DISPATCH tdes_##type##_##lcmode##_functions[] = { \
|
||||
{ OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
|
||||
{ OSSL_FUNC_CIPHER_NEWCTX, \
|
||||
(void (*)(void))tdes_##type##_##lcmode##_newctx }, \
|
||||
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))tdes_dupctx }, \
|
||||
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))tdes_freectx }, \
|
||||
{ OSSL_FUNC_CIPHER_GET_PARAMS, \
|
||||
(void (*)(void))tdes_##type##_##lcmode##_get_params }, \
|
||||
@@ -70,16 +71,18 @@ const OSSL_DISPATCH tdes_##type##_##lcmode##_functions[] = { \
|
||||
|
||||
void *tdes_newctx(void *provctx, int mode, size_t kbits, size_t blkbits,
|
||||
size_t ivbits, uint64_t flags, const PROV_CIPHER_HW *hw);
|
||||
OSSL_OP_cipher_dupctx_fn tdes_dupctx;
|
||||
OSSL_OP_cipher_freectx_fn tdes_freectx;
|
||||
OSSL_OP_cipher_encrypt_init_fn tdes_einit;
|
||||
OSSL_OP_cipher_decrypt_init_fn tdes_dinit;
|
||||
OSSL_OP_cipher_get_ctx_params_fn tdes_get_ctx_params;
|
||||
OSSL_OP_cipher_gettable_ctx_params_fn tdes_gettable_ctx_params;
|
||||
|
||||
#define PROV_CIPHER_HW_tdes_mode(type, mode) \
|
||||
#define PROV_CIPHER_HW_tdes_mode(type, mode) \
|
||||
static const PROV_CIPHER_HW type##_##mode = { \
|
||||
cipher_hw_tdes_##type##_initkey, \
|
||||
cipher_hw_tdes_##mode \
|
||||
cipher_hw_tdes_##mode, \
|
||||
cipher_hw_tdes_copyctx \
|
||||
}; \
|
||||
const PROV_CIPHER_HW *PROV_CIPHER_HW_tdes_##type##_##mode(void) \
|
||||
{ \
|
||||
@@ -88,6 +91,7 @@ const PROV_CIPHER_HW *PROV_CIPHER_HW_tdes_##type##_##mode(void) \
|
||||
|
||||
int cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
size_t keylen);
|
||||
void cipher_hw_tdes_copyctx(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src);
|
||||
int cipher_hw_tdes_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inl);
|
||||
int cipher_hw_tdes_ecb(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES low level APIs are deprecated for public use, but still ok for internal
|
||||
* use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include "prov/ciphercommon.h"
|
||||
#include "cipher_tdes.h"
|
||||
#include <openssl/rand.h>
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
|
||||
void *tdes_newctx(void *provctx, int mode, size_t kbits, size_t blkbits,
|
||||
size_t ivbits, uint64_t flags, const PROV_CIPHER_HW *hw)
|
||||
{
|
||||
PROV_TDES_CTX *tctx = OPENSSL_zalloc(sizeof(*tctx));
|
||||
|
||||
if (tctx != NULL)
|
||||
cipher_generic_initkey(tctx, kbits, blkbits, ivbits, mode, flags, hw,
|
||||
provctx);
|
||||
return tctx;
|
||||
}
|
||||
|
||||
void *tdes_dupctx(void *ctx)
|
||||
{
|
||||
PROV_TDES_CTX *in = (PROV_TDES_CTX *)ctx;
|
||||
PROV_TDES_CTX *ret = OPENSSL_malloc(sizeof(*ret));
|
||||
|
||||
if (ret == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
in->base.hw->copyctx(&ret->base, &in->base);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tdes_freectx(void *vctx)
|
||||
{
|
||||
PROV_TDES_CTX *ctx = (PROV_TDES_CTX *)vctx;
|
||||
|
||||
OPENSSL_clear_free(ctx, sizeof(*ctx));
|
||||
}
|
||||
|
||||
static int tdes_init(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen, int enc)
|
||||
{
|
||||
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
||||
|
||||
ctx->enc = enc;
|
||||
|
||||
if (iv != NULL) {
|
||||
if (!cipher_generic_initiv(ctx, iv, ivlen))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (key != NULL) {
|
||||
if (keylen != ctx->keylen) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEYLEN);
|
||||
return 0;
|
||||
}
|
||||
return ctx->hw->init(ctx, key, ctx->keylen);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tdes_einit(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen)
|
||||
{
|
||||
return tdes_init(vctx, key, keylen, iv, ivlen, 1);
|
||||
}
|
||||
|
||||
int tdes_dinit(void *vctx, const unsigned char *key, size_t keylen,
|
||||
const unsigned char *iv, size_t ivlen)
|
||||
{
|
||||
return tdes_init(vctx, key, keylen, iv, ivlen, 0);
|
||||
}
|
||||
|
||||
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(tdes)
|
||||
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_RANDOM_KEY, NULL, 0),
|
||||
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(tdes)
|
||||
|
||||
static int tdes_generatekey(PROV_CIPHER_CTX *ctx, void *ptr)
|
||||
{
|
||||
|
||||
DES_cblock *deskey = ptr;
|
||||
size_t kl = ctx->keylen;
|
||||
|
||||
if (kl == 0 || RAND_priv_bytes_ex(ctx->libctx, ptr, kl) <= 0)
|
||||
return 0;
|
||||
DES_set_odd_parity(deskey);
|
||||
if (kl >= 16)
|
||||
DES_set_odd_parity(deskey + 1);
|
||||
if (kl >= 24) {
|
||||
DES_set_odd_parity(deskey + 2);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdes_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||
{
|
||||
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if (!cipher_generic_get_ctx_params(vctx, params))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_RANDOM_KEY);
|
||||
if (p != NULL && !tdes_generatekey(ctx, p->data)) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GENERATE_KEY);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -45,6 +45,15 @@ int cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
void cipher_hw_tdes_copyctx(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src)
|
||||
{
|
||||
PROV_TDES_CTX *sctx = (PROV_TDES_CTX *)src;
|
||||
PROV_TDES_CTX *dctx = (PROV_TDES_CTX *)dst;
|
||||
|
||||
*dctx = *sctx;
|
||||
dst->ks = &dctx->tks.ks;
|
||||
}
|
||||
|
||||
int cipher_hw_tdes_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inl)
|
||||
{
|
||||
|
||||
@@ -176,7 +176,12 @@ int cipher_generic_block_update(void *vctx, unsigned char *out, size_t *outl,
|
||||
size_t outlint = 0;
|
||||
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
||||
size_t blksz = ctx->blocksize;
|
||||
size_t nextblocks = fillblock(ctx->buf, &ctx->bufsz, blksz, &in, &inl);
|
||||
size_t nextblocks;
|
||||
|
||||
if (ctx->bufsz != 0)
|
||||
nextblocks = fillblock(ctx->buf, &ctx->bufsz, blksz, &in, &inl);
|
||||
else
|
||||
nextblocks = inl & ~(blksz-1);
|
||||
|
||||
/*
|
||||
* If we're decrypting and we end an update on a block boundary we hold
|
||||
@@ -218,7 +223,7 @@ int cipher_generic_block_update(void *vctx, unsigned char *out, size_t *outl,
|
||||
in += nextblocks;
|
||||
inl -= nextblocks;
|
||||
}
|
||||
if (!trailingdata(ctx->buf, &ctx->bufsz, blksz, &in, &inl)) {
|
||||
if (inl != 0 && !trailingdata(ctx->buf, &ctx->bufsz, blksz, &in, &inl)) {
|
||||
/* ERR_raise already called */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -35,20 +35,17 @@ size_t fillblock(unsigned char *buf, size_t *buflen, size_t blocksize,
|
||||
const unsigned char **in, size_t *inlen)
|
||||
{
|
||||
size_t blockmask = ~(blocksize - 1);
|
||||
size_t bufremain = blocksize - *buflen;
|
||||
|
||||
assert(*buflen <= blocksize);
|
||||
assert(blocksize > 0 && (blocksize & (blocksize - 1)) == 0);
|
||||
|
||||
if (*buflen != blocksize && (*buflen != 0 || *inlen < blocksize)) {
|
||||
size_t bufremain = blocksize - *buflen;
|
||||
|
||||
if (*inlen < bufremain)
|
||||
bufremain = *inlen;
|
||||
memcpy(buf + *buflen, *in, bufremain);
|
||||
*in += bufremain;
|
||||
*inlen -= bufremain;
|
||||
*buflen += bufremain;
|
||||
}
|
||||
if (*inlen < bufremain)
|
||||
bufremain = *inlen;
|
||||
memcpy(buf + *buflen, *in, bufremain);
|
||||
*in += bufremain;
|
||||
*inlen -= bufremain;
|
||||
*buflen += bufremain;
|
||||
|
||||
return *inlen & blockmask;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ static int ccm_tls_cipher(PROV_CCM_CTX *ctx,
|
||||
size_t olen = 0;
|
||||
|
||||
/* Encrypt/decrypt must be performed in place */
|
||||
if (out != in || len < (EVP_CCM_TLS_EXPLICIT_IV_LEN + (size_t)ctx->m))
|
||||
if (in == NULL || out != in || len < EVP_CCM_TLS_EXPLICIT_IV_LEN + ctx->m)
|
||||
goto err;
|
||||
|
||||
/* If encrypting set explicit IV from sequence number (start of AAD) */
|
||||
|
||||
@@ -247,7 +247,7 @@ static void *keccak_dupctx(void *ctx)
|
||||
}
|
||||
|
||||
static const OSSL_PARAM known_shake_settable_ctx_params[] = {
|
||||
{OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
|
||||
{OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM *shake_settable_ctx_params(void)
|
||||
|
||||
@@ -22,5 +22,6 @@ ENDIF
|
||||
IF[{- !$disabled{ec} -}]
|
||||
SOURCE[$ECX_GOAL]=ecx_exch.c
|
||||
DEFINE[$ECX_GOAL]=$ECDEF
|
||||
SOURCE[$ECDH_GOAL]=ecdh_exch.c
|
||||
SOURCE[../../libfips.a]=ecdh_exch.c
|
||||
SOURCE[../../libnonfips.a]=ecdh_exch.c
|
||||
ENDIF
|
||||
@@ -458,6 +458,7 @@ int ecdh_plain_derive(void *vpecdhctx, unsigned char *secret,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
static ossl_inline
|
||||
int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
size_t *psecretlen, size_t outlen)
|
||||
@@ -497,6 +498,7 @@ int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret,
|
||||
OPENSSL_secure_clear_free(stmp, stmplen);
|
||||
return ret;
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
static
|
||||
int ecdh_derive(void *vpecdhctx, unsigned char *secret,
|
||||
@@ -507,8 +509,13 @@ 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
|
||||
case PROV_ECDH_KDF_X9_63:
|
||||
return ecdh_X9_63_kdf_derive(vpecdhctx, secret, psecretlen, outlen);
|
||||
|
||||
#endif /* FIPS_MODE */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -259,6 +259,8 @@ extern const OSSL_DISPATCH dsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH rsa_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x25519_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH x448_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH ed448_keymgmt_functions[];
|
||||
extern const OSSL_DISPATCH ec_keymgmt_functions[];
|
||||
|
||||
/* Key Exchange */
|
||||
@@ -270,6 +272,10 @@ extern const OSSL_DISPATCH ecdh_keyexch_functions[];
|
||||
/* Signature */
|
||||
extern const OSSL_DISPATCH dsa_signature_functions[];
|
||||
extern const OSSL_DISPATCH rsa_signature_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_signature_functions[];
|
||||
extern const OSSL_DISPATCH ed448_signature_functions[];
|
||||
extern const OSSL_DISPATCH ecdsa_signature_functions[];
|
||||
|
||||
|
||||
/* Asym Cipher */
|
||||
extern const OSSL_DISPATCH rsa_asym_cipher_functions[];
|
||||
@@ -316,6 +322,20 @@ extern const OSSL_DISPATCH x448_pub_der_serializer_functions[];
|
||||
extern const OSSL_DISPATCH x448_priv_pem_serializer_functions[];
|
||||
extern const OSSL_DISPATCH x448_pub_pem_serializer_functions[];
|
||||
|
||||
extern const OSSL_DISPATCH ed25519_priv_print_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_pub_print_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_priv_der_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_pub_der_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_priv_pem_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed25519_pub_pem_serializer_functions[];
|
||||
|
||||
extern const OSSL_DISPATCH ed448_priv_print_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed448_pub_print_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed448_priv_der_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed448_pub_der_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed448_priv_pem_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ed448_pub_pem_serializer_functions[];
|
||||
|
||||
extern const OSSL_DISPATCH ec_priv_text_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ec_pub_text_serializer_functions[];
|
||||
extern const OSSL_DISPATCH ec_param_text_serializer_functions[];
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
$DH_GOAL=../../libimplementations.a
|
||||
$DSA_GOAL=../../libimplementations.a
|
||||
$EC_GOAL=../../libimplementations.a
|
||||
$RSA_GOAL=../../libimplementations.a
|
||||
$ECX_GOAL=../../libimplementations.a
|
||||
|
||||
IF[{- !$disabled{dh} -}]
|
||||
@@ -16,7 +15,9 @@ ENDIF
|
||||
IF[{- !$disabled{ec} -}]
|
||||
SOURCE[$EC_GOAL]=ec_kmgmt.c
|
||||
ENDIF
|
||||
SOURCE[$RSA_GOAL]=rsa_kmgmt.c
|
||||
IF[{- !$disabled{ec} -}]
|
||||
SOURCE[$ECX_GOAL]=ecx_kmgmt.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libfips.a]=rsa_kmgmt.c
|
||||
SOURCE[../../libnonfips.a]=rsa_kmgmt.c
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dh.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "openssl/param_build.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn dh_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dh_freedata;
|
||||
@@ -39,32 +39,6 @@ static OSSL_OP_keymgmt_export_types_fn dh_export_types;
|
||||
#define DH_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)
|
||||
|
||||
static int params_to_domparams(DH *dh, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_p, *param_g;
|
||||
BIGNUM *p = NULL, *g = NULL;
|
||||
|
||||
if (dh == NULL)
|
||||
return 0;
|
||||
|
||||
param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_P);
|
||||
param_g = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_G);
|
||||
|
||||
if ((param_p != NULL && !OSSL_PARAM_get_BN(param_p, &p))
|
||||
|| (param_g != NULL && !OSSL_PARAM_get_BN(param_g, &g)))
|
||||
goto err;
|
||||
|
||||
if (!DH_set0_pqg(dh, p, NULL, g))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_free(p);
|
||||
BN_free(g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int domparams_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
|
||||
{
|
||||
const BIGNUM *dh_p = NULL, *dh_g = NULL;
|
||||
@@ -74,56 +48,15 @@ static int domparams_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
|
||||
|
||||
DH_get0_pqg(dh, &dh_p, NULL, &dh_g);
|
||||
if (dh_p != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, dh_p))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, dh_p))
|
||||
return 0;
|
||||
if (dh_g != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, dh_g))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, dh_g))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int params_to_key(DH *dh, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_priv_key, *param_pub_key;
|
||||
BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
|
||||
if (dh == NULL)
|
||||
return 0;
|
||||
|
||||
if (!params_to_domparams(dh, params))
|
||||
return 0;
|
||||
|
||||
param_priv_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
|
||||
/*
|
||||
* DH documentation says that a public key must be present if a
|
||||
* private key is present.
|
||||
* We want to have at least a public key either way, so we end up
|
||||
* requiring it unconditionally.
|
||||
*/
|
||||
if (param_pub_key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((param_priv_key != NULL
|
||||
&& !OSSL_PARAM_get_BN(param_priv_key, &priv_key))
|
||||
|| !OSSL_PARAM_get_BN(param_pub_key, &pub_key))
|
||||
goto err;
|
||||
|
||||
if (!DH_set0_key(dh, pub_key, priv_key))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_clear_free(priv_key);
|
||||
BN_free(pub_key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int key_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
|
||||
{
|
||||
const BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
@@ -135,10 +68,10 @@ static int key_to_params(DH *dh, OSSL_PARAM_BLD *tmpl)
|
||||
|
||||
DH_get0_key(dh, &pub_key, &priv_key);
|
||||
if (priv_key != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
|
||||
return 0;
|
||||
if (pub_key != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@@ -159,15 +92,17 @@ static int dh_has(void *keydata, int selection)
|
||||
DH *dh = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DH_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
if (dh != NULL) {
|
||||
if ((selection & DH_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DH_get0_pub_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DH_get0_priv_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DH_get0_p(dh) != NULL && DH_get0_g(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DH_get0_pub_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DH_get0_priv_key(dh) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DH_get0_p(dh) != NULL && DH_get0_g(dh) != NULL);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -202,9 +137,9 @@ static int dh_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && params_to_domparams(dh, params);
|
||||
ok = ok && ffc_fromdata(dh_get0_params(dh), params);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(dh, params);
|
||||
ok = ok && dh_key_fromdata(dh, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -213,26 +148,31 @@ static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
DH *dh = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ok = 1;
|
||||
|
||||
if (dh == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(dh, &tmpl);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(dh, &tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(dh, tmpl);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(dh, tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) {
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
return 0;
|
||||
}
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
|
||||
ok = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "openssl/param_build.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn dsa_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dsa_freedata;
|
||||
@@ -39,35 +39,6 @@ static OSSL_OP_keymgmt_export_types_fn dsa_export_types;
|
||||
#define DSA_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)
|
||||
|
||||
static int params_to_domparams(DSA *dsa, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_p, *param_q, *param_g;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
|
||||
if (dsa == NULL)
|
||||
return 0;
|
||||
|
||||
param_p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_P);
|
||||
param_q = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_Q);
|
||||
param_g = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_G);
|
||||
|
||||
if ((param_p != NULL && !OSSL_PARAM_get_BN(param_p, &p))
|
||||
|| (param_q != NULL && !OSSL_PARAM_get_BN(param_q, &q))
|
||||
|| (param_g != NULL && !OSSL_PARAM_get_BN(param_g, &g)))
|
||||
goto err;
|
||||
|
||||
if (!DSA_set0_pqg(dsa, p, q, g))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int domparams_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
|
||||
{
|
||||
const BIGNUM *dsa_p = NULL, *dsa_q = NULL, *dsa_g = NULL;
|
||||
@@ -77,58 +48,18 @@ static int domparams_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
|
||||
|
||||
DSA_get0_pqg(dsa, &dsa_p, &dsa_q, &dsa_g);
|
||||
if (dsa_p != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, dsa_p))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, dsa_p))
|
||||
return 0;
|
||||
if (dsa_q != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_Q, dsa_q))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_Q, dsa_q))
|
||||
return 0;
|
||||
if (dsa_g != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, dsa_g))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, dsa_g))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int params_to_key(DSA *dsa, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_priv_key, *param_pub_key;
|
||||
BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
|
||||
if (dsa == NULL)
|
||||
return 0;
|
||||
|
||||
if (!params_to_domparams(dsa, params))
|
||||
return 0;
|
||||
|
||||
param_priv_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
|
||||
/*
|
||||
* DSA documentation says that a public key must be present if a private key
|
||||
* is.
|
||||
*/
|
||||
if (param_priv_key != NULL && param_pub_key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((param_priv_key != NULL
|
||||
&& !OSSL_PARAM_get_BN(param_priv_key, &priv_key))
|
||||
|| (param_pub_key != NULL
|
||||
&& !OSSL_PARAM_get_BN(param_pub_key, &pub_key)))
|
||||
goto err;
|
||||
|
||||
if (pub_key != NULL && !DSA_set0_key(dsa, pub_key, priv_key))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_clear_free(priv_key);
|
||||
BN_free(pub_key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int key_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
|
||||
{
|
||||
const BIGNUM *priv_key = NULL, *pub_key = NULL;
|
||||
@@ -140,10 +71,10 @@ static int key_to_params(DSA *dsa, OSSL_PARAM_BLD *tmpl)
|
||||
|
||||
DSA_get0_key(dsa, &pub_key, &priv_key);
|
||||
if (priv_key != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY, priv_key))
|
||||
return 0;
|
||||
if (pub_key != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
|
||||
&& !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY, pub_key))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@@ -164,15 +95,17 @@ static int dsa_has(void *keydata, int selection)
|
||||
DSA *dsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
if (dsa != NULL) {
|
||||
if ((selection & DSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DSA_get0_pub_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DSA_get0_priv_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DSA_get0_p(dsa) != NULL && DSA_get0_g(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (DSA_get0_pub_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (DSA_get0_priv_key(dsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (DSA_get0_p(dsa) != NULL && DSA_get0_g(dsa) != NULL);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -209,9 +142,9 @@ static int dsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && params_to_domparams(dsa, params);
|
||||
ok = ok && ffc_fromdata(dsa_get0_params(dsa), params);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(dsa, params);
|
||||
ok = ok && dsa_key_fromdata(dsa, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -220,26 +153,26 @@ static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
DSA *dsa = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl = OSSL_PARAM_BLD_new();
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ok = 1;
|
||||
|
||||
if (dsa == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
goto err;;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(dsa, &tmpl);
|
||||
ok = ok && domparams_to_params(dsa, tmpl);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(dsa, &tmpl);
|
||||
ok = ok && key_to_params(dsa, tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
|| (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
|
||||
goto err;;
|
||||
|
||||
ok = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
err:
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,25 @@
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/params.h>
|
||||
#include "crypto/bn.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/ec.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "internal/param_build_set.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn ec_newdata;
|
||||
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;
|
||||
static OSSL_OP_keymgmt_get_params_fn ec_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ec_gettable_params;
|
||||
@@ -32,14 +42,15 @@ static OSSL_OP_keymgmt_set_params_fn ec_set_params;
|
||||
static OSSL_OP_keymgmt_settable_params_fn ec_settable_params;
|
||||
static OSSL_OP_keymgmt_has_fn ec_has;
|
||||
static OSSL_OP_keymgmt_match_fn ec_match;
|
||||
static OSSL_OP_keymgmt_validate_fn ec_validate;
|
||||
static OSSL_OP_keymgmt_import_fn ec_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn ec_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn ec_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn ec_export_types;
|
||||
static OSSL_OP_keymgmt_query_operation_name_fn ec_query_operation_name;
|
||||
|
||||
#define EC_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS )
|
||||
#define EC_POSSIBLE_SELECTIONS \
|
||||
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS)
|
||||
|
||||
static
|
||||
const char *ec_query_operation_name(int operation_id)
|
||||
@@ -47,64 +58,15 @@ const char *ec_query_operation_name(int operation_id)
|
||||
switch (operation_id) {
|
||||
case OSSL_OP_KEYEXCH:
|
||||
return "ECDH";
|
||||
#if 0
|
||||
case OSSL_OP_SIGNATURE:
|
||||
return deflt_signature;
|
||||
#endif
|
||||
return "ECDSA";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ossl_inline
|
||||
int params_to_domparams(EC_KEY *ec, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_ec_name;
|
||||
EC_GROUP *ecg = NULL;
|
||||
char *curve_name = NULL;
|
||||
int ok = 0;
|
||||
|
||||
if (ec == NULL)
|
||||
return 0;
|
||||
|
||||
param_ec_name = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_NAME);
|
||||
if (param_ec_name == NULL) {
|
||||
/* explicit parameters */
|
||||
|
||||
/*
|
||||
* TODO(3.0): should we support explicit parameters curves?
|
||||
*/
|
||||
return 0;
|
||||
} else {
|
||||
/* named curve */
|
||||
int curve_nid;
|
||||
|
||||
if (!OSSL_PARAM_get_utf8_string(param_ec_name, &curve_name, 0)
|
||||
|| curve_name == NULL
|
||||
|| (curve_nid = OBJ_sn2nid(curve_name)) == NID_undef)
|
||||
goto err;
|
||||
|
||||
if ((ecg = EC_GROUP_new_by_curve_name(curve_nid)) == NULL)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EC_KEY_set_group(ec, ecg))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* TODO(3.0): if the group has changed, should we invalidate the private and
|
||||
* public key?
|
||||
*/
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(curve_name);
|
||||
EC_GROUP_free(ecg);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static ossl_inline
|
||||
int domparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl)
|
||||
int domparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
const EC_GROUP *ecg;
|
||||
int curve_nid;
|
||||
@@ -119,135 +81,24 @@ int domparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl)
|
||||
curve_nid = EC_GROUP_get_curve_name(ecg);
|
||||
|
||||
if (curve_nid == NID_undef) {
|
||||
/* explicit parameters */
|
||||
|
||||
/*
|
||||
* TODO(3.0): should we support explicit parameters curves?
|
||||
*/
|
||||
/* TODO(3.0): should we support explicit parameters curves? */
|
||||
return 0;
|
||||
} else {
|
||||
/* named curve */
|
||||
const char *curve_name = NULL;
|
||||
|
||||
if ((curve_name = OBJ_nid2sn(curve_nid)) == NULL)
|
||||
if ((curve_name = ec_curve_nid2name(curve_nid)) == NULL)
|
||||
return 0;
|
||||
if (!ossl_param_build_set_utf8_string(tmpl, params,
|
||||
OSSL_PKEY_PARAM_EC_NAME,
|
||||
curve_name))
|
||||
|
||||
if (!ossl_param_bld_push_utf8_string(tmpl, OSSL_PKEY_PARAM_EC_NAME, curve_name, 0))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callers of params_to_key MUST make sure that params_to_domparams has been
|
||||
* called before!
|
||||
*
|
||||
* This function only imports the bare keypair, domain parameters and other
|
||||
* parameters are imported separately, and domain parameters are required to
|
||||
* define a keypair.
|
||||
*/
|
||||
static ossl_inline
|
||||
int params_to_key(EC_KEY *ec, const OSSL_PARAM params[], int include_private)
|
||||
{
|
||||
const OSSL_PARAM *param_priv_key, *param_pub_key;
|
||||
BIGNUM *priv_key = NULL;
|
||||
unsigned char *pub_key = NULL;
|
||||
size_t pub_key_len;
|
||||
const EC_GROUP *ecg = NULL;
|
||||
EC_POINT *pub_point = NULL;
|
||||
int ok = 0;
|
||||
|
||||
ecg = EC_KEY_get0_group(ec);
|
||||
if (ecg == NULL)
|
||||
return 0;
|
||||
|
||||
param_priv_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
|
||||
/*
|
||||
* We want to have at least a public key either way, so we end up
|
||||
* requiring it unconditionally.
|
||||
*/
|
||||
if (param_pub_key == NULL
|
||||
|| !OSSL_PARAM_get_octet_string(param_pub_key,
|
||||
(void **)&pub_key, 0, &pub_key_len)
|
||||
|| (pub_point = EC_POINT_new(ecg)) == NULL
|
||||
|| !EC_POINT_oct2point(ecg, pub_point,
|
||||
pub_key, pub_key_len, NULL))
|
||||
goto err;
|
||||
|
||||
if (param_priv_key != NULL && include_private) {
|
||||
int fixed_top;
|
||||
const BIGNUM *order;
|
||||
|
||||
/*
|
||||
* Key import/export should never leak the bit length of the secret
|
||||
* scalar in the key.
|
||||
*
|
||||
* For this reason, on export we use padded BIGNUMs with fixed length.
|
||||
*
|
||||
* When importing we also should make sure that, even if short lived,
|
||||
* the newly created BIGNUM is marked with the BN_FLG_CONSTTIME flag as
|
||||
* soon as possible, so that any processing of this BIGNUM might opt for
|
||||
* constant time implementations in the backend.
|
||||
*
|
||||
* Setting the BN_FLG_CONSTTIME flag alone is never enough, we also have
|
||||
* to preallocate the BIGNUM internal buffer to a fixed public size big
|
||||
* enough that operations performed during the processing never trigger
|
||||
* a realloc which would leak the size of the scalar through memory
|
||||
* accesses.
|
||||
*
|
||||
* Fixed Length
|
||||
* ------------
|
||||
*
|
||||
* The order of the large prime subgroup of the curve is our choice for
|
||||
* a fixed public size, as that is generally the upper bound for
|
||||
* generating a private key in EC cryptosystems and should fit all valid
|
||||
* secret scalars.
|
||||
*
|
||||
* For padding on export we just use the bit length of the order
|
||||
* converted to bytes (rounding up).
|
||||
*
|
||||
* For preallocating the BIGNUM storage we look at the number of "words"
|
||||
* required for the internal representation of the order, and we
|
||||
* preallocate 2 extra "words" in case any of the subsequent processing
|
||||
* might temporarily overflow the order length.
|
||||
*/
|
||||
order = EC_GROUP_get0_order(ecg);
|
||||
if (order == NULL || BN_is_zero(order))
|
||||
goto err;
|
||||
|
||||
fixed_top = bn_get_top(order) + 2;
|
||||
|
||||
if ((priv_key = BN_new()) == NULL)
|
||||
goto err;
|
||||
if (bn_wexpand(priv_key, fixed_top) == NULL)
|
||||
goto err;
|
||||
BN_set_flags(priv_key, BN_FLG_CONSTTIME);
|
||||
|
||||
if (!OSSL_PARAM_get_BN(param_priv_key, &priv_key))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (priv_key != NULL
|
||||
&& !EC_KEY_set_private_key(ec, priv_key))
|
||||
goto err;
|
||||
|
||||
if (!EC_KEY_set_public_key(ec, pub_point))
|
||||
goto err;
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
BN_clear_free(priv_key);
|
||||
OPENSSL_free(pub_key);
|
||||
EC_POINT_free(pub_point);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callers of key_to_params MUST make sure that domparams_to_params is also
|
||||
* called!
|
||||
@@ -256,34 +107,33 @@ int params_to_key(EC_KEY *ec, const OSSL_PARAM params[], int include_private)
|
||||
* parameters are exported separately.
|
||||
*/
|
||||
static ossl_inline
|
||||
int key_to_params(const EC_KEY *eckey, OSSL_PARAM_BLD *tmpl, int include_private)
|
||||
int key_to_params(const EC_KEY *eckey, OSSL_PARAM_BLD *tmpl,
|
||||
OSSL_PARAM params[], int include_private,
|
||||
unsigned char **pub_key)
|
||||
{
|
||||
const BIGNUM *priv_key = NULL;
|
||||
const EC_POINT *pub_point = NULL;
|
||||
const EC_GROUP *ecg = NULL;
|
||||
unsigned char *pub_key = NULL;
|
||||
size_t pub_key_len = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (eckey == NULL)
|
||||
if (eckey == NULL
|
||||
|| (ecg = EC_KEY_get0_group(eckey)) == NULL)
|
||||
return 0;
|
||||
|
||||
ecg = EC_KEY_get0_group(eckey);
|
||||
priv_key = EC_KEY_get0_private_key(eckey);
|
||||
pub_point = EC_KEY_get0_public_key(eckey);
|
||||
|
||||
/* group and public_key must be present, priv_key is optional */
|
||||
if (ecg == NULL || pub_point == NULL)
|
||||
return 0;
|
||||
if ((pub_key_len = EC_POINT_point2buf(ecg, pub_point,
|
||||
POINT_CONVERSION_COMPRESSED,
|
||||
&pub_key, NULL)) == 0)
|
||||
return 0;
|
||||
|
||||
if (!ossl_param_bld_push_octet_string(tmpl,
|
||||
OSSL_PKEY_PARAM_PUB_KEY,
|
||||
pub_key, pub_key_len))
|
||||
goto err;
|
||||
if (pub_point != NULL) {
|
||||
/* convert pub_point to a octet string according to the SECG standard */
|
||||
if ((pub_key_len = EC_POINT_point2buf(ecg, pub_point,
|
||||
POINT_CONVERSION_COMPRESSED,
|
||||
pub_key, NULL)) == 0
|
||||
|| !ossl_param_build_set_octet_string(tmpl, params,
|
||||
OSSL_PKEY_PARAM_PUB_KEY,
|
||||
*pub_key, pub_key_len))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (priv_key != NULL && include_private) {
|
||||
size_t sz;
|
||||
@@ -326,71 +176,20 @@ int key_to_params(const EC_KEY *eckey, OSSL_PARAM_BLD *tmpl, int include_private
|
||||
if (ecbits <= 0)
|
||||
goto err;
|
||||
sz = (ecbits + 7 ) / 8;
|
||||
if (!ossl_param_bld_push_BN_pad(tmpl,
|
||||
OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
priv_key, sz))
|
||||
|
||||
if (!ossl_param_build_set_bn_pad(tmpl, params,
|
||||
OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
priv_key, sz))
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(pub_key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ossl_inline
|
||||
int ec_set_param_ecdh_cofactor_mode(EC_KEY *ec, const OSSL_PARAM *p)
|
||||
{
|
||||
const EC_GROUP *ecg = EC_KEY_get0_group(ec);
|
||||
const BIGNUM *cofactor;
|
||||
int mode;
|
||||
|
||||
if (!OSSL_PARAM_get_int(p, &mode))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* mode can be only 0 for disable, or 1 for enable here.
|
||||
*
|
||||
* This is in contrast with the same parameter on an ECDH EVP_PKEY_CTX that
|
||||
* also supports mode == -1 with the meaning of "reset to the default for
|
||||
* the associated key".
|
||||
*/
|
||||
if (mode < 0 || mode > 1)
|
||||
return 0;
|
||||
|
||||
if ((cofactor = EC_GROUP_get0_cofactor(ecg)) == NULL )
|
||||
return 0;
|
||||
|
||||
/* ECDH cofactor mode has no effect if cofactor is 1 */
|
||||
if (BN_is_one(cofactor))
|
||||
return 1;
|
||||
|
||||
if (mode == 1)
|
||||
EC_KEY_set_flags(ec, EC_FLAG_COFACTOR_ECDH);
|
||||
else if (mode == 0)
|
||||
EC_KEY_clear_flags(ec, EC_FLAG_COFACTOR_ECDH);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ossl_inline
|
||||
int params_to_otherparams(EC_KEY *ec, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *p;
|
||||
|
||||
if (ec == NULL)
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_USE_COFACTOR_ECDH);
|
||||
if (p != NULL && !ec_set_param_ecdh_cofactor_mode(ec, p))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ossl_inline
|
||||
int otherparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl)
|
||||
int otherparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
int ecdh_cofactor_mode = 0;
|
||||
|
||||
@@ -399,18 +198,15 @@ int otherparams_to_params(const EC_KEY *ec, OSSL_PARAM_BLD *tmpl)
|
||||
|
||||
ecdh_cofactor_mode =
|
||||
(EC_KEY_get_flags(ec) & EC_FLAG_COFACTOR_ECDH) ? 1 : 0;
|
||||
if (!ossl_param_bld_push_int(tmpl,
|
||||
OSSL_PKEY_PARAM_USE_COFACTOR_ECDH,
|
||||
ecdh_cofactor_mode))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return ossl_param_build_set_int(tmpl, params,
|
||||
OSSL_PKEY_PARAM_USE_COFACTOR_ECDH,
|
||||
ecdh_cofactor_mode);
|
||||
}
|
||||
|
||||
static
|
||||
void *ec_newdata(void *provctx)
|
||||
{
|
||||
return EC_KEY_new();
|
||||
return EC_KEY_new_ex(PROV_LIBRARY_CONTEXT_OF(provctx));
|
||||
}
|
||||
|
||||
static
|
||||
@@ -425,21 +221,22 @@ int ec_has(void *keydata, int selection)
|
||||
EC_KEY *ec = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & EC_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (EC_KEY_get0_public_key(ec) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (EC_KEY_get0_private_key(ec) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (EC_KEY_get0_group(ec) != NULL);
|
||||
/*
|
||||
* We consider OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS to always be available,
|
||||
* so no extra check is needed other than the previous one against
|
||||
* EC_POSSIBLE_SELECTIONS.
|
||||
*/
|
||||
if (ec != NULL) {
|
||||
if ((selection & EC_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (EC_KEY_get0_public_key(ec) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (EC_KEY_get0_private_key(ec) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && (EC_KEY_get0_group(ec) != NULL);
|
||||
/*
|
||||
* We consider OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS to always be
|
||||
* available, so no extra check is needed other than the previous one
|
||||
* against EC_POSSIBLE_SELECTIONS.
|
||||
*/
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -501,15 +298,15 @@ int ec_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && params_to_domparams(ec, params);
|
||||
ok = ok && ec_key_domparams_fromdata(ec, params);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
|
||||
int include_private =
|
||||
selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
|
||||
|
||||
ok = ok && params_to_key(ec, params, include_private);
|
||||
ok = ok && ec_key_fromdata(ec, params, include_private);
|
||||
}
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && params_to_otherparams(ec, params);
|
||||
ok = ok && ec_key_otherparams_fromdata(ec, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -519,8 +316,9 @@ int ec_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
EC_KEY *ec = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
unsigned char *pub_key = NULL;
|
||||
int ok = 1;
|
||||
|
||||
if (ec == NULL)
|
||||
@@ -548,25 +346,28 @@ int ec_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
&& (selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && domparams_to_params(ec, &tmpl);
|
||||
ok = ok && domparams_to_params(ec, tmpl, NULL);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
|
||||
int include_private =
|
||||
selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
|
||||
|
||||
ok = ok && key_to_params(ec, &tmpl, include_private);
|
||||
ok = ok && key_to_params(ec, tmpl, NULL, include_private, &pub_key);
|
||||
}
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && otherparams_to_params(ec, &tmpl);
|
||||
ok = ok && otherparams_to_params(ec, tmpl, NULL);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
if (ok && (params = OSSL_PARAM_BLD_to_param(tmpl)) != NULL)
|
||||
ok = param_cb(params, cbarg);
|
||||
|
||||
ok = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
OPENSSL_free(pub_key);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -626,9 +427,11 @@ const OSSL_PARAM *ec_export_types(int selection)
|
||||
static
|
||||
int ec_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
int ret;
|
||||
EC_KEY *eck = key;
|
||||
const EC_GROUP *ecg = NULL;
|
||||
OSSL_PARAM *p;
|
||||
unsigned char *pub_key = NULL;
|
||||
|
||||
ecg = EC_KEY_get0_group(eck);
|
||||
if (ecg == NULL)
|
||||
@@ -688,15 +491,21 @@ int ec_get_params(void *key, OSSL_PARAM params[])
|
||||
if (!OSSL_PARAM_set_int(p, ecdh_cofactor_mode))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
ret = domparams_to_params(eck, NULL, params)
|
||||
&& key_to_params(eck, NULL, params, 1, &pub_key)
|
||||
&& otherparams_to_params(eck, NULL, params);
|
||||
OPENSSL_free(pub_key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM ec_known_gettable_params[] = {
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH, NULL),
|
||||
EC_IMEXPORTABLE_DOM_PARAMETERS,
|
||||
EC_IMEXPORTABLE_PUBLIC_KEY,
|
||||
EC_IMEXPORTABLE_PRIVATE_KEY,
|
||||
EC_IMEXPORTABLE_OTHER_PARAMETERS,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
@@ -730,8 +539,224 @@ int ec_set_params(void *key, const OSSL_PARAM params[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int ec_validate(void *keydata, int selection)
|
||||
{
|
||||
EC_KEY *eck = keydata;
|
||||
int ok = 0;
|
||||
BN_CTX *ctx = BN_CTX_new_ex(ec_key_get_libctx(eck));
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & EC_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && EC_GROUP_check(EC_KEY_get0_group(eck), ctx);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && ec_key_public_check(eck, ctx);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && ec_key_private_check(eck);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
ok = ok && ec_key_pairwise_check(eck, ctx);
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
return ok;
|
||||
}
|
||||
|
||||
struct ec_gen_ctx {
|
||||
OPENSSL_CTX *libctx;
|
||||
|
||||
EC_GROUP *gen_group;
|
||||
int selection;
|
||||
};
|
||||
|
||||
static void *ec_gen_init(void *provctx, int selection)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
struct ec_gen_ctx *gctx = NULL;
|
||||
|
||||
if ((selection & (EC_POSSIBLE_SELECTIONS)) == 0)
|
||||
return NULL;
|
||||
|
||||
if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) {
|
||||
gctx->libctx = libctx;
|
||||
gctx->gen_group = NULL;
|
||||
gctx->selection = selection;
|
||||
}
|
||||
return gctx;
|
||||
}
|
||||
|
||||
static int ec_gen_set_group(void *genctx, int nid)
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
EC_GROUP *group;
|
||||
|
||||
group = EC_GROUP_new_by_curve_name_ex(gctx->libctx, nid);
|
||||
if (group == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CURVE);
|
||||
return 0;
|
||||
}
|
||||
EC_GROUP_free(gctx->gen_group);
|
||||
gctx->gen_group = group;
|
||||
return 1;
|
||||
}
|
||||
static int ec_gen_set_template(void *genctx, void *templ)
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
EC_KEY *ec = templ;
|
||||
const EC_GROUP *ec_group;
|
||||
|
||||
if (gctx == NULL || ec == NULL)
|
||||
return 0;
|
||||
if ((ec_group = EC_KEY_get0_group(ec)) == NULL)
|
||||
return 0;
|
||||
return ec_gen_set_group(gctx, EC_GROUP_get_curve_name(ec_group));
|
||||
}
|
||||
|
||||
static int ec_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
const OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_NAME))
|
||||
!= NULL) {
|
||||
const char *curve_name = NULL;
|
||||
int ret = 0;
|
||||
|
||||
switch (p->data_type) {
|
||||
case OSSL_PARAM_UTF8_STRING:
|
||||
/* The OSSL_PARAM functions have no support for this */
|
||||
curve_name = p->data;
|
||||
ret = (curve_name != NULL);
|
||||
break;
|
||||
case OSSL_PARAM_UTF8_PTR:
|
||||
ret = OSSL_PARAM_get_utf8_ptr(p, &curve_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
int nid = ec_curve_name2nid(curve_name);
|
||||
|
||||
if (nid == NID_undef) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CURVE);
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = ec_gen_set_group(gctx, nid);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *ec_gen_settable_params(void *provctx)
|
||||
{
|
||||
static OSSL_PARAM settable[] = {
|
||||
{ OSSL_PKEY_PARAM_EC_NAME, OSSL_PARAM_UTF8_STRING, NULL, 0, 0 },
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
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) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_NO_PARAMETERS_SET);
|
||||
return 0;
|
||||
}
|
||||
return EC_KEY_set_group(ec, group) > 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The callback arguments (osslcb & cbarg) are not used by EC_KEY generation
|
||||
*/
|
||||
static void *ec_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
EC_KEY *ec = NULL;
|
||||
int ret = 1; /* Start optimistically */
|
||||
|
||||
if (gctx == NULL
|
||||
|| (ec = EC_KEY_new_ex(gctx->libctx)) == NULL)
|
||||
return NULL;
|
||||
|
||||
/* We must always assign a group, no matter what */
|
||||
ret = ec_gen_assign_group(ec, gctx->gen_group);
|
||||
/* Whether you want it or not, you get a keypair, not just one half */
|
||||
if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ret = ret && EC_KEY_generate_key(ec);
|
||||
|
||||
if (ret)
|
||||
return ec;
|
||||
|
||||
/* Something went wrong, throw the key away */
|
||||
EC_KEY_free(ec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ec_gen_cleanup(void *genctx)
|
||||
{
|
||||
struct ec_gen_ctx *gctx = genctx;
|
||||
|
||||
if (gctx == NULL)
|
||||
return;
|
||||
|
||||
EC_GROUP_free(gctx->gen_group);
|
||||
OPENSSL_free(gctx);
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ec_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))ec_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))ec_gen_init },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE,
|
||||
(void (*)(void))ec_gen_set_template },
|
||||
{ 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 },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))ec_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ec_gettable_params },
|
||||
@@ -739,11 +764,12 @@ const OSSL_DISPATCH ec_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*) (void))ec_settable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ec_has },
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))ec_match },
|
||||
{ OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))ec_validate },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ec_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))ec_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))ec_export },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ec_export_types },
|
||||
{ OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME,
|
||||
(void (*)(void))ec_query_operation_name },
|
||||
(void (*)(void))ec_query_operation_name },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -10,16 +10,19 @@
|
||||
#include <assert.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "internal/param_build_set.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn x25519_new_key;
|
||||
static OSSL_OP_keymgmt_new_fn x448_new_key;
|
||||
static OSSL_OP_keymgmt_new_fn ed25519_new_key;
|
||||
static OSSL_OP_keymgmt_new_fn ed448_new_key;
|
||||
static OSSL_OP_keymgmt_get_params_fn x25519_get_params;
|
||||
static OSSL_OP_keymgmt_get_params_fn x448_get_params;
|
||||
static OSSL_OP_keymgmt_get_params_fn ed25519_get_params;
|
||||
static OSSL_OP_keymgmt_get_params_fn ed448_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn ecx_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn ecx_has;
|
||||
static OSSL_OP_keymgmt_import_fn ecx_import;
|
||||
@@ -31,37 +34,47 @@ static OSSL_OP_keymgmt_export_types_fn ecx_imexport_types;
|
||||
|
||||
static void *x25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(X25519_KEYLEN, 0);
|
||||
return ecx_key_new(ECX_KEY_TYPE_X25519, 0);
|
||||
}
|
||||
|
||||
static void *x448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(X448_KEYLEN, 0);
|
||||
return ecx_key_new(ECX_KEY_TYPE_X448, 0);
|
||||
}
|
||||
|
||||
static void *ed25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED25519, 0);
|
||||
}
|
||||
|
||||
static void *ed448_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(ECX_KEY_TYPE_ED448, 0);
|
||||
}
|
||||
|
||||
static int ecx_has(void *keydata, int selection)
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
int ok = 1;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & ECX_POSSIBLE_SELECTIONS) == 0)
|
||||
return 0;
|
||||
if (key != NULL) {
|
||||
if ((selection & ECX_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && key->haspubkey;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && key->privkey != NULL;
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && key->haspubkey;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && key->privkey != NULL;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
size_t privkeylen = 0, pubkeylen;
|
||||
const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
|
||||
unsigned char *pubkey;
|
||||
int ok = 1;
|
||||
int include_private = 0;
|
||||
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
@@ -69,52 +82,28 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
|
||||
return 0;
|
||||
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
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);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
param_priv_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
|
||||
/*
|
||||
* If a private key is present then a public key must also be present.
|
||||
* Alternatively we've just got a public key.
|
||||
*/
|
||||
if (param_pub_key == NULL)
|
||||
return 0;
|
||||
|
||||
if (param_priv_key != NULL
|
||||
&& !OSSL_PARAM_get_octet_string(param_priv_key,
|
||||
(void **)&key->privkey, key->keylen,
|
||||
&privkeylen))
|
||||
return 0;
|
||||
|
||||
pubkey = key->pubkey;
|
||||
if (!OSSL_PARAM_get_octet_string(param_pub_key,
|
||||
(void **)&pubkey,
|
||||
sizeof(key->pubkey), &pubkeylen))
|
||||
return 0;
|
||||
|
||||
if (pubkeylen != key->keylen
|
||||
|| (param_priv_key != NULL && privkeylen != key->keylen))
|
||||
return 0;
|
||||
|
||||
key->haspubkey = 1;
|
||||
|
||||
return 1;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl)
|
||||
static int key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if (!ossl_param_bld_push_octet_string(tmpl, OSSL_PKEY_PARAM_PUB_KEY,
|
||||
key->pubkey, key->keylen))
|
||||
if (!ossl_param_build_set_octet_string(tmpl, params,
|
||||
OSSL_PKEY_PARAM_PUB_KEY,
|
||||
key->pubkey, key->keylen))
|
||||
return 0;
|
||||
|
||||
if (key->privkey != NULL
|
||||
&& !ossl_param_bld_push_octet_string(tmpl, OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
key->privkey, key->keylen))
|
||||
&& !ossl_param_build_set_octet_string(tmpl, params,
|
||||
OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
key->privkey, key->keylen))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@@ -124,32 +113,42 @@ static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb,
|
||||
void *cbarg)
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
|
||||
&& !key_to_params(key, &tmpl))
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
params = ossl_param_bld_to_param(&tmpl);
|
||||
if (params == NULL) {
|
||||
ossl_param_bld_free(params);
|
||||
return 0;
|
||||
}
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
|
||||
&& !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;
|
||||
|
||||
ret = param_cb(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
err:
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define ECX_KEY_TYPES() \
|
||||
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0), \
|
||||
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0)
|
||||
|
||||
static const OSSL_PARAM ecx_key_types[] = {
|
||||
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0),
|
||||
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
|
||||
ECX_KEY_TYPES(),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
static const OSSL_PARAM *ecx_imexport_types(int selection)
|
||||
@@ -159,9 +158,10 @@ static const OSSL_PARAM *ecx_imexport_types(int selection)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ecx_get_params(OSSL_PARAM params[], int bits, int secbits,
|
||||
static int ecx_get_params(void *key, OSSL_PARAM params[], int bits, int secbits,
|
||||
int size)
|
||||
{
|
||||
ECX_KEY *ecx = key;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL
|
||||
@@ -173,23 +173,38 @@ static int ecx_get_params(OSSL_PARAM params[], int bits, int secbits,
|
||||
if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
|
||||
&& !OSSL_PARAM_set_int(p, size))
|
||||
return 0;
|
||||
return 1;
|
||||
return key_to_params(ecx, NULL, params);
|
||||
}
|
||||
|
||||
static int x25519_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
return ecx_get_params(params, X25519_BITS, X25519_SECURITY_BITS, X25519_KEYLEN);
|
||||
return ecx_get_params(key, params, X25519_BITS, X25519_SECURITY_BITS,
|
||||
X25519_KEYLEN);
|
||||
}
|
||||
|
||||
static int x448_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
return ecx_get_params(params, X448_BITS, X448_SECURITY_BITS, X448_KEYLEN);
|
||||
return ecx_get_params(key, params, X448_BITS, X448_SECURITY_BITS,
|
||||
X448_KEYLEN);
|
||||
}
|
||||
|
||||
static int ed25519_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
return ecx_get_params(key, params, ED25519_BITS, ED25519_SECURITY_BITS,
|
||||
ED25519_KEYLEN);
|
||||
}
|
||||
|
||||
static int ed448_get_params(void *key, OSSL_PARAM params[])
|
||||
{
|
||||
return ecx_get_params(key, params, ED448_BITS, ED448_SECURITY_BITS,
|
||||
ED448_KEYLEN);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM ecx_params[] = {
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL),
|
||||
ECX_KEY_TYPES(),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
@@ -198,28 +213,21 @@ static const OSSL_PARAM *ecx_gettable_params(void)
|
||||
return ecx_params;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH x25519_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))x25519_new_key },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ecx_key_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))x25519_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ecx_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has },
|
||||
{ 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 },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ecx_imexport_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
#define MAKE_KEYMGMT_FUNCTIONS(alg) \
|
||||
const OSSL_DISPATCH alg##_keymgmt_functions[] = { \
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))alg##_new_key }, \
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ecx_key_free }, \
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))alg##_get_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ecx_gettable_params }, \
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has }, \
|
||||
{ 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 }, \
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ecx_imexport_types }, \
|
||||
{ 0, NULL } \
|
||||
};
|
||||
|
||||
const OSSL_DISPATCH x448_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))x448_new_key },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ecx_key_free },
|
||||
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))x448_get_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))ecx_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has },
|
||||
{ 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 },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ecx_imexport_types },
|
||||
{ 0, NULL }
|
||||
};
|
||||
MAKE_KEYMGMT_FUNCTIONS(x25519)
|
||||
MAKE_KEYMGMT_FUNCTIONS(x448)
|
||||
MAKE_KEYMGMT_FUNCTIONS(ed25519)
|
||||
MAKE_KEYMGMT_FUNCTIONS(ed448)
|
||||
@@ -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,15 +13,18 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/types.h>
|
||||
#include "internal/param_build.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/rsa.h"
|
||||
#include "internal/param_build_set.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn rsa_newdata;
|
||||
static OSSL_OP_keymgmt_gen_init_fn rsa_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_fn rsa_gen;
|
||||
static OSSL_OP_keymgmt_gen_cleanup_fn rsa_gen_cleanup;
|
||||
static OSSL_OP_keymgmt_free_fn rsa_freedata;
|
||||
static OSSL_OP_keymgmt_get_params_fn rsa_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn rsa_gettable_params;
|
||||
@@ -34,106 +37,13 @@ static OSSL_OP_keymgmt_export_fn rsa_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn rsa_export_types;
|
||||
|
||||
#define RSA_DEFAULT_MD "SHA256"
|
||||
#define RSA_POSSIBLE_SELECTIONS \
|
||||
#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 collect_numbers(STACK_OF(BIGNUM) *numbers,
|
||||
const OSSL_PARAM params[], const char *key)
|
||||
{
|
||||
const OSSL_PARAM *p = NULL;
|
||||
|
||||
if (numbers == NULL)
|
||||
return 0;
|
||||
|
||||
for (p = params; (p = OSSL_PARAM_locate_const(p, key)) != NULL; p++) {
|
||||
BIGNUM *tmp = NULL;
|
||||
|
||||
if (!OSSL_PARAM_get_BN(p, &tmp))
|
||||
return 0;
|
||||
sk_BIGNUM_push(numbers, tmp);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int params_to_key(RSA *rsa, const OSSL_PARAM params[])
|
||||
{
|
||||
const OSSL_PARAM *param_n, *param_e, *param_d;
|
||||
BIGNUM *n = NULL, *e = NULL, *d = NULL;
|
||||
STACK_OF(BIGNUM) *factors = NULL, *exps = NULL, *coeffs = NULL;
|
||||
int is_private = 0;
|
||||
|
||||
if (rsa == NULL)
|
||||
return 0;
|
||||
|
||||
param_n = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N);
|
||||
param_e = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E);
|
||||
param_d = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
|
||||
|
||||
if ((param_n != NULL && !OSSL_PARAM_get_BN(param_n, &n))
|
||||
|| (param_e != NULL && !OSSL_PARAM_get_BN(param_e, &e))
|
||||
|| (param_d != NULL && !OSSL_PARAM_get_BN(param_d, &d)))
|
||||
goto err;
|
||||
|
||||
is_private = (d != NULL);
|
||||
|
||||
if (!RSA_set0_key(rsa, n, e, d))
|
||||
goto err;
|
||||
n = e = d = NULL;
|
||||
|
||||
if (is_private) {
|
||||
if (!collect_numbers(factors = sk_BIGNUM_new_null(), params,
|
||||
OSSL_PKEY_PARAM_RSA_FACTOR)
|
||||
|| !collect_numbers(exps = sk_BIGNUM_new_null(), params,
|
||||
OSSL_PKEY_PARAM_RSA_EXPONENT)
|
||||
|| !collect_numbers(coeffs = sk_BIGNUM_new_null(), params,
|
||||
OSSL_PKEY_PARAM_RSA_COEFFICIENT))
|
||||
goto err;
|
||||
|
||||
/* It's ok if this private key just has n, e and d */
|
||||
if (sk_BIGNUM_num(factors) != 0
|
||||
&& !rsa_set0_all_params(rsa, factors, exps, coeffs))
|
||||
goto err;
|
||||
}
|
||||
|
||||
sk_BIGNUM_free(factors);
|
||||
sk_BIGNUM_free(exps);
|
||||
sk_BIGNUM_free(coeffs);
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_free(n);
|
||||
BN_free(e);
|
||||
BN_free(d);
|
||||
sk_BIGNUM_pop_free(factors, BN_free);
|
||||
sk_BIGNUM_pop_free(exps, BN_free);
|
||||
sk_BIGNUM_pop_free(coeffs, BN_free);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int export_numbers(OSSL_PARAM_BLD *tmpl, const char *key,
|
||||
STACK_OF(BIGNUM_const) *numbers)
|
||||
{
|
||||
int i, nnum;
|
||||
|
||||
if (numbers == NULL)
|
||||
return 0;
|
||||
|
||||
nnum = sk_BIGNUM_const_num(numbers);
|
||||
|
||||
for (i = 0; i < nnum; i++) {
|
||||
if (!ossl_param_bld_push_BN(tmpl, key,
|
||||
sk_BIGNUM_const_value(numbers, i)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *tmpl)
|
||||
static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
|
||||
{
|
||||
int ret = 0;
|
||||
const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL;
|
||||
@@ -147,21 +57,16 @@ static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *tmpl)
|
||||
RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d);
|
||||
rsa_get0_all_params(rsa, factors, exps, coeffs);
|
||||
|
||||
if (rsa_n != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_N, rsa_n))
|
||||
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;
|
||||
if (rsa_e != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_E, rsa_e))
|
||||
goto err;
|
||||
if (rsa_d != NULL
|
||||
&& !ossl_param_bld_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_D, rsa_d))
|
||||
goto err;
|
||||
|
||||
if (!export_numbers(tmpl, OSSL_PKEY_PARAM_RSA_FACTOR, factors)
|
||||
|| !export_numbers(tmpl, OSSL_PKEY_PARAM_RSA_EXPONENT, exps)
|
||||
|| !export_numbers(tmpl, OSSL_PKEY_PARAM_RSA_COEFFICIENT, coeffs))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
sk_BIGNUM_const_free(factors);
|
||||
@@ -187,14 +92,19 @@ static int rsa_has(void *keydata, int selection)
|
||||
RSA *rsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
if (rsa != NULL) {
|
||||
if ((selection & RSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
ok = ok && (RSA_get0_e(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (RSA_get0_n(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (RSA_get0_d(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
|
||||
ok = ok && 0; /* This will change with PSS and OAEP */
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && (RSA_get0_e(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && (RSA_get0_n(rsa) != NULL);
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && (RSA_get0_d(rsa) != NULL);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -224,7 +134,7 @@ static int rsa_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && params_to_key(rsa, params);
|
||||
ok = ok && rsa_fromdata(rsa, params);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -233,7 +143,7 @@ static int rsa_export(void *keydata, int selection,
|
||||
OSSL_CALLBACK *param_callback, void *cbarg)
|
||||
{
|
||||
RSA *rsa = keydata;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
OSSL_PARAM *params = NULL;
|
||||
int ok = 1;
|
||||
|
||||
@@ -242,20 +152,75 @@ static int rsa_export(void *keydata, int selection,
|
||||
|
||||
/* TODO(3.0) PSS and OAEP should bring on parameters */
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(rsa, &tmpl);
|
||||
|
||||
if (!ok
|
||||
|| (params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
|
||||
ok = ok && key_to_params(rsa, tmpl, NULL);
|
||||
|
||||
if (!ok
|
||||
|| (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
|
||||
goto err;
|
||||
|
||||
ok = param_callback(params, cbarg);
|
||||
ossl_param_bld_free(params);
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
err:
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
/* In fips mode there are no multi-primes. */
|
||||
# define RSA_KEY_MP_TYPES() \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, NULL, 0),
|
||||
#else
|
||||
/*
|
||||
* We allow up to 10 prime factors (starting with p, q).
|
||||
* NOTE: there is only 9 OSSL_PKEY_PARAM_RSA_COEFFICIENT
|
||||
*/
|
||||
# define RSA_KEY_MP_TYPES() \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR3, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR4, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR5, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR6, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR7, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR8, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR9, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR10, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT3, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT4, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT5, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT6, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT7, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT8, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT9, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT10, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT2, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT3, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT4, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT5, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT6, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT7, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT8, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT9, NULL, 0),
|
||||
#endif
|
||||
|
||||
#define RSA_KEY_TYPES() \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0), \
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_D, NULL, 0), \
|
||||
RSA_KEY_MP_TYPES()
|
||||
|
||||
/*
|
||||
* This provider can export everything in an RSA key, so we use the exact
|
||||
* same type description for export as for import. Other providers might
|
||||
@@ -264,41 +229,8 @@ static int rsa_export(void *keydata, int selection,
|
||||
* different arrays.
|
||||
*/
|
||||
static const OSSL_PARAM rsa_key_types[] = {
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_D, NULL, 0),
|
||||
/* We tolerate up to 10 factors... */
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR, NULL, 0),
|
||||
/* ..., up to 10 CRT exponents... */
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT, NULL, 0),
|
||||
/* ..., and up to 9 CRT coefficients */
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT, NULL, 0),
|
||||
RSA_KEY_TYPES()
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
/*
|
||||
* We lied about the amount of factors, exponents and coefficients, the
|
||||
@@ -319,7 +251,6 @@ static const OSSL_PARAM *rsa_import_types(int selection)
|
||||
return rsa_imexport_types(selection);
|
||||
}
|
||||
|
||||
|
||||
static const OSSL_PARAM *rsa_export_types(int selection)
|
||||
{
|
||||
return rsa_imexport_types(selection);
|
||||
@@ -365,8 +296,7 @@ static int rsa_get_params(void *key, OSSL_PARAM params[])
|
||||
if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return key_to_params(rsa, NULL, params);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM rsa_params[] = {
|
||||
@@ -374,6 +304,7 @@ static const OSSL_PARAM rsa_params[] = {
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
|
||||
OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST, NULL, 0),
|
||||
RSA_KEY_TYPES()
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
@@ -403,8 +334,127 @@ static int rsa_validate(void *keydata, int selection)
|
||||
return ok;
|
||||
}
|
||||
|
||||
struct rsa_gen_ctx {
|
||||
OPENSSL_CTX *libctx;
|
||||
|
||||
size_t nbits;
|
||||
BIGNUM *pub_exp;
|
||||
size_t primes;
|
||||
|
||||
/* For generation callback */
|
||||
OSSL_CALLBACK *cb;
|
||||
void *cbarg;
|
||||
};
|
||||
|
||||
static int rsa_gencb(int p, int n, BN_GENCB *cb)
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = BN_GENCB_get_arg(cb);
|
||||
OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END };
|
||||
|
||||
params[0] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_POTENTIAL, &p);
|
||||
params[1] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_ITERATION, &n);
|
||||
|
||||
return gctx->cb(params, gctx->cbarg);
|
||||
}
|
||||
|
||||
static void *rsa_gen_init(void *provctx, int selection)
|
||||
{
|
||||
OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
struct rsa_gen_ctx *gctx = NULL;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
|
||||
return NULL;
|
||||
|
||||
if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) {
|
||||
gctx->libctx = libctx;
|
||||
if ((gctx->pub_exp = BN_new()) == NULL
|
||||
|| !BN_set_word(gctx->pub_exp, RSA_F4)) {
|
||||
BN_free(gctx->pub_exp);
|
||||
gctx = NULL;
|
||||
} else {
|
||||
gctx->nbits = 2048;
|
||||
gctx->primes = RSA_DEFAULT_PRIME_NUM;
|
||||
}
|
||||
}
|
||||
return gctx;
|
||||
}
|
||||
|
||||
static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
const OSSL_PARAM *p;
|
||||
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_BITS)) != NULL
|
||||
&& !OSSL_PARAM_get_size_t(p, &gctx->nbits))
|
||||
return 0;
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_PRIMES)) != NULL
|
||||
&& !OSSL_PARAM_get_size_t(p, &gctx->primes))
|
||||
return 0;
|
||||
if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E)) != NULL
|
||||
&& !OSSL_PARAM_get_BN(p, &gctx->pub_exp))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
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),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
return settable;
|
||||
}
|
||||
|
||||
static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
RSA *rsa = NULL;
|
||||
BN_GENCB *gencb = NULL;
|
||||
|
||||
if (gctx == NULL
|
||||
|| (rsa = rsa_new_with_ctx(gctx->libctx)) == NULL)
|
||||
return NULL;
|
||||
|
||||
gctx->cb = osslcb;
|
||||
gctx->cbarg = cbarg;
|
||||
gencb = BN_GENCB_new();
|
||||
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;
|
||||
}
|
||||
|
||||
BN_GENCB_free(gencb);
|
||||
|
||||
return rsa;
|
||||
}
|
||||
|
||||
static void rsa_gen_cleanup(void *genctx)
|
||||
{
|
||||
struct rsa_gen_ctx *gctx = genctx;
|
||||
|
||||
if (gctx == NULL)
|
||||
return;
|
||||
|
||||
BN_clear_free(gctx->pub_exp);
|
||||
OPENSSL_free(gctx);
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH rsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsa_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsa_gen_init },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS,
|
||||
(void (*)(void))rsa_gen_set_params },
|
||||
{ OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
|
||||
(void (*)(void))rsa_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 },
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/x509.h> /* i2d_X509_PUBKEY_bio() */
|
||||
#include "crypto/bn.h" /* bn_get_words() */
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h" /* ossl_prov_bio_printf() */
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h" /* PROV_R_READ_KEY */
|
||||
|
||||
@@ -26,6 +26,14 @@ void ecx_get_new_free_import(ECX_KEY_TYPE type,
|
||||
*ecx_new = ossl_prov_get_keymgmt_new(x448_keymgmt_functions);
|
||||
*ecx_free = ossl_prov_get_keymgmt_free(x448_keymgmt_functions);
|
||||
*ecx_import = ossl_prov_get_keymgmt_import(x448_keymgmt_functions);
|
||||
} else if (type == ECX_KEY_TYPE_ED25519) {
|
||||
*ecx_new = ossl_prov_get_keymgmt_new(ed25519_keymgmt_functions);
|
||||
*ecx_free = ossl_prov_get_keymgmt_free(ed25519_keymgmt_functions);
|
||||
*ecx_import = ossl_prov_get_keymgmt_import(ed25519_keymgmt_functions);
|
||||
} else if (type == ECX_KEY_TYPE_ED448) {
|
||||
*ecx_new = ossl_prov_get_keymgmt_new(ed448_keymgmt_functions);
|
||||
*ecx_free = ossl_prov_get_keymgmt_free(ed448_keymgmt_functions);
|
||||
*ecx_import = ossl_prov_get_keymgmt_import(ed448_keymgmt_functions);
|
||||
} else {
|
||||
*ecx_new = NULL;
|
||||
*ecx_free = NULL;
|
||||
@@ -40,23 +48,35 @@ int ossl_prov_print_ecx(BIO *out, ECX_KEY *ecxkey, enum ecx_print_type type)
|
||||
|
||||
switch (type) {
|
||||
case ecx_print_priv:
|
||||
switch (ecxkey->keylen) {
|
||||
case X25519_KEYLEN:
|
||||
switch (ecxkey->type) {
|
||||
case ECX_KEY_TYPE_X25519:
|
||||
type_label = "X25519 Private-Key";
|
||||
break;
|
||||
case X448_KEYLEN:
|
||||
case ECX_KEY_TYPE_X448:
|
||||
type_label = "X448 Private-Key";
|
||||
break;
|
||||
case ECX_KEY_TYPE_ED25519:
|
||||
type_label = "ED25519 Private-Key";
|
||||
break;
|
||||
case ECX_KEY_TYPE_ED448:
|
||||
type_label = "ED448 Private-Key";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ecx_print_pub:
|
||||
switch (ecxkey->keylen) {
|
||||
case X25519_KEYLEN:
|
||||
switch (ecxkey->type) {
|
||||
case ECX_KEY_TYPE_X25519:
|
||||
type_label = "X25519 Public-Key";
|
||||
break;
|
||||
case X448_KEYLEN:
|
||||
case ECX_KEY_TYPE_X448:
|
||||
type_label = "X448 Public-Key";
|
||||
break;
|
||||
case ECX_KEY_TYPE_ED25519:
|
||||
type_label = "ED25519 Public-Key";
|
||||
break;
|
||||
case ECX_KEY_TYPE_ED448:
|
||||
type_label = "ED448 Public-Key";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/params.h>
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_priv_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn x448_priv_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn ed25519_priv_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn ed448_priv_newctx;
|
||||
static OSSL_OP_serializer_freectx_fn ecx_priv_freectx;
|
||||
static OSSL_OP_serializer_set_ctx_params_fn ecx_priv_set_ctx_params;
|
||||
static OSSL_OP_serializer_settable_ctx_params_fn ecx_priv_settable_ctx_params;
|
||||
@@ -65,6 +68,16 @@ static void *x448_priv_newctx(void *provctx)
|
||||
return ecx_priv_newctx(provctx, ECX_KEY_TYPE_X448);
|
||||
}
|
||||
|
||||
static void *ed25519_priv_newctx(void *provctx)
|
||||
{
|
||||
return ecx_priv_newctx(provctx, ECX_KEY_TYPE_ED25519);
|
||||
}
|
||||
|
||||
static void *ed448_priv_newctx(void *provctx)
|
||||
{
|
||||
return ecx_priv_newctx(provctx, ECX_KEY_TYPE_ED448);
|
||||
}
|
||||
|
||||
static void ecx_priv_freectx(void *vctx)
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
@@ -150,14 +163,13 @@ static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
ECX_KEY *ecxkey = vecxkey;
|
||||
int ret;
|
||||
int type = (ctx->type == ECX_KEY_TYPE_X25519) ? EVP_PKEY_X25519
|
||||
: EVP_PKEY_X448;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_der_from_obj(out, ecxkey,
|
||||
type,
|
||||
nid,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
@@ -194,14 +206,13 @@ static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
{
|
||||
struct ecx_priv_ctx_st *ctx = vctx;
|
||||
int ret;
|
||||
int type = (ctx->type == ECX_KEY_TYPE_X25519) ? EVP_PKEY_X25519
|
||||
: EVP_PKEY_X448;
|
||||
int nid = KEYTYPE2NID(ctx->type);
|
||||
|
||||
ctx->sc.cb = cb;
|
||||
ctx->sc.cbarg = cbarg;
|
||||
|
||||
ret = ossl_prov_write_priv_pem_from_obj(out, ecxkey,
|
||||
type,
|
||||
nid,
|
||||
NULL,
|
||||
ossl_prov_ecx_priv_to_der,
|
||||
&ctx->sc);
|
||||
@@ -268,3 +279,5 @@ static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out,
|
||||
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(x25519)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(x448)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(ed25519)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(ed448)
|
||||
@@ -12,12 +12,15 @@
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/types.h>
|
||||
#include <openssl/params.h>
|
||||
#include "crypto/ecx.h"
|
||||
#include "prov/bio.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "serializer_local.h"
|
||||
|
||||
static OSSL_OP_serializer_newctx_fn x25519_pub_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn x448_pub_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn ed25519_pub_newctx;
|
||||
static OSSL_OP_serializer_newctx_fn ed448_pub_newctx;
|
||||
static OSSL_OP_serializer_freectx_fn ecx_pub_freectx;
|
||||
static OSSL_OP_serializer_serialize_data_fn ecx_pub_der_data;
|
||||
static OSSL_OP_serializer_serialize_object_fn ecx_pub_der;
|
||||
@@ -57,6 +60,16 @@ static void *x448_pub_newctx(void *provctx)
|
||||
return ecx_pub_newctx(provctx, ECX_KEY_TYPE_X448);
|
||||
}
|
||||
|
||||
static void *ed25519_pub_newctx(void *provctx)
|
||||
{
|
||||
return ecx_pub_newctx(provctx, ECX_KEY_TYPE_ED25519);
|
||||
}
|
||||
|
||||
static void *ed448_pub_newctx(void *provctx)
|
||||
{
|
||||
return ecx_pub_newctx(provctx, ECX_KEY_TYPE_ED448);
|
||||
}
|
||||
|
||||
static void ecx_pub_freectx(void *ctx)
|
||||
{
|
||||
OPENSSL_free(ctx);
|
||||
@@ -92,8 +105,7 @@ static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out,
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
|
||||
return ossl_prov_write_pub_der_from_obj(out, ecxkey,
|
||||
ctx->type == ECX_KEY_TYPE_X25519
|
||||
? EVP_PKEY_X25519 : EVP_PKEY_X448,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
}
|
||||
@@ -128,8 +140,7 @@ static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out,
|
||||
struct ecx_pub_ctx_st *ctx = vctx;
|
||||
|
||||
return ossl_prov_write_pub_pem_from_obj(out, ecxkey,
|
||||
ctx->type == ECX_KEY_TYPE_X25519
|
||||
? EVP_PKEY_X25519 : EVP_PKEY_X448,
|
||||
KEYTYPE2NID(ctx->type),
|
||||
NULL,
|
||||
ossl_prov_ecx_pub_to_der);
|
||||
|
||||
@@ -182,3 +193,5 @@ static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out,
|
||||
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(x25519)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(x448)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(ed25519)
|
||||
MAKE_SERIALIZER_FUNCTIONS_GROUP(ed448)
|
||||
@@ -31,11 +31,6 @@ struct pkcs8_encrypt_ctx_st {
|
||||
void *cbarg;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ECX_KEY_TYPE_X25519,
|
||||
ECX_KEY_TYPE_X448
|
||||
} ECX_KEY_TYPE;
|
||||
|
||||
OSSL_OP_keymgmt_new_fn *ossl_prov_get_keymgmt_new(const OSSL_DISPATCH *fns);
|
||||
OSSL_OP_keymgmt_free_fn *ossl_prov_get_keymgmt_free(const OSSL_DISPATCH *fns);
|
||||
OSSL_OP_keymgmt_import_fn *ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns);
|
||||
@@ -64,12 +59,14 @@ int ossl_prov_prepare_dh_params(const void *dh, int nid,
|
||||
int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder);
|
||||
int ossl_prov_dh_priv_to_der(const void *dh, unsigned char **pder);
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
void ecx_get_new_free_import(ECX_KEY_TYPE type,
|
||||
OSSL_OP_keymgmt_new_fn **ecx_new,
|
||||
OSSL_OP_keymgmt_free_fn **ecx_free,
|
||||
OSSL_OP_keymgmt_import_fn **ecx_import);
|
||||
int ossl_prov_ecx_pub_to_der(const void *ecxkey, unsigned char **pder);
|
||||
int ossl_prov_ecx_priv_to_der(const void *ecxkey, unsigned char **pder);
|
||||
#endif
|
||||
|
||||
int ossl_prov_prepare_dsa_params(const void *dsa, int nid,
|
||||
void **pstr, int *pstrtype);
|
||||
|
||||
@@ -110,4 +110,3 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv)
|
||||
sk_BIGNUM_const_free(coeffs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
# switch each to the Legacy provider when needed.
|
||||
|
||||
$DSA_GOAL=../../libimplementations.a
|
||||
$RSA_GOAL=../../libimplementations.a
|
||||
$EC_GOAL=../../libimplementations.a
|
||||
$ECDSA_GOAL=../../libimplementations.a
|
||||
|
||||
IF[{- !$disabled{dsa} -}]
|
||||
SOURCE[$DSA_GOAL]=dsa.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[$RSA_GOAL]=rsa.c
|
||||
IF[{- !$disabled{ec} -}]
|
||||
SOURCE[$EC_GOAL]=eddsa.c
|
||||
SOURCE[$ECDSA_GOAL]=ecdsa.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libfips.a]=rsa.c
|
||||
SOURCE[../../libnonfips.a]=rsa.c
|
||||
|
||||
DEPEND[rsa.o]=../../common/include/prov/der_rsa.h
|
||||
DEPEND[dsa.o]=../../common/include/prov/der_dsa.h
|
||||
DEPEND[ecdsa.o]=../../common/include/prov/der_ec.h
|
||||
@@ -25,11 +25,13 @@
|
||||
#include <openssl/err.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/sizes.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "prov/der_dsa.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn dsa_newctx;
|
||||
static OSSL_OP_signature_sign_init_fn dsa_signature_init;
|
||||
@@ -73,8 +75,9 @@ typedef struct {
|
||||
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
|
||||
/* The Algorithm Identifier of the combined signature agorithm */
|
||||
unsigned char aid[OSSL_MAX_ALGORITHM_ID_SIZE];
|
||||
/* The Algorithm Identifier of the combined signature algorithm */
|
||||
unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
|
||||
unsigned char *aid;
|
||||
size_t aid_len;
|
||||
|
||||
/* main digest */
|
||||
@@ -146,25 +149,35 @@ static int dsa_setup_md(PROV_DSA_CTX *ctx,
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = dsa_get_md_nid(md);
|
||||
size_t algorithmidentifier_len = 0;
|
||||
const unsigned char *algorithmidentifier;
|
||||
WPACKET pkt;
|
||||
|
||||
EVP_MD_free(ctx->md);
|
||||
ctx->md = NULL;
|
||||
ctx->mdname[0] = '\0';
|
||||
|
||||
algorithmidentifier =
|
||||
dsa_algorithmidentifier_encoding(md_nid, &algorithmidentifier_len);
|
||||
|
||||
if (algorithmidentifier == NULL) {
|
||||
if (md == NULL || md_nid == NID_undef) {
|
||||
EVP_MD_free(md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(ctx->mdctx);
|
||||
EVP_MD_free(ctx->md);
|
||||
|
||||
/*
|
||||
* TODO(3.0) Should we care about DER writing errors?
|
||||
* All it really means is that for some reason, there's no
|
||||
* AlgorithmIdentifier to be had, but the operation itself is
|
||||
* still valid, just as long as it's not used to construct
|
||||
* anything that needs an AlgorithmIdentifier.
|
||||
*/
|
||||
ctx->aid_len = 0;
|
||||
if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
|
||||
&& DER_w_algorithmIdentifier_DSA_with(&pkt, -1, ctx->dsa, md_nid)
|
||||
&& WPACKET_finish(&pkt)) {
|
||||
WPACKET_get_total_written(&pkt, &ctx->aid_len);
|
||||
ctx->aid = WPACKET_get_curr(&pkt);
|
||||
}
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
ctx->mdctx = NULL;
|
||||
ctx->md = md;
|
||||
OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
|
||||
memcpy(ctx->aid, algorithmidentifier, algorithmidentifier_len);
|
||||
ctx->aid_len = algorithmidentifier_len;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,527 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* ECDSA low level APIs are deprecated for public use, but still ok for
|
||||
* internal use.
|
||||
*/
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <string.h> /* memcpy */
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/sizes.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/ec.h"
|
||||
#include "prov/der_ec.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn ecdsa_newctx;
|
||||
static OSSL_OP_signature_sign_init_fn ecdsa_signature_init;
|
||||
static OSSL_OP_signature_verify_init_fn ecdsa_signature_init;
|
||||
static OSSL_OP_signature_sign_fn ecdsa_sign;
|
||||
static OSSL_OP_signature_verify_fn ecdsa_verify;
|
||||
static OSSL_OP_signature_digest_sign_init_fn ecdsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_sign_update_fn ecdsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_sign_final_fn ecdsa_digest_sign_final;
|
||||
static OSSL_OP_signature_digest_verify_init_fn ecdsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_verify_update_fn ecdsa_digest_signverify_update;
|
||||
static OSSL_OP_signature_digest_verify_final_fn ecdsa_digest_verify_final;
|
||||
static OSSL_OP_signature_freectx_fn ecdsa_freectx;
|
||||
static OSSL_OP_signature_dupctx_fn ecdsa_dupctx;
|
||||
static OSSL_OP_signature_get_ctx_params_fn ecdsa_get_ctx_params;
|
||||
static OSSL_OP_signature_gettable_ctx_params_fn ecdsa_gettable_ctx_params;
|
||||
static OSSL_OP_signature_set_ctx_params_fn ecdsa_set_ctx_params;
|
||||
static OSSL_OP_signature_settable_ctx_params_fn ecdsa_settable_ctx_params;
|
||||
static OSSL_OP_signature_get_ctx_md_params_fn ecdsa_get_ctx_md_params;
|
||||
static OSSL_OP_signature_gettable_ctx_md_params_fn ecdsa_gettable_ctx_md_params;
|
||||
static OSSL_OP_signature_set_ctx_md_params_fn ecdsa_set_ctx_md_params;
|
||||
static OSSL_OP_signature_settable_ctx_md_params_fn ecdsa_settable_ctx_md_params;
|
||||
|
||||
/*
|
||||
* What's passed as an actual key is defined by the KEYMGMT interface.
|
||||
* We happen to know that our KEYMGMT simply passes DSA structures, so
|
||||
* we use that here too.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
EC_KEY *ec;
|
||||
char mdname[OSSL_MAX_NAME_SIZE];
|
||||
|
||||
/* The Algorithm Identifier of the combined signature algorithm */
|
||||
unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
|
||||
unsigned char *aid;
|
||||
size_t aid_len;
|
||||
size_t mdsize;
|
||||
|
||||
EVP_MD *md;
|
||||
EVP_MD_CTX *mdctx;
|
||||
/*
|
||||
* This indicates that KAT (CAVS) test is running. Externally an app will
|
||||
* override the random callback such that the generated private key and k
|
||||
* are known.
|
||||
* Normal operation will loop to choose a new k if the signature is not
|
||||
* valid - but for this mode of operation it forces a failure instead.
|
||||
*/
|
||||
unsigned int kattest;
|
||||
/*
|
||||
* Internally used to cache the results of calling the EC group
|
||||
* sign_setup() methods which are then passed to the sign operation.
|
||||
* This is used by CAVS failure tests to terminate a loop if the signature
|
||||
* is not valid.
|
||||
* This could of also been done with a simple flag.
|
||||
*/
|
||||
BIGNUM *kinv;
|
||||
BIGNUM *r;
|
||||
} PROV_ECDSA_CTX;
|
||||
|
||||
static void *ecdsa_newctx(void *provctx)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECDSA_CTX));
|
||||
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static int ecdsa_signature_init(void *vctx, void *ec)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx == NULL || ec == NULL || !EC_KEY_up_ref(ec))
|
||||
return 0;
|
||||
EC_KEY_free(ctx->ec);
|
||||
ctx->ec = ec;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ecdsa_sign(void *vctx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize, const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
int ret;
|
||||
unsigned int sltmp;
|
||||
size_t ecsize = ECDSA_size(ctx->ec);
|
||||
|
||||
if (sig == NULL) {
|
||||
*siglen = ecsize;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ctx->kattest && !ECDSA_sign_setup(ctx->ec, NULL, &ctx->kinv, &ctx->r))
|
||||
return 0;
|
||||
|
||||
if (sigsize < (size_t)ecsize)
|
||||
return 0;
|
||||
|
||||
if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
|
||||
return 0;
|
||||
|
||||
ret = ECDSA_sign_ex(0, tbs, tbslen, sig, &sltmp, ctx->kinv, ctx->r, ctx->ec);
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
|
||||
*siglen = sltmp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ecdsa_verify(void *vctx, const unsigned char *sig, size_t siglen,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
|
||||
return 0;
|
||||
|
||||
return ECDSA_verify(0, tbs, tbslen, sig, siglen, ctx->ec);
|
||||
}
|
||||
|
||||
static int get_md_nid(const EVP_MD *md)
|
||||
{
|
||||
/*
|
||||
* Because the ECDSA library deals with NIDs, we need to translate.
|
||||
* We do so using EVP_MD_is_a(), and therefore need a name to NID
|
||||
* map.
|
||||
*/
|
||||
static const OSSL_ITEM name_to_nid[] = {
|
||||
{ NID_sha1, OSSL_DIGEST_NAME_SHA1 },
|
||||
{ NID_sha224, OSSL_DIGEST_NAME_SHA2_224 },
|
||||
{ NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
|
||||
{ NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
|
||||
{ NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
|
||||
{ NID_sha3_224, OSSL_DIGEST_NAME_SHA3_224 },
|
||||
{ NID_sha3_256, OSSL_DIGEST_NAME_SHA3_256 },
|
||||
{ NID_sha3_384, OSSL_DIGEST_NAME_SHA3_384 },
|
||||
{ NID_sha3_512, OSSL_DIGEST_NAME_SHA3_512 },
|
||||
/* TODO - Add SHAKE OIDS when they are standardized */
|
||||
|
||||
};
|
||||
size_t i;
|
||||
int mdnid = NID_undef;
|
||||
|
||||
if (md == NULL)
|
||||
goto end;
|
||||
|
||||
for (i = 0; i < OSSL_NELEM(name_to_nid); i++) {
|
||||
if (EVP_MD_is_a(md, name_to_nid[i].ptr)) {
|
||||
mdnid = (int)name_to_nid[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mdnid == NID_undef)
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
|
||||
|
||||
end:
|
||||
return mdnid;
|
||||
}
|
||||
|
||||
static void free_md(PROV_ECDSA_CTX *ctx)
|
||||
{
|
||||
EVP_MD_CTX_free(ctx->mdctx);
|
||||
EVP_MD_free(ctx->md);
|
||||
ctx->mdctx = NULL;
|
||||
ctx->md = NULL;
|
||||
ctx->mdsize = 0;
|
||||
}
|
||||
|
||||
static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
|
||||
const char *props, void *ec)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
int md_nid = NID_undef;
|
||||
WPACKET pkt;
|
||||
|
||||
free_md(ctx);
|
||||
|
||||
if (!ecdsa_signature_init(vctx, ec))
|
||||
return 0;
|
||||
|
||||
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, props);
|
||||
if ((md_nid = get_md_nid(ctx->md)) == NID_undef)
|
||||
goto error;
|
||||
|
||||
ctx->mdsize = EVP_MD_size(ctx->md);
|
||||
ctx->mdctx = EVP_MD_CTX_new();
|
||||
if (ctx->mdctx == NULL)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* TODO(3.0) Should we care about DER writing errors?
|
||||
* All it really means is that for some reason, there's no
|
||||
* AlgorithmIdentifier to be had, but the operation itself is
|
||||
* still valid, just as long as it's not used to construct
|
||||
* anything that needs an AlgorithmIdentifier.
|
||||
*/
|
||||
ctx->aid_len = 0;
|
||||
if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
|
||||
&& DER_w_algorithmIdentifier_ECDSA_with(&pkt, -1, ctx->ec, md_nid)
|
||||
&& WPACKET_finish(&pkt)) {
|
||||
WPACKET_get_total_written(&pkt, &ctx->aid_len);
|
||||
ctx->aid = WPACKET_get_curr(&pkt);
|
||||
}
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
if (!EVP_DigestInit_ex(ctx->mdctx, ctx->md, NULL))
|
||||
goto error;
|
||||
return 1;
|
||||
error:
|
||||
free_md(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ecdsa_digest_signverify_update(void *vctx, const unsigned char *data,
|
||||
size_t datalen)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx == NULL || ctx->mdctx == NULL)
|
||||
return 0;
|
||||
|
||||
return EVP_DigestUpdate(ctx->mdctx, data, datalen);
|
||||
}
|
||||
|
||||
int ecdsa_digest_sign_final(void *vctx, unsigned char *sig, size_t *siglen,
|
||||
size_t sigsize)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen = 0;
|
||||
|
||||
if (ctx == NULL || ctx->mdctx == NULL)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If sig is NULL then we're just finding out the sig size. Other fields
|
||||
* are ignored. Defer to ecdsa_sign.
|
||||
*/
|
||||
if (sig != NULL) {
|
||||
/*
|
||||
* TODO(3.0): There is the possibility that some externally provided
|
||||
* digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow -
|
||||
* but that problem is much larger than just in DSA.
|
||||
*/
|
||||
if (!EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ecdsa_sign(vctx, sig, siglen, sigsize, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
int ecdsa_digest_verify_final(void *vctx, const unsigned char *sig,
|
||||
size_t siglen)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen = 0;
|
||||
|
||||
if (ctx == NULL || ctx->mdctx == NULL)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* TODO(3.0): There is the possibility that some externally provided
|
||||
* digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow -
|
||||
* but that problem is much larger than just in DSA.
|
||||
*/
|
||||
if (!EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
|
||||
return 0;
|
||||
|
||||
return ecdsa_verify(ctx, sig, siglen, digest, (size_t)dlen);
|
||||
}
|
||||
|
||||
static void ecdsa_freectx(void *vctx)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
free_md(ctx);
|
||||
EC_KEY_free(ctx->ec);
|
||||
BN_clear_free(ctx->kinv);
|
||||
BN_clear_free(ctx->r);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
static void *ecdsa_dupctx(void *vctx)
|
||||
{
|
||||
PROV_ECDSA_CTX *srcctx = (PROV_ECDSA_CTX *)vctx;
|
||||
PROV_ECDSA_CTX *dstctx;
|
||||
|
||||
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
|
||||
if (dstctx == NULL)
|
||||
return NULL;
|
||||
|
||||
*dstctx = *srcctx;
|
||||
dstctx->ec = NULL;
|
||||
dstctx->md = NULL;
|
||||
dstctx->mdctx = NULL;
|
||||
|
||||
if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
|
||||
goto err;
|
||||
/* Test KATS should not need to be supported */
|
||||
if (srcctx->kinv != NULL || srcctx->r != NULL)
|
||||
goto err;
|
||||
dstctx->ec = srcctx->ec;
|
||||
|
||||
if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
|
||||
goto err;
|
||||
dstctx->md = srcctx->md;
|
||||
|
||||
if (srcctx->mdctx != NULL) {
|
||||
dstctx->mdctx = EVP_MD_CTX_new();
|
||||
if (dstctx->mdctx == NULL
|
||||
|| !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
|
||||
goto err;
|
||||
}
|
||||
|
||||
return dstctx;
|
||||
err:
|
||||
ecdsa_freectx(dstctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ecdsa_get_ctx_params(void *vctx, OSSL_PARAM *params)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
OSSL_PARAM *p;
|
||||
|
||||
if (ctx == NULL || params == NULL)
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
|
||||
if (p != NULL && !OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
|
||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->mdsize))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_string(p, ctx->md == NULL
|
||||
? ctx->mdname
|
||||
: EVP_MD_name(ctx->md)))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM known_gettable_ctx_params[] = {
|
||||
OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
|
||||
OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *ecdsa_gettable_ctx_params(void)
|
||||
{
|
||||
return known_gettable_ctx_params;
|
||||
}
|
||||
|
||||
static int ecdsa_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
const OSSL_PARAM *p;
|
||||
char *mdname;
|
||||
|
||||
if (ctx == NULL || params == NULL)
|
||||
return 0;
|
||||
|
||||
if (ctx->md != NULL) {
|
||||
/*
|
||||
* You cannot set the digest name/size when doing a DigestSign or
|
||||
* DigestVerify.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_KAT);
|
||||
if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->kattest))
|
||||
return 0;
|
||||
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
|
||||
if (p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->mdsize))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* We never actually use the mdname, but we do support getting it later.
|
||||
* This can be useful for applications that want to know the MD that they
|
||||
* previously set.
|
||||
*/
|
||||
p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
|
||||
mdname = ctx->mdname;
|
||||
if (p != NULL
|
||||
&& !OSSL_PARAM_get_utf8_string(p, &mdname, sizeof(ctx->mdname)))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_PARAM known_settable_ctx_params[] = {
|
||||
OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
|
||||
OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
|
||||
OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_KAT, NULL),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
static const OSSL_PARAM *ecdsa_settable_ctx_params(void)
|
||||
{
|
||||
/*
|
||||
* TODO(3.0): Should this function return a different set of settable ctx
|
||||
* params if the ctx is being used for a DigestSign/DigestVerify? In that
|
||||
* case it is not allowed to set the digest size/digest name because the
|
||||
* digest is explicitly set as part of the init.
|
||||
*/
|
||||
return known_settable_ctx_params;
|
||||
}
|
||||
|
||||
static int ecdsa_get_ctx_md_params(void *vctx, OSSL_PARAM *params)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx->mdctx == NULL)
|
||||
return 0;
|
||||
|
||||
return EVP_MD_CTX_get_params(ctx->mdctx, params);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *ecdsa_gettable_ctx_md_params(void *vctx)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx->md == NULL)
|
||||
return 0;
|
||||
|
||||
return EVP_MD_gettable_ctx_params(ctx->md);
|
||||
}
|
||||
|
||||
static int ecdsa_set_ctx_md_params(void *vctx, const OSSL_PARAM params[])
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx->mdctx == NULL)
|
||||
return 0;
|
||||
|
||||
return EVP_MD_CTX_set_params(ctx->mdctx, params);
|
||||
}
|
||||
|
||||
static const OSSL_PARAM *ecdsa_settable_ctx_md_params(void *vctx)
|
||||
{
|
||||
PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
|
||||
|
||||
if (ctx->md == NULL)
|
||||
return 0;
|
||||
|
||||
return EVP_MD_settable_ctx_params(ctx->md);
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ecdsa_signature_functions[] = {
|
||||
{ OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))ecdsa_newctx },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))ecdsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))ecdsa_sign },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))ecdsa_signature_init },
|
||||
{ OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))ecdsa_verify },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
|
||||
(void (*)(void))ecdsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
|
||||
(void (*)(void))ecdsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
|
||||
(void (*)(void))ecdsa_digest_sign_final },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
|
||||
(void (*)(void))ecdsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
|
||||
(void (*)(void))ecdsa_digest_signverify_update },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
|
||||
(void (*)(void))ecdsa_digest_verify_final },
|
||||
{ OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))ecdsa_freectx },
|
||||
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))ecdsa_dupctx },
|
||||
{ OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))ecdsa_get_ctx_params },
|
||||
{ OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
|
||||
(void (*)(void))ecdsa_gettable_ctx_params },
|
||||
{ OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))ecdsa_set_ctx_params },
|
||||
{ OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
|
||||
(void (*)(void))ecdsa_settable_ctx_params },
|
||||
{ OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
|
||||
(void (*)(void))ecdsa_get_ctx_md_params },
|
||||
{ OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
|
||||
(void (*)(void))ecdsa_gettable_ctx_md_params },
|
||||
{ OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
|
||||
(void (*)(void))ecdsa_set_ctx_md_params },
|
||||
{ OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
|
||||
(void (*)(void))ecdsa_settable_ctx_md_params },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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 <openssl/crypto.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/sizes.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/ecx.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn eddsa_newctx;
|
||||
static OSSL_OP_signature_digest_sign_init_fn eddsa_digest_signverify_init;
|
||||
static OSSL_OP_signature_digest_sign_fn ed25519_digest_sign;
|
||||
static OSSL_OP_signature_digest_sign_fn ed448_digest_sign;
|
||||
static OSSL_OP_signature_digest_verify_fn ed25519_digest_verify;
|
||||
static OSSL_OP_signature_digest_verify_fn ed448_digest_verify;
|
||||
static OSSL_OP_signature_freectx_fn eddsa_freectx;
|
||||
static OSSL_OP_signature_dupctx_fn eddsa_dupctx;
|
||||
|
||||
typedef struct {
|
||||
OPENSSL_CTX *libctx;
|
||||
ECX_KEY *key;
|
||||
} PROV_EDDSA_CTX;
|
||||
|
||||
static void *eddsa_newctx(void *provctx)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX));
|
||||
|
||||
if (peddsactx == NULL) {
|
||||
PROVerr(0, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
peddsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
|
||||
|
||||
return peddsactx;
|
||||
}
|
||||
|
||||
static int eddsa_digest_signverify_init(void *vpeddsactx, const char *mdname,
|
||||
const char *props, void *vedkey)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
ECX_KEY *edkey = (ECX_KEY *)vedkey;
|
||||
|
||||
if (mdname != NULL) {
|
||||
PROVerr(0, PROV_R_INVALID_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ecx_key_up_ref(edkey)) {
|
||||
PROVerr(0, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
peddsactx->key = edkey;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ed25519_digest_sign(void *vpeddsactx, unsigned char *sigret,
|
||||
size_t *siglen, size_t sigsize,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
const ECX_KEY *edkey = peddsactx->key;
|
||||
|
||||
if (sigret == NULL) {
|
||||
*siglen = ED25519_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
if (sigsize < ED25519_SIGSIZE) {
|
||||
PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ED25519_sign(sigret, tbs, tbslen, edkey->pubkey, edkey->privkey,
|
||||
peddsactx->libctx, NULL) == 0) {
|
||||
PROVerr(0, PROV_R_FAILED_TO_SIGN);
|
||||
return 0;
|
||||
}
|
||||
*siglen = ED25519_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ed448_digest_sign(void *vpeddsactx, unsigned char *sigret,
|
||||
size_t *siglen, size_t sigsize,
|
||||
const unsigned char *tbs, size_t tbslen)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
const ECX_KEY *edkey = peddsactx->key;
|
||||
|
||||
if (sigret == NULL) {
|
||||
*siglen = ED448_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
if (sigsize < ED448_SIGSIZE) {
|
||||
PROVerr(0, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ED448_sign(peddsactx->libctx, sigret, tbs, tbslen, edkey->pubkey,
|
||||
edkey->privkey, NULL, 0) == 0) {
|
||||
PROVerr(0, PROV_R_FAILED_TO_SIGN);
|
||||
return 0;
|
||||
}
|
||||
*siglen = ED448_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ed25519_digest_verify(void *vpeddsactx, const unsigned char *sig,
|
||||
size_t siglen, const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
const ECX_KEY *edkey = peddsactx->key;
|
||||
|
||||
if (siglen != ED25519_SIGSIZE)
|
||||
return 0;
|
||||
|
||||
return ED25519_verify(tbs, tbslen, sig, edkey->pubkey, peddsactx->libctx,
|
||||
NULL);
|
||||
}
|
||||
|
||||
int ed448_digest_verify(void *vpeddsactx, const unsigned char *sig,
|
||||
size_t siglen, const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
const ECX_KEY *edkey = peddsactx->key;
|
||||
|
||||
if (siglen != ED448_SIGSIZE)
|
||||
return 0;
|
||||
|
||||
return ED448_verify(peddsactx->libctx, tbs, tbslen, sig, edkey->pubkey,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
static void eddsa_freectx(void *vpeddsactx)
|
||||
{
|
||||
PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
|
||||
ecx_key_free(peddsactx->key);
|
||||
|
||||
OPENSSL_free(peddsactx);
|
||||
}
|
||||
|
||||
static void *eddsa_dupctx(void *vpeddsactx)
|
||||
{
|
||||
PROV_EDDSA_CTX *srcctx = (PROV_EDDSA_CTX *)vpeddsactx;
|
||||
PROV_EDDSA_CTX *dstctx;
|
||||
|
||||
dstctx = OPENSSL_zalloc(sizeof(*srcctx));
|
||||
if (dstctx == NULL)
|
||||
return NULL;
|
||||
|
||||
*dstctx = *srcctx;
|
||||
dstctx->key = NULL;
|
||||
|
||||
if (srcctx->key != NULL && !ecx_key_up_ref(srcctx->key)) {
|
||||
PROVerr(0, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
dstctx->key = srcctx->key;
|
||||
|
||||
return dstctx;
|
||||
err:
|
||||
eddsa_freectx(dstctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH ed25519_signature_functions[] = {
|
||||
{ OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))eddsa_newctx },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
|
||||
(void (*)(void))eddsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN,
|
||||
(void (*)(void))ed25519_digest_sign },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
|
||||
(void (*)(void))eddsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY,
|
||||
(void (*)(void))ed25519_digest_verify },
|
||||
{ OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))eddsa_freectx },
|
||||
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))eddsa_dupctx },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
const OSSL_DISPATCH ed448_signature_functions[] = {
|
||||
{ OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))eddsa_newctx },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
|
||||
(void (*)(void))eddsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN,
|
||||
(void (*)(void))ed448_digest_sign },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
|
||||
(void (*)(void))eddsa_digest_signverify_init },
|
||||
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY,
|
||||
(void (*)(void))ed448_digest_verify },
|
||||
{ OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))eddsa_freectx },
|
||||
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))eddsa_dupctx },
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "prov/providercommonerr.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "prov/der_rsa.h"
|
||||
|
||||
static OSSL_OP_signature_newctx_fn rsa_newctx;
|
||||
static OSSL_OP_signature_sign_init_fn rsa_signature_init;
|
||||
@@ -83,7 +84,8 @@ typedef struct {
|
||||
unsigned int flag_allow_md : 1;
|
||||
|
||||
/* The Algorithm Identifier of the combined signature agorithm */
|
||||
unsigned char aid[128];
|
||||
unsigned char aid_buf[128];
|
||||
unsigned char *aid;
|
||||
size_t aid_len;
|
||||
|
||||
/* main digest */
|
||||
@@ -216,35 +218,38 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname,
|
||||
if (mdname != NULL) {
|
||||
EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
|
||||
int md_nid = rsa_get_md_nid(md);
|
||||
size_t algorithmidentifier_len = 0;
|
||||
const unsigned char *algorithmidentifier = NULL;
|
||||
WPACKET pkt;
|
||||
|
||||
if (md == NULL)
|
||||
return 0;
|
||||
|
||||
if (!rsa_check_padding(md_nid, ctx->pad_mode)) {
|
||||
if (md == NULL
|
||||
|| md_nid == NID_undef
|
||||
|| !rsa_check_padding(md_nid, ctx->pad_mode)) {
|
||||
EVP_MD_free(md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(ctx->mdctx);
|
||||
EVP_MD_free(ctx->md);
|
||||
ctx->md = NULL;
|
||||
ctx->mdctx = NULL;
|
||||
ctx->mdname[0] = '\0';
|
||||
ctx->aid[0] = '\0';
|
||||
|
||||
/*
|
||||
* TODO(3.0) Should we care about DER writing errors?
|
||||
* All it really means is that for some reason, there's no
|
||||
* AlgorithmIdentifier to be had (consider RSA with MD5-SHA1),
|
||||
* but the operation itself is still valid, just as long as it's
|
||||
* not used to construct anything that needs an AlgorithmIdentifier.
|
||||
*/
|
||||
ctx->aid_len = 0;
|
||||
if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
|
||||
&& DER_w_algorithmIdentifier_RSA_with(&pkt, -1, ctx->rsa, md_nid)
|
||||
&& WPACKET_finish(&pkt)) {
|
||||
WPACKET_get_total_written(&pkt, &ctx->aid_len);
|
||||
ctx->aid = WPACKET_get_curr(&pkt);
|
||||
}
|
||||
WPACKET_cleanup(&pkt);
|
||||
|
||||
algorithmidentifier =
|
||||
rsa_algorithmidentifier_encoding(md_nid, &algorithmidentifier_len);
|
||||
|
||||
ctx->mdctx = NULL;
|
||||
ctx->md = md;
|
||||
ctx->mdnid = md_nid;
|
||||
OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
|
||||
if (algorithmidentifier != NULL) {
|
||||
memcpy(ctx->aid, algorithmidentifier, algorithmidentifier_len);
|
||||
ctx->aid_len = algorithmidentifier_len;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -328,7 +333,6 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen,
|
||||
goto end;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (prsactx->pad_mode) {
|
||||
case RSA_X931_PADDING:
|
||||
if ((size_t)RSA_size(prsactx->rsa) < tbslen + 1) {
|
||||
|
||||
+66
-9
@@ -15,6 +15,8 @@
|
||||
#include <openssl/params.h>
|
||||
#include "prov/implementations.h"
|
||||
|
||||
#define ALG(NAMES, FUNC) { NAMES, "provider=legacy", FUNC }
|
||||
|
||||
#ifdef STATIC_LEGACY
|
||||
OSSL_provider_init_fn ossl_legacy_provider_init;
|
||||
# define OSSL_provider_init ossl_legacy_provider_init
|
||||
@@ -56,25 +58,78 @@ static int legacy_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
|
||||
static const OSSL_ALGORITHM legacy_digests[] = {
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
{ "MD2", "provider=legacy", md2_functions },
|
||||
ALG("MD2", md2_functions),
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_MD4
|
||||
{ "MD4", "provider=legacy", md4_functions },
|
||||
ALG("MD4", md4_functions),
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_MDC2
|
||||
{ "MDC2", "provider=legacy", mdc2_functions },
|
||||
ALG("MDC2", mdc2_functions),
|
||||
#endif /* OPENSSL_NO_MDC2 */
|
||||
|
||||
#ifndef OPENSSL_NO_WHIRLPOOL
|
||||
{ "WHIRLPOOL", "provider=legacy", wp_functions },
|
||||
ALG("WHIRLPOOL", wp_functions),
|
||||
#endif /* OPENSSL_NO_WHIRLPOOL */
|
||||
|
||||
#ifndef OPENSSL_NO_RMD160
|
||||
{ "RIPEMD-160:RIPEMD160:RIPEMD:RMD160", "provider=legacy", ripemd160_functions },
|
||||
ALG("RIPEMD-160:RIPEMD160:RIPEMD:RMD160", ripemd160_functions),
|
||||
#endif /* OPENSSL_NO_RMD160 */
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
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),
|
||||
#endif /* OPENSSL_NO_CAST */
|
||||
#ifndef OPENSSL_NO_BF
|
||||
ALG("BF-ECB", blowfish128ecb_functions),
|
||||
ALG("BF-CBC:BF:BLOWFISH", blowfish128cbc_functions),
|
||||
ALG("BF-OFB", blowfish64ofb64_functions),
|
||||
ALG("BF-CFB", blowfish64cfb64_functions),
|
||||
#endif /* OPENSSL_NO_BF */
|
||||
#ifndef OPENSSL_NO_IDEA
|
||||
ALG("IDEA-ECB", idea128ecb_functions),
|
||||
ALG("IDEA-CBC:IDEA", idea128cbc_functions),
|
||||
ALG("IDEA-OFB:IDEA-OFB64", idea128ofb64_functions),
|
||||
ALG("IDEA-CFB:IDEA-CFB64", idea128cfb64_functions),
|
||||
#endif /* OPENSSL_NO_IDEA */
|
||||
#ifndef OPENSSL_NO_SEED
|
||||
ALG("SEED-ECB", seed128ecb_functions),
|
||||
ALG("SEED-CBC:SEED", seed128cbc_functions),
|
||||
ALG("SEED-OFB:SEED-OFB128", seed128ofb128_functions),
|
||||
ALG("SEED-CFB:SEED-CFB128", seed128cfb128_functions),
|
||||
#endif /* OPENSSL_NO_SEED */
|
||||
#ifndef OPENSSL_NO_RC2
|
||||
ALG("RC2-ECB", rc2128ecb_functions),
|
||||
ALG("RC2-CBC", rc2128cbc_functions),
|
||||
ALG("RC2-40-CBC", rc240cbc_functions),
|
||||
ALG("RC2-64-CBC", rc264cbc_functions),
|
||||
ALG("RC2-CFB", rc2128cfb128_functions),
|
||||
ALG("RC2-OFB", rc2128ofb128_functions),
|
||||
#endif /* OPENSSL_NO_RC2 */
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
ALG("RC4", rc4128_functions),
|
||||
ALG("RC4-40", rc440_functions),
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
ALG("RC4-HMAC-MD5", rc4_hmac_md5_functions),
|
||||
# endif /* OPENSSL_NO_MD5 */
|
||||
#endif /* OPENSSL_NO_RC4 */
|
||||
#ifndef OPENSSL_NO_RC5
|
||||
ALG("RC5-ECB", rc5128ecb_functions),
|
||||
ALG("RC5-CBC", rc5128cbc_functions),
|
||||
ALG("RC5-OFB", rc5128ofb64_functions),
|
||||
ALG("RC5-CFB", rc5128cfb64_functions),
|
||||
#endif /* OPENSSL_NO_RC5 */
|
||||
#ifndef OPENSSL_NO_DES
|
||||
ALG("DESX-CBC:DESX", tdes_desx_cbc_functions),
|
||||
ALG("DES-ECB", des_ecb_functions),
|
||||
ALG("DES-CBC:DES", des_cbc_functions),
|
||||
ALG("DES-OFB", des_ofb64_functions),
|
||||
ALG("DES-CFB", des_cfb64_functions),
|
||||
ALG("DES-CFB1", des_cfb1_functions),
|
||||
ALG("DES-CFB8", des_cfb8_functions),
|
||||
#endif /* OPENSSL_NO_DES */
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -86,6 +141,8 @@ static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov,
|
||||
switch (operation_id) {
|
||||
case OSSL_OP_DIGEST:
|
||||
return legacy_digests;
|
||||
case OSSL_OP_CIPHER:
|
||||
return legacy_ciphers;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 <string.h>
|
||||
#include <stdio.h>
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include "prov/implementations.h"
|
||||
|
||||
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 },
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
|
||||
{ OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const OSSL_ITEM *null_gettable_params(const OSSL_PROVIDER *prov)
|
||||
{
|
||||
return null_param_types;
|
||||
}
|
||||
|
||||
static int null_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
|
||||
{
|
||||
OSSL_PARAM *p;
|
||||
|
||||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
|
||||
return 0;
|
||||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
|
||||
return 0;
|
||||
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
|
||||
if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
|
||||
int operation_id,
|
||||
int *no_cache)
|
||||
{
|
||||
*no_cache = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Functions we provide to the core */
|
||||
static const OSSL_DISPATCH null_dispatch_table[] = {
|
||||
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
int ossl_null_provider_init(const OSSL_PROVIDER *provider,
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user