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.

bitcoin_secp.m4 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell.
  2. AC_DEFUN([SECP_64BIT_ASM_CHECK],[
  3. AC_MSG_CHECKING(for x86_64 assembly availability)
  4. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  5. #include <stdint.h>]],[[
  6. uint64_t a = 11, tmp;
  7. __asm__ __volatile__("movq \@S|@0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx");
  8. ]])],[has_64bit_asm=yes],[has_64bit_asm=no])
  9. AC_MSG_RESULT([$has_64bit_asm])
  10. ])
  11. dnl
  12. AC_DEFUN([SECP_OPENSSL_CHECK],[
  13. has_libcrypto=no
  14. m4_ifdef([PKG_CHECK_MODULES],[
  15. PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes],[has_libcrypto=no])
  16. if test x"$has_libcrypto" = x"yes"; then
  17. TEMP_LIBS="$LIBS"
  18. LIBS="$LIBS $CRYPTO_LIBS"
  19. AC_CHECK_LIB(crypto, main,[AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no])
  20. LIBS="$TEMP_LIBS"
  21. fi
  22. ])
  23. if test x$has_libcrypto = xno; then
  24. AC_CHECK_HEADER(openssl/crypto.h,[
  25. AC_CHECK_LIB(crypto, main,[
  26. has_libcrypto=yes
  27. CRYPTO_LIBS=-lcrypto
  28. AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])
  29. ])
  30. ])
  31. LIBS=
  32. fi
  33. if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
  34. AC_MSG_CHECKING(for EC functions in libcrypto)
  35. CPPFLAGS_TEMP="$CPPFLAGS"
  36. CPPFLAGS="$CRYPTO_CPPFLAGS $CPPFLAGS"
  37. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  38. #include <openssl/bn.h>
  39. #include <openssl/ec.h>
  40. #include <openssl/ecdsa.h>
  41. #include <openssl/obj_mac.h>]],[[
  42. # if OPENSSL_VERSION_NUMBER < 0x10100000L
  43. void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {(void)sig->r; (void)sig->s;}
  44. # endif
  45. unsigned int zero = 0;
  46. const unsigned char *zero_ptr = (unsigned char*)&zero;
  47. EC_KEY_free(EC_KEY_new_by_curve_name(NID_secp256k1));
  48. EC_KEY *eckey = EC_KEY_new();
  49. EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
  50. EC_KEY_set_group(eckey, group);
  51. ECDSA_sign(0, NULL, 0, NULL, &zero, eckey);
  52. ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
  53. o2i_ECPublicKey(&eckey, &zero_ptr, 0);
  54. d2i_ECPrivateKey(&eckey, &zero_ptr, 0);
  55. EC_KEY_check_key(eckey);
  56. EC_KEY_free(eckey);
  57. EC_GROUP_free(group);
  58. ECDSA_SIG *sig_openssl;
  59. sig_openssl = ECDSA_SIG_new();
  60. d2i_ECDSA_SIG(&sig_openssl, &zero_ptr, 0);
  61. i2d_ECDSA_SIG(sig_openssl, NULL);
  62. ECDSA_SIG_get0(sig_openssl, NULL, NULL);
  63. ECDSA_SIG_free(sig_openssl);
  64. const BIGNUM *bignum = BN_value_one();
  65. BN_is_negative(bignum);
  66. BN_num_bits(bignum);
  67. if (sizeof(zero) >= BN_num_bytes(bignum)) {
  68. BN_bn2bin(bignum, (unsigned char*)&zero);
  69. }
  70. ]])],[has_openssl_ec=yes],[has_openssl_ec=no])
  71. AC_MSG_RESULT([$has_openssl_ec])
  72. CPPFLAGS="$CPPFLAGS_TEMP"
  73. fi
  74. ])
  75. dnl
  76. AC_DEFUN([SECP_GMP_CHECK],[
  77. if test x"$has_gmp" != x"yes"; then
  78. CPPFLAGS_TEMP="$CPPFLAGS"
  79. CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
  80. LIBS_TEMP="$LIBS"
  81. LIBS="$GMP_LIBS $LIBS"
  82. AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS="$GMP_LIBS -lgmp"; AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])])])
  83. CPPFLAGS="$CPPFLAGS_TEMP"
  84. LIBS="$LIBS_TEMP"
  85. fi
  86. ])