summaryrefslogtreecommitdiffstats
path: root/config.m4
blob: ecaa8ed1baf557f58217d3a788a96c7bfed114e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
dnl config.m4 for extension xpass

PHP_ARG_ENABLE([xpass],
  [whether to enable xpass support],
  [AS_HELP_STRING([--enable-xpass],
    [Enable xpass support])],
  [no])

if test "$PHP_XPASS" != "no"; then
  PKG_CHECK_MODULES([LIBXCRYPT], [libxcrypt >= 4.4])
  PHP_EVAL_INCLINE([$LIBXCRYPT_CFLAGS])
  PHP_EVAL_LIBLINE([$LIBXCRYPT_LIBS], [XPASS_SHARED_LIBADD])

  old_CFLAGS=$CFLAGS; CFLAGS="$CFLAGS $LIBXCRYPT_CFLAGS"
  old_LIBS=$LIBS; LIBS="$LIBS $LIBXCRYPT_LIBS"

  AC_MSG_CHECKING([for yescrypt algo])
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>

int main(void) {
    char algo[8], *salt, *hash;
	algo[0]='$'; algo[1]='y'; algo[2]='$'; algo[3]=0;
	salt = crypt_gensalt(algo, 0, NULL, 0);
	if (salt) {
		hash = crypt("secret", salt);
		return (hash && strlen(hash) == 73 && !memcmp(hash, algo, 3) ? 0 : 1);
	}
	return 1;
}]])],[
    AC_DEFINE([HAVE_CRYPT_YESCRYPT], [1], [ Have yescrypt hash support ])
    AC_MSG_RESULT([available])
  ], [
    AC_MSG_RESULT([missing])
  ])

  AC_MSG_CHECKING([for sha512 algo])
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>

int main(void) {
    char algo[8], *salt, *hash;
	algo[0]='$'; algo[1]='6'; algo[2]='$'; algo[3]=0;
	salt = crypt_gensalt(algo, 0, NULL, 0);
	if (salt) {
		hash = crypt("secret", salt);
		return (hash && strlen(hash) == 106 && !memcmp(hash, algo, 3) ? 0 : 1);
	}
	return 1;
}]])],[
    AC_DEFINE([HAVE_CRYPT_SHA512], [1], [ Have sha512 hash support ])
    AC_MSG_RESULT([available])
  ], [
    AC_MSG_RESULT([missing])
  ])

  AC_MSG_CHECKING([for sm3 algo])
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <stdlib.h>

int main(void) {
    char algo[8], *salt, *hash;
	algo[0]='$'; algo[1]='s'; algo[2]='m'; algo[3]='3'; algo[4]='$'; algo[5]=0;
	salt = crypt_gensalt(algo, 0, NULL, 0);
	if (salt) {
		hash = crypt("secret", salt);
		return (hash && strlen(hash) == 65 && !memcmp(hash, algo, 5) ? 0 : 1);
	}
	return 1;
}]])],[
    AC_DEFINE([HAVE_CRYPT_SM3], [1], [ Have sm3 hash support ])
    AC_MSG_RESULT([available])
  ], [
    AC_MSG_RESULT([missing])
  ])

  CFLAGS=$old_CFLAGS
  LIBS=$old_LIBS

  PHP_SUBST([XPASS_SHARED_LIBADD])

  AC_DEFINE([HAVE_XPASS], [1], [ Have xpass support ])

  PHP_NEW_EXTENSION(xpass, xpass.c, $ext_shared)
fi