Latest update.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
$COMMON=dsa_sign.c dsa_vrf.c dsa_lib.c dsa_ossl.c dsa_aid.c dsa_check.c \
|
||||
dsa_key.c
|
||||
$COMMON=dsa_sign.c dsa_vrf.c dsa_lib.c dsa_ossl.c dsa_check.c \
|
||||
dsa_key.c dsa_backend.c
|
||||
|
||||
SOURCE[../../libcrypto]=$COMMON\
|
||||
dsa_gen.c dsa_asn1.c \
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/objects.h>
|
||||
#include "crypto/dsa.h"
|
||||
|
||||
#define ASN1_SEQUENCE 0x30
|
||||
#define ASN1_OID 0x06
|
||||
|
||||
/*
|
||||
* id-dsa-with-sha1 OBJECT IDENTIFIER ::= {
|
||||
* iso(1) member-body(2) us(840) x9-57(10040) x9cm(4) 3
|
||||
* }
|
||||
*/
|
||||
#define ENCODE_ALGORITHMIDENTIFIER_RFC3279(name, n) \
|
||||
static const unsigned char algorithmidentifier_##name##_der[] = { \
|
||||
ASN1_SEQUENCE, 0x09, \
|
||||
ASN1_OID, 0x07, 1 * 40 + 2, 134, 72, 206, 56, 4, n \
|
||||
}
|
||||
|
||||
ENCODE_ALGORITHMIDENTIFIER_RFC3279(sha1, 3);
|
||||
|
||||
/*
|
||||
* dsaWithSHAx OIDs are of the form: (sigAlgs |n|)
|
||||
* where sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
|
||||
*/
|
||||
#define ENCODE_ALGORITHMIDENTIFIER_SIGALGS(name, n) \
|
||||
static const unsigned char algorithmidentifier_##name##_der[] = { \
|
||||
ASN1_SEQUENCE, 0x0b, \
|
||||
ASN1_OID, 0x09, 2 * 40 + 16, 0x86, 0x48, 1, 101, 3, 4, 3, n \
|
||||
}
|
||||
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha224, 1);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha256, 2);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha384, 3);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha512, 4);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_224, 5);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_256, 6);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_384, 7);
|
||||
ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_512, 8);
|
||||
|
||||
#define MD_CASE(name) \
|
||||
case NID_##name: \
|
||||
*len = sizeof(algorithmidentifier_##name##_der); \
|
||||
return algorithmidentifier_##name##_der
|
||||
|
||||
const unsigned char *dsa_algorithmidentifier_encoding(int md_nid, size_t *len)
|
||||
{
|
||||
switch (md_nid) {
|
||||
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 NULL;
|
||||
}
|
||||
}
|
||||
+59
-20
@@ -21,8 +21,10 @@
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "internal/param_build.h"
|
||||
#include "openssl/param_build.h"
|
||||
#include "internal/ffc.h"
|
||||
#include "dsa_local.h"
|
||||
|
||||
static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
@@ -518,45 +520,81 @@ static size_t dsa_pkey_dirty_cnt(const EVP_PKEY *pkey)
|
||||
}
|
||||
|
||||
static int dsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
|
||||
EVP_KEYMGMT *to_keymgmt)
|
||||
EVP_KEYMGMT *to_keymgmt, OPENSSL_CTX *libctx,
|
||||
const char *propq)
|
||||
{
|
||||
DSA *dsa = from->pkey.dsa;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
OSSL_PARAM_BLD *tmpl;
|
||||
const BIGNUM *p = DSA_get0_p(dsa), *g = DSA_get0_g(dsa);
|
||||
const BIGNUM *q = DSA_get0_q(dsa), *pub_key = DSA_get0_pub_key(dsa);
|
||||
const BIGNUM *priv_key = DSA_get0_priv_key(dsa);
|
||||
OSSL_PARAM *params;
|
||||
int rv;
|
||||
int selection = 0;
|
||||
int rv = 0;
|
||||
|
||||
/*
|
||||
* If the DSA method is foreign, then we can't be sure of anything, and
|
||||
* can therefore not export or pretend to export.
|
||||
*/
|
||||
if (DSA_get_method(dsa) != DSA_OpenSSL())
|
||||
return 0;
|
||||
|
||||
if (p == NULL || q == NULL || g == NULL)
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_G, g))
|
||||
return 0;
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_PUB_KEY,
|
||||
pub_key))
|
||||
tmpl = OSSL_PARAM_BLD_new();
|
||||
if (tmpl == NULL)
|
||||
return 0;
|
||||
|
||||
if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_Q, q)
|
||||
|| !OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_FFC_G, g))
|
||||
goto err;
|
||||
selection |= OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS;
|
||||
if (pub_key != NULL) {
|
||||
if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PUB_KEY,
|
||||
pub_key))
|
||||
goto err;
|
||||
selection |= OSSL_KEYMGMT_SELECT_PUBLIC_KEY;
|
||||
}
|
||||
if (priv_key != NULL) {
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_PRIV_KEY,
|
||||
priv_key))
|
||||
return 0;
|
||||
goto err;
|
||||
selection |= OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
|
||||
}
|
||||
|
||||
if ((params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
if ((params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
|
||||
goto err;
|
||||
|
||||
/* We export, the provider imports */
|
||||
rv = evp_keymgmt_import(to_keymgmt, to_keydata, OSSL_KEYMGMT_SELECT_ALL,
|
||||
params);
|
||||
|
||||
ossl_param_bld_free(params);
|
||||
rv = evp_keymgmt_import(to_keymgmt, to_keydata, selection, params);
|
||||
|
||||
OSSL_PARAM_BLD_free_params(params);
|
||||
err:
|
||||
OSSL_PARAM_BLD_free(tmpl);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int dsa_pkey_import_from(const OSSL_PARAM params[], void *key)
|
||||
{
|
||||
EVP_PKEY *pkey = key;
|
||||
DSA *dsa = DSA_new();
|
||||
|
||||
if (dsa == NULL) {
|
||||
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ffc_fromdata(dsa_get0_params(dsa), params)
|
||||
|| !dsa_key_fromdata(dsa, params)
|
||||
|| !EVP_PKEY_assign_DSA(pkey, dsa)) {
|
||||
DSA_free(dsa);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* NB these are sorted in pkey_id order, lowest first */
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5] = {
|
||||
@@ -620,6 +658,7 @@ const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5] = {
|
||||
NULL, NULL, NULL, NULL,
|
||||
|
||||
dsa_pkey_dirty_cnt,
|
||||
dsa_pkey_export_to
|
||||
dsa_pkey_export_to,
|
||||
dsa_pkey_import_from
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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/core_names.h>
|
||||
#include "crypto/dsa.h"
|
||||
|
||||
/*
|
||||
* The intention with the "backend" source file is to offer backend support
|
||||
* for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider
|
||||
* implementations alike.
|
||||
*/
|
||||
|
||||
int dsa_key_fromdata(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;
|
||||
|
||||
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);
|
||||
|
||||
/* It's ok if neither half is present */
|
||||
if (param_priv_key == NULL && param_pub_key == NULL)
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* DH documentation says that a public key must be present if a
|
||||
* private key is present.
|
||||
*/
|
||||
if (param_priv_key != NULL && param_pub_key == NULL)
|
||||
return 0;
|
||||
|
||||
if (param_pub_key != NULL && !OSSL_PARAM_get_BN(param_pub_key, &pub_key))
|
||||
goto err;
|
||||
if (param_priv_key != NULL && !OSSL_PARAM_get_BN(param_priv_key, &priv_key))
|
||||
goto err;
|
||||
|
||||
if (!DSA_set0_key(dsa, pub_key, priv_key))
|
||||
goto err;
|
||||
|
||||
return 1;
|
||||
|
||||
err:
|
||||
BN_clear_free(priv_key);
|
||||
BN_free(pub_key);
|
||||
return 0;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ int DSA_set_ex_data(DSA *d, int idx, void *arg)
|
||||
return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
|
||||
}
|
||||
|
||||
void *DSA_get_ex_data(DSA *d, int idx)
|
||||
void *DSA_get_ex_data(const DSA *d, int idx)
|
||||
{
|
||||
return CRYPTO_get_ex_data(&d->ex_data, idx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user