Binary files /tmp/tmpBi8HUl/DDUaiQON8Z/argon2-0~20161029/argon2-specs.pdf and /tmp/tmpBi8HUl/FgaFBMIsIi/argon2-0~20171227/argon2-specs.pdf differ diff -Nru argon2-0~20161029/CHANGELOG.md argon2-0~20171227/CHANGELOG.md --- argon2-0~20161029/CHANGELOG.md 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/CHANGELOG.md 2017-12-27 19:56:31.000000000 +0000 @@ -1,3 +1,10 @@ +# 20171227 +* Added ABI version number +* AVX2/AVX-512F optimizations of BLAMKA +* Set Argon2 version number from the command line +* New bindings +* Minor bug and warning fixes (no security issue) + # 20161029 * Argon2id added diff -Nru argon2-0~20161029/debian/changelog argon2-0~20171227/debian/changelog --- argon2-0~20161029/debian/changelog 2018-04-23 20:59:38.000000000 +0000 +++ argon2-0~20171227/debian/changelog 2018-06-06 20:08:10.000000000 +0000 @@ -1,3 +1,12 @@ +argon2 (0~20171227-0.1) unstable; urgency=medium + + * Non-maintainer upload. + * New upstream release + * ABI bump. + * Build udeb without a dependency on pthreads. + + -- Matthew Garrett Wed, 06 Jun 2018 13:08:10 -0700 + argon2 (0~20161029-2) unstable; urgency=medium * control: move vcs to salsa gitlab diff -Nru argon2-0~20161029/debian/control argon2-0~20171227/debian/control --- argon2-0~20161029/debian/control 2018-04-23 20:42:46.000000000 +0000 +++ argon2-0~20171227/debian/control 2018-06-06 20:08:10.000000000 +0000 @@ -9,10 +9,13 @@ Vcs-Browser: https://salsa.debian.org/debian/argon2 Vcs-Git: https://salsa.debian.org/debian/argon2.git -Package: libargon2-0-dev +Package: libargon2-dev Section: libdevel Architecture: any -Depends: libargon2-0 (= ${binary:Version}), ${misc:Depends} +Depends: libargon2-1 (= ${binary:Version}), ${misc:Depends} +Provides: libargon2-0-dev +Replaces: libargon2-0-dev +Conflicts: libargon2-0-dev Multi-Arch: same Description: memory-hard hashing function - development files Argon2 is a password-hashing function that can be used to hash passwords @@ -32,6 +35,28 @@ on argon2. Package: libargon2-0 +Section: libdevel +Architecture: any +Depends: libargon2-1 (= ${binary:Version}) +Description: memory-hard hashing function - runtime library + Argon2 is a password-hashing function that can be used to hash passwords + for credential storage, key derivation, or other applications. + . + There are two main versions of Argon2: Argon2i and Argon2d. + Argon2i is the safest against side-channel attacks, while Argon2d provides + the highest resistance against GPU cracking attacks. + . + Argon2i and Argon2d are parametrized by: + * A time cost, which defines the amount of computation realized and + therefore the execution time, given in number of iterations + * A memory cost, which defines the memory usage, given in kibibytes + * A parallelism degree, which defines the number of parallel threads + . + This package provides compatibility for packages built against older + versions of libargon2. + + +Package: libargon2-1 Architecture: any Pre-Depends: ${misc:Pre-Depends} Depends: ${shlibs:Depends}, ${misc:Depends} @@ -73,7 +98,7 @@ . This package contains the argon2 tool for hashing data on the command-line. -Package: libargon2-0-udeb +Package: libargon2-1-udeb Section: debian-installer Package-Type: udeb Architecture: any diff -Nru argon2-0~20161029/debian/libargon2-0-dev.install argon2-0~20171227/debian/libargon2-0-dev.install --- argon2-0~20161029/debian/libargon2-0-dev.install 2017-07-16 10:59:25.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0-dev.install 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -#!/usr/bin/dh-exec -include/argon2.h usr/include -libargon2.a usr/lib/${DEB_HOST_MULTIARCH} -libargon2.pc usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig diff -Nru argon2-0~20161029/debian/libargon2-0-dev.links argon2-0~20171227/debian/libargon2-0-dev.links --- argon2-0~20161029/debian/libargon2-0-dev.links 2017-07-16 10:59:25.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0-dev.links 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -#!/usr/bin/dh-exec -usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} usr/lib/${DEB_HOST_MULTIARCH}/libargon2.so diff -Nru argon2-0~20161029/debian/libargon2-0.install argon2-0~20171227/debian/libargon2-0.install --- argon2-0~20161029/debian/libargon2-0.install 2017-07-16 10:59:25.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0.install 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -#!/usr/bin/dh-exec -libargon2.so => usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} diff -Nru argon2-0~20161029/debian/libargon2-0.links argon2-0~20171227/debian/libargon2-0.links --- argon2-0~20161029/debian/libargon2-0.links 1970-01-01 00:00:00.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0.links 2018-06-06 20:08:10.000000000 +0000 @@ -0,0 +1,2 @@ +#!/usr/bin/dh-exec +usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} usr/lib/${DEB_HOST_MULTIARCH}/libargon2.so.0 diff -Nru argon2-0~20161029/debian/libargon2-0.symbols argon2-0~20171227/debian/libargon2-0.symbols --- argon2-0~20161029/debian/libargon2-0.symbols 2017-07-16 10:59:25.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0.symbols 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -libargon2.so.0 libargon2-0 #MINVER# - argon2_ctx@Base 0~20160406~ - argon2_encodedlen@Base 0~20160406~ - argon2_error_message@Base 0~20160406~ - argon2_hash@Base 0~20160406~ - argon2_type2string@Base 0~20161029~ - argon2_verify@Base 0~20160406~ - argon2_verify_ctx@Base 0~20160406~ - argon2d_ctx@Base 0~20160406~ - argon2d_hash_encoded@Base 0~20160406~ - argon2d_hash_raw@Base 0~20160406~ - argon2d_verify@Base 0~20160406~ - argon2d_verify_ctx@Base 0~20160406~ - argon2i_ctx@Base 0~20160406~ - argon2i_hash_encoded@Base 0~20160406~ - argon2i_hash_raw@Base 0~20160406~ - argon2i_verify@Base 0~20160406~ - argon2i_verify_ctx@Base 0~20160406~ - argon2id_ctx@Base 0~20161029~ - argon2id_hash_encoded@Base 0~20161029~ - argon2id_hash_raw@Base 0~20161029~ - argon2id_verify@Base 0~20161029~ - argon2id_verify_ctx@Base 0~20161029~ diff -Nru argon2-0~20161029/debian/libargon2-0-udeb.install argon2-0~20171227/debian/libargon2-0-udeb.install --- argon2-0~20161029/debian/libargon2-0-udeb.install 2018-04-23 20:30:52.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-0-udeb.install 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -#!/usr/bin/dh-exec -libargon2.so => usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} diff -Nru argon2-0~20161029/debian/libargon2-1.install argon2-0~20171227/debian/libargon2-1.install --- argon2-0~20161029/debian/libargon2-1.install 1970-01-01 00:00:00.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-1.install 2018-06-06 20:08:10.000000000 +0000 @@ -0,0 +1,2 @@ +#!/usr/bin/dh-exec +libargon2.so.1 => usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} diff -Nru argon2-0~20161029/debian/libargon2-1.symbols argon2-0~20171227/debian/libargon2-1.symbols --- argon2-0~20161029/debian/libargon2-1.symbols 1970-01-01 00:00:00.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-1.symbols 2018-06-06 20:08:10.000000000 +0000 @@ -0,0 +1,23 @@ +libargon2.so.1 libargon2-1 #MINVER# + argon2_ctx@Base 0~20171227 + argon2_encodedlen@Base 0~20171227 + argon2_error_message@Base 0~20171227 + argon2_hash@Base 0~20171227 + argon2_type2string@Base 0~20171227 + argon2_verify@Base 0~20171227 + argon2_verify_ctx@Base 0~20171227 + argon2d_ctx@Base 0~20171227 + argon2d_hash_encoded@Base 0~20171227 + argon2d_hash_raw@Base 0~20171227 + argon2d_verify@Base 0~20171227 + argon2d_verify_ctx@Base 0~20171227 + argon2i_ctx@Base 0~20171227 + argon2i_hash_encoded@Base 0~20171227 + argon2i_hash_raw@Base 0~20171227 + argon2i_verify@Base 0~20171227 + argon2i_verify_ctx@Base 0~20171227 + argon2id_ctx@Base 0~20171227 + argon2id_hash_encoded@Base 0~20171227 + argon2id_hash_raw@Base 0~20171227 + argon2id_verify@Base 0~20171227 + argon2id_verify_ctx@Base 0~20171227 diff -Nru argon2-0~20161029/debian/libargon2-dev.install argon2-0~20171227/debian/libargon2-dev.install --- argon2-0~20161029/debian/libargon2-dev.install 1970-01-01 00:00:00.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-dev.install 2018-06-06 20:08:10.000000000 +0000 @@ -0,0 +1,4 @@ +#!/usr/bin/dh-exec +include/argon2.h usr/include +libargon2.a usr/lib/${DEB_HOST_MULTIARCH} +libargon2.pc usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig diff -Nru argon2-0~20161029/debian/libargon2-dev.links argon2-0~20171227/debian/libargon2-dev.links --- argon2-0~20161029/debian/libargon2-dev.links 1970-01-01 00:00:00.000000000 +0000 +++ argon2-0~20171227/debian/libargon2-dev.links 2018-06-06 20:08:10.000000000 +0000 @@ -0,0 +1,2 @@ +#!/usr/bin/dh-exec +usr/lib/${DEB_HOST_MULTIARCH}/${SONAME} usr/lib/${DEB_HOST_MULTIARCH}/libargon2.so diff -Nru argon2-0~20161029/debian/rules argon2-0~20171227/debian/rules --- argon2-0~20161029/debian/rules 2018-04-23 20:55:23.000000000 +0000 +++ argon2-0~20171227/debian/rules 2018-06-06 20:08:10.000000000 +0000 @@ -9,24 +9,36 @@ include /usr/share/dpkg/buildflags.mk include /usr/share/dpkg/default.mk +export PKG=libargon2 export OPTTARGET=$(DEB_TARGET_GNU_CPU) -export SONAME=libargon2.so.$(SOVER) -export SOPKG=libargon2-$(SOVER) -export SOVER=0 +export SONAME=$(PKG).so.$(SOVER) +export SOPKG=$(PKG)-$(SOVER) +export SOVER=1 export DEBPREFIX=0~ export UPSTREAMVER=$(subst $(DEBPREFIX),,$(DEB_VERSION_UPSTREAM)) +export UDEBLIB=$(SONAME).udeb %: dh $@ +override_dh_auto_build: + dh_auto_build -- NO_THREADS=1 + mv $(SONAME) $(UDEBLIB) + dh_auto_build + override_dh_install: dh_install - sed -i '/^## /d' debian/${SOPKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc - sed -i s/@HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/ debian/${SOPKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc - sed -i s/@UPSTREAM_VER@/$(UPSTREAMVER)/ debian/${SOPKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc + sed -i '/^## /d' debian/${PKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc + sed -i s/@HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/ debian/${PKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc + sed -i s/@UPSTREAM_VER@/$(UPSTREAMVER)/ debian/${PKG}-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libargon2.pc + install -D $(UDEBLIB) debian/$(SOPKG)-udeb/usr/lib/$(DEB_HOST_MULTIARCH)/$(SONAME) + +override_dh_auto_clean: + dh_auto_clean + -rm $(UDEBLIB) override_dh_auto_test: -$(MAKE) -j1 test override_dh_makeshlibs: - dh_makeshlibs -V --add-udeb="libargon2-0-udeb" + dh_makeshlibs -V --add-udeb="libargon2-1-udeb" diff -Nru argon2-0~20161029/include/argon2.h argon2-0~20171227/include/argon2.h --- argon2-0~20161029/include/argon2.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/include/argon2.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -29,10 +29,13 @@ /* Symbols visibility control */ #ifdef A2_VISCTL #define ARGON2_PUBLIC __attribute__((visibility("default"))) +#define ARGON2_LOCAL __attribute__ ((visibility ("hidden"))) #elif _MSC_VER #define ARGON2_PUBLIC __declspec(dllexport) +#define ARGON2_LOCAL #else #define ARGON2_PUBLIC +#define ARGON2_LOCAL #endif /* @@ -267,8 +270,7 @@ const size_t encodedlen); /** - * Hashes a password with Argon2i, producing a raw hash by allocating memory at - * @hash + * Hashes a password with Argon2i, producing a raw hash at @hash * @param t_cost Number of iterations * @param m_cost Sets memory usage to m_cost kibibytes * @param parallelism Number of threads and compute lanes @@ -421,6 +423,7 @@ * @param parallelism Number of threads; used to compute lanes * @param saltlen Salt size in bytes * @param hashlen Hash size in bytes + * @param type The argon2_type that we want the encoded length for * @return The encoded hash length in bytes */ ARGON2_PUBLIC size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, diff -Nru argon2-0~20161029/Makefile argon2-0~20171227/Makefile --- argon2-0~20161029/Makefile 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/Makefile 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ # Copyright 2015 # Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves # -# You may use this work under the terms of a Creative Commons CC0 1.0 +# You may use this work under the terms of a Creative Commons CC0 1.0 # License/Waiver or the Apache Public License 2.0, at your option. The terms of # these licenses can be found at: # @@ -19,6 +19,9 @@ BENCH = bench GENKAT = genkat +# Increment on an ABI breaking change +ABI_VERSION = 1 + DIST = phc-winner-argon2 SRC = src/argon2.c src/core.c src/blake2/blake2b.c src/thread.c src/encoding.c @@ -27,7 +30,14 @@ SRC_GENKAT = src/genkat.c OBJ = $(SRC:.c=.o) -CFLAGS += -std=c89 -pthread -O3 -Wall -g -Iinclude -Isrc +CFLAGS += -std=c89 -O3 -Wall -g -Iinclude -Isrc + +ifeq ($(NO_THREADS), 1) +CFLAGS += -DARGON2_NO_THREADS +else +CFLAGS += -pthread +endif + CI_CFLAGS := $(CFLAGS) -Werror=declaration-after-statement -D_FORTIFY_SOURCE=2 \ -Wextra -Wno-type-limits -Werror -coverage -DTEST_LARGE_RAM @@ -49,17 +59,19 @@ LIB_NAME=argon2 ifeq ($(KERNEL_NAME), Linux) - LIB_EXT := so + LIB_EXT := so.$(ABI_VERSION) LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1 - SO_LDFLAGS := -Wl,-soname,libargon2.so.0 + SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT) + LINKED_LIB_EXT := so endif ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),FreeBSD NetBSD OpenBSD)) LIB_EXT := so LIB_CFLAGS := -shared -fPIC endif ifeq ($(KERNEL_NAME), Darwin) - LIB_EXT := dylib + LIB_EXT := $(ABI_VERSION).dylib LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT) + LINKED_LIB_EXT := dylib endif ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN) LIB_EXT := dll @@ -88,6 +100,12 @@ LIB_SH := lib$(LIB_NAME).$(LIB_EXT) LIB_ST := lib$(LIB_NAME).a + +ifdef LINKED_LIB_EXT +LINKED_LIB_SH := lib$(LIB_NAME).$(LINKED_LIB_EXT) +endif + + LIBRARIES = $(LIB_SH) $(LIB_ST) HEADERS = include/argon2.h @@ -105,7 +123,7 @@ .PHONY: clean dist format $(GENKAT) all install -all: clean $(RUN) libs +all: $(RUN) libs libs: $(LIBRARIES) $(RUN): $(SRC) $(SRC_RUN) @@ -125,7 +143,7 @@ clean: rm -f $(RUN) $(BENCH) $(GENKAT) - rm -f $(LIB_SH) $(LIB_ST) kat-argon2* + rm -f $(LIB_SH) $(LIB_ST) kat-argon2* rm -f testcase rm -rf *.dSYM cd src/ && rm -f *.o @@ -154,8 +172,16 @@ install: $(RUN) libs $(INSTALL) -d $(INST_INCLUDE) - $(INSTALL) $(HEADERS) $(INST_INCLUDE) + $(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE) $(INSTALL) -d $(INST_LIBRARY) $(INSTALL) $(LIBRARIES) $(INST_LIBRARY) +ifdef LINKED_LIB_SH + cd $(INST_LIBRARY) && ln -s $(notdir $(LIB_SH) $(LINKED_LIB_SH)) +endif $(INSTALL) -d $(INST_BINARY) $(INSTALL) $(RUN) $(INST_BINARY) + +uninstall: + cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS)) + cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH)) + cd $(INST_BINARY) && rm -f $(notdir $(RUN)) diff -Nru argon2-0~20161029/man/argon2.1 argon2-0~20171227/man/argon2.1 --- argon2-0~20161029/man/argon2.1 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/man/argon2.1 2017-12-27 19:56:31.000000000 +0000 @@ -45,6 +45,9 @@ .TP .B \-r Output only the raw bytes of the hash +.TP +.B \-v (10|13) +Argon2 version (defaults to the most recent version, currently 13) .SH COPYRIGHT This manpage was written by \fBDaniel Kahn Gillmor\fR for the Debian diff -Nru argon2-0~20161029/README.md argon2-0~20171227/README.md --- argon2-0~20161029/README.md 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/README.md 2017-12-27 19:56:31.000000000 +0000 @@ -54,7 +54,7 @@ on your system. To show usage instructions, run `./argon2 -h` as ``` -Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] +Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)] Password is read from stdin Parameters: salt The salt to use, at least 8 characters @@ -67,6 +67,7 @@ -l N Sets hash output length to N bytes (default 32) -e Output only encoded hash -r Output only the raw bytes of the hash + -v (10|13) Argon2 version (defaults to the most recent version, currently 13) -h Print argon2 usage ``` For example, to hash "password" using "somesalt" as a salt and doing 2 @@ -255,13 +256,17 @@ * [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady) * [Python (native)](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow) * [Python (ffi)](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek) +* [Python (ffi, with keyed hashing)](https://github.com/thusoy/porridge), by [@thusoy](https://github.com/thusoy) +* [R](https://cran.r-project.org/package=argon2) by [@wrathematics](https://github.com/wrathematics) * [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion) * [Rust](https://github.com/quininer/argon2-rs) by [@quininer](https://github.com/quininer) * [C#/.NET CoreCLR](https://github.com/kmaragon/Konscious.Security.Cryptography) by [@kmaragon](https://github.com/kmaragon) * [Perl](https://github.com/Leont/crypt-argon2) by [@leont](https://github.com/Leont) +* [mruby](https://github.com/Asmod4n/mruby-argon2) by [@Asmod4n](https://github.com/Asmod4n) +* [Swift](https://github.com/ImKcat/CatCrypto) by [@ImKcat](https://github.com/ImKcat) -## Test Suite +## Test suite There are two sets of test suites. One is a low level test for the hash function, the other tests the higher level API. Both of these are built and diff -Nru argon2-0~20161029/src/argon2.c argon2-0~20171227/src/argon2.c --- argon2-0~20161029/src/argon2.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/argon2.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -72,6 +72,10 @@ instance.threads = context->threads; instance.type = type; + if (instance.threads > instance.lanes) { + instance.threads = instance.lanes; + } + /* 3. Initialization: Hashing inputs, allocating memory, filling first * blocks */ @@ -104,6 +108,14 @@ int result; uint8_t *out; + if (pwdlen > ARGON2_MAX_PWD_LENGTH) { + return ARGON2_PWD_TOO_LONG; + } + + if (saltlen > ARGON2_MAX_SALT_LENGTH) { + return ARGON2_SALT_TOO_LONG; + } + if (hashlen > ARGON2_MAX_OUTLEN) { return ARGON2_OUTPUT_TOO_LONG; } @@ -245,6 +257,10 @@ size_t encoded_len; uint32_t max_field_len; + if (pwdlen > ARGON2_MAX_PWD_LENGTH) { + return ARGON2_PWD_TOO_LONG; + } + if (encoded == NULL) { return ARGON2_DECODING_FAIL; } @@ -268,7 +284,7 @@ } ctx.pwd = (uint8_t *)pwd; - ctx.pwdlen = pwdlen; + ctx.pwdlen = (uint32_t)pwdlen; ret = decode_string(&ctx, encoded, type); if (ret != ARGON2_OK) { diff -Nru argon2-0~20161029/src/bench.c argon2-0~20171227/src/bench.c --- argon2-0~20161029/src/bench.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/bench.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -45,7 +45,7 @@ } /* - * Benchmarks Argon2 with salt length 16, password length 16, t_cost 1, + * Benchmarks Argon2 with salt length 16, password length 16, t_cost 3, and different m_cost and threads */ static void benchmark() { diff -Nru argon2-0~20161029/src/blake2/blake2b.c argon2-0~20171227/src/blake2/blake2b.c --- argon2-0~20161029/src/blake2/blake2b.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/blake2/blake2b.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * diff -Nru argon2-0~20161029/src/blake2/blake2.h argon2-0~20171227/src/blake2/blake2.h --- argon2-0~20161029/src/blake2/blake2.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/blake2/blake2.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -18,9 +18,7 @@ #ifndef PORTABLE_BLAKE2_H #define PORTABLE_BLAKE2_H -#include -#include -#include +#include #if defined(__cplusplus) extern "C" { @@ -69,19 +67,19 @@ }; /* Streaming API */ -int blake2b_init(blake2b_state *S, size_t outlen); -int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, +ARGON2_LOCAL int blake2b_init(blake2b_state *S, size_t outlen); +ARGON2_LOCAL int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t keylen); -int blake2b_init_param(blake2b_state *S, const blake2b_param *P); -int blake2b_update(blake2b_state *S, const void *in, size_t inlen); -int blake2b_final(blake2b_state *S, void *out, size_t outlen); +ARGON2_LOCAL int blake2b_init_param(blake2b_state *S, const blake2b_param *P); +ARGON2_LOCAL int blake2b_update(blake2b_state *S, const void *in, size_t inlen); +ARGON2_LOCAL int blake2b_final(blake2b_state *S, void *out, size_t outlen); /* Simple API */ -int blake2b(void *out, size_t outlen, const void *in, size_t inlen, - const void *key, size_t keylen); +ARGON2_LOCAL int blake2b(void *out, size_t outlen, const void *in, size_t inlen, + const void *key, size_t keylen); /* Argon2 Team - Begin Code */ -int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); +ARGON2_LOCAL int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); /* Argon2 Team - End Code */ #if defined(__cplusplus) diff -Nru argon2-0~20161029/src/blake2/blake2-impl.h argon2-0~20171227/src/blake2/blake2-impl.h --- argon2-0~20161029/src/blake2/blake2-impl.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/blake2/blake2-impl.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * diff -Nru argon2-0~20161029/src/blake2/blamka-round-opt.h argon2-0~20171227/src/blake2/blamka-round-opt.h --- argon2-0~20161029/src/blake2/blamka-round-opt.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/blake2/blamka-round-opt.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -29,6 +29,8 @@ #include #endif +#if !defined(__AVX512F__) +#if !defined(__AVX2__) #if !defined(__XOP__) #if defined(__SSSE3__) #define r16 \ @@ -176,5 +178,294 @@ \ UNDIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1); \ } while ((void)0, 0) +#else /* __AVX2__ */ -#endif +#include + +#define rotr32(x) _mm256_shuffle_epi32(x, _MM_SHUFFLE(2, 3, 0, 1)) +#define rotr24(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10)) +#define rotr16(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9)) +#define rotr63(x) _mm256_xor_si256(_mm256_srli_epi64((x), 63), _mm256_add_epi64((x), (x))) + +#define G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i ml = _mm256_mul_epu32(A0, B0); \ + ml = _mm256_add_epi64(ml, ml); \ + A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \ + D0 = _mm256_xor_si256(D0, A0); \ + D0 = rotr32(D0); \ + \ + ml = _mm256_mul_epu32(C0, D0); \ + ml = _mm256_add_epi64(ml, ml); \ + C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \ + \ + B0 = _mm256_xor_si256(B0, C0); \ + B0 = rotr24(B0); \ + \ + ml = _mm256_mul_epu32(A1, B1); \ + ml = _mm256_add_epi64(ml, ml); \ + A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \ + D1 = _mm256_xor_si256(D1, A1); \ + D1 = rotr32(D1); \ + \ + ml = _mm256_mul_epu32(C1, D1); \ + ml = _mm256_add_epi64(ml, ml); \ + C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \ + \ + B1 = _mm256_xor_si256(B1, C1); \ + B1 = rotr24(B1); \ + } while((void)0, 0); + +#define G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i ml = _mm256_mul_epu32(A0, B0); \ + ml = _mm256_add_epi64(ml, ml); \ + A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \ + D0 = _mm256_xor_si256(D0, A0); \ + D0 = rotr16(D0); \ + \ + ml = _mm256_mul_epu32(C0, D0); \ + ml = _mm256_add_epi64(ml, ml); \ + C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \ + B0 = _mm256_xor_si256(B0, C0); \ + B0 = rotr63(B0); \ + \ + ml = _mm256_mul_epu32(A1, B1); \ + ml = _mm256_add_epi64(ml, ml); \ + A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \ + D1 = _mm256_xor_si256(D1, A1); \ + D1 = rotr16(D1); \ + \ + ml = _mm256_mul_epu32(C1, D1); \ + ml = _mm256_add_epi64(ml, ml); \ + C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \ + B1 = _mm256_xor_si256(B1, C1); \ + B1 = rotr63(B1); \ + } while((void)0, 0); + +#define DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(0, 3, 2, 1)); \ + C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(2, 1, 0, 3)); \ + \ + B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(0, 3, 2, 1)); \ + C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ + D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(2, 1, 0, 3)); \ + } while((void)0, 0); + +#define DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \ + __m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \ + B1 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + B0 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + \ + tmp1 = C0; \ + C0 = C1; \ + C1 = tmp1; \ + \ + tmp1 = _mm256_blend_epi32(D0, D1, 0xCC); \ + tmp2 = _mm256_blend_epi32(D0, D1, 0x33); \ + D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + } while(0); + +#define UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(2, 1, 0, 3)); \ + C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(0, 3, 2, 1)); \ + \ + B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(2, 1, 0, 3)); \ + C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ + D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(0, 3, 2, 1)); \ + } while((void)0, 0); + +#define UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \ + __m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \ + B0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + B1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + \ + tmp1 = C0; \ + C0 = C1; \ + C1 = tmp1; \ + \ + tmp1 = _mm256_blend_epi32(D0, D1, 0x33); \ + tmp2 = _mm256_blend_epi32(D0, D1, 0xCC); \ + D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + } while((void)0, 0); + +#define BLAKE2_ROUND_1(A0, A1, B0, B1, C0, C1, D0, D1) \ + do{ \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + } while((void)0, 0); + +#define BLAKE2_ROUND_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do{ \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + } while((void)0, 0); + +#endif /* __AVX2__ */ + +#else /* __AVX512F__ */ + +#include + +#define ror64(x, n) _mm512_ror_epi64((x), (n)) + +static __m512i muladd(__m512i x, __m512i y) +{ + __m512i z = _mm512_mul_epu32(x, y); + return _mm512_add_epi64(_mm512_add_epi64(x, y), _mm512_add_epi64(z, z)); +} + +#define G1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + A0 = muladd(A0, B0); \ + A1 = muladd(A1, B1); \ +\ + D0 = _mm512_xor_si512(D0, A0); \ + D1 = _mm512_xor_si512(D1, A1); \ +\ + D0 = ror64(D0, 32); \ + D1 = ror64(D1, 32); \ +\ + C0 = muladd(C0, D0); \ + C1 = muladd(C1, D1); \ +\ + B0 = _mm512_xor_si512(B0, C0); \ + B1 = _mm512_xor_si512(B1, C1); \ +\ + B0 = ror64(B0, 24); \ + B1 = ror64(B1, 24); \ + } while ((void)0, 0) + +#define G2(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + A0 = muladd(A0, B0); \ + A1 = muladd(A1, B1); \ +\ + D0 = _mm512_xor_si512(D0, A0); \ + D1 = _mm512_xor_si512(D1, A1); \ +\ + D0 = ror64(D0, 16); \ + D1 = ror64(D1, 16); \ +\ + C0 = muladd(C0, D0); \ + C1 = muladd(C1, D1); \ +\ + B0 = _mm512_xor_si512(B0, C0); \ + B1 = _mm512_xor_si512(B1, C1); \ +\ + B0 = ror64(B0, 63); \ + B1 = ror64(B1, 63); \ + } while ((void)0, 0) + +#define DIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm512_permutex_epi64(B0, _MM_SHUFFLE(0, 3, 2, 1)); \ + B1 = _mm512_permutex_epi64(B1, _MM_SHUFFLE(0, 3, 2, 1)); \ +\ + C0 = _mm512_permutex_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + C1 = _mm512_permutex_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ +\ + D0 = _mm512_permutex_epi64(D0, _MM_SHUFFLE(2, 1, 0, 3)); \ + D1 = _mm512_permutex_epi64(D1, _MM_SHUFFLE(2, 1, 0, 3)); \ + } while ((void)0, 0) + +#define UNDIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm512_permutex_epi64(B0, _MM_SHUFFLE(2, 1, 0, 3)); \ + B1 = _mm512_permutex_epi64(B1, _MM_SHUFFLE(2, 1, 0, 3)); \ +\ + C0 = _mm512_permutex_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + C1 = _mm512_permutex_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ +\ + D0 = _mm512_permutex_epi64(D0, _MM_SHUFFLE(0, 3, 2, 1)); \ + D1 = _mm512_permutex_epi64(D1, _MM_SHUFFLE(0, 3, 2, 1)); \ + } while ((void)0, 0) + +#define BLAKE2_ROUND(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + G1(A0, B0, C0, D0, A1, B1, C1, D1); \ + G2(A0, B0, C0, D0, A1, B1, C1, D1); \ +\ + DIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1); \ +\ + G1(A0, B0, C0, D0, A1, B1, C1, D1); \ + G2(A0, B0, C0, D0, A1, B1, C1, D1); \ +\ + UNDIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1); \ + } while ((void)0, 0) + +#define SWAP_HALVES(A0, A1) \ + do { \ + __m512i t0, t1; \ + t0 = _mm512_shuffle_i64x2(A0, A1, _MM_SHUFFLE(1, 0, 1, 0)); \ + t1 = _mm512_shuffle_i64x2(A0, A1, _MM_SHUFFLE(3, 2, 3, 2)); \ + A0 = t0; \ + A1 = t1; \ + } while((void)0, 0) + +#define SWAP_QUARTERS(A0, A1) \ + do { \ + SWAP_HALVES(A0, A1); \ + A0 = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), A0); \ + A1 = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), A1); \ + } while((void)0, 0) + +#define UNSWAP_QUARTERS(A0, A1) \ + do { \ + A0 = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), A0); \ + A1 = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), A1); \ + SWAP_HALVES(A0, A1); \ + } while((void)0, 0) + +#define BLAKE2_ROUND_1(A0, C0, B0, D0, A1, C1, B1, D1) \ + do { \ + SWAP_HALVES(A0, B0); \ + SWAP_HALVES(C0, D0); \ + SWAP_HALVES(A1, B1); \ + SWAP_HALVES(C1, D1); \ + BLAKE2_ROUND(A0, B0, C0, D0, A1, B1, C1, D1); \ + SWAP_HALVES(A0, B0); \ + SWAP_HALVES(C0, D0); \ + SWAP_HALVES(A1, B1); \ + SWAP_HALVES(C1, D1); \ + } while ((void)0, 0) + +#define BLAKE2_ROUND_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + SWAP_QUARTERS(A0, A1); \ + SWAP_QUARTERS(B0, B1); \ + SWAP_QUARTERS(C0, C1); \ + SWAP_QUARTERS(D0, D1); \ + BLAKE2_ROUND(A0, B0, C0, D0, A1, B1, C1, D1); \ + UNSWAP_QUARTERS(A0, A1); \ + UNSWAP_QUARTERS(B0, B1); \ + UNSWAP_QUARTERS(C0, C1); \ + UNSWAP_QUARTERS(D0, D1); \ + } while ((void)0, 0) + +#endif /* __AVX512F__ */ +#endif /* BLAKE_ROUND_MKA_OPT_H */ diff -Nru argon2-0~20161029/src/blake2/blamka-round-ref.h argon2-0~20171227/src/blake2/blamka-round-ref.h --- argon2-0~20161029/src/blake2/blamka-round-ref.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/blake2/blamka-round-ref.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -21,7 +21,7 @@ #include "blake2.h" #include "blake2-impl.h" -/*designed by the Lyra PHC team */ +/* designed by the Lyra PHC team */ static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) { const uint64_t m = UINT64_C(0xFFFFFFFF); const uint64_t xy = (x & m) * (y & m); diff -Nru argon2-0~20161029/src/core.c argon2-0~20171227/src/core.c --- argon2-0~20161029/src/core.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/core.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -25,7 +25,6 @@ #endif #define VC_GE_2005(version) (version >= 1400) -#include #include #include #include @@ -246,6 +245,26 @@ return absolute_position; } +/* Single-threaded version for p=1 case */ +static int fill_memory_blocks_st(argon2_instance_t *instance) { + uint32_t r, s, l; + + for (r = 0; r < instance->passes; ++r) { + for (s = 0; s < ARGON2_SYNC_POINTS; ++s) { + for (l = 0; l < instance->lanes; ++l) { + argon2_position_t position = {r, l, (uint8_t)s, 0}; + fill_segment(instance, position); + } + } +#ifdef GENKAT + internal_kat(instance, r); /* Print all memory blocks */ +#endif + } + return ARGON2_OK; +} + +#if !defined(ARGON2_NO_THREADS) + #ifdef _WIN32 static unsigned __stdcall fill_segment_thr(void *thread_data) #else @@ -258,17 +277,13 @@ return 0; } -int fill_memory_blocks(argon2_instance_t *instance) { +/* Multi-threaded version for p > 1 case */ +static int fill_memory_blocks_mt(argon2_instance_t *instance) { uint32_t r, s; argon2_thread_handle_t *thread = NULL; argon2_thread_data *thr_data = NULL; int rc = ARGON2_OK; - if (instance == NULL || instance->lanes == 0) { - rc = ARGON2_THREAD_FAIL; - goto fail; - } - /* 1. Allocating space for threads */ thread = calloc(instance->lanes, sizeof(argon2_thread_handle_t)); if (thread == NULL) { @@ -342,6 +357,20 @@ return rc; } +#endif /* ARGON2_NO_THREADS */ + +int fill_memory_blocks(argon2_instance_t *instance) { + if (instance == NULL || instance->lanes == 0) { + return ARGON2_INCORRECT_PARAMETER; + } +#if defined(ARGON2_NO_THREADS) + return fill_memory_blocks_st(instance); +#else + return instance->threads == 1 ? + fill_memory_blocks_st(instance) : fill_memory_blocks_mt(instance); +#endif +} + int validate_inputs(const argon2_context *context) { if (NULL == context) { return ARGON2_INCORRECT_PARAMETER; @@ -471,8 +500,8 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { uint32_t l; - /* Make the first and second block in each lane as G(H0||i||0) or - G(H0||i||1) */ + /* Make the first and second block in each lane as G(H0||0||i) or + G(H0||1||i) */ uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE]; for (l = 0; l < instance->lanes; ++l) { diff -Nru argon2-0~20161029/src/core.h argon2-0~20171227/src/core.h --- argon2-0~20161029/src/core.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/core.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -20,14 +20,6 @@ #include "argon2.h" -#if defined(_MSC_VER) -#define ALIGN(n) __declspec(align(16)) -#elif defined(__GNUC__) || defined(__clang) -#define ALIGN(x) __attribute__((__aligned__(x))) -#else -#define ALIGN(x) -#endif - #define CONST_CAST(x) (x)(uintptr_t) /**********************Argon2 internal constants*******************************/ @@ -37,6 +29,8 @@ ARGON2_BLOCK_SIZE = 1024, ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8, ARGON2_OWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 16, + ARGON2_HWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 32, + ARGON2_512BIT_WORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 64, /* Number of pseudo-random values generated by one call to Blake in Argon2i to diff -Nru argon2-0~20161029/src/encoding.c argon2-0~20171227/src/encoding.c --- argon2-0~20161029/src/encoding.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/encoding.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -288,6 +288,19 @@ (x) = dec_x; \ } while ((void)0, 0) + +/* Decoding prefix into uint32_t decimal */ +#define DECIMAL_U32(x) \ + do { \ + unsigned long dec_x; \ + str = decode_decimal(str, &dec_x); \ + if (str == NULL || dec_x > UINT32_MAX) { \ + return ARGON2_DECODING_FAIL; \ + } \ + (x) = (uint32_t)dec_x; \ + } while ((void)0, 0) + + /* Decoding base64 into a binary buffer */ #define BIN(buf, max_len, len) \ do { \ @@ -315,14 +328,14 @@ /* Reading the version number if the default is suppressed */ ctx->version = ARGON2_VERSION_10; - CC_opt("$v=", DECIMAL(ctx->version)); + CC_opt("$v=", DECIMAL_U32(ctx->version)); CC("$m="); - DECIMAL(ctx->m_cost); + DECIMAL_U32(ctx->m_cost); CC(",t="); - DECIMAL(ctx->t_cost); + DECIMAL_U32(ctx->t_cost); CC(",p="); - DECIMAL(ctx->lanes); + DECIMAL_U32(ctx->lanes); ctx->threads = ctx->lanes; CC("$"); diff -Nru argon2-0~20161029/src/encoding.h argon2-0~20171227/src/encoding.h --- argon2-0~20161029/src/encoding.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/encoding.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * diff -Nru argon2-0~20161029/src/genkat.c argon2-0~20171227/src/genkat.c --- argon2-0~20161029/src/genkat.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/genkat.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -15,7 +15,6 @@ * software. If not, they may be obtained at the above URLs. */ -#include #include #include #include @@ -116,8 +115,8 @@ : ARGON2_QWORDS_IN_BLOCK; for (j = 0; j < how_many_words; ++j) - printf("Block %.4u [%3u]: %016" PRIx64 "\n", i, j, - instance->memory[i].v[j]); + printf("Block %.4u [%3u]: %016llx\n", i, j, + (unsigned long long)instance->memory[i].v[j]); } } } diff -Nru argon2-0~20161029/src/genkat.h argon2-0~20171227/src/genkat.h --- argon2-0~20161029/src/genkat.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/genkat.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * diff -Nru argon2-0~20161029/src/opt.c argon2-0~20171227/src/opt.c --- argon2-0~20161029/src/opt.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/opt.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -20,13 +20,95 @@ #include #include "argon2.h" -#include "opt.h" +#include "core.h" #include "blake2/blake2.h" #include "blake2/blamka-round-opt.h" -void fill_block(__m128i *state, const block *ref_block, block *next_block, - int with_xor) { +/* + * Function fills a new memory block and optionally XORs the old block over the new one. + * Memory must be initialized. + * @param state Pointer to the just produced block. Content will be updated(!) + * @param ref_block Pointer to the reference block + * @param next_block Pointer to the block to be XORed over. May coincide with @ref_block + * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) + * @pre all block pointers must be valid + */ +#if defined(__AVX512F__) +static void fill_block(__m512i *state, const block *ref_block, + block *next_block, int with_xor) { + __m512i block_XY[ARGON2_512BIT_WORDS_IN_BLOCK]; + unsigned int i; + + if (with_xor) { + for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) { + state[i] = _mm512_xor_si512( + state[i], _mm512_loadu_si512((const __m512i *)ref_block->v + i)); + block_XY[i] = _mm512_xor_si512( + state[i], _mm512_loadu_si512((const __m512i *)next_block->v + i)); + } + } else { + for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) { + block_XY[i] = state[i] = _mm512_xor_si512( + state[i], _mm512_loadu_si512((const __m512i *)ref_block->v + i)); + } + } + + for (i = 0; i < 2; ++i) { + BLAKE2_ROUND_1( + state[8 * i + 0], state[8 * i + 1], state[8 * i + 2], state[8 * i + 3], + state[8 * i + 4], state[8 * i + 5], state[8 * i + 6], state[8 * i + 7]); + } + + for (i = 0; i < 2; ++i) { + BLAKE2_ROUND_2( + state[2 * 0 + i], state[2 * 1 + i], state[2 * 2 + i], state[2 * 3 + i], + state[2 * 4 + i], state[2 * 5 + i], state[2 * 6 + i], state[2 * 7 + i]); + } + + for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) { + state[i] = _mm512_xor_si512(state[i], block_XY[i]); + _mm512_storeu_si512((__m512i *)next_block->v + i, state[i]); + } +} +#elif defined(__AVX2__) +static void fill_block(__m256i *state, const block *ref_block, + block *next_block, int with_xor) { + __m256i block_XY[ARGON2_HWORDS_IN_BLOCK]; + unsigned int i; + + if (with_xor) { + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + state[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i *)ref_block->v + i)); + block_XY[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i *)next_block->v + i)); + } + } else { + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + block_XY[i] = state[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i *)ref_block->v + i)); + } + } + + for (i = 0; i < 4; ++i) { + BLAKE2_ROUND_1(state[8 * i + 0], state[8 * i + 4], state[8 * i + 1], state[8 * i + 5], + state[8 * i + 2], state[8 * i + 6], state[8 * i + 3], state[8 * i + 7]); + } + + for (i = 0; i < 4; ++i) { + BLAKE2_ROUND_2(state[ 0 + i], state[ 4 + i], state[ 8 + i], state[12 + i], + state[16 + i], state[20 + i], state[24 + i], state[28 + i]); + } + + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + state[i] = _mm256_xor_si256(state[i], block_XY[i]); + _mm256_storeu_si256((__m256i *)next_block->v + i, state[i]); + } +} +#else +static void fill_block(__m128i *state, const block *ref_block, + block *next_block, int with_xor) { __m128i block_XY[ARGON2_OWORDS_IN_BLOCK]; unsigned int i; @@ -61,11 +143,20 @@ _mm_storeu_si128((__m128i *)next_block->v + i, state[i]); } } +#endif static void next_addresses(block *address_block, block *input_block) { /*Temporary zero-initialized blocks*/ +#if defined(__AVX512F__) + __m512i zero_block[ARGON2_512BIT_WORDS_IN_BLOCK]; + __m512i zero2_block[ARGON2_512BIT_WORDS_IN_BLOCK]; +#elif defined(__AVX2__) + __m256i zero_block[ARGON2_HWORDS_IN_BLOCK]; + __m256i zero2_block[ARGON2_HWORDS_IN_BLOCK]; +#else __m128i zero_block[ARGON2_OWORDS_IN_BLOCK]; __m128i zero2_block[ARGON2_OWORDS_IN_BLOCK]; +#endif memset(zero_block, 0, sizeof(zero_block)); memset(zero2_block, 0, sizeof(zero2_block)); @@ -87,7 +178,13 @@ uint64_t pseudo_rand, ref_index, ref_lane; uint32_t prev_offset, curr_offset; uint32_t starting_index, i; - __m128i state[64]; +#if defined(__AVX512F__) + __m512i state[ARGON2_512BIT_WORDS_IN_BLOCK]; +#elif defined(__AVX2__) + __m256i state[ARGON2_HWORDS_IN_BLOCK]; +#else + __m128i state[ARGON2_OWORDS_IN_BLOCK]; +#endif int data_independent_addressing; if (instance == NULL) { diff -Nru argon2-0~20161029/src/opt.h argon2-0~20171227/src/opt.h --- argon2-0~20161029/src/opt.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/opt.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -/* - * Argon2 reference source code package - reference C implementations - * - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves - * - * You may use this work under the terms of a Creative Commons CC0 1.0 - * License/Waiver or the Apache Public License 2.0, at your option. The terms of - * these licenses can be found at: - * - * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - * - * You should have received a copy of both of these licenses along with this - * software. If not, they may be obtained at the above URLs. - */ - -#ifndef ARGON2_OPT_H -#define ARGON2_OPT_H - -#include "core.h" -#include - -/* - * Function fills a new memory block and optionally XORs the old block over the new one. - * Memory must be initialized. - * @param state Pointer to the just produced block. Content will be updated(!) - * @param ref_block Pointer to the reference block - * @param next_block Pointer to the block to be XORed over. May coincide with @ref_block - * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) - * @pre all block pointers must be valid - */ -void fill_block(__m128i *s, const block *ref_block, block *next_block, int with_xor); - -#endif /* ARGON2_OPT_H */ diff -Nru argon2-0~20161029/src/ref.c argon2-0~20171227/src/ref.c --- argon2-0~20161029/src/ref.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/ref.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -20,15 +20,24 @@ #include #include "argon2.h" -#include "ref.h" +#include "core.h" #include "blake2/blamka-round-ref.h" #include "blake2/blake2-impl.h" #include "blake2/blake2.h" -void fill_block(const block *prev_block, const block *ref_block, - block *next_block, int with_xor) { +/* + * Function fills a new memory block and optionally XORs the old block over the new one. + * @next_block must be initialized. + * @param prev_block Pointer to the previous block + * @param ref_block Pointer to the reference block + * @param next_block Pointer to the block to be constructed + * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) + * @pre all block pointers must be valid + */ +static void fill_block(const block *prev_block, const block *ref_block, + block *next_block, int with_xor) { block blockR, block_tmp; unsigned i; diff -Nru argon2-0~20161029/src/ref.h argon2-0~20171227/src/ref.h --- argon2-0~20161029/src/ref.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/ref.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -/* - * Argon2 reference source code package - reference C implementations - * - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves - * - * You may use this work under the terms of a Creative Commons CC0 1.0 - * License/Waiver or the Apache Public License 2.0, at your option. The terms of - * these licenses can be found at: - * - * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 - * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 - * - * You should have received a copy of both of these licenses along with this - * software. If not, they may be obtained at the above URLs. - */ - -#ifndef ARGON2_REF_H -#define ARGON2_REF_H - -#include "core.h" - -/* - * Function fills a new memory block and optionally XORs the old block over the new one. - * @next_block must be initialized. - * @param prev_block Pointer to the previous block - * @param ref_block Pointer to the reference block - * @param next_block Pointer to the block to be constructed - * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) - * @pre all block pointers must be valid - */ -void fill_block(const block *prev_block, const block *ref_block, - block *next_block, int with_xor); - -#endif /* ARGON2_REF_H */ diff -Nru argon2-0~20161029/src/run.c argon2-0~20171227/src/run.c --- argon2-0~20161029/src/run.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/run.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -17,7 +17,6 @@ #define _GNU_SOURCE 1 -#include #include #include #include @@ -37,8 +36,9 @@ #define UNUSED_PARAMETER(x) (void)(x) static void usage(const char *cmd) { - printf("Usage: %s [-h] salt [-i|-d|-id] [-t iterations] [-m memory] " - "[-p parallelism] [-l hash length] [-e|-r]\n", + printf("Usage: %s [-h] salt [-i|-d|-id] [-t iterations] " + "[-m log2(memory in KiB) | -k memory in KiB] [-p parallelism] " + "[-l hash length] [-e|-r] [-v (10|13)]\n", cmd); printf("\tPassword is read from stdin\n"); printf("Parameters:\n"); @@ -50,12 +50,16 @@ T_COST_DEF); printf("\t-m N\t\tSets the memory usage of 2^N KiB (default %d)\n", LOG_M_COST_DEF); + printf("\t-k N\t\tSets the memory usage of N KiB (default %d)\n", + 1 << LOG_M_COST_DEF); printf("\t-p N\t\tSets parallelism to N threads (default %d)\n", THREADS_DEF); printf("\t-l N\t\tSets hash output length to N bytes (default %d)\n", OUTLEN_DEF); printf("\t-e\t\tOutput only encoded hash\n"); printf("\t-r\t\tOutput only the raw bytes of the hash\n"); + printf("\t-v (10|13)\tArgon2 version (defaults to the most recent version, currently %x)\n", + ARGON2_VERSION_NUMBER); printf("\t-h\t\tPrint %s usage\n", cmd); } @@ -85,12 +89,13 @@ @type Argon2 type we want to run @encoded_only display only the encoded hash @raw_only display only the hexadecimal of the hash +@version Argon2 version */ -static void run(uint32_t outlen, char *pwd, char *salt, uint32_t t_cost, +static void run(uint32_t outlen, char *pwd, size_t pwdlen, char *salt, uint32_t t_cost, uint32_t m_cost, uint32_t lanes, uint32_t threads, - argon2_type type, int encoded_only, int raw_only) { + argon2_type type, int encoded_only, int raw_only, uint32_t version) { clock_t start_time, stop_time; - size_t pwdlen, saltlen, encodedlen; + size_t saltlen, encodedlen; int result; unsigned char * out = NULL; char * encoded = NULL; @@ -102,11 +107,10 @@ } if (!salt) { - clear_internal_memory(pwd, strlen(pwd)); + clear_internal_memory(pwd, pwdlen); fatal("salt missing"); } - pwdlen = strlen(pwd); saltlen = strlen(salt); if(UINT32_MAX < saltlen) { fatal("salt is too long"); @@ -116,20 +120,20 @@ out = malloc(outlen + 1); if (!out) { - clear_internal_memory(pwd, strlen(pwd)); + clear_internal_memory(pwd, pwdlen); fatal("could not allocate memory for output"); } encodedlen = argon2_encodedlen(t_cost, m_cost, lanes, (uint32_t)saltlen, outlen, type); encoded = malloc(encodedlen + 1); if (!encoded) { - clear_internal_memory(pwd, strlen(pwd)); + clear_internal_memory(pwd, pwdlen); fatal("could not allocate memory for hash"); } result = argon2_hash(t_cost, m_cost, threads, pwd, pwdlen, salt, saltlen, out, outlen, encoded, encodedlen, type, - ARGON2_VERSION_NUMBER); + version); if (result != ARGON2_OK) fatal(argon2_error_message(result)); @@ -171,10 +175,12 @@ uint32_t threads = THREADS_DEF; argon2_type type = Argon2_i; /* Argon2i is the default type */ int types_specified = 0; + int m_cost_specified = 0; int encoded_only = 0; int raw_only = 0; + uint32_t version = ARGON2_VERSION_NUMBER; int i; - size_t n; + size_t pwdlen; char pwd[MAX_PASS_LEN], *salt; if (argc < 2) { @@ -186,19 +192,14 @@ } /* get password from stdin */ - n = fread(pwd, 1, sizeof pwd - 1, stdin); - if(n < 1) { + pwdlen = fread(pwd, 1, sizeof pwd, stdin); + if(pwdlen < 1) { fatal("no password read"); } - if(n == MAX_PASS_LEN-1) { + if(pwdlen == MAX_PASS_LEN) { fatal("Provided password longer than supported in command line utility"); } - pwd[n] = '\0'; - if (pwd[n - 1] == '\n') { - pwd[n - 1] = '\0'; - } - salt = argv[1]; /* parse options */ @@ -209,6 +210,10 @@ usage(argv[0]); return 1; } else if (!strcmp(a, "-m")) { + if (m_cost_specified) { + fatal("-m or -k can only be used once"); + } + m_cost_specified = 1; if (i < argc - 1) { i++; input = strtoul(argv[i], NULL, 10); @@ -224,6 +229,25 @@ } else { fatal("missing -m argument"); } + } else if (!strcmp(a, "-k")) { + if (m_cost_specified) { + fatal("-m or -k can only be used once"); + } + m_cost_specified = 1; + if (i < argc - 1) { + i++; + input = strtoul(argv[i], NULL, 10); + if (input == 0 || input == ULONG_MAX) { + fatal("bad numeric input for -k"); + } + m_cost = ARGON2_MIN(input, UINT32_C(0xFFFFFFFF)); + if (m_cost > ARGON2_MAX_MEMORY) { + fatal("m_cost overflow"); + } + continue; + } else { + fatal("missing -k argument"); + } } else if (!strcmp(a, "-t")) { if (i < argc - 1) { i++; @@ -273,6 +297,19 @@ encoded_only = 1; } else if (!strcmp(a, "-r")) { raw_only = 1; + } else if (!strcmp(a, "-v")) { + if (i < argc - 1) { + i++; + if (!strcmp(argv[i], "10")) { + version = ARGON2_VERSION_10; + } else if (!strcmp(argv[i], "13")) { + version = ARGON2_VERSION_13; + } else { + fatal("invalid Argon2 version"); + } + } else { + fatal("missing -v argument"); + } } else { fatal("unknown argument"); } @@ -287,13 +324,13 @@ if(!encoded_only && !raw_only) { printf("Type:\t\t%s\n", argon2_type2string(type, 1)); - printf("Iterations:\t%" PRIu32 " \n", t_cost); - printf("Memory:\t\t%" PRIu32 " KiB\n", m_cost); - printf("Parallelism:\t%" PRIu32 " \n", lanes); + printf("Iterations:\t%u\n", t_cost); + printf("Memory:\t\t%u KiB\n", m_cost); + printf("Parallelism:\t%u\n", lanes); } - run(outlen, pwd, salt, t_cost, m_cost, lanes, threads, type, - encoded_only, raw_only); + run(outlen, pwd, pwdlen, salt, t_cost, m_cost, lanes, threads, type, + encoded_only, raw_only, version); return ARGON2_OK; } diff -Nru argon2-0~20161029/src/test.c argon2-0~20171227/src/test.c --- argon2-0~20161029/src/test.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/test.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -81,7 +80,7 @@ "$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ" "$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ"); #ifdef TEST_LARGE_RAM - hashtest(version, 2, 20, 1, "password", "somesalt", + hashtest(version, 2, 20, 1, "password", "somesalt", "9690ec55d28d3ed32562f2e73ea62b02b018757643a2ae6e79528459de8106e9", "$argon2i$m=1048576,t=2,p=1$c29tZXNhbHQ" "$lpDsVdKNPtMlYvLnPqYrArAYdXZDoq5ueVKEWd6BBuk"); @@ -160,10 +159,10 @@ "$argon2i$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" "$wWKIMhR9lyDFvRz9YTZweHKfbftvj+qf+YFY4NeBbtA"); #ifdef TEST_LARGE_RAM - hashtest(version, 2, 20, 1, "password", "somesalt", + hashtest(version, 2, 20, 1, "password", "somesalt", "d1587aca0922c3b5d6a83edab31bee3c4ebaef342ed6127a55d19b2351ad1f41", - "$argon2i$v=19$m=1048576,t=2,p=1$c29tZXNhbHQ" - "$0Vh6ygkiw7XWqD7asxvuPE667zQu1hJ6VdGbI1GtH0E"); + "$argon2i$v=19$m=1048576,t=2,p=1$c29tZXNhbHQ" + "$0Vh6ygkiw7XWqD7asxvuPE667zQu1hJ6VdGbI1GtH0E"); #endif hashtest(version, 2, 18, 1, "password", "somesalt", "296dbae80b807cdceaad44ae741b506f14db0959267b183b118f9b24229bc7cb", diff -Nru argon2-0~20161029/src/thread.c argon2-0~20171227/src/thread.c --- argon2-0~20161029/src/thread.c 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/thread.c 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -15,6 +15,8 @@ * software. If not, they may be obtained at the above URLs. */ +#if !defined(ARGON2_NO_THREADS) + #include "thread.h" #if defined(_WIN32) #include @@ -51,3 +53,5 @@ pthread_exit(NULL); #endif } + +#endif /* ARGON2_NO_THREADS */ diff -Nru argon2-0~20161029/src/thread.h argon2-0~20171227/src/thread.h --- argon2-0~20161029/src/thread.h 2016-10-29 09:24:03.000000000 +0000 +++ argon2-0~20171227/src/thread.h 2017-12-27 19:56:31.000000000 +0000 @@ -4,7 +4,7 @@ * Copyright 2015 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * - * You may use this work under the terms of a Creative Commons CC0 1.0 + * You may use this work under the terms of a Creative Commons CC0 1.0 * License/Waiver or the Apache Public License 2.0, at your option. The terms of * these licenses can be found at: * @@ -17,6 +17,9 @@ #ifndef ARGON2_THREAD_H #define ARGON2_THREAD_H + +#if !defined(ARGON2_NO_THREADS) + /* Here we implement an abstraction layer for the simpĺe requirements of the Argon2 code. We only require 3 primitives---thread creation, @@ -43,7 +46,7 @@ * @param func A function pointer for the thread's entry point. Must not be * NULL. * @param args Pointer that is passed as an argument to @func. May be NULL. - * @return 0 if @handle and @func are valid pointers and a thread is successfuly + * @return 0 if @handle and @func are valid pointers and a thread is successfully * created. */ int argon2_thread_create(argon2_thread_handle_t *handle, @@ -60,4 +63,5 @@ */ void argon2_thread_exit(void); +#endif /* ARGON2_NO_THREADS */ #endif