From aaf1cd609fb4ca7c4885aa22553565f923339e20 Mon Sep 17 00:00:00 2001 From: Hunter Morris Date: Thu, 26 Nov 2009 14:12:22 +0000 Subject: [PATCH] Simplify build process (must set ERL_TOP) --- .gitignore | 25 +---- Makefile | 37 +++++++ Makefile.am | 52 --------- _build.cfg | 2 +- acinclude.m4.in | 18 ---- bootstrap | 193 ---------------------------------- configure.ac | 151 -------------------------- lib/Makefile.am | 15 --- lib/bcrypt/Makefile.am | 43 -------- lib/bcrypt/c_src/bcrypt_nif.c | 28 ++--- lib/bcrypt/priv/Makefile.am | 25 ----- lib/bcrypt/src/bcrypt.erl | 172 ------------------------------ lib/bcrypt/src/bcrypt_app.erl | 37 ------- lib/bcrypt/src/bcrypt_nif.erl | 78 ++++++++++++++ lib/bcrypt/src/bcrypt_sup.erl | 37 ------- m4/.gitignore | 0 16 files changed, 133 insertions(+), 780 deletions(-) create mode 100644 Makefile delete mode 100644 Makefile.am delete mode 100644 acinclude.m4.in delete mode 100755 bootstrap delete mode 100644 configure.ac delete mode 100644 lib/Makefile.am delete mode 100644 lib/bcrypt/Makefile.am delete mode 100644 lib/bcrypt/priv/Makefile.am delete mode 100644 lib/bcrypt/src/bcrypt.erl delete mode 100644 lib/bcrypt/src/bcrypt_app.erl create mode 100644 lib/bcrypt/src/bcrypt_nif.erl delete mode 100644 lib/bcrypt/src/bcrypt_sup.erl delete mode 100644 m4/.gitignore diff --git a/.gitignore b/.gitignore index 82f9eff..11c4c20 100644 --- a/.gitignore +++ b/.gitignore @@ -3,30 +3,6 @@ ebin _build/ lib/bcrypt/bcrypt -## Make-related -Makefile - -## Autoconf -m4 -Makefile.in -config.guess -config.log -config.status -config.sub -config.h -config.h.in -configure -depcomp -install-sh -libtool -ltmain.sh -missing -aclocal.m4 -acinclude.m4 -autom4te.cache -stamp-* -INSTALL - ## libtool .deps .erl @@ -37,6 +13,7 @@ INSTALL *.lo *.loT *.o +*.so ## Distribution files *.gz diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..40bc887 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +ERL_TOP=../otp +include $(ERL_TOP)/make/target.mk + +INCLUDES = \ + -I$(ERL_TOP)/erts/$(TARGET) \ + -I$(ERL_TOP)/erts/emulator/$(TARGET) \ + -I$(ERL_TOP)/erts/emulator/$(TARGET)/opt/smp \ + -I$(ERL_TOP)/erts/emulator/beam/ \ + -I$(ERL_TOP)/erts/emulator/sys/unix \ + -I$(ERL_TOP)/erts/include/$(TARGET) \ + -I$(ERL_TOP)/erts/include/internal \ + -no-cpp-precomp -DHAVE_CONFIG_H + +# OS X Snow Leopard flags. +GCCFLAGS = -m64 -O3 -fPIC -bundle -flat_namespace -undefined suppress -fno-common -Wall + +# Linux Flags +#GCCFLAGS = -O3 -fPIC -shared -fno-common -Wall + +CFLAGS = $(GCCFLAGS) $(INCLUDES) +LDFLAGS = $(GCCFLAGS) $(LIBS) + +OBJECTS = lib/bcrypt/c_src/blowfish.o lib/bcrypt/c_src/bcrypt.o lib/bcrypt/c_src/bcrypt_nif.o + +DRIVER = lib/bcrypt/c_src/bcrypt_nif.so +BEAM = lib/bcrypt/ebin/bcrypt_nif.beam + +all: $(DRIVER) $(BEAM) + +clean: + rm -f *.o *.beam $(DRIVER) + +$(DRIVER): $(OBJECTS) + gcc -o $@ $^ $(LDFLAGS) + +$(BEAM): lib/bcrypt/src/bcrypt_nif.erl + erlc $^ \ No newline at end of file diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 4ec13fc..0000000 --- a/Makefile.am +++ /dev/null @@ -1,52 +0,0 @@ -## Copyright (c) 2008 Hunter Morris - -## Permission to use, copy, modify, and distribute this software for any -## purpose with or without fee is hereby granted, provided that the above -## copyright notice and this permission notice appear in all copies. - -## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -SUBDIRS = lib - -localdoc_DATA = README.rst.gz LICENSE.gz - -DISTCLEANFILES = $(localdoc_DATA) - -EXTRA_DIST = README.rst LICENSE - -README.rst.gz: $(top_srcdir)/README.rst - -gzip -9 < $< > $@ - -LICENSE.gz: $(top_srcdir)/LICENSE - -gzip -9 < $< > $@ - -.PHONY: local-clean -local-clean: maintainer-clean - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may need special tools to rebuild." - rm -f $(top_srcdir)/INSTALL - rm -f $(top_srcdir)/acinclude.m4 - rm -f $(top_srcdir)/aclocal.m4 - rm -f $(top_srcdir)/config.h.in - rm -f $(top_srcdir)/configure - rm -f $(top_srcdir)/*.tar.gz - rm -f $(top_srcdir)/*.tar.gz.* - rm -fr $(top_srcdir)/build-aux - rm -fr $(top_srcdir)/m4 - find $(top_srcdir) -name Makefile.in -exec rm {} \; - -.PHONY: distsign -distsign: distcheck - gpg --armor --detach-sig \ - < $(top_srcdir)/$(distdir).tar.gz \ - > $(top_srcdir)/$(distdir).tar.gz.asc - md5sum $(top_srcdir)/$(distdir).tar.gz \ - > $(top_srcdir)/$(distdir).tar.gz.md5 - sha1sum $(top_srcdir)/$(distdir).tar.gz \ - > $(top_srcdir)/$(distdir).tar.gz.sha diff --git a/_build.cfg b/_build.cfg index 0cdfb99..d0efa44 100644 --- a/_build.cfg +++ b/_build.cfg @@ -1,6 +1,6 @@ project : { name : bcrypt - vsn : "0.1.0" + vsn : "0.2.0" }, repositories : ["http://repo.erlware.org/pub"], diff --git a/acinclude.m4.in b/acinclude.m4.in deleted file mode 100644 index ab3ae79..0000000 --- a/acinclude.m4.in +++ /dev/null @@ -1,18 +0,0 @@ -m4_define([LOCAL_PACKAGE_AUTHOR_NAME], [Hunter Morris]) -m4_define([LOCAL_PACKAGE_AUTHOR_ADDRESS], [huntermorris@gmail.com]) -m4_define([LOCAL_PACKAGE_IDENTIFIER], [erlang-bcrypt]) -m4_define([LOCAL_PACKAGE_TARNAME], [erlang-bcrypt]) -m4_define([LOCAL_PACKAGE_NAME], [Erlang Bcrypt]) - -m4_define([LOCAL_VERSION_MAJOR], [0]) -m4_define([LOCAL_VERSION_MINOR], [1]) -m4_define([LOCAL_VERSION_REVISION], [0]) -m4_define([LOCAL_VERSION_STAGE], [a]) -m4_define([LOCAL_VERSION_RELEASE], [%release%]) -m4_define([LOCAL_VERSION_STATUS], [dev]) -m4_define([LOCAL_VERSION_PRIMARY], - [LOCAL_VERSION_MAJOR.LOCAL_VERSION_MINOR.LOCAL_VERSION_REVISION]) -m4_define([LOCAL_VERSION_SECONDARY], - [LOCAL_VERSION_STAGE[]LOCAL_VERSION_RELEASE-LOCAL_VERSION_STATUS]) -m4_define([LOCAL_VERSION], - [LOCAL_VERSION_PRIMARY[]LOCAL_VERSION_SECONDARY]) diff --git a/bootstrap b/bootstrap deleted file mode 100755 index 3ce1a37..0000000 --- a/bootstrap +++ /dev/null @@ -1,193 +0,0 @@ -#!/bin/sh -e - -# Bootstrap the pristine source ready for distribution and deployment. - -SCRIPT_OK=0 -SCRIPT_ERROR=1 - -ACINCLUDE_FILE="acinclude.m4" -ACINCLUDE_IN_FILE="acinclude.m4.in" -ACINCLUDE_TMP_FILE="acinclude.m4.tmp" -AUTHORS_FILE="authors.xml" -BUILD_AUX_DIRECTORY="build-aux" -CONFIG_GUESS_FILE="build-aux/config.guess" -CONFIG_SUB_FILE="build-aux/config.sub" - -basename=`basename $0` - -get () { - variable_name=$1 - echo "changequote(\`[', \`]')" > $ACINCLUDE_TMP_FILE - sed -e "s/m4_//" < $ACINCLUDE_IN_FILE >> $ACINCLUDE_TMP_FILE - echo $variable_name >> $ACINCLUDE_TMP_FILE - if test -x "`which m4 || true`"; then - `which m4` $ACINCLUDE_TMP_FILE | grep -v "^$" || true - else - if test -x "`which gm4 || true`"; then - `which gm4` $ACINCLUDE_TMP_FILE | grep -v "^$" || true - else - echo unknown - fi - fi - rm -f $ACINCLUDE_TMP_FILE -} - -display_version () { - cat << EOF -$basename - `get LOCAL_PACKAGE_NAME` `get LOCAL_VERSION_PRIMARY` - -Copyright (c) 2008 Hunter Morris - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -EOF -} - -display_help () { - cat << EOF -Usage: $basename [OPTION]... - -The $basename script bootstraps the pristine source so that it can be built. - -The exit status is 0 for success or 1 for failure. - -Options: - - -h display a short help message and exit - -v display version information and exit - -Environment variables: - - REVISION manual override for revision information - -EOF -} - -display_error () { - if test -n "$1"; then - echo $1 >&2 - fi - echo >&2 - echo "Try \`"$basename" -h' for more information." >&2 - exit $SCRIPT_ERROR -} - -generate_acinclude () { - if test -z "$REVISION"; then - REVISION="" - fi - if test -z "`get LOCAL_VERSION_STAGE`" -o -z "$REVISION"; then - sed "s/%release%//" < $ACINCLUDE_IN_FILE > $ACINCLUDE_FILE - else - sed "s/%release%/$REVISION/" < $ACINCLUDE_IN_FILE > $ACINCLUDE_FILE - fi -} - -process_file_collection () { - echo "Installing \`"$BUILD_AUX_DIRECTORY"'" - mkdir -p $BUILD_AUX_DIRECTORY -} - -run_aclocal () { - if test -x "`which aclocal || true`"; then - echo "Running aclocal" - `which aclocal` -I m4 - else - echo "Can't find aclocal" - exit $SCRIPT_ERROR - fi -} - -run_libtoolize () { - if test -x "`which libtoolize || true`"; then - echo "Running libtoolize" - `which libtoolize` -f -c - else - if test -x "`which glibtoolize || true`"; then - echo "Running glibtoolize" - `which glibtoolize` -f -c - else - echo "Can't find libtoolize or glibtoolize" - exit $SCRIPT_ERROR - fi - fi -} - -run_autoheader () { - if test -x "`which autoheader || true`"; then - echo "Running autoheader" - `which autoheader` -f - else - echo "Can't find autoheader" - exit $SCRIPT_ERROR - fi -} - -run_automake () { - AUTOMAKE_OPTION_COLLECTION="" - if test -x "`which automake || true`"; then - echo "Running automake" - `which automake` -f -c -a --gnits - else - echo "Can't find automake" - exit $SCRIPT_ERROR - fi -} - -run_autoconf () { - if test -x "`which autoconf || true`"; then - echo "Running autoconf" - `which autoconf` -f - else - echo "Can't find autoconf" - exit $SCRIPT_ERROR - fi -} - -run_command_collection () { - run_libtoolize - run_aclocal - run_autoheader - run_automake - run_autoconf - cat << EOF - -You have bootstrapped erlang-bcrypt. - -Run \`./configure' to configure the source before you install. -EOF -} - -parse_script_option_list () { - set +e - options=`getopt hVC $@` - if test ! $? -eq 0; then - display_error - fi - set -e - eval set -- $options - while [ $# -gt 0 ]; do - case "$1" in - -h) shift; display_help; exit $SCRIPT_OK;; - -V) shift; display_version; exit $SCRIPT_OK;; - --) shift; break;; - *) display_error "Unknown option: $1" >&2;; - esac - done - cd `dirname $0` - process_file_collection - generate_acinclude - run_command_collection -} - -parse_script_option_list $@ diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 8c0992c..0000000 --- a/configure.ac +++ /dev/null @@ -1,151 +0,0 @@ -dnl Copyright (c) 2008 Hunter Morris -dnl -dnl Permission to use, copy, modify, and distribute this software for any -dnl purpose with or without fee is hereby granted, provided that the above -dnl copyright notice and this permission notice appear in all copies. -dnl -dnl THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -dnl WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -dnl MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -dnl ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -AC_INIT([LOCAL_PACKAGE_NAME], [LOCAL_VERSION], [], [LOCAL_PACKAGE_TARNAME]) - -AC_PREREQ([2.59]) - -AC_CONFIG_SRCDIR([README.rst]) -AC_CONFIG_AUX_DIR([build-aux]) - -AM_CONFIG_HEADER([config.h]) - -AM_INIT_AUTOMAKE([1.6.3 foreign]) - -AC_GNU_SOURCE -AC_ENABLE_SHARED -AC_DISABLE_STATIC - -AM_PROG_AS -AC_PROG_CC -AC_PROG_LIBTOOL -AC_PROG_LN_S - -AC_MSG_CHECKING([for pthread_create in -lpthread]) - -original_LIBS="$LIBS" -LIBS="-lpthread $original_LIBS" - -AC_TRY_LINK([#include], - [pthread_create((void *)0, (void *)0, (void *)0, (void *)0)], - [pthread=yes], [pthread=no]) - -if test x${pthread} = xyes; then - AC_MSG_RESULT([yes]) -else - LIBS="$original_LIBS" - AC_MSG_RESULT([no]) -fi - -AC_ARG_WITH([erlang], [AC_HELP_STRING([--with-erlang=PATH], - [set PATH to the Erlang include directory])], [ - ERLANG_FLAGS="-I$withval" -], [ - ERLANG_FLAGS="-I${libdir}/erlang/usr/include" - ERLANG_FLAGS="$ERLANG_FLAGS -I/usr/lib/erlang/usr/include" - ERLANG_FLAGS="$ERLANG_FLAGS -I/usr/local/lib/erlang/usr/include" - ERLANG_FLAGS="$ERLANG_FLAGS -I/opt/local/lib/erlang/usr/include" -]) - -AC_ARG_WITH([erl_interface], [AC_HELP_STRING([--with-erl-interface=PATH], - [set PATH to the erl_interface directory])], [ - ERLANG_FLAGS="$ERLANG_FLAGS -I$withval/include -L$withval/lib" -], [ - ERLANG_FLAGS="$ERLANG_FLAGS" -]) - -# XP_UNIX required for various things and has been tested to work on Linux and Darwin. -LIB_FLAGS="-L/usr/local/lib -L/opt/local/lib" -LIBS="$LIB_FLAGS $LIBS" -FLAGS="$LIB_FLAGS $ERLANG_FLAGS -DXP_UNIX $FLAGS" -CPPFLAGS="$FLAGS $CPPFLAGS" -LDFLAGS="$FLAGS $LDFLAGS" - -AC_PATH_PROG([ERL], [erl]) - -if test x${ERL} = x; then - AC_MSG_ERROR([Could not find the `erl' executable. Is Erlang installed?]) -fi - -erlang_version_error="The installed Erlang version is less than 5.6.0 (R12B)." - -version="`${ERL} -version 2>&1 | ${SED} "s/[[^0-9]]/ /g"`" - -if test `echo $version | ${AWK} "{print \\$1}"` -lt 5; then - AC_MSG_ERROR([$erlang_version_error]) -fi - -if test `echo $version | ${AWK} "{print \\$2}"` -lt 6; then - AC_MSG_ERROR([$erlang_version_error]) -fi - -AC_PATH_PROG([ERLC], [erlc]) - -if test x${ERLC} = x; then - AC_MSG_ERROR([Could not find the `erlc' executable. Is Erlang installed?]) -fi - -AC_CHECK_HEADER([erl_driver.h], [], [ - AC_MSG_ERROR([Could not find the `erl_driver.h' header. - -Are the Erlang headers installed? Use the `--with-erlang' option to specify -the path to the Erlang directory.])]) - -AC_CHECK_HEADER([erl_interface.h], [], [ - AC_MSG_ERROR([Could not find the `erl_interface.h' header. - -Are the erl_interface headers installed? Use the `--with-erl-interface' -option to specify the path to erl_interface directory.])]) - -AC_CHECK_LIB(socket, connect) -AC_CHECK_LIB(resolv, herror) -AC_CHECK_LIB(nsl, gethostent) -AC_CHECK_LIB(dl, dlopen) - -AC_ARG_VAR([ERL_EXECUTABLE], [path to the `erl' executable]) -AC_ARG_VAR([ERLC_EXECUTABLE], [path to the `erlc' executable]) - -AC_SUBST([package_author_name], ["LOCAL_PACKAGE_AUTHOR_NAME"]) -AC_SUBST([package_author_address], ["LOCAL_PACKAGE_AUTHOR_ADDRESS"]) -AC_SUBST([package_identifier], ["LOCAL_PACKAGE_IDENTIFIER"]) -AC_SUBST([package_tarname], ["LOCAL_PACKAGE_TARNAME"]) -AC_SUBST([package_name], ["LOCAL_PACKAGE_NAME"]) - -AC_SUBST([version], ["LOCAL_VERSION"]) -AC_SUBST([version_major], ["LOCAL_VERSION_MAJOR"]) -AC_SUBST([version_minor], ["LOCAL_VERSION_MINOR"]) -AC_SUBST([version_revision], ["LOCAL_VERSION_REVISION"]) -AC_SUBST([version_stage], ["LOCAL_VERSION_STAGE"]) -AC_SUBST([version_release], ["LOCAL_VERSION_RELEASE"]) - -AC_SUBST([bug_uri], ["LOCAL_BUG_URI"]) - -AC_SUBST([localconfdir], [${sysconfdir}/${package_identifier}]) -AC_SUBST([localdatadir], [${datadir}/${package_identifier}]) -AC_SUBST([localdocdir], [${datadir}/doc/${package_identifier}]) -AC_SUBST([locallibdir], [${libdir}/${package_identifier}]) -AC_SUBST([localstatelibdir], [${localstatedir}/lib/${package_identifier}]) -AC_SUBST([localstatelogdir], [${localstatedir}/log/${package_identifier}]) -AC_SUBST([locallibbindir], [${locallibdir}/bin]) -AC_SUBST([localerlangbindir], [${locallibdir}/erlang/bin]) -AC_SUBST([localerlanglibdir], [${locallibdir}/erlang/lib]) - -AC_REVISION([LOCAL_VERSION]) - -AC_CONFIG_FILES([Makefile]) -AC_CONFIG_FILES([lib/Makefile]) -AC_CONFIG_FILES([lib/bcrypt/Makefile]) -AC_CONFIG_FILES([lib/bcrypt/priv/Makefile]) - -AC_OUTPUT diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index 1b96745..0000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -## Copyright (c) 2008 Hunter Morris - -## Permission to use, copy, modify, and distribute this software for any -## purpose with or without fee is hereby granted, provided that the above -## copyright notice and this permission notice appear in all copies. - -## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -SUBDIRS = bcrypt diff --git a/lib/bcrypt/Makefile.am b/lib/bcrypt/Makefile.am deleted file mode 100644 index 1010435..0000000 --- a/lib/bcrypt/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -## Copyright (c) 2009 Hunter Morris - -## Permission to use, copy, modify, and distribute this software for any -## purpose with or without fee is hereby granted, provided that the above -## copyright notice and this permission notice appear in all copies. - -## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -SUBDIRS = priv - -bcryptebindir = $(localerlanglibdir)/bcrypt/ebin - -bcrypt_file_collection = \ - src/bcrypt_app.erl \ - src/bcrypt_sup.erl \ - src/bcrypt.erl - -bcryptebin_static_file = ebin/bcrypt.app - -bcryptebin_make_generated_file_list = \ - ebin/bcrypt_app.beam \ - ebin/bcrypt_sup.beam \ - ebin/bcrypt.beam - -bcryptebin_DATA = \ - $(bcryptebin_static_file) \ - $(bcryptebin_make_generated_file_list) - -EXTRA_DIST = \ - $(bcrypt_file_collection) \ - $(bcryptebin_static_file) - -CLEANFILES = \ - $(bcryptebin_make_generated_file_list) - -ebin/%.beam: src/%.erl - $(ERLC) -o ebin $< diff --git a/lib/bcrypt/c_src/bcrypt_nif.c b/lib/bcrypt/c_src/bcrypt_nif.c index 7e41afc..61cbdbb 100644 --- a/lib/bcrypt/c_src/bcrypt_nif.c +++ b/lib/bcrypt/c_src/bcrypt_nif.c @@ -28,7 +28,7 @@ char *bcrypt(const char *, const char *); void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); static ERL_NIF_TERM -encode_salt(ErlNifEnv* env, ERL_NIF_TERM csalt_term, ERL_NIF_TERM log_rounds_term) +erl_encode_salt(ErlNifEnv* env, ERL_NIF_TERM csalt_term, ERL_NIF_TERM log_rounds_term) { ErlNifBinary csalt, bin; unsigned long log_rounds; @@ -38,24 +38,24 @@ encode_salt(ErlNifEnv* env, ERL_NIF_TERM csalt_term, ERL_NIF_TERM log_rounds_ter } if (!enif_get_ulong(env, log_rounds_term, &log_rounds)) { + enif_release_binary(env, &csalt); return enif_make_badarg(env); } if (!enif_alloc_binary(env, 64, &bin)) { + enif_release_binary(env, &csalt); return enif_make_badarg(env); } - if (!encode_salt(bin.data, (u_int8_t*)csalt.data, csalt.size, log_rounds)) { - return enif_make_badarg(env); - } - - return enif_make_binary(env, bin); + encode_salt((char *)bin.data, (u_int8_t*)csalt.data, csalt.size, log_rounds); + enif_release_binary(env, &csalt); + return enif_make_binary(env, &bin); } static ERL_NIF_TERM hashpw(ErlNifEnv* env, ERL_NIF_TERM pass_term, ERL_NIF_TERM salt_term) { - ErlNifBinary pass, salt, bin; + ErlNifBinary pass, salt; char *ret = NULL; if (!enif_inspect_binary(env, pass_term, &pass)) { @@ -63,23 +63,27 @@ hashpw(ErlNifEnv* env, ERL_NIF_TERM pass_term, ERL_NIF_TERM salt_term) } if (!enif_inspect_binary(env, salt_term, &salt)) { + enif_release_binary(env, &pass); return enif_make_badarg(env); } - if (!enif_alloc_binary(env, 60, &bin)) { - return enif_make_badarg(env); - } + char pass_data[pass.size + 1]; + pass_data[pass.size] = '\0'; + char salt_data[salt.size + 1]; + salt_data[salt.size] = '\0'; - if (NULL == (ret = bcrypt(pass.data, salt.data)) || 0 == strcmp(ret, ":")) { + if (NULL == (ret = bcrypt(pass_data, salt_data)) || 0 == strcmp(ret, ":")) { return enif_make_badarg(env); } + enif_release_binary(env, &pass); + enif_release_binary(env, &salt); return enif_make_string(env, ret); } static ErlNifFunc bcrypt_nif_funcs[] = { - {"encode_salt", 2, encode_salt}, + {"encode_salt", 2, erl_encode_salt}, {"hashpw", 2, hashpw} }; diff --git a/lib/bcrypt/priv/Makefile.am b/lib/bcrypt/priv/Makefile.am deleted file mode 100644 index 7c5cb0c..0000000 --- a/lib/bcrypt/priv/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Copyright (c) 2009 Hunter Morris - -## Permission to use, copy, modify, and distribute this software for any -## purpose with or without fee is hereby granted, provided that the above -## copyright notice and this permission notice appear in all copies. - -## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -bcryptprivlibdir = $(localerlanglibdir)/bcrypt/priv - -bcryptprivlib_PROGRAMS = bcrypt - -bcrypt_SOURCES = \ - ../c_src/bcrypt_erlang.c \ - ../c_src/blowfish.c \ - ../c_src/bcrypt.c \ - ../c_src/erl_blf.h - -bcrypt_LDADD = -lpthread -lerl_interface -lei diff --git a/lib/bcrypt/src/bcrypt.erl b/lib/bcrypt/src/bcrypt.erl deleted file mode 100644 index 4fc3a58..0000000 --- a/lib/bcrypt/src/bcrypt.erl +++ /dev/null @@ -1,172 +0,0 @@ -%% @author Hunter Morris -%% @copyright 2009 Hunter Morris -%% -%% @doc Wrapper around the OpenBSD Blowfish password hashing algorithm, as -%% described in "A Future-Adaptable Password Scheme" by Niels Provos and -%% David Mazieres: http://www.openbsd.org/papers/bcrypt-paper.ps -%% -%% Types: -%% @type fname() = string() | atom() | deeplist() -%% @type deeplist() = [char() | atom() | deeplist()] -%% @type password() = string() | binary() -%% -%% @end -%% -%% Permission to use, copy, modify, and distribute this software for any -%% purpose with or without fee is hereby granted, provided that the above -%% copyright notice and this permission notice appear in all copies. - -%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --module(bcrypt). --author('Hunter Morris '). - --behaviour(gen_server). - -%% API --export([start_link/0, start_link/1, stop/0]). --export([gen_salt/0, gen_salt/1]). --export([hashpw/2]). - -%% gen_server callbacks --export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, - code_change/3]). - --define(CMD_SALT, 0). --define(CMD_HASHPW, 1). --record(state, {port}). - --define(BCRYPT_ERROR(F, D), error_logger:error_msg(F, D)). --define(BCRYPT_WARNING(F, D), error_logger:warning_msg(F, D)). --define(DEFAULT_LOG_ROUNDS, 12). --define(MAX_LOG_ROUNDS(L), L < 32). --define(MIN_LOG_ROUNDS(L), L > 3). - -%%-------------------------------------------------------------------- -%% @doc Start a bcrypt port using the default filename -%% @spec start_link() -> {ok, pid()} -%% @end -%%-------------------------------------------------------------------- -start_link() -> - case application:get_env(bcrypt, bcrypt_filename) of - {ok, Filename} -> - start_link(Filename); - undefined -> - case code:priv_dir(bcrypt) of - {error, bad_name} -> - {stop, bcrypt_not_found}; - Dir -> - start_link(Dir ++ "/bcrypt") - end - end. - -%%-------------------------------------------------------------------- -%% @doc Start a bcrypt port server -%% @spec start_link(Filename::fname()) -> {ok, pid()} -%% @end -%%-------------------------------------------------------------------- -start_link(Filename) when is_list(Filename) - ; is_atom(Filename) -> - gen_server:start_link({local, ?MODULE}, ?MODULE, - [{filename, Filename}], []). - -%%-------------------------------------------------------------------- -%% @doc Stop a bcrypt port server -%% @spec stop() -> ok -%% @end -%%-------------------------------------------------------------------- -stop() -> - gen_server:call(?MODULE, stop). - -%%-------------------------------------------------------------------- -%% @doc Generate a salt with the default number of rounds, 12. -%% @see gen_salt/1 -%% @spec gen_salt() -> string() -%% @end -%%-------------------------------------------------------------------- -gen_salt() -> - gen_salt(?DEFAULT_LOG_ROUNDS). - -%%-------------------------------------------------------------------- -%% @doc Generate a random text salt for use with hashpw/3. LogRounds -%% defines the complexity of the hashing, increasing the cost as -%% 2^log_rounds. -%% @spec gen_salt(integer()) -> string() -%% @end -%%-------------------------------------------------------------------- -gen_salt(LogRounds) when is_integer(LogRounds), - ?MAX_LOG_ROUNDS(LogRounds), - ?MIN_LOG_ROUNDS(LogRounds) -> - R = crypto:rand_bytes(16), - gen_server:call(?MODULE, {encode_salt, R, LogRounds}). - -%%-------------------------------------------------------------------- -%% @doc Hash the specified password and the salt using the OpenBSD -%% Blowfish password hashing algorithm. Returns the hashed password. -%% @spec hashpw(Password::password(), Salt::string()) -> string() -%% @end -%%-------------------------------------------------------------------- -hashpw(Password, Salt) - when is_list(Password); is_binary(Password), - is_list(Salt) -> - gen_server:call(?MODULE, {hashpw, Password, Salt}, infinity). - -%%==================================================================== -%% gen_server callbacks -%%==================================================================== -init(L) -> - Filename = proplists:get_value(filename, L), - case file:read_file_info(Filename) of - {ok, _Info} -> - Port = open_port({spawn, Filename}, [{packet, 2}, binary, exit_status]), - {ok, #state{port=Port}}; - {error, Reason} -> - ?BCRYPT_ERROR("Can't open file ~p: ~p", [Filename, Reason]), - error - end. - -terminate(_Reason, #state{port=Port}) -> - catch port_close(Port), - ok. - -handle_call({encode_salt, R, LogRounds}, From, State) -> - Port = State#state.port, - Data = term_to_binary({?CMD_SALT, From, {R, LogRounds}}), - port_command(Port, Data), - {noreply, State}; -handle_call({hashpw, Password, Salt}, From, State) -> - Port = State#state.port, - Data = term_to_binary({?CMD_HASHPW, From, {Password, Salt}}), - port_command(Port, Data), - {noreply, State}; -handle_call(stop, _From, State) -> - {stop, normal, ok, State}; -handle_call(_Request, _From, State) -> - {reply, bad_request, State}. - -handle_info({Port, {data, Data}}, #state{port=Port}=State) -> - case binary_to_term(Data) of - {Cmd, To, Reply} when Cmd == ?CMD_SALT; Cmd == ?CMD_HASHPW -> - gen_server:reply(To, Reply); - Err -> - ?BCRYPT_ERROR("Got invalid reply from ~p: ~p", [Port, Err]) - end, - {noreply, State}; -handle_info({Port, {exit_status, Status}}, #state{port=Port}=State) -> - %% Rely on whomever is supervising this process to restart. - ?BCRYPT_WARNING("Port died: ~p", [Status]), - {stop, port_died, State}; -handle_info(Msg, State) -> - ?BCRYPT_WARNING("Got unexpected message: ~p", [Msg]), - {noreply, State}. - -handle_cast(_Msg, State) -> - {noreply, State}. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. diff --git a/lib/bcrypt/src/bcrypt_app.erl b/lib/bcrypt/src/bcrypt_app.erl deleted file mode 100644 index 1aa7c82..0000000 --- a/lib/bcrypt/src/bcrypt_app.erl +++ /dev/null @@ -1,37 +0,0 @@ -%% @author Hunter Morris -%% @copyright 2009 Hunter Morris -%% -%% @doc Bcrypt application callback module -%% @end -%% -%% Permission to use, copy, modify, and distribute this software for any -%% purpose with or without fee is hereby granted, provided that the above -%% copyright notice and this permission notice appear in all copies. - -%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --module(bcrypt_app). --author('Hunter Morris '). - --behaviour(application). - --export([start/0, start/2, stop/1]). - -start() -> - start(normal, []). - -start(normal, Args) -> - case bcrypt_sup:start_link(Args) of - {ok, Pid} -> - {ok, Pid}; - Error -> - Error - end. - -stop(_State) -> - ok. diff --git a/lib/bcrypt/src/bcrypt_nif.erl b/lib/bcrypt/src/bcrypt_nif.erl new file mode 100644 index 0000000..7d7ba72 --- /dev/null +++ b/lib/bcrypt/src/bcrypt_nif.erl @@ -0,0 +1,78 @@ +%% @author Hunter Morris +%% @copyright 2009 Hunter Morris +%% +%% @doc Wrapper around the OpenBSD Blowfish password hashing algorithm, as +%% described in "A Future-Adaptable Password Scheme" by Niels Provos and +%% David Mazieres: http://www.openbsd.org/papers/bcrypt-paper.ps +%% @end +%% +%% Permission to use, copy, modify, and distribute this software for any +%% purpose with or without fee is hereby granted, provided that the above +%% copyright notice and this permission notice appear in all copies. + +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +-module(bcrypt_nif). +-author('Hunter Morris '). + +%% API +-export([start/0]). +-export([gen_salt/0, gen_salt/1]). +-export([hash/2]). + +-define(DEFAULT_LOG_ROUNDS, 12). +-define(MAX_LOG_ROUNDS(L), L < 32). +-define(MIN_LOG_ROUNDS(L), L > 3). + +%%-------------------------------------------------------------------- +%% @doc Load the bcrypt NIFs +%% @spec start() -> ok +%% @end +%%-------------------------------------------------------------------- +start() -> + erlang:load_nif("bcrypt_nif", 0). + +%%-------------------------------------------------------------------- +%% @doc Generate a salt with the default number of rounds, 12. +%% @see gen_salt/1 +%% @spec gen_salt() -> string() +%% @end +%%-------------------------------------------------------------------- +gen_salt() -> + gen_salt(?DEFAULT_LOG_ROUNDS). + +%%-------------------------------------------------------------------- +%% @doc Generate a random text salt for use with hashpw/3. LogRounds +%% defines the complexity of the hashing, increasing the cost as +%% 2^log_rounds. +%% @spec gen_salt(integer()) -> string() +%% @end +%%-------------------------------------------------------------------- +gen_salt(LogRounds) when is_integer(LogRounds), + ?MAX_LOG_ROUNDS(LogRounds), + ?MIN_LOG_ROUNDS(LogRounds) -> + R = crypto:rand_bytes(16), + encode_salt(R, LogRounds). + +encode_salt(_R, _LogRounds) -> + nif_error(?LINE). + +%%-------------------------------------------------------------------- +%% @doc Hash the specified password and the salt using the OpenBSD +%% Blowfish password hashing algorithm. Returns the hashed password. +%% @spec hashpw(Password::binary(), Salt::binary()) -> string() +%% @end +%%-------------------------------------------------------------------- +hash(Password, Salt) when is_binary(Password), is_binary(Salt) -> + hashpw(Password, Salt). + +hashpw(_Password, _Salt) -> + nif_error(?LINE). + +nif_error(Line) -> + exit({nif_not_loaded, module, ?MODULE, line, Line}). diff --git a/lib/bcrypt/src/bcrypt_sup.erl b/lib/bcrypt/src/bcrypt_sup.erl deleted file mode 100644 index ad8b05b..0000000 --- a/lib/bcrypt/src/bcrypt_sup.erl +++ /dev/null @@ -1,37 +0,0 @@ -%% @author Hunter Morris -%% @copyright 2009 Hunter Morris -%% -%% @doc Bcrypt supervisor -%% @end -%% -%% Permission to use, copy, modify, and distribute this software for any -%% purpose with or without fee is hereby granted, provided that the above -%% copyright notice and this permission notice appear in all copies. - -%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --module(bcrypt_sup). --author('Hunter Morris '). - --behaviour(supervisor). - -%% External --export([start_link/1]). - -%% supervisor cb --export([init/1]). - -start_link(Args) -> - supervisor:start_link({local, ?MODULE}, ?MODULE, Args). - -init(_Args) -> - Bcrypt = - {bcrypt, {bcrypt, start_link, []}, - permanent, 2000, worker, [bcrypt]}, - - {ok,{{one_for_one, 15, 60}, [Bcrypt]}}. diff --git a/m4/.gitignore b/m4/.gitignore deleted file mode 100644 index e69de29..0000000