Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.8 KiB

  1. #ifndef __CRYPTDSA_
  2. #define __CRYPTDSA_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define SHA_BITS 160
  7. // Number of bits output by SHA
  8. #define SHA_DWORDS 5
  9. // Number of DWORDS output by SHA
  10. #define DSA_Q_MINDWORDS 5
  11. // Minimum number of DWORDS in q
  12. #define DSA_Q_MAXDWORDS 128
  13. // Maximum number of DWORDS in q
  14. #define DSA_P_MINDWORDS 16
  15. // Minimum number of DWORDS in p
  16. #define DSA_P_MAXDWORDS 128
  17. // Maximum number of DWORDS in p
  18. #define DSA_Q_MAXDIGITS DWORDS_TO_DIGITS(DSA_Q_MAXDWORDS)
  19. #define DSA_P_MAXDIGITS DWORDS_TO_DIGITS(DSA_P_MAXDWORDS)
  20. typedef struct {
  21. void *pInfo;
  22. void *pFuncRNG;
  23. } RNGINFO;
  24. typedef struct {
  25. DWORD nbitp; // Number of significant bits in p.
  26. // (Multiple of 64, 512 <= nbitp <= 1024)
  27. DWORD nbitq; // Number of significant bits in q.
  28. // Must be exactly 160.
  29. DWORD p[DSA_P_MAXDWORDS];// Public prime p, 512-1024 bits
  30. DWORD q[DSA_Q_MAXDWORDS];// Public prime q (160 bits, divides p-1)
  31. DWORD g[DSA_P_MAXDWORDS];// Public generator g of order q (mod p)
  32. DWORD j[DSA_P_MAXDWORDS];// j = (p - 1) / q
  33. DWORD y[DSA_P_MAXDWORDS];// Public value g^x (mod p), where x is private
  34. DWORD S[SHA_DWORDS]; // 160-bit pattern used to construct q
  35. DWORD C; // 12-bit value of C used to construct p
  36. } dsa_public_t;
  37. typedef struct {
  38. digit_t qdigit[DSA_Q_MAXDIGITS];
  39. DWORD lngq_digits; // Length of q in digits
  40. reciprocal_1_t qrecip; // Information about 1/q
  41. digit_t gmodular[DSA_P_MAXDIGITS];
  42. // g as residue mod p
  43. digit_t ymodular[DSA_P_MAXDIGITS];
  44. // y as residue mod p
  45. mp_modulus_t pmodulus; // Constants mod p
  46. } dsa_precomputed_t;
  47. typedef struct {
  48. dsa_public_t pub; // Public data
  49. DWORD x[DSA_P_MAXDWORDS];// Private exponent x (mod q)
  50. dsa_precomputed_t precomputed; // Precomputed public data
  51. } dsa_private_t;
  52. typedef struct {
  53. DWORD r[SHA_DWORDS]; // (g^k mod p) mod q
  54. DWORD s[SHA_DWORDS]; // (SHA(m) + x*r)/k mod q
  55. } dsa_signature_t;
  56. typedef struct {
  57. VOID *pOffload; // pointer to expo offload info
  58. FARPROC pFuncExpoOffload;
  59. RNGINFO *pRNGInfo; // pointer to RNG info
  60. } dsa_other_info;
  61. typedef const dsa_precomputed_t dsa_precomputed_tc;
  62. typedef const dsa_private_t dsa_private_tc;
  63. typedef const dsa_public_t dsa_public_tc;
  64. typedef const dsa_signature_t dsa_signature_tc;
  65. void DSA_gen_x(DWORDC cXDigits, // In
  66. DWORDC cXDwords, // In
  67. digit_t *pMod, // In
  68. dsa_other_info *pOtherInfo, // In
  69. DWORD *pdwX, // Out
  70. digit_t *pXDigit); // Out
  71. BOOL DSA_gen_x_and_y(BOOL fUseQ, // In
  72. dsa_other_info *pOtherInfo, // In
  73. dsa_private_t *privkey); // Out
  74. BOOL DSA_check_g(DWORDC lngp_digits, // In
  75. digit_tc *pGModular, // In
  76. mp_modulus_t *pPModulo, // In
  77. DWORDC lngq_digits, // In
  78. digit_tc *pQDigit); // In
  79. BOOL DSA_key_generation(DWORDC nbitp, // In
  80. DWORDC nbitq, // In
  81. dsa_other_info *pOtherInfo, // In
  82. dsa_private_t *privkey); // Out
  83. BOOL DSA_key_import_fillin(dsa_private_t *privkey); // In, Out
  84. BOOL DSA_precompute_pgy(dsa_public_tc *pubkey, // In
  85. dsa_precomputed_t *precomputed); // Out
  86. BOOL DSA_precompute(dsa_public_tc *pubkey, // In
  87. dsa_precomputed_t *precomputed, // Out
  88. const BOOL checkSC); // In
  89. BOOL DSA_sign(DWORDC message_hash[SHA_DWORDS], /* TBD */
  90. dsa_private_tc *privkey,
  91. dsa_signature_t *signature,
  92. dsa_other_info *pOtherInfo);
  93. BOOL DSA_signature_verification(DWORDC message_hash[SHA_DWORDS],
  94. dsa_public_tc *pubkey,
  95. dsa_precomputed_tc *precomputed_argument,
  96. dsa_signature_tc *signature,
  97. dsa_other_info *pOtherInfo);
  98. BOOL DSA_parameter_verification(
  99. dsa_public_tc *pPubkey,
  100. dsa_precomputed_tc *pPrecomputed
  101. );
  102. BOOL DSA_verify_j(
  103. dsa_public_tc *pPubkey,
  104. dsa_precomputed_tc *pPrecomputed
  105. );
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif __CRYPTDSA_