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.

203 lines
4.4 KiB

  1. #include <bignum.h>
  2. #include "cryptdsa.h"
  3. #include <crtdbg.h>
  4. inline void WINAPI BN_ResetError(void)
  5. {
  6. SetMpErrno(MP_ERRNO_NO_ERROR);
  7. }
  8. inline DWORD WINAPI BN_MapError(BOOL fSts)
  9. {
  10. DWORD dwRet = ERROR_INTERNAL_ERROR;
  11. if (fSts)
  12. dwRet = ERROR_SUCCESS;
  13. else if (MP_ERRNO_NO_MEMORY == GetMpErrno())
  14. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  15. else
  16. dwRet = (DWORD)NTE_FAIL;
  17. return dwRet;
  18. }
  19. // extern digit_t Stdcall86 sub_same(digit_tc a[], digit_tc b[], digit_t c[], DWORDC d);
  20. inline DWORD
  21. BN_DSA_verify_j(
  22. dsa_public_tc *pPubkey,
  23. dsa_precomputed_tc *pPrecomputed)
  24. {
  25. BOOL fSts;
  26. BN_ResetError();
  27. fSts = DSA_verify_j(pPubkey, pPrecomputed);
  28. return BN_MapError(fSts);
  29. }
  30. inline DWORD
  31. BN_DSA_check_g(
  32. DWORDC lngp_digits, // In
  33. digit_tc *pGModular, // In
  34. mp_modulus_t *pPModulo, // In
  35. DWORDC lngq_digits, // In
  36. digit_tc *pQDigit) // In
  37. {
  38. BOOL fSts;
  39. BN_ResetError();
  40. fSts = DSA_check_g(lngp_digits, pGModular, pPModulo, lngq_digits, pQDigit);
  41. return BN_MapError(fSts);
  42. }
  43. inline DWORD
  44. BN_DSA_parameter_verification(
  45. dsa_public_tc *pPubkey,
  46. dsa_precomputed_tc *pPrecomputed)
  47. {
  48. BOOL fSts;
  49. BN_ResetError();
  50. fSts = DSA_parameter_verification(pPubkey, pPrecomputed);
  51. return BN_MapError(fSts);
  52. }
  53. inline DWORD
  54. BN_DSA_precompute(
  55. dsa_public_tc *pubkey, // In
  56. dsa_precomputed_t *precomputed, // Out
  57. const BOOL checkSC) // In
  58. {
  59. BOOL fSts;
  60. BN_ResetError();
  61. fSts = DSA_precompute(pubkey, precomputed, checkSC);
  62. return BN_MapError(fSts);
  63. }
  64. inline DWORD
  65. BN_from_modular(
  66. digit_tc a[],
  67. digit_t b[],
  68. mp_modulus_tc *modulo)
  69. {
  70. DWORD dwSts;
  71. BN_ResetError();
  72. dwSts = from_modular(a, b, modulo);
  73. if (ERROR_SUCCESS != BN_MapError(0 != dwSts))
  74. dwSts = 0;
  75. return dwSts;
  76. }
  77. inline DWORD
  78. BN_mod_exp(
  79. digit_tc base[],
  80. digit_tc exponent[],
  81. DWORDC lngexpon,
  82. digit_t answer[],
  83. mp_modulus_tc *modulo)
  84. {
  85. BN_ResetError();
  86. mod_exp(base, exponent, lngexpon, answer, modulo);
  87. return BN_MapError(TRUE);
  88. }
  89. inline DWORD
  90. BN_to_modular(
  91. digit_tc a[],
  92. DWORDC lnga,
  93. digit_t b[],
  94. mp_modulus_tc *modulo)
  95. {
  96. DWORD dwSts;
  97. BN_ResetError();
  98. dwSts = to_modular(a, lnga, b, modulo);
  99. if (ERROR_SUCCESS != BN_MapError(0 != dwSts))
  100. dwSts = 0;
  101. return dwSts;
  102. }
  103. inline DWORD
  104. BN_DSA_gen_x_and_y(
  105. BOOL fUseQ, // In
  106. dsa_other_info *pOtherInfo, // In
  107. dsa_private_t *privkey) // Out
  108. {
  109. BOOL fSts;
  110. BN_ResetError();
  111. fSts = DSA_gen_x_and_y(fUseQ, pOtherInfo, privkey);
  112. return BN_MapError(fSts);
  113. }
  114. inline DWORD
  115. BN_DSA_precompute_pgy(
  116. dsa_public_tc *pubkey, // In
  117. dsa_precomputed_t *precomputed) // Out
  118. {
  119. BOOL fSts;
  120. BN_ResetError();
  121. fSts = DSA_precompute_pgy(pubkey, precomputed);
  122. return BN_MapError(fSts);
  123. }
  124. inline DWORD
  125. BN_DSA_key_generation(
  126. DWORDC nbitp, // In
  127. DWORDC nbitq, // In
  128. dsa_other_info *pOtherInfo, // In
  129. dsa_private_t *privkey) // Out
  130. {
  131. BOOL fSts;
  132. BN_ResetError();
  133. fSts = DSA_key_generation(nbitp, nbitq, pOtherInfo, privkey);
  134. return BN_MapError(fSts);
  135. }
  136. inline DWORD
  137. BN_DSA_signature_verification(
  138. DWORDC message_hash[SHA_DWORDS],
  139. dsa_public_tc *pubkey,
  140. dsa_precomputed_tc *precomputed_argument,
  141. dsa_signature_tc *signature,
  142. dsa_other_info *pOtherInfo)
  143. {
  144. BOOL fSts;
  145. BN_ResetError();
  146. fSts = DSA_signature_verification(message_hash, pubkey,
  147. precomputed_argument,
  148. signature, pOtherInfo);
  149. return BN_MapError(fSts);
  150. }
  151. inline DWORD
  152. BN_DSA_sign(
  153. DWORDC message_hash[SHA_DWORDS], /* TBD */
  154. dsa_private_tc *privkey,
  155. dsa_signature_t *signature,
  156. dsa_other_info *pOtherInfo)
  157. {
  158. BOOL fSts;
  159. BN_ResetError();
  160. fSts = DSA_sign(message_hash, privkey, signature, pOtherInfo);
  161. return BN_MapError(fSts);
  162. }
  163. inline DWORD
  164. BN_create_modulus(
  165. digit_tc a[],
  166. DWORDC lnga,
  167. reddir_tc reddir,
  168. mp_modulus_t *modulo)
  169. {
  170. BOOL fSts;
  171. BN_ResetError();
  172. fSts = create_modulus(a, lnga, reddir, modulo);
  173. return BN_MapError(fSts);
  174. }
  175. inline DWORD
  176. BN_DSA_key_import_fillin(
  177. dsa_private_t *privkey)
  178. {
  179. BOOL fSts;
  180. BN_ResetError();
  181. fSts = DSA_key_import_fillin(privkey);
  182. return BN_MapError(fSts);
  183. }