dsa_asn1.c 2.0 KB

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