Rename <openssl/core_numbers.h> -> <openssl/core_dispatch.h>
[oweals/openssl.git] / providers / implementations / serializers / serializer_rsa_pub.c
index 3ee0501ee1ca32d95dda44e2dd479c120ee452ad..d5da6df80515402e359eba13f6a869dc39ce504c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-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
@@ -13,7 +13,7 @@
  */
 #include "internal/deprecated.h"
 
-#include <openssl/core_numbers.h>
+#include <openssl/core_dispatch.h>
 #include <openssl/pem.h>
 #include <openssl/rsa.h>
 #include <openssl/types.h>
@@ -21,6 +21,7 @@
 #include "prov/bio.h"
 #include "prov/implementations.h"
 #include "prov/providercommonerr.h"
+#include "prov/provider_ctx.h"
 #include "serializer_local.h"
 
 static OSSL_OP_serializer_newctx_fn rsa_pub_newctx;
@@ -48,7 +49,8 @@ static void rsa_pub_freectx(void *ctx)
 }
 
 /* Public key : DER */
-static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[],
+                            OSSL_CORE_BIO *out,
                             OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
     OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
@@ -69,14 +71,27 @@ static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out,
     return ok;
 }
 
-static int rsa_pub_der(void *ctx, void *rsa, BIO *out,
+static int rsa_pub_der(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
                        OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
-    return i2d_RSA_PUBKEY_bio(out, rsa);
+    BIO *out = bio_new_from_core_bio(ctx, cout);
+    int ret;
+
+    if (out == NULL)
+        return 0;
+
+    ret = ossl_prov_write_pub_der_from_obj(out, rsa,
+                                           ossl_prov_rsa_type_to_evp(rsa),
+                                           ossl_prov_prepare_rsa_params,
+                                           (i2d_of_void *)i2d_RSAPublicKey);
+    BIO_free(out);
+
+    return ret;
 }
 
 /* Public key : PEM */
-static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[],
+                            OSSL_CORE_BIO *out,
                             OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
     OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
@@ -97,13 +112,26 @@ static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out,
     return ok;
 }
 
-static int rsa_pub_pem(void *ctx, void *rsa, BIO *out,
+static int rsa_pub_pem(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
                        OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
-    return PEM_write_bio_RSA_PUBKEY(out, rsa);
+    BIO *out = bio_new_from_core_bio(ctx, cout);
+    int ret;
+
+    if (out == NULL)
+        return 0;
+
+    ret = ossl_prov_write_pub_pem_from_obj(out, rsa,
+                                           ossl_prov_rsa_type_to_evp(rsa),
+                                           ossl_prov_prepare_rsa_params,
+                                           (i2d_of_void *)i2d_RSAPublicKey);
+    BIO_free(out);
+
+    return ret;
 }
 
-static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
+static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[],
+                              OSSL_CORE_BIO *out,
                               OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
     OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new();
@@ -124,10 +152,19 @@ static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out,
     return ok;
 }
 
-static int rsa_pub_print(void *ctx, void *rsa, BIO *out,
+static int rsa_pub_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout,
                          OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)
 {
-    return ossl_prov_print_rsa(out, rsa, 0);
+    BIO *out = bio_new_from_core_bio(ctx, cout);
+    int ret;
+
+    if (out == NULL)
+        return 0;
+
+    ret = ossl_prov_print_rsa(out, rsa, 0);
+    BIO_free(out);
+
+    return ret;
 }
 
 const OSSL_DISPATCH rsa_pub_der_serializer_functions[] = {