dsa_asn1.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 1999-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 "dsa_local.h"
  17. #include <openssl/asn1.h>
  18. #include <openssl/asn1t.h>
  19. #include <openssl/rand.h>
  20. #include "crypto/asn1_dsa.h"
  21. /* Override the default free and new methods */
  22. static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
  23. void *exarg)
  24. {
  25. if (operation == ASN1_OP_NEW_PRE) {
  26. *pval = (ASN1_VALUE *)DSA_new();
  27. if (*pval != NULL)
  28. return 2;
  29. return 0;
  30. } else if (operation == ASN1_OP_FREE_PRE) {
  31. DSA_free((DSA *)*pval);
  32. *pval = NULL;
  33. return 2;
  34. }
  35. return 1;
  36. }
  37. ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
  38. ASN1_EMBED(DSA, version, INT32),
  39. ASN1_SIMPLE(DSA, params.p, BIGNUM),
  40. ASN1_SIMPLE(DSA, params.q, BIGNUM),
  41. ASN1_SIMPLE(DSA, params.g, BIGNUM),
  42. ASN1_SIMPLE(DSA, pub_key, BIGNUM),
  43. ASN1_SIMPLE(DSA, priv_key, CBIGNUM)
  44. } static_ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
  45. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPrivateKey, DSAPrivateKey)
  46. ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
  47. ASN1_SIMPLE(DSA, params.p, BIGNUM),
  48. ASN1_SIMPLE(DSA, params.q, BIGNUM),
  49. ASN1_SIMPLE(DSA, params.g, BIGNUM),
  50. } static_ASN1_SEQUENCE_END_cb(DSA, DSAparams)
  51. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAparams, DSAparams)
  52. ASN1_SEQUENCE_cb(DSAPublicKey, dsa_cb) = {
  53. ASN1_SIMPLE(DSA, pub_key, BIGNUM),
  54. ASN1_SIMPLE(DSA, params.p, BIGNUM),
  55. ASN1_SIMPLE(DSA, params.q, BIGNUM),
  56. ASN1_SIMPLE(DSA, params.g, BIGNUM)
  57. } static_ASN1_SEQUENCE_END_cb(DSA, DSAPublicKey)
  58. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(DSA, DSAPublicKey, DSAPublicKey)
  59. DSA *DSAparams_dup(const DSA *dsa)
  60. {
  61. return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
  62. }