rsa_prn.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * RSA low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <stdio.h>
  15. #include "internal/cryptlib.h"
  16. #include <openssl/rsa.h>
  17. #include <openssl/evp.h>
  18. #ifndef OPENSSL_NO_STDIO
  19. int RSA_print_fp(FILE *fp, const RSA *x, int off)
  20. {
  21. BIO *b;
  22. int ret;
  23. if ((b = BIO_new(BIO_s_file())) == NULL) {
  24. ERR_raise(ERR_LIB_RSA, ERR_R_BUF_LIB);
  25. return 0;
  26. }
  27. BIO_set_fp(b, fp, BIO_NOCLOSE);
  28. ret = RSA_print(b, x, off);
  29. BIO_free(b);
  30. return ret;
  31. }
  32. #endif
  33. int RSA_print(BIO *bp, const RSA *x, int off)
  34. {
  35. EVP_PKEY *pk;
  36. int ret;
  37. pk = EVP_PKEY_new();
  38. if (pk == NULL || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
  39. return 0;
  40. ret = EVP_PKEY_print_private(bp, pk, off, NULL);
  41. EVP_PKEY_free(pk);
  42. return ret;
  43. }