Skip to content

Commit

Permalink
Squashed commit - Add ext/sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security authored and remicollet committed Jul 11, 2017
1 parent da2583b commit 5cfa26c
Show file tree
Hide file tree
Showing 30 changed files with 3,848 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addons:
- libpspell-dev
- librecode-dev
- libsasl2-dev
- libsodium-dev
- libxpm-dev
- libt1-dev

Expand Down
6 changes: 6 additions & 0 deletions EXTENSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ MAINTENANCE: Maintained
STATUS: Working
SINCE: 4.0.2
-------------------------------------------------------------------------------
EXTENSION: sodium
PRIMARY MAINTAINER: Frank Denis <[email protected]>
MAINTENANCE: Maintained
STATUS: Working
SINCE: 7.2.0
-------------------------------------------------------------------------------
EXTENSION: spl
PRIMARY MAINTAINER: Marcus Boerger <[email protected]>, Etienne Kneuss <[email protected]>
MAINTENANCE: Maintained
Expand Down
2 changes: 2 additions & 0 deletions ext/sodium/CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;; libsodium
Frank Denis [[email protected]] (lead)
13 changes: 13 additions & 0 deletions ext/sodium/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[![Build Status](https://travis-ci.org/jedisct1/libsodium-php.svg?branch=master)](https://travis-ci.org/jedisct1/libsodium-php?branch=master)

libsodium-php
=============

A simple, low-level PHP extension for
[libsodium](https://github.com/jedisct1/libsodium).

Full documentation here:
[Using Libsodium in PHP Projects](https://paragonie.com/book/pecl-libsodium),
a guide to using the libsodium PHP extension for modern, secure, and
fast cryptography.

68 changes: 68 additions & 0 deletions ext/sodium/config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
dnl $Id$
dnl config.m4 for extension sodium

PHP_ARG_WITH(sodium, for sodium support,
[ --with-sodium Include sodium support])

PHP_ARG_WITH(libsodium, for libsodium library location,
[ --with-libsodium[[=DIR]] libsodium library location, else rely on pkg-config])

if test "$PHP_SODIUM" != "no"; then
SEARCH_PATH="/usr/local /usr" # you might want to change this
SEARCH_FOR="/include/sodium.h" # you most likely want to change this

AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
AC_MSG_CHECKING([for libsodium])

dnl user provided location
if test -r $PHP_LIBSODIUM/$SEARCH_FOR; then # path given as parameter
LIBSODIUM_DIR=$PHP_LIBSODIUM
AC_MSG_RESULT([found in $PHP_LIBSODIUM])

dnl pkg-config output
elif test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libsodium; then
LIBSODIUM_CFLAGS=`$PKG_CONFIG libsodium --cflags`
LIBSODIUM_LIBS=`$PKG_CONFIG libsodium --libs`
LIBSODIUM_VERSION=`$PKG_CONFIG libsodium --modversion`
AC_MSG_RESULT(version $LIBSODIUM_VERSION found using pkg-config)
PHP_EVAL_LIBLINE($LIBSODIUM_LIBS, SODIUM_SHARED_LIBADD)
PHP_EVAL_INCLINE($LIBSODIUM_CFLAGS)

dnl search default path list
else
for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
LIBSODIUM_DIR=$i
AC_MSG_RESULT(found in $i)
fi
done
if test -z "$LIBSODIUM_DIR"; then
AC_MSG_ERROR([Please install libsodium - See https://github.com/jedisct1/libsodium])
fi
fi

LIBNAME=sodium
LIBSYMBOL=crypto_pwhash_scryptsalsa208sha256

if test -n "$LIBSODIUM_DIR"; then
PHP_ADD_INCLUDE($LIBSODIUM_DIR/include)
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBSODIUM_DIR/$PHP_LIBDIR, SODIUM_SHARED_LIBADD)
fi

PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
AC_DEFINE(HAVE_LIBSODIUMLIB,1,[ ])
],[
AC_MSG_ERROR([wrong libsodium lib version or lib not found])
],[
])
PHP_CHECK_LIBRARY($LIBNAME,crypto_aead_aes256gcm_encrypt,
[
AC_DEFINE(HAVE_CRYPTO_AEAD_AES256GCM,1,[ ])
],[],[
])

PHP_SUBST(SODIUM_SHARED_LIBADD)

PHP_NEW_EXTENSION(sodium, libsodium.c, $ext_shared)
fi
14 changes: 14 additions & 0 deletions ext/sodium/config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// $Id$
// vim:ft=javascript

ARG_WITH("sodium", "for libsodium support", "no");

if (PHP_SODIUM != "no") {
if (CHECK_LIB("libsodium.lib", "sodium", PHP_SODIUM) && CHECK_HEADER_ADD_INCLUDE("sodium.h", "CFLAGS_SODIUM")) {
EXTENSION("sodium", "libsodium.c");
AC_DEFINE('HAVE_LIBSODIUMLIB', 1 , 'Have the Sodium library');
PHP_INSTALL_HEADERS("ext/sodium/", "php_libsodium.h");
} else {
WARNING("libsodium not enabled; libraries and headers not found");
}
}
Loading

0 comments on commit 5cfa26c

Please sign in to comment.