2018-07-25 11:01:19 +00:00
|
|
|
/*
|
2018-08-08 16:23:11 +00:00
|
|
|
* Copyright (C) 2018 Tobias Brunner
|
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
2018-07-25 11:01:19 +00:00
|
|
|
* Copyright (C) 2018 René Korthaus
|
|
|
|
* Copyright (C) 2018 Konstantinos Kolelis
|
|
|
|
* Rohde & Schwarz Cybersecurity GmbH
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "botan_ec_private_key.h"
|
2018-08-09 11:00:50 +00:00
|
|
|
#include "botan_ec_public_key.h"
|
2018-08-06 15:46:54 +00:00
|
|
|
#include "botan_util.h"
|
2018-07-25 11:01:19 +00:00
|
|
|
|
|
|
|
#include <botan/build.h>
|
|
|
|
|
|
|
|
#ifdef BOTAN_HAS_ECDSA
|
|
|
|
|
|
|
|
#include <asn1/asn1.h>
|
|
|
|
#include <asn1/oid.h>
|
|
|
|
|
|
|
|
#include <utils/debug.h>
|
|
|
|
|
|
|
|
#include <botan/ffi.h>
|
|
|
|
|
|
|
|
typedef struct private_botan_ec_private_key_t private_botan_ec_private_key_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of a botan_ec_private_key_t object.
|
|
|
|
*/
|
|
|
|
struct private_botan_ec_private_key_t {
|
2018-08-06 15:46:54 +00:00
|
|
|
|
2018-07-25 11:01:19 +00:00
|
|
|
/**
|
2018-08-06 15:46:54 +00:00
|
|
|
* Public interface
|
2018-07-25 11:01:19 +00:00
|
|
|
*/
|
|
|
|
botan_ec_private_key_t public;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Botan ec private key
|
|
|
|
*/
|
|
|
|
botan_privkey_t key;
|
|
|
|
|
2018-08-08 16:23:11 +00:00
|
|
|
/**
|
|
|
|
* OID of the curve
|
|
|
|
*/
|
|
|
|
int oid;
|
|
|
|
|
2018-07-25 11:01:19 +00:00
|
|
|
/**
|
|
|
|
* Reference count
|
|
|
|
*/
|
|
|
|
refcount_t ref;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIG_FORMAT_IEEE_1363 0
|
|
|
|
#define SIG_FORMAT_DER_SEQUENCE 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a DER encoded signature as in RFC 3279 or as in RFC 4754
|
|
|
|
*/
|
|
|
|
static bool build_signature(botan_privkey_t key, const char *hash_and_padding,
|
|
|
|
int signature_format, chunk_t data,
|
|
|
|
chunk_t *signature)
|
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
if (!botan_get_signature(key, hash_and_padding, data, signature))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signature_format == SIG_FORMAT_DER_SEQUENCE)
|
|
|
|
{
|
|
|
|
/* format as ASN.1 sequence of two integers r,s */
|
2018-08-06 15:46:54 +00:00
|
|
|
chunk_t r = chunk_empty, s = chunk_empty;
|
|
|
|
|
2018-07-25 11:01:19 +00:00
|
|
|
chunk_split(*signature, "aa", signature->len / 2, &r,
|
2018-08-06 15:46:54 +00:00
|
|
|
signature->len / 2, &s);
|
2018-07-25 11:01:19 +00:00
|
|
|
|
|
|
|
chunk_free(signature);
|
2018-08-06 15:46:54 +00:00
|
|
|
*signature = asn1_wrap(ASN1_SEQUENCE, "mm", asn1_integer("m", r),
|
|
|
|
asn1_integer("m", s));
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, sign, bool,
|
|
|
|
private_botan_ec_private_key_t *this, signature_scheme_t scheme,
|
|
|
|
void *params, chunk_t data, chunk_t *signature)
|
|
|
|
{
|
|
|
|
switch (scheme)
|
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
/* r||s -> Botan::IEEE_1363, data is the hash already */
|
2018-07-25 11:01:19 +00:00
|
|
|
case SIGN_ECDSA_WITH_NULL:
|
|
|
|
return build_signature(this->key, "Raw",
|
2018-08-06 15:46:54 +00:00
|
|
|
SIG_FORMAT_IEEE_1363, data, signature);
|
|
|
|
/* DER SEQUENCE of two INTEGERS r,s -> Botan::DER_SEQUENCE */
|
2018-07-25 11:01:19 +00:00
|
|
|
case SIGN_ECDSA_WITH_SHA1_DER:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-1)",
|
|
|
|
SIG_FORMAT_DER_SEQUENCE, data, signature);
|
|
|
|
case SIGN_ECDSA_WITH_SHA256_DER:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-256)",
|
|
|
|
SIG_FORMAT_DER_SEQUENCE, data, signature);
|
|
|
|
case SIGN_ECDSA_WITH_SHA384_DER:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-384)",
|
|
|
|
SIG_FORMAT_DER_SEQUENCE, data, signature);
|
|
|
|
case SIGN_ECDSA_WITH_SHA512_DER:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-512)",
|
|
|
|
SIG_FORMAT_DER_SEQUENCE, data, signature);
|
2018-08-06 15:46:54 +00:00
|
|
|
/* r||s -> Botan::IEEE_1363 */
|
2018-07-25 11:01:19 +00:00
|
|
|
case SIGN_ECDSA_256:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-256)",
|
|
|
|
SIG_FORMAT_IEEE_1363, data, signature);
|
|
|
|
case SIGN_ECDSA_384:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-384)",
|
|
|
|
SIG_FORMAT_IEEE_1363, data, signature);
|
|
|
|
case SIGN_ECDSA_521:
|
|
|
|
return build_signature(this->key, "EMSA1(SHA-512)",
|
|
|
|
SIG_FORMAT_IEEE_1363, data, signature);
|
|
|
|
default:
|
|
|
|
DBG1(DBG_LIB, "signature scheme %N not supported via botan",
|
|
|
|
signature_scheme_names, scheme);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, decrypt, bool,
|
|
|
|
private_botan_ec_private_key_t *this, encryption_scheme_t scheme,
|
|
|
|
chunk_t crypto, chunk_t *plain)
|
|
|
|
{
|
|
|
|
DBG1(DBG_LIB, "EC private key decryption not implemented");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_keysize, int,
|
|
|
|
private_botan_ec_private_key_t *this)
|
|
|
|
{
|
|
|
|
botan_mp_t p;
|
2018-08-06 15:46:54 +00:00
|
|
|
size_t bits = 0;
|
2018-07-25 11:01:19 +00:00
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
if (botan_mp_init(&p))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
if (botan_privkey_get_field(p, this->key, "p") ||
|
|
|
|
botan_mp_num_bits(p, &bits))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
botan_mp_destroy(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
botan_mp_destroy(p);
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_type, key_type_t,
|
|
|
|
private_botan_ec_private_key_t *this)
|
|
|
|
{
|
|
|
|
return KEY_ECDSA;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_public_key, public_key_t*,
|
|
|
|
private_botan_ec_private_key_t *this)
|
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
botan_pubkey_t pubkey;
|
2018-07-25 11:01:19 +00:00
|
|
|
|
|
|
|
if (botan_privkey_export_pubkey(&pubkey, this->key))
|
|
|
|
{
|
2018-08-09 11:00:50 +00:00
|
|
|
return NULL;
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
2018-08-09 11:00:50 +00:00
|
|
|
return (public_key_t*)botan_ec_public_key_adopt(pubkey);
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_fingerprint, bool,
|
|
|
|
private_botan_ec_private_key_t *this, cred_encoding_type_t type,
|
|
|
|
chunk_t *fingerprint)
|
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
botan_pubkey_t pubkey;
|
2018-07-25 11:01:19 +00:00
|
|
|
bool success = FALSE;
|
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
/* check the cache before doing the export */
|
|
|
|
if (lib->encoding->get_cache(lib->encoding, type, this, fingerprint))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-07-25 11:01:19 +00:00
|
|
|
if (botan_privkey_export_pubkey(&pubkey, this->key))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-08-06 15:46:54 +00:00
|
|
|
success = botan_get_fingerprint(pubkey, this, type, fingerprint);
|
2018-07-25 11:01:19 +00:00
|
|
|
botan_pubkey_destroy(pubkey);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_encoding, bool,
|
|
|
|
private_botan_ec_private_key_t *this, cred_encoding_type_t type,
|
|
|
|
chunk_t *encoding)
|
|
|
|
{
|
2018-08-10 07:02:26 +00:00
|
|
|
return botan_get_privkey_encoding(this->key, type, encoding);
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, get_ref, private_key_t*,
|
|
|
|
private_botan_ec_private_key_t *this)
|
|
|
|
{
|
|
|
|
ref_get(&this->ref);
|
|
|
|
return &this->public.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(private_key_t, destroy, void,
|
|
|
|
private_botan_ec_private_key_t *this)
|
|
|
|
{
|
|
|
|
if (ref_put(&this->ref))
|
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
lib->encoding->clear_cache(lib->encoding, this);
|
|
|
|
botan_privkey_destroy(this->key);
|
2018-07-25 11:01:19 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal generic constructor
|
|
|
|
*/
|
2018-08-08 16:23:11 +00:00
|
|
|
static private_botan_ec_private_key_t *create_empty(int oid)
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
private_botan_ec_private_key_t *this;
|
|
|
|
|
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.key = {
|
|
|
|
.get_type = _get_type,
|
|
|
|
.sign = _sign,
|
|
|
|
.decrypt = _decrypt,
|
|
|
|
.get_keysize = _get_keysize,
|
|
|
|
.get_public_key = _get_public_key,
|
|
|
|
.equals = private_key_equals,
|
|
|
|
.belongs_to = private_key_belongs_to,
|
|
|
|
.get_fingerprint = _get_fingerprint,
|
|
|
|
.has_fingerprint = private_key_has_fingerprint,
|
|
|
|
.get_encoding = _get_encoding,
|
|
|
|
.get_ref = _get_ref,
|
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
},
|
2018-08-08 16:23:11 +00:00
|
|
|
.oid = oid,
|
2018-07-25 11:01:19 +00:00
|
|
|
.ref = 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-08-09 11:00:50 +00:00
|
|
|
/*
|
|
|
|
* Described in header
|
|
|
|
*/
|
|
|
|
botan_ec_private_key_t *botan_ec_private_key_adopt(botan_privkey_t key, int oid)
|
|
|
|
{
|
|
|
|
private_botan_ec_private_key_t *this;
|
|
|
|
|
|
|
|
this = create_empty(oid);
|
|
|
|
this->key = key;
|
|
|
|
|
|
|
|
return &this->public;
|
|
|
|
}
|
|
|
|
|
2018-07-25 11:01:19 +00:00
|
|
|
/*
|
2018-08-06 15:46:54 +00:00
|
|
|
* Described in header
|
2018-07-25 11:01:19 +00:00
|
|
|
*/
|
|
|
|
botan_ec_private_key_t *botan_ec_private_key_gen(key_type_t type, va_list args)
|
|
|
|
{
|
|
|
|
private_botan_ec_private_key_t *this;
|
2018-08-06 15:46:54 +00:00
|
|
|
botan_rng_t rng;
|
2018-07-25 11:01:19 +00:00
|
|
|
u_int key_size = 0;
|
2018-08-08 16:23:11 +00:00
|
|
|
int oid;
|
2018-08-06 15:46:54 +00:00
|
|
|
const char *curve;
|
2018-07-25 11:01:19 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
switch (va_arg(args, builder_part_t))
|
|
|
|
{
|
|
|
|
case BUILD_KEY_SIZE:
|
|
|
|
key_size = va_arg(args, u_int);
|
|
|
|
continue;
|
|
|
|
case BUILD_END:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key_size)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (key_size)
|
|
|
|
{
|
|
|
|
case 256:
|
|
|
|
curve = "secp256r1";
|
2018-08-08 16:23:11 +00:00
|
|
|
oid = OID_PRIME256V1;
|
2018-07-25 11:01:19 +00:00
|
|
|
break;
|
|
|
|
case 384:
|
|
|
|
curve = "secp384r1";
|
2018-08-08 16:23:11 +00:00
|
|
|
oid = OID_SECT384R1;
|
2018-07-25 11:01:19 +00:00
|
|
|
break;
|
|
|
|
case 521:
|
|
|
|
curve = "secp521r1";
|
2018-08-08 16:23:11 +00:00
|
|
|
oid = OID_SECT521R1;
|
2018-07-25 11:01:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBG1(DBG_LIB, "EC private key size %d not supported via botan",
|
|
|
|
key_size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-01-22 12:38:01 +00:00
|
|
|
if (!botan_get_rng(&rng, RNG_TRUE))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-08 16:23:11 +00:00
|
|
|
this = create_empty(oid);
|
2018-07-25 11:01:19 +00:00
|
|
|
|
2019-07-02 08:47:54 +00:00
|
|
|
if (botan_privkey_create(&this->key, "ECDSA", curve, rng))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
2018-08-06 15:46:54 +00:00
|
|
|
DBG1(DBG_LIB, "EC private key generation failed");
|
2018-07-25 11:01:19 +00:00
|
|
|
botan_rng_destroy(rng);
|
2018-08-06 15:46:54 +00:00
|
|
|
free(this);
|
2018-07-25 11:01:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
botan_rng_destroy(rng);
|
|
|
|
return &this->public;
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
/*
|
|
|
|
* Described in header
|
2018-07-25 11:01:19 +00:00
|
|
|
*/
|
|
|
|
botan_ec_private_key_t *botan_ec_private_key_load(key_type_t type, va_list args)
|
|
|
|
{
|
|
|
|
private_botan_ec_private_key_t *this;
|
|
|
|
chunk_t params = chunk_empty, key = chunk_empty;
|
2018-08-08 16:23:11 +00:00
|
|
|
chunk_t alg_id = chunk_empty, pkcs8 = chunk_empty;
|
2018-08-06 15:46:54 +00:00
|
|
|
botan_rng_t rng;
|
2018-08-08 16:23:11 +00:00
|
|
|
int oid = OID_UNKNOWN;
|
2018-07-25 11:01:19 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
switch (va_arg(args, builder_part_t))
|
|
|
|
{
|
|
|
|
case BUILD_BLOB_ALGID_PARAMS:
|
|
|
|
params = va_arg(args, chunk_t);
|
|
|
|
continue;
|
|
|
|
case BUILD_BLOB_ASN1_DER:
|
|
|
|
key = va_arg(args, chunk_t);
|
|
|
|
continue;
|
|
|
|
case BUILD_END:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-08-08 16:23:11 +00:00
|
|
|
* Botan expects a PKCS#8 private key, so we build one, if necessary.
|
|
|
|
* RFC 5480 mandates ECParameters as part of the algorithmIdentifier, which
|
|
|
|
* we should get from e.g. the pkcs8 plugin.
|
2018-07-25 11:01:19 +00:00
|
|
|
*/
|
2018-08-08 16:23:11 +00:00
|
|
|
if (params.len != 0 && type == KEY_ECDSA)
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
2018-08-08 16:23:11 +00:00
|
|
|
/* if ECParameters is passed, just use it */
|
2018-08-06 15:46:54 +00:00
|
|
|
alg_id = asn1_algorithmIdentifier_params(OID_EC_PUBLICKEY,
|
|
|
|
chunk_clone(params));
|
2018-08-08 16:23:11 +00:00
|
|
|
if (asn1_unwrap(¶ms, ¶ms) == ASN1_OID)
|
|
|
|
{
|
|
|
|
oid = asn1_known_oid(params);
|
|
|
|
}
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2018-08-08 16:23:11 +00:00
|
|
|
* no explicit ECParameters passed, try to extract them from the
|
|
|
|
* ECPrivateKey structure and create an algorithmIdentifier
|
2018-07-25 11:01:19 +00:00
|
|
|
*/
|
2018-08-08 16:23:11 +00:00
|
|
|
chunk_t unwrap = key, inner;
|
|
|
|
|
|
|
|
if (asn1_unwrap(&unwrap, &unwrap) == ASN1_SEQUENCE &&
|
|
|
|
asn1_unwrap(&unwrap, &inner) == ASN1_INTEGER &&
|
|
|
|
asn1_parse_integer_uint64(inner) == 1 &&
|
|
|
|
asn1_unwrap(&unwrap, &inner) == ASN1_OCTET_STRING &&
|
|
|
|
asn1_unwrap(&unwrap, &inner) == ASN1_CONTEXT_C_0 &&
|
|
|
|
asn1_unwrap(&inner, &inner) == ASN1_OID)
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
2018-08-08 16:23:11 +00:00
|
|
|
oid = asn1_known_oid(inner);
|
|
|
|
if (oid != OID_UNKNOWN)
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
2018-08-08 16:23:11 +00:00
|
|
|
alg_id = asn1_algorithmIdentifier_params(OID_EC_PUBLICKEY,
|
|
|
|
asn1_simple_object(ASN1_OID, inner));
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 16:23:11 +00:00
|
|
|
}
|
2018-07-25 11:01:19 +00:00
|
|
|
|
2018-08-08 16:23:11 +00:00
|
|
|
if (oid == OID_UNKNOWN)
|
|
|
|
{
|
|
|
|
chunk_free(&alg_id);
|
|
|
|
return NULL;
|
2018-07-25 11:01:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
pkcs8 = asn1_wrap(ASN1_SEQUENCE, "mms",
|
2018-07-25 11:01:19 +00:00
|
|
|
asn1_integer("c", chunk_from_chars(0x00)),
|
|
|
|
alg_id,
|
|
|
|
asn1_wrap(ASN1_OCTET_STRING, "c", key));
|
|
|
|
|
2018-08-08 16:23:11 +00:00
|
|
|
this = create_empty(oid);
|
2018-08-06 15:46:54 +00:00
|
|
|
|
2021-01-22 12:38:01 +00:00
|
|
|
if (!botan_get_rng(&rng, RNG_STRONG))
|
2018-07-25 11:01:19 +00:00
|
|
|
{
|
|
|
|
chunk_clear(&pkcs8);
|
2018-08-06 15:46:54 +00:00
|
|
|
free(this);
|
2018-07-25 11:01:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (botan_privkey_load(&this->key, rng, pkcs8.ptr, pkcs8.len, NULL))
|
|
|
|
{
|
|
|
|
chunk_clear(&pkcs8);
|
|
|
|
botan_rng_destroy(rng);
|
2018-08-06 15:46:54 +00:00
|
|
|
free(this);
|
2018-07-25 11:01:19 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk_clear(&pkcs8);
|
|
|
|
botan_rng_destroy(rng);
|
|
|
|
return &this->public;
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:46:54 +00:00
|
|
|
#endif
|