dsa.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* dsa.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/dsa.h
  23. */
  24. #ifndef WOLF_CRYPT_DSA_H
  25. #define WOLF_CRYPT_DSA_H
  26. #include <wolfssl/wolfcrypt/types.h>
  27. #ifndef NO_DSA
  28. #include <wolfssl/wolfcrypt/integer.h>
  29. #include <wolfssl/wolfcrypt/random.h>
  30. /* for DSA reverse compatibility */
  31. #define InitDsaKey wc_InitDsaKey
  32. #define FreeDsaKey wc_FreeDsaKey
  33. #define DsaSign wc_DsaSign
  34. #define DsaVerify wc_DsaVerify
  35. #define DsaPublicKeyDecode wc_DsaPublicKeyDecode
  36. #define DsaPrivateKeyDecode wc_DsaPrivateKeyDecode
  37. #define DsaKeyToDer wc_DsaKeyToDer
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. enum {
  42. DSA_PUBLIC = 0,
  43. DSA_PRIVATE = 1
  44. };
  45. enum {
  46. /* 160 bit q length */
  47. DSA_160_HALF_SIZE = 20, /* r and s size */
  48. DSA_160_SIG_SIZE = 40, /* signature size */
  49. DSA_HALF_SIZE = DSA_160_HALF_SIZE, /* kept for compatiblity */
  50. DSA_SIG_SIZE = DSA_160_SIG_SIZE, /* kept for compatiblity */
  51. /* 256 bit q length */
  52. DSA_256_HALF_SIZE = 32, /* r and s size */
  53. DSA_256_SIG_SIZE = 64, /* signature size */
  54. DSA_MIN_HALF_SIZE = DSA_160_HALF_SIZE,
  55. DSA_MIN_SIG_SIZE = DSA_160_SIG_SIZE,
  56. DSA_MAX_HALF_SIZE = DSA_256_HALF_SIZE,
  57. DSA_MAX_SIG_SIZE = DSA_256_SIG_SIZE,
  58. };
  59. /* DSA */
  60. typedef struct DsaKey {
  61. mp_int p, q, g, y, x;
  62. int type; /* public or private */
  63. void* heap; /* memory hint */
  64. } DsaKey;
  65. WOLFSSL_API int wc_InitDsaKey(DsaKey* key);
  66. WOLFSSL_API int wc_InitDsaKey_h(DsaKey* key, void* h);
  67. WOLFSSL_API void wc_FreeDsaKey(DsaKey* key);
  68. WOLFSSL_API int wc_DsaSign(const byte* digest, byte* out,
  69. DsaKey* key, WC_RNG* rng);
  70. WOLFSSL_API int wc_DsaVerify(const byte* digest, const byte* sig,
  71. DsaKey* key, int* answer);
  72. WOLFSSL_API int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx,
  73. DsaKey* key, word32 inSz);
  74. WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
  75. DsaKey* key, word32 inSz);
  76. WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
  77. WOLFSSL_API int wc_SetDsaPublicKey(byte* output, DsaKey* key,
  78. int outLen, int with_header);
  79. WOLFSSL_API int wc_DsaKeyToPublicDer(DsaKey* key, byte* output, word32 inLen);
  80. #ifdef WOLFSSL_KEY_GEN
  81. WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
  82. WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);
  83. #endif
  84. /* raw export functions */
  85. WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p,
  86. const char* q, const char* g);
  87. WOLFSSL_API int wc_DsaImportParamsRawCheck(DsaKey* dsa, const char* p,
  88. const char* q, const char* g,
  89. int trusted, WC_RNG* rng);
  90. WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz,
  91. byte* q, word32* qSz, byte* g,
  92. word32* gSz);
  93. WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y,
  94. word32* ySz);
  95. #ifdef __cplusplus
  96. } /* extern "C" */
  97. #endif
  98. #endif /* NO_DSA */
  99. #endif /* WOLF_CRYPT_DSA_H */