2
0

dsa_prn.c 1.7 KB

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