11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci/*
111cb0ef41Sopenharmony_ci * RSA low level APIs are deprecated for public use, but still ok for
121cb0ef41Sopenharmony_ci * internal use.
131cb0ef41Sopenharmony_ci */
141cb0ef41Sopenharmony_ci#include "internal/deprecated.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include <stdio.h>
171cb0ef41Sopenharmony_ci#include "internal/cryptlib.h"
181cb0ef41Sopenharmony_ci#include <openssl/rsa.h>
191cb0ef41Sopenharmony_ci#include <openssl/evp.h>
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci#ifndef OPENSSL_NO_STDIO
221cb0ef41Sopenharmony_ciint RSA_print_fp(FILE *fp, const RSA *x, int off)
231cb0ef41Sopenharmony_ci{
241cb0ef41Sopenharmony_ci    BIO *b;
251cb0ef41Sopenharmony_ci    int ret;
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci    if ((b = BIO_new(BIO_s_file())) == NULL) {
281cb0ef41Sopenharmony_ci        ERR_raise(ERR_LIB_RSA, ERR_R_BUF_LIB);
291cb0ef41Sopenharmony_ci        return 0;
301cb0ef41Sopenharmony_ci    }
311cb0ef41Sopenharmony_ci    BIO_set_fp(b, fp, BIO_NOCLOSE);
321cb0ef41Sopenharmony_ci    ret = RSA_print(b, x, off);
331cb0ef41Sopenharmony_ci    BIO_free(b);
341cb0ef41Sopenharmony_ci    return ret;
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci#endif
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciint RSA_print(BIO *bp, const RSA *x, int off)
391cb0ef41Sopenharmony_ci{
401cb0ef41Sopenharmony_ci    EVP_PKEY *pk;
411cb0ef41Sopenharmony_ci    int ret;
421cb0ef41Sopenharmony_ci    pk = EVP_PKEY_new();
431cb0ef41Sopenharmony_ci    if (pk == NULL)
441cb0ef41Sopenharmony_ci        return 0;
451cb0ef41Sopenharmony_ci    ret = EVP_PKEY_set1_RSA(pk, (RSA *)x);
461cb0ef41Sopenharmony_ci    if (ret)
471cb0ef41Sopenharmony_ci        ret = EVP_PKEY_print_private(bp, pk, off, NULL);
481cb0ef41Sopenharmony_ci    EVP_PKEY_free(pk);
491cb0ef41Sopenharmony_ci    return ret;
501cb0ef41Sopenharmony_ci}
51