xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/crypto/rsa/rsa_prn.c (revision 4724848cf0da353df257f730694b7882798e5daf)
1c9496f6bSchristos /*
2*4724848cSchristos  * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
3c9496f6bSchristos  *
4*4724848cSchristos  * Licensed under the OpenSSL license (the "License").  You may not use
5*4724848cSchristos  * this file except in compliance with the License.  You can obtain a copy
6*4724848cSchristos  * in the file LICENSE in the source distribution or at
7*4724848cSchristos  * https://www.openssl.org/source/license.html
8c9496f6bSchristos  */
9c9496f6bSchristos 
10c9496f6bSchristos #include <stdio.h>
11*4724848cSchristos #include "internal/cryptlib.h"
12c9496f6bSchristos #include <openssl/rsa.h>
13c9496f6bSchristos #include <openssl/evp.h>
14c9496f6bSchristos 
15*4724848cSchristos #ifndef OPENSSL_NO_STDIO
RSA_print_fp(FILE * fp,const RSA * x,int off)16c9496f6bSchristos int RSA_print_fp(FILE *fp, const RSA *x, int off)
17c9496f6bSchristos {
18c9496f6bSchristos     BIO *b;
19c9496f6bSchristos     int ret;
20c9496f6bSchristos 
21c9496f6bSchristos     if ((b = BIO_new(BIO_s_file())) == NULL) {
22c9496f6bSchristos         RSAerr(RSA_F_RSA_PRINT_FP, ERR_R_BUF_LIB);
23*4724848cSchristos         return 0;
24c9496f6bSchristos     }
25c9496f6bSchristos     BIO_set_fp(b, fp, BIO_NOCLOSE);
26c9496f6bSchristos     ret = RSA_print(b, x, off);
27c9496f6bSchristos     BIO_free(b);
28*4724848cSchristos     return ret;
29c9496f6bSchristos }
30c9496f6bSchristos #endif
31c9496f6bSchristos 
RSA_print(BIO * bp,const RSA * x,int off)32c9496f6bSchristos int RSA_print(BIO *bp, const RSA *x, int off)
33c9496f6bSchristos {
34c9496f6bSchristos     EVP_PKEY *pk;
35c9496f6bSchristos     int ret;
36c9496f6bSchristos     pk = EVP_PKEY_new();
37*4724848cSchristos     if (pk == NULL)
38c9496f6bSchristos         return 0;
39*4724848cSchristos     ret = EVP_PKEY_set1_RSA(pk, (RSA *)x);
40*4724848cSchristos     if (ret)
41c9496f6bSchristos         ret = EVP_PKEY_print_private(bp, pk, off, NULL);
42c9496f6bSchristos     EVP_PKEY_free(pk);
43c9496f6bSchristos     return ret;
44c9496f6bSchristos }
45