dsa_prn.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2006-2016 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 || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
  47. return 0;
  48. ret = EVP_PKEY_print_private(bp, pk, off, NULL);
  49. EVP_PKEY_free(pk);
  50. return ret;
  51. }
  52. int DSAparams_print(BIO *bp, const DSA *x)
  53. {
  54. EVP_PKEY *pk;
  55. int ret;
  56. pk = EVP_PKEY_new();
  57. if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
  58. return 0;
  59. ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
  60. EVP_PKEY_free(pk);
  61. return ret;
  62. }