mirror of https://github.com/openssl/openssl.git
skey: convert generic SKEY to use generated param parser
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/28144)
This commit is contained in:
parent
b20da23280
commit
d1d94e0fbe
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <openssl/core_dispatch.h>
|
#include <openssl/core_dispatch.h>
|
||||||
#include "crypto/types.h"
|
#include "crypto/types.h"
|
||||||
#include "skeymgmt_lcl.h"
|
#include "prov/skeymgmt_lcl.h"
|
||||||
#include "internal/skey.h"
|
#include "internal/skey.h"
|
||||||
#include "prov/implementations.h"
|
#include "prov/implementations.h"
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,20 @@
|
||||||
* in the file LICENSE in the source distribution or at
|
* in the file LICENSE in the source distribution or at
|
||||||
* https://www.openssl.org/source/license.html
|
* https://www.openssl.org/source/license.html
|
||||||
*/
|
*/
|
||||||
|
{-
|
||||||
|
use OpenSSL::paramnames qw(produce_param_decoder);
|
||||||
|
-}
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <openssl/core_dispatch.h>
|
#include <openssl/core_dispatch.h>
|
||||||
#include <openssl/core_names.h>
|
#include <openssl/core_names.h>
|
||||||
#include "crypto/types.h"
|
#include "crypto/types.h"
|
||||||
|
#include "internal/cryptlib.h"
|
||||||
#include "internal/skey.h"
|
#include "internal/skey.h"
|
||||||
#include "prov/provider_ctx.h"
|
#include "prov/provider_ctx.h"
|
||||||
#include "prov/providercommon.h"
|
#include "prov/providercommon.h"
|
||||||
#include "prov/implementations.h"
|
#include "prov/implementations.h"
|
||||||
#include "skeymgmt_lcl.h"
|
#include "prov/skeymgmt_lcl.h"
|
||||||
|
|
||||||
void generic_free(void *keydata)
|
void generic_free(void *keydata)
|
||||||
{
|
{
|
||||||
|
@ -23,14 +28,18 @@ void generic_free(void *keydata)
|
||||||
if (generic == NULL)
|
if (generic == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OPENSSL_free(generic->data);
|
OPENSSL_clear_free(generic->data, generic->length);
|
||||||
OPENSSL_free(generic);
|
OPENSSL_free(generic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- produce_param_decoder('generic_skey_import',
|
||||||
|
(['SKEY_PARAM_RAW_BYTES', 'raw_bytes', 'octet_string'],
|
||||||
|
)); -}
|
||||||
|
|
||||||
void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
|
void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx);
|
OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx);
|
||||||
const OSSL_PARAM *raw_bytes;
|
struct generic_skey_import_st p;
|
||||||
PROV_SKEY *generic = NULL;
|
PROV_SKEY *generic = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
|
@ -40,8 +49,11 @@ void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
|
||||||
if ((selection & OSSL_SKEYMGMT_SELECT_SECRET_KEY) == 0)
|
if ((selection & OSSL_SKEYMGMT_SELECT_SECRET_KEY) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
raw_bytes = OSSL_PARAM_locate_const(params, OSSL_SKEY_PARAM_RAW_BYTES);
|
if (!generic_skey_import_decoder(params, &p))
|
||||||
if (raw_bytes == NULL)
|
return NULL;
|
||||||
|
|
||||||
|
if (p.raw_bytes == NULL
|
||||||
|
|| p.raw_bytes->data_type != OSSL_PARAM_OCTET_STRING)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
generic = OPENSSL_zalloc(sizeof(PROV_SKEY));
|
generic = OPENSSL_zalloc(sizeof(PROV_SKEY));
|
||||||
|
@ -52,9 +64,10 @@ void *generic_import(void *provctx, int selection, const OSSL_PARAM params[])
|
||||||
|
|
||||||
generic->type = SKEY_TYPE_GENERIC;
|
generic->type = SKEY_TYPE_GENERIC;
|
||||||
|
|
||||||
if ((generic->data = OPENSSL_memdup(raw_bytes->data, raw_bytes->data_size)) == NULL)
|
if ((generic->data = OPENSSL_memdup(p.raw_bytes->data,
|
||||||
|
p.raw_bytes->data_size)) == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
generic->length = raw_bytes->data_size;
|
generic->length = p.raw_bytes->data_size;
|
||||||
ok = 1;
|
ok = 1;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -65,14 +78,9 @@ end:
|
||||||
return generic;
|
return generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const OSSL_PARAM generic_import_params[] = {
|
|
||||||
OSSL_PARAM_octet_string(OSSL_SKEY_PARAM_RAW_BYTES, NULL, 0),
|
|
||||||
OSSL_PARAM_END
|
|
||||||
};
|
|
||||||
|
|
||||||
const OSSL_PARAM *generic_imp_settable_params(void *provctx)
|
const OSSL_PARAM *generic_imp_settable_params(void *provctx)
|
||||||
{
|
{
|
||||||
return generic_import_params;
|
return generic_skey_import_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generic_export(void *keydata, int selection,
|
int generic_export(void *keydata, int selection,
|
Loading…
Reference in New Issue