dsa_prn.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * 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 || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
  52. return 0;
  53. ret = EVP_PKEY_print_private(bp, pk, off, NULL);
  54. EVP_PKEY_free(pk);
  55. return ret;
  56. }
  57. int DSAparams_print(BIO *bp, const DSA *x)
  58. {
  59. EVP_PKEY *pk;
  60. int ret;
  61. pk = EVP_PKEY_new();
  62. if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
  63. return 0;
  64. ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
  65. EVP_PKEY_free(pk);
  66. return ret;
  67. }