dsa_prn.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2006-2021 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/evp.h>
  12. #include <openssl/dsa.h>
  13. #ifndef OPENSSL_NO_STDIO
  14. int DSA_print_fp(FILE *fp, const DSA *x, int off)
  15. {
  16. BIO *b;
  17. int ret;
  18. if ((b = BIO_new(BIO_s_file())) == NULL) {
  19. DSAerr(DSA_F_DSA_PRINT_FP, ERR_R_BUF_LIB);
  20. return 0;
  21. }
  22. BIO_set_fp(b, fp, BIO_NOCLOSE);
  23. ret = DSA_print(b, x, off);
  24. BIO_free(b);
  25. return ret;
  26. }
  27. int DSAparams_print_fp(FILE *fp, const DSA *x)
  28. {
  29. BIO *b;
  30. int ret;
  31. if ((b = BIO_new(BIO_s_file())) == NULL) {
  32. DSAerr(DSA_F_DSAPARAMS_PRINT_FP, ERR_R_BUF_LIB);
  33. return 0;
  34. }
  35. BIO_set_fp(b, fp, BIO_NOCLOSE);
  36. ret = DSAparams_print(b, x);
  37. BIO_free(b);
  38. return ret;
  39. }
  40. #endif
  41. int DSA_print(BIO *bp, const DSA *x, int off)
  42. {
  43. EVP_PKEY *pk;
  44. int ret;
  45. pk = EVP_PKEY_new();
  46. if (pk == NULL)
  47. return 0;
  48. ret = EVP_PKEY_set1_DSA(pk, (DSA *)x);
  49. if (ret)
  50. ret = EVP_PKEY_print_private(bp, pk, off, NULL);
  51. EVP_PKEY_free(pk);
  52. return ret;
  53. }
  54. int DSAparams_print(BIO *bp, const DSA *x)
  55. {
  56. EVP_PKEY *pk;
  57. int ret;
  58. pk = EVP_PKEY_new();
  59. if (pk == NULL)
  60. return 0;
  61. ret = EVP_PKEY_set1_DSA(pk, (DSA *)x);
  62. if (ret)
  63. ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
  64. EVP_PKEY_free(pk);
  65. return ret;
  66. }