rsa_prn.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/rsa.h>
  12. #include <openssl/evp.h>
  13. #ifndef OPENSSL_NO_STDIO
  14. int RSA_print_fp(FILE *fp, const RSA *x, int off)
  15. {
  16. BIO *b;
  17. int ret;
  18. if ((b = BIO_new(BIO_s_file())) == NULL) {
  19. RSAerr(RSA_F_RSA_PRINT_FP, ERR_R_BUF_LIB);
  20. return 0;
  21. }
  22. BIO_set_fp(b, fp, BIO_NOCLOSE);
  23. ret = RSA_print(b, x, off);
  24. BIO_free(b);
  25. return ret;
  26. }
  27. #endif
  28. int RSA_print(BIO *bp, const RSA *x, int off)
  29. {
  30. EVP_PKEY *pk;
  31. int ret;
  32. pk = EVP_PKEY_new();
  33. if (pk == NULL || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
  34. return 0;
  35. ret = EVP_PKEY_print_private(bp, pk, off, NULL);
  36. EVP_PKEY_free(pk);
  37. return ret;
  38. }