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
|
From fbecbcfcbe819a1fae9663689e9c34b9d904502a Mon Sep 17 00:00:00 2001
From: Remi Collet <fedora@famillecollet.com>
Date: Tue, 27 Oct 2015 08:28:00 +0100
Subject: [PATCH 1/2] fix build with old libsodium
---
libsodium.c | 3 +++
tests/crypto_aead.phpt | 5 ++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/libsodium.c b/libsodium.c
index bc03b49..f9f12f7 100644
--- a/libsodium.c
+++ b/libsodium.c
@@ -2033,6 +2033,8 @@ PHP_FUNCTION(crypto_sign_ed25519_pk_to_curve25519)
RETURN_STR(ecdhkey);
}
+#if SODIUM_LIBRARY_VERSION_MAJOR > 7 || \
+ (SODIUM_LIBRARY_VERSION_MAJOR == 7 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
PHP_FUNCTION(sodium_compare)
{
char *buf1;
@@ -2054,3 +2056,4 @@ PHP_FUNCTION(sodium_compare)
(const unsigned char *) buf2, (size_t) len1));
}
}
+#endif
\ No newline at end of file
diff --git a/tests/crypto_aead.phpt b/tests/crypto_aead.phpt
index c2a5ff1..96029aa 100644
--- a/tests/crypto_aead.phpt
+++ b/tests/crypto_aead.phpt
@@ -1,7 +1,10 @@
--TEST--
Check for libsodium AEAD
--SKIPIF--
-<?php if (!extension_loaded("libsodium")) print "skip"; ?>
+<?php
+if (!extension_loaded("libsodium")) print "skip extension not loaded";
+if (!defined('Sodium\CRYPTO_AEAD_AES256GCM_NPUBBYTES')) print "skip libsodium without AESGCM";
+?>
--FILE--
<?php
$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
From dddee3245f58a424151d901c3085806529e67503 Mon Sep 17 00:00:00 2001
From: Remi Collet <fedora@famillecollet.com>
Date: Tue, 27 Oct 2015 09:18:18 +0100
Subject: [PATCH 2/2] add check for crypto_aead_aes256gcm_encrypt symbol
---
config.m4 | 8 +++++++-
libsodium.c | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/config.m4 b/config.m4
index 2a7fe2e..eb11468 100644
--- a/config.m4
+++ b/config.m4
@@ -38,7 +38,13 @@ if test "$PHP_LIBSODIUM" != "no"; then
],[
-L$LIBSODIUM_DIR/$PHP_LIBDIR
])
-
+ PHP_CHECK_LIBRARY($LIBNAME,crypto_aead_aes256gcm_encrypt,
+ [
+ AC_DEFINE(HAVE_CRYPTO_AEAD_AES256GCM,1,[ ])
+ ],[],[
+ -L$LIBSODIUM_DIR/$PHP_LIBDIR
+ ])
+
PHP_SUBST(LIBSODIUM_SHARED_LIBADD)
PHP_NEW_EXTENSION(libsodium, libsodium.c, $ext_shared)
diff --git a/libsodium.c b/libsodium.c
index f9f12f7..f73e62f 100644
--- a/libsodium.c
+++ b/libsodium.c
@@ -148,7 +148,7 @@ ZEND_END_ARG_INFO()
# define PHP_FE_END { NULL, NULL, NULL }
#endif
-#if defined(crypto_aead_aes256gcm_KEYBYTES) && \
+#if defined(HAVE_CRYPTO_AEAD_AES256GCM) && defined(crypto_aead_aes256gcm_KEYBYTES) && \
(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || defined(__i386__) || \
defined(_M_AMD64) || defined(_M_IX86))
# define HAVE_AESGCM 1
|