* https://www.openssl.org/source/license.html
*/
-#include <openssl/core_numbers.h>
+#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
#include <openssl/err.h>
#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 "prov/provider_ctx.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;
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;
}
/* Private key : DER */
-static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_priv_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out,
+static int ecx_priv_der(void *vctx, void *vecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_priv_ctx_st *ctx = vctx;
ECX_KEY *ecxkey = vecxkey;
int ret;
- int type = (ctx->type == ECX_KEY_TYPE_X25519) ? EVP_PKEY_X25519
- : EVP_PKEY_X448;
+ int nid = KEYTYPE2NID(ctx->type);
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
ret = ossl_prov_write_priv_der_from_obj(out, ecxkey,
- type,
+ nid,
NULL,
ossl_prov_ecx_priv_to_der,
&ctx->sc);
+ BIO_free(out);
return ret;
}
/* Private key : PEM */
-static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_priv_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out,
+static int ecx_priv_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_priv_ctx_st *ctx = vctx;
int ret;
- int type = (ctx->type == ECX_KEY_TYPE_X25519) ? EVP_PKEY_X25519
- : EVP_PKEY_X448;
+ int nid = KEYTYPE2NID(ctx->type);
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+
+ if (out == NULL)
+ return 0;
ctx->sc.cb = cb;
ctx->sc.cbarg = cbarg;
ret = ossl_prov_write_priv_pem_from_obj(out, ecxkey,
- type,
+ nid,
NULL,
ossl_prov_ecx_priv_to_der,
&ctx->sc);
+ BIO_free(out);
return ret;
}
-static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_priv_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out,
+static int ecx_priv_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
+ struct ecx_priv_ctx_st *ctx = vctx;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
+
+ ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_priv);
+ BIO_free(out);
+
+ return ret;
}
#define MAKE_SERIALIZER_FUNCTIONS(alg, type) \
MAKE_SERIALIZER_FUNCTIONS_GROUP(x25519)
MAKE_SERIALIZER_FUNCTIONS_GROUP(x448)
+MAKE_SERIALIZER_FUNCTIONS_GROUP(ed25519)
+MAKE_SERIALIZER_FUNCTIONS_GROUP(ed448)