* https://www.openssl.org/source/license.html
*/
-#include <openssl/core_numbers.h>
+#include <openssl/core_dispatch.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_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;
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);
}
/* Public key : DER */
-static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_pub_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out,
+static int ecx_pub_der(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_pub_ctx_st *ctx = vctx;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
- return ossl_prov_write_pub_der_from_obj(out, ecxkey,
- ctx->type == ECX_KEY_TYPE_X25519
- ? EVP_PKEY_X25519 : EVP_PKEY_X448,
- NULL,
- ossl_prov_ecx_pub_to_der);
+ ret = ossl_prov_write_pub_der_from_obj(out, ecxkey,
+ KEYTYPE2NID(ctx->type),
+ NULL,
+ ossl_prov_ecx_pub_to_der);
+ BIO_free(out);
+
+ return ret;
}
/* Public key : PEM */
-static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_pub_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out,
+static int ecx_pub_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_pub_ctx_st *ctx = vctx;
+ BIO *out = bio_new_from_core_bio(ctx->provctx, cout);
+ int ret;
+
+ if (out == NULL)
+ return 0;
- return ossl_prov_write_pub_pem_from_obj(out, ecxkey,
- ctx->type == ECX_KEY_TYPE_X25519
- ? EVP_PKEY_X25519 : EVP_PKEY_X448,
- NULL,
- ossl_prov_ecx_pub_to_der);
+ ret = ossl_prov_write_pub_pem_from_obj(out, ecxkey,
+ KEYTYPE2NID(ctx->type),
+ NULL,
+ ossl_prov_ecx_pub_to_der);
+ BIO_free(out);
+ return ret;
}
-static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out,
+static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[],
+ OSSL_CORE_BIO *out,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
struct ecx_pub_ctx_st *ctx = vctx;
return ok;
}
-static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out,
+static int ecx_pub_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout,
OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
{
- return ossl_prov_print_ecx(out, ecxkey, ecx_print_pub);
+ struct ecx_pub_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_pub);
+ 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)