├── v.1.1 ├── README.md ├── Argon2.pdf ├── Argon2d │ ├── opt-sse │ │ ├── Makefile │ │ ├── blake2-config.h │ │ ├── argon2d.h │ │ ├── blake2-round.h │ │ ├── blake2-impl.h │ │ ├── blake2b-load-sse2.h │ │ └── blake2.h │ └── ref │ │ ├── Makefile │ │ ├── blake-round.h │ │ ├── argon2d.h │ │ ├── blake2-impl.h │ │ └── blake2.h └── Argon2i │ ├── opt-sse │ ├── Makefile │ ├── blake2-config.h │ ├── argon2i.h │ ├── blake2-round.h │ ├── blake2-impl.h │ ├── blake2b-load-sse2.h │ ├── blake2b-round-perm.h │ └── blake2.h │ └── ref │ ├── Makefile │ ├── blake-round.h │ ├── argon2i.h │ ├── blake2-impl.h │ └── blake2.h ├── v.1.2 └── v.1.2 │ ├── README.md │ ├── Argon2.pdf │ ├── Argon2d │ ├── opt-sse │ │ ├── Makefile │ │ ├── blake2-config.h │ │ ├── blake2-round.h │ │ ├── blake2-round-mka.h │ │ ├── blake2-impl.h │ │ ├── argon2d.h │ │ ├── blake2b-load-sse2.h │ │ └── blake2.h │ └── ref │ │ ├── Makefile │ │ ├── blake-round-mka.h │ │ ├── blake2-impl.h │ │ ├── argon2d.h │ │ └── blake2.h │ └── Argon2i │ ├── opt-sse │ ├── Makefile │ ├── blake2-config.h │ ├── argon2i.h │ ├── blake2-round.h │ ├── blake2-round-mka.h │ ├── blake2-impl.h │ ├── blake2b-load-sse2.h │ ├── blake2b-round-perm.h │ └── blake2.h │ └── ref │ ├── Makefile │ ├── blake-round.h │ ├── blake-round-mka.h │ ├── argon2i.h │ ├── blake2-impl.h │ └── blake2.h ├── Doc ├── Argon2.pdf └── LaTeX │ └── pics │ ├── generic.pdf │ ├── instant.pdf │ ├── over-v2.pdf │ ├── precomp.pdf │ ├── argon2-par.pdf │ ├── parallel.pdf │ ├── parallel2.pdf │ ├── compression.pdf │ └── power-distribution.jpg ├── Build └── .gitignore ├── Output └── .gitignore ├── Scripts ├── clean.sh └── check_test_vectors.sh ├── Source ├── C++11 │ ├── Test │ │ ├── genkat.cpp │ │ └── bench.cpp │ ├── Argon2 │ │ └── kat.h │ ├── Blake2 │ │ ├── blamka-round-ref.h │ │ ├── blake2.h │ │ └── blake2-impl.h │ └── Makefile └── C99 │ ├── Blake2 │ ├── blake-round-mka.h │ ├── blake2-config.h │ ├── blake2-round.h │ ├── blake2-round-mka.h │ ├── blake2-impl.h │ └── blake2b-load-sse2.h │ ├── Argon2 │ ├── kat.h │ ├── argon2-ref-core.h │ ├── argon2-opt-core.h │ └── kat.c │ └── Makefile └── README.md /v.1.1/README.md: -------------------------------------------------------------------------------- 1 | # Argon2 2 | Memory-hard scheme Argon2 3 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/README.md: -------------------------------------------------------------------------------- 1 | # Argon2 2 | Memory-hard scheme Argon2 3 | -------------------------------------------------------------------------------- /Doc/Argon2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/Argon2.pdf -------------------------------------------------------------------------------- /v.1.1/Argon2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/v.1.1/Argon2.pdf -------------------------------------------------------------------------------- /Build/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/v.1.2/v.1.2/Argon2.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/generic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/generic.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/instant.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/instant.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/over-v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/over-v2.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/precomp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/precomp.pdf -------------------------------------------------------------------------------- /Output/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /Doc/LaTeX/pics/argon2-par.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/argon2-par.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/parallel.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/parallel.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/parallel2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/parallel2.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/compression.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/compression.pdf -------------------------------------------------------------------------------- /Doc/LaTeX/pics/power-distribution.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khovratovich/Argon2/HEAD/Doc/LaTeX/pics/power-distribution.jpg -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b.cpp argon2d-opt-sse.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2d 6 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/ref/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b-ref.cpp argon2d-ref.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2d-ref 6 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b.cpp argon2i-opt-sse.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2i 6 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/ref/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b-ref.cpp argon2i-ref.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2i-ref 6 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b.cpp argon2d-opt-sse.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2d 6 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/ref/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b-ref.cpp argon2d-ref.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2d-ref 6 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b.cpp argon2i-opt-sse.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2i 6 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-m64 -mavx -std=c++11 -pthread -O3 2 | SOURCE=blake2b-ref.cpp argon2i-ref.cpp genkat.cpp 3 | CC=g++ 4 | all: 5 | $(CC) $(CFLAGS) $(SOURCE) -o argon2i-ref 6 | -------------------------------------------------------------------------------- /Scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Call this script to clean all *~ files from the project 5 | # ./clean.sh 6 | # 7 | 8 | 9 | # The root directory path 10 | ROOT_DIR=./../ 11 | 12 | 13 | # Get current script path 14 | script_path=$(dirname $0) 15 | 16 | 17 | # Change current directory to script source path directory 18 | if [ '.' != $script_path ] ; then 19 | cd $script_path 20 | fi 21 | 22 | 23 | # Change curent directory to root directory 24 | cd $ROOT_DIR 25 | 26 | 27 | # Remove all *~ files 28 | find . -name "*~" -type f -delete 29 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/ref/blake-round.h: -------------------------------------------------------------------------------- 1 | #define G(a,b,c,d) \ 2 | a = a + b ; \ 3 | d = rotr64(d ^ a, 32); \ 4 | c = c + d; \ 5 | b = rotr64(b ^ c, 24); \ 6 | a = a + b ; \ 7 | d = rotr64(d ^ a, 16); \ 8 | c = c + d; \ 9 | b = rotr64(b ^ c, 63); 10 | 11 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 12 | G(v0, v4, v8, v12); \ 13 | G(v1, v5, v9, v13); \ 14 | G(v2, v6, v10, v14); \ 15 | G(v3, v7, v11, v15); \ 16 | G(v0, v5, v10, v15); \ 17 | G(v1, v6, v11, v12); \ 18 | G(v2, v7, v8, v13); \ 19 | G(v3, v4, v9, v14); 20 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/ref/blake-round.h: -------------------------------------------------------------------------------- 1 | #define G(a,b,c,d) \ 2 | a = a + b ; \ 3 | d = rotr64(d ^ a, 32); \ 4 | c = c + d; \ 5 | b = rotr64(b ^ c, 24); \ 6 | a = a + b ; \ 7 | d = rotr64(d ^ a, 16); \ 8 | c = c + d; \ 9 | b = rotr64(b ^ c, 63); 10 | 11 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 12 | G(v0, v4, v8, v12); \ 13 | G(v1, v5, v9, v13); \ 14 | G(v2, v6, v10, v14); \ 15 | G(v3, v7, v11, v15); \ 16 | G(v0, v5, v10, v15); \ 17 | G(v1, v6, v11, v12); \ 18 | G(v2, v7, v8, v13); \ 19 | G(v3, v4, v9, v14); 20 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/blake-round.h: -------------------------------------------------------------------------------- 1 | #define G(a,b,c,d) \ 2 | a = a + b ; \ 3 | d = rotr64(d ^ a, 32); \ 4 | c = c + d; \ 5 | b = rotr64(b ^ c, 24); \ 6 | a = a + b ; \ 7 | d = rotr64(d ^ a, 16); \ 8 | c = c + d; \ 9 | b = rotr64(b ^ c, 63); 10 | 11 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 12 | G(v0, v4, v8, v12); \ 13 | G(v1, v5, v9, v13); \ 14 | G(v2, v6, v10, v14); \ 15 | G(v3, v7, v11, v15); \ 16 | G(v0, v5, v10, v15); \ 17 | G(v1, v6, v11, v12); \ 18 | G(v2, v7, v8, v13); \ 19 | G(v3, v4, v9, v14); 20 | -------------------------------------------------------------------------------- /Source/C++11/Test/genkat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | #include "kat.h" 13 | 14 | int main(int argc, char *argv[]) { 15 | const char *type = (argc > 1) ? argv[1] : "i"; 16 | GenerateTestVectors(type); 17 | return ARGON2_OK; 18 | } 19 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/ref/blake-round-mka.h: -------------------------------------------------------------------------------- 1 | /*designed by the Lyra PHC team */ 2 | static inline uint64_t fBlaMka(uint64_t x, uint64_t y){ 3 | uint32_t lessX = (uint32_t)x; 4 | uint32_t lessY = (uint32_t)y; 5 | 6 | uint64_t lessZ = (uint64_t)lessX; 7 | lessZ = lessZ * lessY; 8 | lessZ = lessZ << 1; 9 | 10 | uint64_t z = lessZ + x + y; 11 | 12 | return z; 13 | } 14 | 15 | 16 | #define G(a,b,c,d) \ 17 | a = fBlaMka(a, b) ; \ 18 | d = rotr64(d ^ a, 32); \ 19 | c = fBlaMka(c, d); \ 20 | b = rotr64(b ^ c, 24); \ 21 | a = fBlaMka(a, b) ; \ 22 | d = rotr64(d ^ a, 16); \ 23 | c = fBlaMka(c, d); \ 24 | b = rotr64(b ^ c, 63); 25 | 26 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 27 | G(v0, v4, v8, v12); \ 28 | G(v1, v5, v9, v13); \ 29 | G(v2, v6, v10, v14); \ 30 | G(v3, v7, v11, v15); \ 31 | G(v0, v5, v10, v15); \ 32 | G(v1, v6, v11, v12); \ 33 | G(v2, v7, v8, v13); \ 34 | G(v3, v4, v9, v14); 35 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/blake-round-mka.h: -------------------------------------------------------------------------------- 1 | /*designed by the Lyra PHC team */ 2 | static inline uint64_t fBlaMka(uint64_t x, uint64_t y){ 3 | uint32_t lessX = (uint32_t)x; 4 | uint32_t lessY = (uint32_t)y; 5 | 6 | uint64_t lessZ = (uint64_t)lessX; 7 | lessZ = lessZ * lessY; 8 | lessZ = lessZ << 1; 9 | 10 | uint64_t z = lessZ + x + y; 11 | 12 | return z; 13 | } 14 | 15 | 16 | #define G(a,b,c,d) \ 17 | a = fBlaMka(a, b) ; \ 18 | d = rotr64(d ^ a, 32); \ 19 | c = fBlaMka(c, d); \ 20 | b = rotr64(b ^ c, 24); \ 21 | a = fBlaMka(a, b) ; \ 22 | d = rotr64(d ^ a, 16); \ 23 | c = fBlaMka(c, d); \ 24 | b = rotr64(b ^ c, 63); 25 | 26 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 27 | G(v0, v4, v8, v12); \ 28 | G(v1, v5, v9, v13); \ 29 | G(v2, v6, v10, v14); \ 30 | G(v3, v7, v11, v15); \ 31 | G(v0, v5, v10, v15); \ 32 | G(v1, v6, v11, v12); \ 33 | G(v2, v7, v8, v13); \ 34 | G(v3, v4, v9, v14); 35 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake-round-mka.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __BLAKE_ROUND_MKA_H__ 4 | #define __BLAKE_ROUND_MKA_H__ 5 | 6 | 7 | #define G(a,b,c,d) \ 8 | a = fBlaMka(a, b) ; \ 9 | d = rotr64(d ^ a, 32); \ 10 | c = fBlaMka(c, d); \ 11 | b = rotr64(b ^ c, 24); \ 12 | a = fBlaMka(a, b) ; \ 13 | d = rotr64(d ^ a, 16); \ 14 | c = fBlaMka(c, d); \ 15 | b = rotr64(b ^ c, 63); 16 | 17 | #define BLAKE2_ROUND_NOMSG(v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \ 18 | G(v0, v4, v8, v12); \ 19 | G(v1, v5, v9, v13); \ 20 | G(v2, v6, v10, v14); \ 21 | G(v3, v7, v11, v15); \ 22 | G(v0, v5, v10, v15); \ 23 | G(v1, v6, v11, v12); \ 24 | G(v2, v7, v8, v13); \ 25 | G(v3, v4, v9, v14); 26 | 27 | 28 | /*designed by the Lyra PHC team */ 29 | static inline uint64_t fBlaMka(uint64_t x, uint64_t y) 30 | { 31 | uint32_t lessX = (uint32_t)x; 32 | uint32_t lessY = (uint32_t)y; 33 | 34 | uint64_t lessZ = (uint64_t)lessX; 35 | lessZ = lessZ * lessY; 36 | lessZ = lessZ << 1; 37 | 38 | uint64_t z = lessZ + x + y; 39 | 40 | return z; 41 | } 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Source/C99/Argon2/kat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | 13 | #ifndef __ARGON2_KAT_H__ 14 | #define __ARGON2_KAT_H__ 15 | 16 | 17 | /* 18 | * Initial KAT function that prints the inputs to the file 19 | * @param blockhash Array that contains pre-hashing digest 20 | * @param context Holds inputs 21 | * @param type Argon2 type 22 | * @pre blockhash must point to INPUT_INITIAL_HASH_LENGTH bytes 23 | * @pre context member pointers must point to allocated memory of size according to the length values 24 | */ 25 | void InitialKat(const uint8_t* blockhash, const Argon2_Context* context, Argon2_type type); 26 | 27 | /* 28 | * Function that prints the output tag 29 | * @param out output array pointer 30 | * @param outlen digest length 31 | * @pre out must point to @a outlen bytes 32 | **/ 33 | void PrintTag(const void* out, uint32_t outlen); 34 | 35 | /* 36 | * Function that prints the internal state at given moment 37 | * @param instance pointer to the current instance 38 | * @param pass current pass number 39 | * @pre instance must have necessary memory allocated 40 | **/ 41 | void InternalKat(const Argon2_instance_t* instance, uint32_t pass); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake2-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_CONFIG_H__ 15 | #define __BLAKE2_CONFIG_H__ 16 | 17 | // These don't work everywhere 18 | #if defined(__SSE2__) 19 | #define HAVE_SSE2 20 | #endif 21 | 22 | #if defined(__SSSE3__) 23 | #define HAVE_SSSE3 24 | #endif 25 | 26 | #if defined(__SSE4_1__) 27 | #define HAVE_SSE41 28 | #endif 29 | 30 | #if defined(__AVX__) 31 | #define HAVE_AVX 32 | #endif 33 | 34 | #if defined(__XOP__) 35 | #define HAVE_XOP 36 | #endif 37 | 38 | 39 | #ifdef HAVE_AVX2 40 | #ifndef HAVE_AVX 41 | #define HAVE_AVX 42 | #endif 43 | #endif 44 | 45 | #ifdef HAVE_XOP 46 | #ifndef HAVE_AVX 47 | #define HAVE_AVX 48 | #endif 49 | #endif 50 | 51 | #ifdef HAVE_AVX 52 | #ifndef HAVE_SSE41 53 | #define HAVE_SSE41 54 | #endif 55 | #endif 56 | 57 | #ifdef HAVE_SSE41 58 | #ifndef HAVE_SSSE3 59 | #define HAVE_SSSE3 60 | #endif 61 | #endif 62 | 63 | #ifdef HAVE_SSSE3 64 | #define HAVE_SSE2 65 | #endif 66 | 67 | #if !defined(HAVE_SSE2) 68 | #error "This code requires at least SSE2." 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/blake2-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_CONFIG_H__ 15 | #define __BLAKE2_CONFIG_H__ 16 | 17 | // These don't work everywhere 18 | #if defined(__SSE2__) 19 | #define HAVE_SSE2 20 | #endif 21 | 22 | #if defined(__SSSE3__) 23 | #define HAVE_SSSE3 24 | #endif 25 | 26 | #if defined(__SSE4_1__) 27 | #define HAVE_SSE41 28 | #endif 29 | 30 | #if defined(__AVX__) 31 | #define HAVE_AVX 32 | #endif 33 | 34 | #if defined(__XOP__) 35 | #define HAVE_XOP 36 | #endif 37 | 38 | 39 | #ifdef HAVE_AVX2 40 | #ifndef HAVE_AVX 41 | #define HAVE_AVX 42 | #endif 43 | #endif 44 | 45 | #ifdef HAVE_XOP 46 | #ifndef HAVE_AVX 47 | #define HAVE_AVX 48 | #endif 49 | #endif 50 | 51 | #ifdef HAVE_AVX 52 | #ifndef HAVE_SSE41 53 | #define HAVE_SSE41 54 | #endif 55 | #endif 56 | 57 | #ifdef HAVE_SSE41 58 | #ifndef HAVE_SSSE3 59 | #define HAVE_SSSE3 60 | #endif 61 | #endif 62 | 63 | #ifdef HAVE_SSSE3 64 | #define HAVE_SSE2 65 | #endif 66 | 67 | #if !defined(HAVE_SSE2) 68 | #error "This code requires at least SSE2." 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_CONFIG_H__ 15 | #define __BLAKE2_CONFIG_H__ 16 | 17 | // These don't work everywhere 18 | #if defined(__SSE2__) 19 | #define HAVE_SSE2 20 | #endif 21 | 22 | #if defined(__SSSE3__) 23 | #define HAVE_SSSE3 24 | #endif 25 | 26 | #if defined(__SSE4_1__) 27 | #define HAVE_SSE41 28 | #endif 29 | 30 | #if defined(__AVX__) 31 | #define HAVE_AVX 32 | #endif 33 | 34 | #if defined(__XOP__) 35 | #define HAVE_XOP 36 | #endif 37 | 38 | 39 | #ifdef HAVE_AVX2 40 | #ifndef HAVE_AVX 41 | #define HAVE_AVX 42 | #endif 43 | #endif 44 | 45 | #ifdef HAVE_XOP 46 | #ifndef HAVE_AVX 47 | #define HAVE_AVX 48 | #endif 49 | #endif 50 | 51 | #ifdef HAVE_AVX 52 | #ifndef HAVE_SSE41 53 | #define HAVE_SSE41 54 | #endif 55 | #endif 56 | 57 | #ifdef HAVE_SSE41 58 | #ifndef HAVE_SSSE3 59 | #define HAVE_SSSE3 60 | #endif 61 | #endif 62 | 63 | #ifdef HAVE_SSSE3 64 | #define HAVE_SSE2 65 | #endif 66 | 67 | #if !defined(HAVE_SSE2) 68 | #error "This code requires at least SSE2." 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_CONFIG_H__ 15 | #define __BLAKE2_CONFIG_H__ 16 | 17 | // These don't work everywhere 18 | #if defined(__SSE2__) 19 | #define HAVE_SSE2 20 | #endif 21 | 22 | #if defined(__SSSE3__) 23 | #define HAVE_SSSE3 24 | #endif 25 | 26 | #if defined(__SSE4_1__) 27 | #define HAVE_SSE41 28 | #endif 29 | 30 | #if defined(__AVX__) 31 | #define HAVE_AVX 32 | #endif 33 | 34 | #if defined(__XOP__) 35 | #define HAVE_XOP 36 | #endif 37 | 38 | 39 | #ifdef HAVE_AVX2 40 | #ifndef HAVE_AVX 41 | #define HAVE_AVX 42 | #endif 43 | #endif 44 | 45 | #ifdef HAVE_XOP 46 | #ifndef HAVE_AVX 47 | #define HAVE_AVX 48 | #endif 49 | #endif 50 | 51 | #ifdef HAVE_AVX 52 | #ifndef HAVE_SSE41 53 | #define HAVE_SSE41 54 | #endif 55 | #endif 56 | 57 | #ifdef HAVE_SSE41 58 | #ifndef HAVE_SSSE3 59 | #define HAVE_SSSE3 60 | #endif 61 | #endif 62 | 63 | #ifdef HAVE_SSSE3 64 | #define HAVE_SSE2 65 | #endif 66 | 67 | #if !defined(HAVE_SSE2) 68 | #error "This code requires at least SSE2." 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_CONFIG_H__ 15 | #define __BLAKE2_CONFIG_H__ 16 | 17 | // These don't work everywhere 18 | #if defined(__SSE2__) 19 | #define HAVE_SSE2 20 | #endif 21 | 22 | #if defined(__SSSE3__) 23 | #define HAVE_SSSE3 24 | #endif 25 | 26 | #if defined(__SSE4_1__) 27 | #define HAVE_SSE41 28 | #endif 29 | 30 | #if defined(__AVX__) 31 | #define HAVE_AVX 32 | #endif 33 | 34 | #if defined(__XOP__) 35 | #define HAVE_XOP 36 | #endif 37 | 38 | 39 | #ifdef HAVE_AVX2 40 | #ifndef HAVE_AVX 41 | #define HAVE_AVX 42 | #endif 43 | #endif 44 | 45 | #ifdef HAVE_XOP 46 | #ifndef HAVE_AVX 47 | #define HAVE_AVX 48 | #endif 49 | #endif 50 | 51 | #ifdef HAVE_AVX 52 | #ifndef HAVE_SSE41 53 | #define HAVE_SSE41 54 | #endif 55 | #endif 56 | 57 | #ifdef HAVE_SSE41 58 | #ifndef HAVE_SSSE3 59 | #define HAVE_SSSE3 60 | #endif 61 | #endif 62 | 63 | #ifdef HAVE_SSSE3 64 | #define HAVE_SSE2 65 | #endif 66 | 67 | #if !defined(HAVE_SSE2) 68 | #error "This code requires at least SSE2." 69 | #endif 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /Source/C++11/Argon2/kat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | 13 | #ifndef __ARGON2_KAT_H__ 14 | #define __ARGON2_KAT_H__ 15 | 16 | #include 17 | #include "argon2.h" 18 | #include "argon2-core.h" 19 | /* 20 | * Initial KAT function that prints the inputs to the file 21 | * @param blockhash Array that contains pre-hashing digest 22 | * @param context Holds inputs 23 | * @param type Argon2 type 24 | * @pre blockhash must point to INPUT_INITIAL_HASH_LENGTH bytes 25 | * @pre context member pointers must point to allocated memory of size according to the length values 26 | */ 27 | void InitialKat(const uint8_t* blockhash, const Argon2_Context* context, Argon2_type type); 28 | 29 | /* 30 | * Function that prints the output tag 31 | * @param out output array pointer 32 | * @param outlen digest length 33 | * @pre out must point to @a outlen bytes 34 | **/ 35 | void PrintTag(const void* out, uint32_t outlen); 36 | 37 | /* 38 | * Function that prints the internal state at given moment 39 | * @param instance pointer to the current instance 40 | * @param pass current pass number 41 | * @pre instance must have necessary memory allocated 42 | **/ 43 | void InternalKat(const Argon2_instance_t* instance, uint32_t pass); 44 | 45 | 46 | /*Generate test vectors of Argon2 of type @type 47 | * 48 | */ 49 | void GenerateTestVectors(const std::string &type); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/ref/argon2d.h: -------------------------------------------------------------------------------- 1 | #include // ADDED for size_t 2 | #include // ADDED for unit32_t 3 | 4 | #define MIN_LANES 1 5 | #define SYNC_POINTS 4 6 | #define MAX_OUTLEN 0xFFFFFFFF 7 | #define MIN_OUTLEN 4 8 | #define MIN_MEMORY 1 9 | #define MAX_MEMORY 0xFFFFFFFF 10 | #define MIN_TIME 1 11 | #define MIN_MSG 0 12 | #define MAX_MSG 0xFFFFFFFF 13 | #define MIN_AD 0 14 | #define MAX_AD 0xFFFFFFFF 15 | #define MAX_NONCE 0xFFFFFFFF 16 | #define MIN_NONCE 8 17 | #define MIN_SECRET 0 18 | #define MAX_SECRET 32 19 | #define BLOCK_SIZE_KILOBYTE 1 20 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 21 | #define BLOCK_SIZE BYTES_IN_BLOCK 22 | #define VERSION_NUMBER 0x10 23 | #define ADDRESSES_IN_BLOCK (BYTES_IN_BLOCK/4) 24 | 25 | #define ALIGN_ARGON 16 26 | #define KAT_FILENAME "kat-argon2d.log" 27 | #define BLAKE_INPUT_HASH_SIZE 64 28 | #define BLAKE_OUTPUT_HASH_SIZE 64 29 | 30 | //#define KAT 31 | #define _MEASURE 32 | //#define KAT_INTERNAL 33 | 34 | struct block{ 35 | uint8_t v[BYTES_IN_BLOCK]; 36 | 37 | block(){ memset(v, 0, BYTES_IN_BLOCK); } 38 | uint64_t& operator[](uint8_t i){ return *(uint64_t*)(v + 8 * i); } 39 | block& operator=(const block& r){ memcpy(v, r.v, BYTES_IN_BLOCK); return *this; } 40 | block operator^(const block& r){static block a; for (unsigned j = 0; j < BYTES_IN_BLOCK; ++j) a.v[j] = v[j] ^ r.v[j]; return a; } 41 | }; 42 | 43 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 44 | unsigned int t_cost, unsigned int m_cost); 45 | 46 | extern int Argon2dRef(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 47 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 48 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/argon2d.h: -------------------------------------------------------------------------------- 1 | 2 | //#define KAT 3 | //#define KAT_INTERNAL 4 | 5 | #define MIN_LANES 1 6 | #define SYNC_POINTS 4 7 | #define MAX_OUTLEN 0xFFFFFFFF 8 | #define MIN_OUTLEN 4 9 | #define MIN_MEMORY 1 10 | #define MAX_MEMORY 0xFFFFFFFF 11 | #define MIN_TIME 1 12 | #define MIN_MSG 0 13 | #define MAX_MSG 0xFFFFFFFF 14 | #define MIN_AD 0 15 | #define MAX_AD 0xFFFFFFFF 16 | #define MAX_NONCE 0xFFFFFFFF 17 | #define MIN_NONCE 8 18 | #define MIN_SECRET 0 19 | #define MAX_SECRET 32 20 | #define BLOCK_SIZE_KILOBYTE 1 21 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 22 | #define BLOCK_SIZE BYTES_IN_BLOCK 23 | #define VERSION_NUMBER 0x10 24 | #define BLAKE_INPUT_HASH_SIZE 64 25 | #define BLAKE_OUTPUT_HASH_SIZE 64 26 | #define KAT_FILENAME "kat-argon2d-opt.log" 27 | 28 | #define ALIGN_ARGON 16 29 | 30 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 31 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 32 | 33 | 34 | struct scheme_info_t 35 | { 36 | uint8_t *state; 37 | uint32_t mem_size; 38 | uint32_t passes; 39 | uint8_t lanes; 40 | scheme_info_t(uint8_t* s, uint32_t m, uint32_t p, uint8_t l){ state = s; mem_size = m; passes = p; lanes = l; } 41 | }; 42 | 43 | struct position_info_t { 44 | 45 | uint32_t pass; 46 | uint8_t slice; 47 | uint8_t lane; 48 | uint32_t index; 49 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 50 | }; 51 | 52 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 53 | unsigned int t_cost, unsigned int m_cost); 54 | 55 | extern int Argon2dOpt(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 56 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 57 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/argon2i.h: -------------------------------------------------------------------------------- 1 | 2 | //#define KAT 3 | //#define KAT_INTERNAL 4 | 5 | #define MIN_LANES 1 6 | #define SYNC_POINTS 4 7 | #define MAX_OUTLEN 0xFFFFFFFF 8 | #define MIN_OUTLEN 4 9 | #define MIN_MEMORY 1 10 | #define MAX_MEMORY 0xFFFFFFFF 11 | #define MIN_TIME 3 12 | #define MIN_MSG 0 13 | #define MAX_MSG 0xFFFFFFFF 14 | #define MIN_AD 0 15 | #define MAX_AD 0xFFFFFFFF 16 | #define MAX_NONCE 0xFFFFFFFF 17 | #define MIN_NONCE 8 18 | #define MIN_SECRET 0 19 | #define MAX_SECRET 32 20 | #define BLOCK_SIZE_KILOBYTE 1 21 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 22 | #define BLOCK_SIZE BYTES_IN_BLOCK 23 | #define VERSION_NUMBER 0x11 24 | #define BLAKE_INPUT_HASH_SIZE 64 25 | #define BLAKE_OUTPUT_HASH_SIZE 64 26 | #define ADDRESSES_PER_BLOCK (BLOCK_SIZE/4) 27 | #define ADDRESSES_MASK (BLOCK_SIZE/4-1) 28 | #define KAT_FILENAME "kat-argon2i-opt.log" 29 | 30 | #define ALIGN_ARGON 16 31 | 32 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 33 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 34 | 35 | 36 | struct scheme_info_t 37 | { 38 | uint8_t *state; 39 | uint32_t mem_size; 40 | uint32_t passes; 41 | uint8_t lanes; 42 | scheme_info_t(uint8_t* s, uint32_t m, uint32_t p, uint8_t l){ state = s; mem_size = m; passes = p; lanes = l; } 43 | }; 44 | 45 | struct position_info_t { 46 | 47 | uint32_t pass; 48 | uint8_t slice; 49 | uint8_t lane; 50 | uint32_t index; 51 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 52 | }; 53 | 54 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 55 | unsigned int t_cost, unsigned int m_cost); 56 | 57 | 58 | extern int Argon2iOpt(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 59 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 60 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/argon2i.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARGON2_ 2 | #define _ARGON2_ 3 | 4 | //#define KAT 5 | //#define KAT_INTERNAL 6 | 7 | #define MIN_LANES 1 8 | #define SYNC_POINTS 4 9 | #define MAX_OUTLEN 0xFFFFFFFF 10 | #define MIN_OUTLEN 4 11 | #define MIN_MEMORY 1 12 | #define MAX_MEMORY 0xFFFFFF 13 | #define MIN_TIME 3 14 | #define MIN_MSG 0 15 | #define MAX_MSG 0xFFFFFFFF 16 | #define MIN_AD 0 17 | #define MAX_AD 0xFFFFFFFF 18 | #define MAX_NONCE 0xFFFFFFFF 19 | #define MIN_NONCE 8 20 | #define MIN_SECRET 0 21 | #define MAX_SECRET 32 22 | #define BLOCK_SIZE_KILOBYTE 1 23 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 24 | #define BLOCK_SIZE BYTES_IN_BLOCK 25 | #define VERSION_NUMBER 0x11 26 | #define BLAKE_INPUT_HASH_SIZE 64 27 | #define BLAKE_OUTPUT_HASH_SIZE 64 28 | #define ADDRESSES_PER_BLOCK (BLOCK_SIZE/4) 29 | #define ADDRESSES_MASK (BLOCK_SIZE/4-1) 30 | #define KAT_FILENAME "kat-argon2i-opt.log" 31 | 32 | #define ALIGN_ARGON 16 33 | 34 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 35 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 36 | 37 | 38 | struct scheme_info_t 39 | { 40 | uint8_t *state; 41 | uint32_t mem_size; 42 | uint32_t passes; 43 | uint8_t lanes; 44 | scheme_info_t(uint8_t* s, uint32_t m, uint32_t p, uint8_t l){ state = s; mem_size = m; passes = p; lanes = l; } 45 | }; 46 | 47 | struct position_info_t { 48 | 49 | uint32_t pass; 50 | uint8_t slice; 51 | uint8_t lane; 52 | uint32_t index; 53 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 54 | }; 55 | 56 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 57 | unsigned int t_cost, unsigned int m_cost); 58 | 59 | 60 | extern int Argon2i(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 61 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 62 | 63 | #endif -------------------------------------------------------------------------------- /Source/C99/Argon2/argon2-ref-core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | #ifndef ARGON2_REF_CORE_H 13 | #define ARGON2_REF_CORE_H 14 | 15 | 16 | /* 17 | * Function fills a new memory block 18 | * @param prev_block Pointer to the previous block 19 | * @param ref_block Pointer to the reference block 20 | * @param next_block Pointer to the block to be constructed 21 | * @param Sbox Pointer to the Sbox (used in Argon2_ds only) 22 | * @pre all block pointers must be valid 23 | */ 24 | void FillBlock(const block* prev_block, const block* ref_block, block* next_block, const uint64_t* Sbox); 25 | 26 | /* 27 | * Generate pseudo-random values to reference blocks in the segment and puts them into the array 28 | * @param instance Pointer to the current instance 29 | * @param position Pointer to the current position 30 | * @param pseudo_rands Pointer to the array of 64-bit values 31 | * @pre pseudo_rands must point to @a instance->segment_length allocated values 32 | */ 33 | void GenerateAddresses(const Argon2_instance_t* instance, const Argon2_position_t* position, uint64_t* pseudo_rands); 34 | 35 | /* 36 | * Function that fills the segment using previous segments also from other threads 37 | * @param instance Pointer to the current instance 38 | * @param position Current position 39 | * @pre all block pointers must be valid 40 | */ 41 | void FillSegment(const Argon2_instance_t* instance, Argon2_position_t position); 42 | 43 | 44 | /* 45 | * Generates the Sbox from the first memory block (must be ready at that time) 46 | * @param instance Pointer to the current instance 47 | */ 48 | void GenerateSbox(Argon2_instance_t* instance); 49 | #endif /* ARGON2_REF_CORE_H */ 50 | 51 | -------------------------------------------------------------------------------- /Source/C99/Argon2/argon2-opt-core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | #ifndef ARGON2_OPT_CORE_H 13 | #define ARGON2_OPT_CORE_H 14 | 15 | /* 16 | * Function fills a new memory block. Differs from the 17 | * @param state Pointer to the just produced block. Content will be updated(!) 18 | * @param ref_block Pointer to the reference block 19 | * @param next_block Pointer to the block to be constructed 20 | * @param Sbox Pointer to the Sbox (used in Argon2_ds only) 21 | * @pre all block pointers must be valid 22 | */ 23 | void FillBlock(__m128i* state, const uint8_t *ref_block, uint8_t *next_block, const uint64_t* Sbox); 24 | 25 | 26 | /* 27 | * Generate pseudo-random values to reference blocks in the segment and puts them into the array 28 | * @param instance Pointer to the current instance 29 | * @param position Pointer to the current position 30 | * @param pseudo_rands Pointer to the array of 64-bit values 31 | * @pre pseudo_rands must point to @a instance->segment_length allocated values 32 | */ 33 | void GenerateAddresses(const Argon2_instance_t* instance, const Argon2_position_t* position, uint64_t* pseudo_rands); 34 | 35 | /* 36 | * Function that fills the segment using previous segments also from other threads. 37 | * Identical to the reference code except that it calls optimized FillBlock() 38 | * @param instance Pointer to the current instance 39 | * @param position Current position 40 | * @pre all block pointers must be valid 41 | */ 42 | void FillSegment(const Argon2_instance_t* instance, Argon2_position_t position); 43 | 44 | /* 45 | * Generates the Sbox from the first memory block (must be ready at that time) 46 | * @param instance Pointer to the current instance 47 | */ 48 | void GenerateSbox(Argon2_instance_t* instance); 49 | 50 | #endif /* ARGON2_OPT_CORE_H */ 51 | 52 | -------------------------------------------------------------------------------- /Source/C++11/Blake2/blamka-round-ref.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE_ROUND_MKA_H 2 | #define BLAKE_ROUND_MKA_H 3 | 4 | #include "blake2.h" 5 | #include "blake2-impl.h" 6 | 7 | /*designed by the Lyra PHC team */ 8 | static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) { 9 | const uint64_t m = UINT64_C(0xFFFFFFFF); 10 | const uint64_t xy = (x & m) * (y & m); 11 | return x + y + 2 * xy; 12 | } 13 | 14 | #define G(a, b, c, d) \ 15 | do { \ 16 | a = fBlaMka(a, b); \ 17 | d = rotr64(d ^ a, 32); \ 18 | c = fBlaMka(c, d); \ 19 | b = rotr64(b ^ c, 24); \ 20 | a = fBlaMka(a, b); \ 21 | d = rotr64(d ^ a, 16); \ 22 | c = fBlaMka(c, d); \ 23 | b = rotr64(b ^ c, 63); \ 24 | } while ((void)0, 0) 25 | 26 | #define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \ 27 | v12, v13, v14, v15) \ 28 | do { \ 29 | G(v0, v4, v8, v12); \ 30 | G(v1, v5, v9, v13); \ 31 | G(v2, v6, v10, v14); \ 32 | G(v3, v7, v11, v15); \ 33 | G(v0, v5, v10, v15); \ 34 | G(v1, v6, v11, v12); \ 35 | G(v2, v7, v8, v13); \ 36 | G(v3, v4, v9, v14); \ 37 | } while ((void)0, 0) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/ref/argon2i.h: -------------------------------------------------------------------------------- 1 | 2 | //#define KAT 3 | //#define KAT_INTERNAL 4 | 5 | #define MIN_LANES 1 6 | #define SYNC_POINTS 4 7 | #define MAX_OUTLEN 0xFFFFFFFF 8 | #define MIN_OUTLEN 4 9 | #define MIN_MEMORY 1 10 | #define MAX_MEMORY 0xFFFFFFFF 11 | #define MIN_TIME 3 12 | #define MIN_MSG 0 13 | #define MAX_MSG 0xFFFFFFFF 14 | #define MIN_AD 0 15 | #define MAX_AD 0xFFFFFFFF 16 | #define MAX_NONCE 0xFFFFFFFF 17 | #define MIN_NONCE 8 18 | #define MIN_SECRET 0 19 | #define MAX_SECRET 32 20 | #define BLOCK_SIZE_KILOBYTE 1 21 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 22 | #define BLOCK_SIZE BYTES_IN_BLOCK 23 | #define VERSION_NUMBER 0x11 24 | #define BLAKE_INPUT_HASH_SIZE 64 25 | #define BLAKE_OUTPUT_HASH_SIZE 64 26 | #define ADDRESSES_PER_BLOCK (BLOCK_SIZE/4) 27 | #define ADDRESSES_MASK (BLOCK_SIZE/4-1) 28 | #define KAT_FILENAME "kat-argon2i-ref.log" 29 | 30 | #define ALIGN_ARGON 16 31 | 32 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 33 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 34 | struct block{ 35 | uint8_t v[BYTES_IN_BLOCK]; 36 | 37 | block(){ memset(v, 0, BYTES_IN_BLOCK); } 38 | uint64_t& operator[](uint8_t i){ return *(uint64_t*)(v + 8 * i); } 39 | block& operator=(const block& r){ memcpy(v, r.v, BYTES_IN_BLOCK); return *this; } 40 | block operator^(const block& r){ block a; for (unsigned j = 0; j < BYTES_IN_BLOCK; ++j) a.v[j] = v[j] ^ r.v[j]; return a; } 41 | }; 42 | 43 | struct scheme_info_t 44 | { 45 | block *state; 46 | uint32_t mem_size; 47 | uint32_t passes; 48 | uint32_t lanes; 49 | scheme_info_t(block* s, uint32_t m, uint32_t p, uint32_t l){ state = s; mem_size = m; passes = p; lanes = l; } 50 | }; 51 | 52 | struct position_info_t { 53 | 54 | uint32_t pass; 55 | uint8_t slice; 56 | uint8_t lane; 57 | uint32_t index; 58 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 59 | }; 60 | 61 | 62 | 63 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 64 | unsigned int t_cost, unsigned int m_cost); 65 | 66 | extern int Argon2iRef(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 67 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 68 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/argon2i.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARGON2_ 2 | #define _ARGON2_ 3 | 4 | //#define KAT 5 | //#define KAT_INTERNAL 6 | #define KAT_FILENAME "kat-argon2i-ref.log" 7 | 8 | 9 | #define MIN_LANES 1 10 | #define SYNC_POINTS 4 11 | #define MAX_OUTLEN 0xFFFFFFFF 12 | #define MIN_OUTLEN 4 13 | #define MIN_MEMORY 1 14 | #define MAX_MEMORY 0xFFFFFF 15 | #define MIN_TIME 3 16 | #define MIN_MSG 0 17 | #define MAX_MSG 0xFFFFFFFF 18 | #define MIN_AD 0 19 | #define MAX_AD 0xFFFFFFFF 20 | #define MAX_NONCE 0xFFFFFFFF 21 | #define MIN_NONCE 8 22 | #define MIN_SECRET 0 23 | #define MAX_SECRET 32 24 | #define BLOCK_SIZE_KILOBYTE 1 25 | #define BYTES_IN_BLOCK (1024*BLOCK_SIZE_KILOBYTE) 26 | #define BLOCK_SIZE BYTES_IN_BLOCK 27 | #define VERSION_NUMBER 0x11 28 | #define BLAKE_INPUT_HASH_SIZE 64 29 | #define BLAKE_OUTPUT_HASH_SIZE 64 30 | #define ADDRESSES_PER_BLOCK (BLOCK_SIZE/4) 31 | #define ADDRESSES_MASK (BLOCK_SIZE/4-1) 32 | 33 | #define ALIGN_ARGON 16 34 | 35 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 36 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 37 | struct block{ 38 | uint8_t v[BYTES_IN_BLOCK]; 39 | 40 | block(){ memset(v, 0, BYTES_IN_BLOCK); } 41 | uint64_t& operator[](uint8_t i){ return *(uint64_t*)(v + 8 * i); } 42 | block& operator=(const block& r){ memcpy(v, r.v, BYTES_IN_BLOCK); return *this; } 43 | block operator^(const block& r){ block a; for (unsigned j = 0; j < BYTES_IN_BLOCK; ++j) a.v[j] = v[j] ^ r.v[j]; return a; } 44 | }; 45 | 46 | struct scheme_info_t 47 | { 48 | block *state; 49 | uint32_t mem_size; 50 | uint32_t passes; 51 | uint32_t lanes; 52 | scheme_info_t(block* s, uint32_t m, uint32_t p, uint32_t l){ state = s; mem_size = m; passes = p; lanes = l; } 53 | }; 54 | 55 | struct position_info_t { 56 | 57 | uint32_t pass; 58 | uint8_t slice; 59 | uint8_t lane; 60 | uint32_t index; 61 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 62 | }; 63 | 64 | 65 | 66 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 67 | unsigned int t_cost, unsigned int m_cost); 68 | 69 | extern int Argon2i(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 70 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 71 | 72 | #endif -------------------------------------------------------------------------------- /Source/C++11/Blake2/blake2.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLE_BLAKE2_H 2 | #define PORTABLE_BLAKE2_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined(__cplusplus) 9 | extern "C" { 10 | #endif 11 | 12 | enum blake2b_constant { 13 | BLAKE2B_BLOCKBYTES = 128, 14 | BLAKE2B_OUTBYTES = 64, 15 | BLAKE2B_KEYBYTES = 64, 16 | BLAKE2B_SALTBYTES = 16, 17 | BLAKE2B_PERSONALBYTES = 16 18 | }; 19 | 20 | #pragma pack(push, 1) 21 | typedef struct __blake2b_param { 22 | uint8_t digest_length; /* 1 */ 23 | uint8_t key_length; /* 2 */ 24 | uint8_t fanout; /* 3 */ 25 | uint8_t depth; /* 4 */ 26 | uint32_t leaf_length; /* 8 */ 27 | uint64_t node_offset; /* 16 */ 28 | uint8_t node_depth; /* 17 */ 29 | uint8_t inner_length; /* 18 */ 30 | uint8_t reserved[14]; /* 32 */ 31 | uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */ 32 | uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */ 33 | } blake2b_param; 34 | #pragma pack(pop) 35 | 36 | typedef struct __blake2b_state { 37 | uint64_t h[8]; 38 | uint64_t t[2]; 39 | uint64_t f[2]; 40 | uint8_t buf[BLAKE2B_BLOCKBYTES]; 41 | unsigned buflen; 42 | unsigned outlen; 43 | uint8_t last_node; 44 | } blake2b_state; 45 | 46 | /* Ensure param structs have not been wrongly padded */ 47 | /* Poor man's static_assert */ 48 | enum { 49 | blake2_size_check_0 = 1 / !!(CHAR_BIT == 8), 50 | blake2_size_check_2 = 51 | 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT) 52 | }; 53 | 54 | /* Streaming API */ 55 | int blake2b_init(blake2b_state *S, size_t outlen); 56 | int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, 57 | size_t keylen); 58 | int blake2b_init_param(blake2b_state *S, const blake2b_param *P); 59 | int blake2b_update(blake2b_state *S, const void *in, size_t inlen); 60 | int blake2b_final(blake2b_state *S, void *out, size_t outlen); 61 | 62 | /* Simple API */ 63 | int blake2b(void *out, size_t outlen, const void *in, size_t inlen, 64 | const void *key, size_t keylen); 65 | 66 | /* Argon2 Team - Begin Code */ 67 | int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); 68 | /* Argon2 Team - End Code */ 69 | 70 | #if defined(__cplusplus) 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake2-round.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 9 | row1l = _mm_add_epi64(row1l, row2l); \ 10 | row1h = _mm_add_epi64(row1h, row2h); \ 11 | \ 12 | row4l = _mm_xor_si128(row4l, row1l); \ 13 | row4h = _mm_xor_si128(row4h, row1h); \ 14 | \ 15 | row4l = _mm_roti_epi64(row4l, -32); \ 16 | row4h = _mm_roti_epi64(row4h, -32); \ 17 | \ 18 | row3l = _mm_add_epi64(row3l, row4l); \ 19 | row3h = _mm_add_epi64(row3h, row4h); \ 20 | \ 21 | row2l = _mm_xor_si128(row2l, row3l); \ 22 | row2h = _mm_xor_si128(row2h, row3h); \ 23 | \ 24 | row2l = _mm_roti_epi64(row2l, -24); \ 25 | row2h = _mm_roti_epi64(row2h, -24); \ 26 | 27 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 28 | row1l = _mm_add_epi64(row1l, row2l); \ 29 | row1h = _mm_add_epi64(row1h, row2h); \ 30 | \ 31 | row4l = _mm_xor_si128(row4l, row1l); \ 32 | row4h = _mm_xor_si128(row4h, row1h); \ 33 | \ 34 | row4l = _mm_roti_epi64(row4l, -16); \ 35 | row4h = _mm_roti_epi64(row4h, -16); \ 36 | \ 37 | row3l = _mm_add_epi64(row3l, row4l); \ 38 | row3h = _mm_add_epi64(row3h, row4h); \ 39 | \ 40 | row2l = _mm_xor_si128(row2l, row3l); \ 41 | row2h = _mm_xor_si128(row2h, row3h); \ 42 | \ 43 | row2l = _mm_roti_epi64(row2l, -63); \ 44 | row2h = _mm_roti_epi64(row2h, -63); \ 45 | 46 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 47 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 48 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 49 | row2l = t0; \ 50 | row2h = t1; \ 51 | \ 52 | t0 = row3l; \ 53 | row3l = row3h; \ 54 | row3h = t0; \ 55 | \ 56 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 57 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 58 | row4l = t1; \ 59 | row4h = t0; 60 | 61 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 62 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 63 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 64 | row2l = t0; \ 65 | row2h = t1; \ 66 | \ 67 | t0 = row3l; \ 68 | row3l = row3h; \ 69 | row3h = t0; \ 70 | \ 71 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 72 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 73 | row4l = t1; \ 74 | row4h = t0; 75 | 76 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 77 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 78 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 79 | \ 80 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 81 | \ 82 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 83 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 84 | \ 85 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 86 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/blake2-round.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 9 | row1l = _mm_add_epi64(row1l, row2l); \ 10 | row1h = _mm_add_epi64(row1h, row2h); \ 11 | \ 12 | row4l = _mm_xor_si128(row4l, row1l); \ 13 | row4h = _mm_xor_si128(row4h, row1h); \ 14 | \ 15 | row4l = _mm_roti_epi64(row4l, -32); \ 16 | row4h = _mm_roti_epi64(row4h, -32); \ 17 | \ 18 | row3l = _mm_add_epi64(row3l, row4l); \ 19 | row3h = _mm_add_epi64(row3h, row4h); \ 20 | \ 21 | row2l = _mm_xor_si128(row2l, row3l); \ 22 | row2h = _mm_xor_si128(row2h, row3h); \ 23 | \ 24 | row2l = _mm_roti_epi64(row2l, -24); \ 25 | row2h = _mm_roti_epi64(row2h, -24); \ 26 | 27 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 28 | row1l = _mm_add_epi64(row1l, row2l); \ 29 | row1h = _mm_add_epi64(row1h, row2h); \ 30 | \ 31 | row4l = _mm_xor_si128(row4l, row1l); \ 32 | row4h = _mm_xor_si128(row4h, row1h); \ 33 | \ 34 | row4l = _mm_roti_epi64(row4l, -16); \ 35 | row4h = _mm_roti_epi64(row4h, -16); \ 36 | \ 37 | row3l = _mm_add_epi64(row3l, row4l); \ 38 | row3h = _mm_add_epi64(row3h, row4h); \ 39 | \ 40 | row2l = _mm_xor_si128(row2l, row3l); \ 41 | row2h = _mm_xor_si128(row2h, row3h); \ 42 | \ 43 | row2l = _mm_roti_epi64(row2l, -63); \ 44 | row2h = _mm_roti_epi64(row2h, -63); \ 45 | 46 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 47 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 48 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 49 | row2l = t0; \ 50 | row2h = t1; \ 51 | \ 52 | t0 = row3l; \ 53 | row3l = row3h; \ 54 | row3h = t0; \ 55 | \ 56 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 57 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 58 | row4l = t1; \ 59 | row4h = t0; 60 | 61 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 62 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 63 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 64 | row2l = t0; \ 65 | row2h = t1; \ 66 | \ 67 | t0 = row3l; \ 68 | row3l = row3h; \ 69 | row3h = t0; \ 70 | \ 71 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 72 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 73 | row4l = t1; \ 74 | row4h = t0; 75 | 76 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 77 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 78 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 79 | \ 80 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 81 | \ 82 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 83 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 84 | \ 85 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 86 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2-round.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 9 | row1l = _mm_add_epi64(row1l, row2l); \ 10 | row1h = _mm_add_epi64(row1h, row2h); \ 11 | \ 12 | row4l = _mm_xor_si128(row4l, row1l); \ 13 | row4h = _mm_xor_si128(row4h, row1h); \ 14 | \ 15 | row4l = _mm_roti_epi64(row4l, -32); \ 16 | row4h = _mm_roti_epi64(row4h, -32); \ 17 | \ 18 | row3l = _mm_add_epi64(row3l, row4l); \ 19 | row3h = _mm_add_epi64(row3h, row4h); \ 20 | \ 21 | row2l = _mm_xor_si128(row2l, row3l); \ 22 | row2h = _mm_xor_si128(row2h, row3h); \ 23 | \ 24 | row2l = _mm_roti_epi64(row2l, -24); \ 25 | row2h = _mm_roti_epi64(row2h, -24); \ 26 | 27 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 28 | row1l = _mm_add_epi64(row1l, row2l); \ 29 | row1h = _mm_add_epi64(row1h, row2h); \ 30 | \ 31 | row4l = _mm_xor_si128(row4l, row1l); \ 32 | row4h = _mm_xor_si128(row4h, row1h); \ 33 | \ 34 | row4l = _mm_roti_epi64(row4l, -16); \ 35 | row4h = _mm_roti_epi64(row4h, -16); \ 36 | \ 37 | row3l = _mm_add_epi64(row3l, row4l); \ 38 | row3h = _mm_add_epi64(row3h, row4h); \ 39 | \ 40 | row2l = _mm_xor_si128(row2l, row3l); \ 41 | row2h = _mm_xor_si128(row2h, row3h); \ 42 | \ 43 | row2l = _mm_roti_epi64(row2l, -63); \ 44 | row2h = _mm_roti_epi64(row2h, -63); \ 45 | 46 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 47 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 48 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 49 | row2l = t0; \ 50 | row2h = t1; \ 51 | \ 52 | t0 = row3l; \ 53 | row3l = row3h; \ 54 | row3h = t0; \ 55 | \ 56 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 57 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 58 | row4l = t1; \ 59 | row4h = t0; 60 | 61 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 62 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 63 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 64 | row2l = t0; \ 65 | row2h = t1; \ 66 | \ 67 | t0 = row3l; \ 68 | row3l = row3h; \ 69 | row3h = t0; \ 70 | \ 71 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 72 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 73 | row4l = t1; \ 74 | row4h = t0; 75 | 76 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 77 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 78 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 79 | \ 80 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 81 | \ 82 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 83 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 84 | \ 85 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 86 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2-round.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 9 | row1l = _mm_add_epi64(row1l, row2l); \ 10 | row1h = _mm_add_epi64(row1h, row2h); \ 11 | \ 12 | row4l = _mm_xor_si128(row4l, row1l); \ 13 | row4h = _mm_xor_si128(row4h, row1h); \ 14 | \ 15 | row4l = _mm_roti_epi64(row4l, -32); \ 16 | row4h = _mm_roti_epi64(row4h, -32); \ 17 | \ 18 | row3l = _mm_add_epi64(row3l, row4l); \ 19 | row3h = _mm_add_epi64(row3h, row4h); \ 20 | \ 21 | row2l = _mm_xor_si128(row2l, row3l); \ 22 | row2h = _mm_xor_si128(row2h, row3h); \ 23 | \ 24 | row2l = _mm_roti_epi64(row2l, -24); \ 25 | row2h = _mm_roti_epi64(row2h, -24); \ 26 | 27 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 28 | row1l = _mm_add_epi64(row1l, row2l); \ 29 | row1h = _mm_add_epi64(row1h, row2h); \ 30 | \ 31 | row4l = _mm_xor_si128(row4l, row1l); \ 32 | row4h = _mm_xor_si128(row4h, row1h); \ 33 | \ 34 | row4l = _mm_roti_epi64(row4l, -16); \ 35 | row4h = _mm_roti_epi64(row4h, -16); \ 36 | \ 37 | row3l = _mm_add_epi64(row3l, row4l); \ 38 | row3h = _mm_add_epi64(row3h, row4h); \ 39 | \ 40 | row2l = _mm_xor_si128(row2l, row3l); \ 41 | row2h = _mm_xor_si128(row2h, row3h); \ 42 | \ 43 | row2l = _mm_roti_epi64(row2l, -63); \ 44 | row2h = _mm_roti_epi64(row2h, -63); \ 45 | 46 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 47 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 48 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 49 | row2l = t0; \ 50 | row2h = t1; \ 51 | \ 52 | t0 = row3l; \ 53 | row3l = row3h; \ 54 | row3h = t0; \ 55 | \ 56 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 57 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 58 | row4l = t1; \ 59 | row4h = t0; 60 | 61 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 62 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 63 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 64 | row2l = t0; \ 65 | row2h = t1; \ 66 | \ 67 | t0 = row3l; \ 68 | row3l = row3h; \ 69 | row3h = t0; \ 70 | \ 71 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 72 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 73 | row4l = t1; \ 74 | row4h = t0; 75 | 76 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 77 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 78 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 79 | \ 80 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 81 | \ 82 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 83 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 84 | \ 85 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 86 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2-round.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 9 | row1l = _mm_add_epi64(row1l, row2l); \ 10 | row1h = _mm_add_epi64(row1h, row2h); \ 11 | \ 12 | row4l = _mm_xor_si128(row4l, row1l); \ 13 | row4h = _mm_xor_si128(row4h, row1h); \ 14 | \ 15 | row4l = _mm_roti_epi64(row4l, -32); \ 16 | row4h = _mm_roti_epi64(row4h, -32); \ 17 | \ 18 | row3l = _mm_add_epi64(row3l, row4l); \ 19 | row3h = _mm_add_epi64(row3h, row4h); \ 20 | \ 21 | row2l = _mm_xor_si128(row2l, row3l); \ 22 | row2h = _mm_xor_si128(row2h, row3h); \ 23 | \ 24 | row2l = _mm_roti_epi64(row2l, -24); \ 25 | row2h = _mm_roti_epi64(row2h, -24); \ 26 | 27 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 28 | row1l = _mm_add_epi64(row1l, row2l); \ 29 | row1h = _mm_add_epi64(row1h, row2h); \ 30 | \ 31 | row4l = _mm_xor_si128(row4l, row1l); \ 32 | row4h = _mm_xor_si128(row4h, row1h); \ 33 | \ 34 | row4l = _mm_roti_epi64(row4l, -16); \ 35 | row4h = _mm_roti_epi64(row4h, -16); \ 36 | \ 37 | row3l = _mm_add_epi64(row3l, row4l); \ 38 | row3h = _mm_add_epi64(row3h, row4h); \ 39 | \ 40 | row2l = _mm_xor_si128(row2l, row3l); \ 41 | row2h = _mm_xor_si128(row2h, row3h); \ 42 | \ 43 | row2l = _mm_roti_epi64(row2l, -63); \ 44 | row2h = _mm_roti_epi64(row2h, -63); \ 45 | 46 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 47 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 48 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 49 | row2l = t0; \ 50 | row2h = t1; \ 51 | \ 52 | t0 = row3l; \ 53 | row3l = row3h; \ 54 | row3h = t0; \ 55 | \ 56 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 57 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 58 | row4l = t1; \ 59 | row4h = t0; 60 | 61 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 62 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 63 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 64 | row2l = t0; \ 65 | row2h = t1; \ 66 | \ 67 | t0 = row3l; \ 68 | row3l = row3h; \ 69 | row3h = t0; \ 70 | \ 71 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 72 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 73 | row4l = t1; \ 74 | row4h = t0; 75 | 76 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 77 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 78 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 79 | \ 80 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 81 | \ 82 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 83 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 84 | \ 85 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 86 | -------------------------------------------------------------------------------- /Scripts/check_test_vectors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Argon2 source code package 5 | # 6 | # This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | # 8 | # You should have received a copy of the CC0 Public Domain Dedication along with 9 | # this software. If not, see . 10 | # 11 | 12 | # Get current dir 13 | initial_dir=$(pwd) 14 | 15 | # Get current script path 16 | script_path=$(dirname $0) 17 | 18 | 19 | # Change current directory to root directory 20 | if [ '.' != $script_path ] ; then 21 | cd $script_path/../ 22 | fi 23 | 24 | 25 | ARGON2_TYPES=(Argon2d Argon2i Argon2id Argon2ds) 26 | ARGON2_IMPLEMENTATIONS=(REF OPT) 27 | 28 | OUTPUT_PATH=./../../Output/ 29 | TEST_VECTORS_PATH=./../../TestVectors/ 30 | 31 | KAT_REF=kat-argon2-ref.log 32 | KAT_OPT=kat-argon2-opt.log 33 | 34 | 35 | # Default arguments 36 | SOURCE_DIR=$initial_dir 37 | 38 | # Parse script arguments 39 | for i in "$@" 40 | do 41 | case $i in 42 | -s=*|-src=*|--source=*) 43 | SOURCE_DIR="${i#*=}" 44 | shift 45 | ;; 46 | *) 47 | # Unknown option 48 | ;; 49 | esac 50 | done 51 | 52 | 53 | # Change current directory to source directory 54 | cd $SOURCE_DIR 55 | 56 | 57 | for implementation in ${ARGON2_IMPLEMENTATIONS[@]} 58 | do 59 | echo "Test for $implementation" 60 | 61 | make_log=$OUTPUT_PATH"make_"$implementation".log" 62 | rm -f $make_log 63 | 64 | flags="" 65 | if [ "OPT" == "$implementation" ] ; then 66 | flags="OPT=TRUE" 67 | fi 68 | 69 | make $flags &> $make_log 70 | 71 | if [ 0 -ne $? ] ; then 72 | echo -e "\t\t -> Wrong! Make error! See $make_log for details!" 73 | continue 74 | else 75 | rm -f $make_log 76 | fi 77 | 78 | 79 | for type in ${ARGON2_TYPES[@]} 80 | do 81 | echo -e "\t Test for $type" 82 | 83 | kat_file_name="KAT_"$implementation 84 | kat_file=${!kat_file_name} 85 | rm -f $kat_file 86 | 87 | run_log=$OUTPUT_PATH"run_"$type"_"$implementation".log" 88 | if [[ $SOURCE_DIR == *"C++11"* ]] ; then 89 | ./../../Build/argon2-kat $type > $run_log 90 | fi 91 | if [[ $SOURCE_DIR == *"C99"* ]] ; then 92 | ./../../Build/argon2 -gen-tv -type $type > $run_log 93 | fi 94 | if [ 0 -ne $? ] ; then 95 | echo -e "\t\t -> Wrong! Run error! See $run_log for details!" 96 | continue 97 | else 98 | rm -f $run_log 99 | fi 100 | 101 | 102 | kat_file_copy=$OUTPUT_PATH${kat_file/"argon2"/$type} 103 | cp $kat_file $kat_file_copy 104 | rm -f $kat_file 105 | 106 | test_vectors_file=$TEST_VECTORS_PATH$type".txt" 107 | 108 | diff_file=$OUTPUT_PATH"diff_"$type"_"$implementation 109 | rm -f $diff_file 110 | 111 | 112 | if diff -Naur $kat_file_copy $test_vectors_file > $diff_file ; then 113 | echo -e "\t\t -> OK!" 114 | rm -f $kat_file_copy 115 | rm -f $diff_file 116 | else 117 | echo -e "\t\t -> Wrong! See $diff_file for details!" 118 | fi 119 | done 120 | done 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Argon2 source code package 2 | 3 | 4 | ## Warning 5 | Argon2 is the basis for the eventual winner of Password Hashing Competition. 6 | The final winner may be different from the current version (1.2.1). 7 | 8 | ## About 9 | The Argon2 source code package in `Source/` includes: 10 | 11 | * Reference C99 & C++11 implementations of the password hashing scheme Argon2 12 | 13 | `make` 14 | 15 | * Optimized C99 & C++11 implementations of the password hashing scheme Argon2 16 | 17 | `make OPT=TRUE` 18 | 19 | Build result: 20 | * Argon2 without debug messages 21 | `argon2` 22 | * Argon2 shared library 23 | `libargon2.so` 24 | * Argon2 built with the shared library 25 | `argon2-lib-test` 26 | 27 | 28 | ## Usage 29 | Options: 30 | 31 | `argon2 -help` 32 | 33 | Benchmark Argon2d, Argon2id, Argon2i, Argon2ds with different level of parallelism: 34 | 35 | `argon2 -benchmark` 36 | 37 | Generate detailed test vectors for type 't', where 't' is one of {Argon2d, Argon2id, Argon2i, Argon2ds}: 38 | 39 | `argon2 -gen-tv -type t` 40 | 41 | Check generated test vectors against available test vectors: 42 | 43 | `./Scripts/check_test_vectors.sh -s=./Source/C++11/` 44 | 45 | `./Scripts/check_test_vectors.sh -s=./Source/C99/` 46 | 47 | ##Library usage 48 | 49 | 1. Initialize Argon2_Context structure with 50 | - address of output buffer (can not be NULL) 51 | - output length 52 | - address of password array 53 | - password length * 54 | - address of salt array 55 | - salt length * 56 | - address of secret/key array 57 | - key length * 58 | - address of associated data array 59 | - associated data length 60 | - number of iterations * 61 | - amount of memory in KBytes * 62 | - number of parallel threads 63 | - pointer to memory allocator 64 | - pointer to memory deallocator 65 | - password erase indicator * 66 | - secret erase indicator * 67 | - memory erase indicator * 68 | 69 | All these parameters but the last five affect the output digest. Parameters marked by * are security critical and should be selected according to the specification. Parameters 'number of iterations', 'amount of memory', 'number of parallel threads', and (to some extent) 'memory erase indicator' affect performance. 70 | 71 | 2. Select the Argon2 mode that fits the needs. Argon2i is safe against side-channel attacks but is more vulnerable to GPU cracking and memory-reduction attacks than Argon2d (factor 1.5 for memory reduction) and Argon2ds (factor 5 for GPU cracking). Argon2d(s) is recommended for side-channel free environments. 72 | 73 | 3. Call 'mode'(context) such as Argon2d(context) and read the output buffer. 74 | 75 | ## Language Bindings 76 | Bindings to the Argon2 library are available in a number of languages 77 | * [Rust](https://github.com/quininer/argon2-rs) 78 | * [Haskell](https://github.com/ocharles/argon2) 79 | * [Python](https://github.com/flamewow/argon2_py) 80 | * [GO](https://github.com/xebia/argon2-go) 81 | 82 | ## Copyright 83 | Argon2 source code package is distributed under the Creative Commons CC0 1.0 License. 84 | 85 | 86 | ## Third Party Code 87 | * Blake 2 source code 88 | `./Source/Blake2/*` 89 | * platform independent endianess detection 90 | `./Source/Common/brg-endian.h` 91 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake2-round-mka.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | static inline __m128i fBlaMka(__m128i x, __m128i y){ 9 | __m128i z = _mm_mul_epu32 (x, y); 10 | 11 | z = _mm_slli_epi64 (z, 1); 12 | 13 | z = _mm_add_epi64 (z, x); 14 | z = _mm_add_epi64 (z, y); 15 | 16 | return z; 17 | } 18 | 19 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 20 | row1l = fBlaMka(row1l, row2l); \ 21 | row1h = fBlaMka(row1h, row2h); \ 22 | \ 23 | row4l = _mm_xor_si128(row4l, row1l); \ 24 | row4h = _mm_xor_si128(row4h, row1h); \ 25 | \ 26 | row4l = _mm_roti_epi64(row4l, -32); \ 27 | row4h = _mm_roti_epi64(row4h, -32); \ 28 | \ 29 | row3l = fBlaMka(row3l, row4l); \ 30 | row3h = fBlaMka(row3h, row4h); \ 31 | \ 32 | row2l = _mm_xor_si128(row2l, row3l); \ 33 | row2h = _mm_xor_si128(row2h, row3h); \ 34 | \ 35 | row2l = _mm_roti_epi64(row2l, -24); \ 36 | row2h = _mm_roti_epi64(row2h, -24); \ 37 | 38 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 39 | row1l = fBlaMka(row1l, row2l); \ 40 | row1h = fBlaMka(row1h, row2h); \ 41 | \ 42 | row4l = _mm_xor_si128(row4l, row1l); \ 43 | row4h = _mm_xor_si128(row4h, row1h); \ 44 | \ 45 | row4l = _mm_roti_epi64(row4l, -16); \ 46 | row4h = _mm_roti_epi64(row4h, -16); \ 47 | \ 48 | row3l = fBlaMka(row3l, row4l); \ 49 | row3h = fBlaMka(row3h, row4h); \ 50 | \ 51 | row2l = _mm_xor_si128(row2l, row3l); \ 52 | row2h = _mm_xor_si128(row2h, row3h); \ 53 | \ 54 | row2l = _mm_roti_epi64(row2l, -63); \ 55 | row2h = _mm_roti_epi64(row2h, -63); \ 56 | 57 | 58 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 59 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 60 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 61 | row2l = t0; \ 62 | row2h = t1; \ 63 | \ 64 | t0 = row3l; \ 65 | row3l = row3h; \ 66 | row3h = t0; \ 67 | \ 68 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 69 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 70 | row4l = t1; \ 71 | row4h = t0; 72 | 73 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 74 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 75 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 76 | row2l = t0; \ 77 | row2h = t1; \ 78 | \ 79 | t0 = row3l; \ 80 | row3l = row3h; \ 81 | row3h = t0; \ 82 | \ 83 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 84 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 85 | row4l = t1; \ 86 | row4h = t0; 87 | 88 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 89 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 90 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 91 | \ 92 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 93 | \ 94 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 95 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 96 | \ 97 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 98 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2-round-mka.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | static inline __m128i fBlaMka(__m128i x, __m128i y){ 9 | __m128i z = _mm_mul_epu32 (x, y); 10 | 11 | z = _mm_slli_epi64 (z, 1); 12 | 13 | z = _mm_add_epi64 (z, x); 14 | z = _mm_add_epi64 (z, y); 15 | 16 | return z; 17 | } 18 | 19 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 20 | row1l = fBlaMka(row1l, row2l); \ 21 | row1h = fBlaMka(row1h, row2h); \ 22 | \ 23 | row4l = _mm_xor_si128(row4l, row1l); \ 24 | row4h = _mm_xor_si128(row4h, row1h); \ 25 | \ 26 | row4l = _mm_roti_epi64(row4l, -32); \ 27 | row4h = _mm_roti_epi64(row4h, -32); \ 28 | \ 29 | row3l = fBlaMka(row3l, row4l); \ 30 | row3h = fBlaMka(row3h, row4h); \ 31 | \ 32 | row2l = _mm_xor_si128(row2l, row3l); \ 33 | row2h = _mm_xor_si128(row2h, row3h); \ 34 | \ 35 | row2l = _mm_roti_epi64(row2l, -24); \ 36 | row2h = _mm_roti_epi64(row2h, -24); \ 37 | 38 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 39 | row1l = fBlaMka(row1l, row2l); \ 40 | row1h = fBlaMka(row1h, row2h); \ 41 | \ 42 | row4l = _mm_xor_si128(row4l, row1l); \ 43 | row4h = _mm_xor_si128(row4h, row1h); \ 44 | \ 45 | row4l = _mm_roti_epi64(row4l, -16); \ 46 | row4h = _mm_roti_epi64(row4h, -16); \ 47 | \ 48 | row3l = fBlaMka(row3l, row4l); \ 49 | row3h = fBlaMka(row3h, row4h); \ 50 | \ 51 | row2l = _mm_xor_si128(row2l, row3l); \ 52 | row2h = _mm_xor_si128(row2h, row3h); \ 53 | \ 54 | row2l = _mm_roti_epi64(row2l, -63); \ 55 | row2h = _mm_roti_epi64(row2h, -63); \ 56 | 57 | 58 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 59 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 60 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 61 | row2l = t0; \ 62 | row2h = t1; \ 63 | \ 64 | t0 = row3l; \ 65 | row3l = row3h; \ 66 | row3h = t0; \ 67 | \ 68 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 69 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 70 | row4l = t1; \ 71 | row4h = t0; 72 | 73 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 74 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 75 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 76 | row2l = t0; \ 77 | row2h = t1; \ 78 | \ 79 | t0 = row3l; \ 80 | row3l = row3h; \ 81 | row3h = t0; \ 82 | \ 83 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 84 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 85 | row4l = t1; \ 86 | row4h = t0; 87 | 88 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 89 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 90 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 91 | \ 92 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 93 | \ 94 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 95 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 96 | \ 97 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 98 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2-round-mka.h: -------------------------------------------------------------------------------- 1 | #define _mm_roti_epi64(x, c) \ 2 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2,3,0,1)) \ 3 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 4 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 5 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 6 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64-(-(c)))) 7 | 8 | static inline __m128i fBlaMka(__m128i x, __m128i y){ 9 | __m128i z = _mm_mul_epu32 (x, y); 10 | 11 | z = _mm_slli_epi64 (z, 1); 12 | 13 | z = _mm_add_epi64 (z, x); 14 | z = _mm_add_epi64 (z, y); 15 | 16 | return z; 17 | } 18 | 19 | #define G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 20 | row1l = fBlaMka(row1l, row2l); \ 21 | row1h = fBlaMka(row1h, row2h); \ 22 | \ 23 | row4l = _mm_xor_si128(row4l, row1l); \ 24 | row4h = _mm_xor_si128(row4h, row1h); \ 25 | \ 26 | row4l = _mm_roti_epi64(row4l, -32); \ 27 | row4h = _mm_roti_epi64(row4h, -32); \ 28 | \ 29 | row3l = fBlaMka(row3l, row4l); \ 30 | row3h = fBlaMka(row3h, row4h); \ 31 | \ 32 | row2l = _mm_xor_si128(row2l, row3l); \ 33 | row2h = _mm_xor_si128(row2h, row3h); \ 34 | \ 35 | row2l = _mm_roti_epi64(row2l, -24); \ 36 | row2h = _mm_roti_epi64(row2h, -24); \ 37 | 38 | #define G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 39 | row1l = fBlaMka(row1l, row2l); \ 40 | row1h = fBlaMka(row1h, row2h); \ 41 | \ 42 | row4l = _mm_xor_si128(row4l, row1l); \ 43 | row4h = _mm_xor_si128(row4h, row1h); \ 44 | \ 45 | row4l = _mm_roti_epi64(row4l, -16); \ 46 | row4h = _mm_roti_epi64(row4h, -16); \ 47 | \ 48 | row3l = fBlaMka(row3l, row4l); \ 49 | row3h = fBlaMka(row3h, row4h); \ 50 | \ 51 | row2l = _mm_xor_si128(row2l, row3l); \ 52 | row2h = _mm_xor_si128(row2h, row3h); \ 53 | \ 54 | row2l = _mm_roti_epi64(row2l, -63); \ 55 | row2h = _mm_roti_epi64(row2h, -63); \ 56 | 57 | 58 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 59 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 60 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 61 | row2l = t0; \ 62 | row2h = t1; \ 63 | \ 64 | t0 = row3l; \ 65 | row3l = row3h; \ 66 | row3h = t0; \ 67 | \ 68 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 69 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 70 | row4l = t1; \ 71 | row4h = t0; 72 | 73 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 74 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 75 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 76 | row2l = t0; \ 77 | row2h = t1; \ 78 | \ 79 | t0 = row3l; \ 80 | row3l = row3h; \ 81 | row3h = t0; \ 82 | \ 83 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 84 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 85 | row4l = t1; \ 86 | row4h = t0; 87 | 88 | #define BLAKE2_ROUND(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 89 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 90 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 91 | \ 92 | DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 93 | \ 94 | G1(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 95 | G2(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); \ 96 | \ 97 | UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h); 98 | -------------------------------------------------------------------------------- /Source/C99/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Argon2 source code package 3 | # 4 | # This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 5 | # 6 | # You should have received a copy of the CC0 Public Domain Dedication along with 7 | # this software. If not, see . 8 | # 9 | 10 | 11 | CC = gcc #clang 12 | REF_CFLAGS = -std=c99 -pthread -O3 -Wall 13 | OPT_CFLAGS = -std=c99 -pthread -O3 -Wall -march=native 14 | 15 | 16 | ARGON2_DIR = ./Argon2 17 | BLAKE2_DIR = ./Blake2 18 | TEST_DIR = ./Test 19 | COMMON_DIR = ./Common 20 | 21 | ARGON2_SOURCES = argon2.c argon2-core.c kat.c 22 | BLAKE2_SOURCES = blake2b-ref.c 23 | TEST_SOURCES = argon2-test.c 24 | 25 | REF_SOURCES = argon2-ref-core.c 26 | OPT_SOURCES = argon2-opt-core.c 27 | 28 | 29 | BUILD_DIR = ./../../Build 30 | 31 | 32 | LIB_NAME=argon2 33 | 34 | 35 | SCRIPTS_DIR = ./../../Scripts 36 | 37 | 38 | ARGON2_BUILD_SOURCES = $(addprefix $(ARGON2_DIR)/,$(ARGON2_SOURCES)) 39 | BLAKE2_BUILD_SOURCES = $(addprefix $(BLAKE2_DIR)/,$(BLAKE2_SOURCES)) 40 | TEST_BUILD_SOURCES = $(addprefix $(TEST_DIR)/,$(TEST_SOURCES)) 41 | 42 | 43 | #OPT=TRUE 44 | ifeq ($(OPT), TRUE) 45 | CFLAGS=$(OPT_CFLAGS) 46 | ARGON2_BUILD_SOURCES += $(addprefix $(ARGON2_DIR)/,$(OPT_SOURCES)) 47 | else 48 | CFLAGS=$(REF_CFLAGS) 49 | ARGON2_BUILD_SOURCES += $(addprefix $(ARGON2_DIR)/,$(REF_SOURCES)) 50 | endif 51 | 52 | 53 | SRC_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 54 | 55 | 56 | BUILD_DIR_PATH := $(shell pwd)/$(BUILD_DIR) 57 | 58 | SYSTEM_KERNEL_NAME := $(shell uname -s) 59 | 60 | ifeq ($(SYSTEM_KERNEL_NAME), Linux) 61 | LIB_EXT := so 62 | LIB_CFLAGS := -shared -fPIC 63 | LIB_PATH := -Wl,-rpath=$(BUILD_DIR_PATH) 64 | endif 65 | ifeq ($(SYSTEM_KERNEL_NAME), Darwin) 66 | LIB_EXT := dylib 67 | LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT) 68 | LIB_PATH := -Xlinker -rpath -Xlinker $(BUILD_DIR_PATH) 69 | endif 70 | ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW) 71 | LIB_EXT := dll 72 | LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a 73 | LIB_PATH := -Wl,-rpath=$(BUILD_PATH) 74 | endif 75 | ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD)) 76 | LIB_EXT := so 77 | LIB_CFLAGS := -shared -fPIC 78 | LIB_PATH := -Wl,-rpath=$(BUILD_PATH) 79 | endif 80 | 81 | 82 | .PHONY: all 83 | all: cleanall argon2 argon2-lib argon2-lib-test 84 | 85 | 86 | .PHONY: argon2 87 | argon2: 88 | $(CC) $(CFLAGS) \ 89 | $(ARGON2_BUILD_SOURCES) \ 90 | $(BLAKE2_BUILD_SOURCES) \ 91 | $(TEST_BUILD_SOURCES) \ 92 | -I$(ARGON2_DIR) \ 93 | -I$(BLAKE2_DIR) \ 94 | -I$(TEST_DIR) \ 95 | -I$(COMMON_DIR) \ 96 | -o $(BUILD_DIR)/$@ 97 | 98 | 99 | .PHONY: argon2-lib 100 | argon2-lib: 101 | $(CC) $(CFLAGS) \ 102 | $(LIB_CFLAGS) \ 103 | $(ARGON2_BUILD_SOURCES) \ 104 | $(BLAKE2_BUILD_SOURCES) \ 105 | -I$(ARGON2_DIR) \ 106 | -I$(BLAKE2_DIR) \ 107 | -I$(COMMON_DIR) \ 108 | -o $(BUILD_DIR)/lib$(LIB_NAME).$(LIB_EXT) 109 | 110 | 111 | .PHONY: argon2-lib-test 112 | argon2-lib-test: argon2-lib 113 | $(CC) $(CFLAGS) \ 114 | $(TEST_BUILD_SOURCES) \ 115 | -I$(ARGON2_DIR) \ 116 | -I$(TEST_DIR) \ 117 | -L$(BUILD_DIR_PATH) \ 118 | $(LIB_PATH) \ 119 | -l$(LIB_NAME) \ 120 | -o $(BUILD_DIR)/$@ 121 | 122 | 123 | .PHONY: check-tv 124 | check-tv: 125 | $(SCRIPTS_DIR)/check_test_vectors.sh -src=$(SRC_DIR) 126 | 127 | 128 | .PHONY: clean 129 | clean: 130 | rm -f $(BUILD_DIR)/* 131 | 132 | 133 | .PHONY: cleanall 134 | cleanall: clean 135 | rm -f *~ 136 | rm -f $(ARGON2_DIR)/*~ 137 | rm -f $(BLAKE2_DIR)/*~ 138 | rm -f $(TEST_DIR)/*~ 139 | rm -f $(COMMON_DIR)/*~ 140 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/ref/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/ref/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/ref/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | static inline uint32_t load32( const void *src ) 20 | { 21 | #if defined(NATIVE_LITTLE_ENDIAN) 22 | uint32_t w; 23 | memcpy(&w, src, sizeof w); 24 | return w; 25 | #else 26 | const uint8_t *p = ( const uint8_t * )src; 27 | uint32_t w = *p++; 28 | w |= ( uint32_t )( *p++ ) << 8; 29 | w |= ( uint32_t )( *p++ ) << 16; 30 | w |= ( uint32_t )( *p++ ) << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64( const void *src ) 36 | { 37 | #if defined(NATIVE_LITTLE_ENDIAN) 38 | uint64_t w; 39 | memcpy(&w, src, sizeof w); 40 | return w; 41 | #else 42 | const uint8_t *p = ( const uint8_t * )src; 43 | uint64_t w = *p++; 44 | w |= ( uint64_t )( *p++ ) << 8; 45 | w |= ( uint64_t )( *p++ ) << 16; 46 | w |= ( uint64_t )( *p++ ) << 24; 47 | w |= ( uint64_t )( *p++ ) << 32; 48 | w |= ( uint64_t )( *p++ ) << 40; 49 | w |= ( uint64_t )( *p++ ) << 48; 50 | w |= ( uint64_t )( *p++ ) << 56; 51 | return w; 52 | #endif 53 | } 54 | 55 | static inline void store32( void *dst, uint32_t w ) 56 | { 57 | #if defined(NATIVE_LITTLE_ENDIAN) 58 | memcpy(dst, &w, sizeof w); 59 | #else 60 | uint8_t *p = ( uint8_t * )dst; 61 | *p++ = ( uint8_t )w; w >>= 8; 62 | *p++ = ( uint8_t )w; w >>= 8; 63 | *p++ = ( uint8_t )w; w >>= 8; 64 | *p++ = ( uint8_t )w; 65 | #endif 66 | } 67 | 68 | static inline void store64( void *dst, uint64_t w ) 69 | { 70 | #if defined(NATIVE_LITTLE_ENDIAN) 71 | memcpy(dst, &w, sizeof w); 72 | #else 73 | uint8_t *p = ( uint8_t * )dst; 74 | *p++ = ( uint8_t )w; w >>= 8; 75 | *p++ = ( uint8_t )w; w >>= 8; 76 | *p++ = ( uint8_t )w; w >>= 8; 77 | *p++ = ( uint8_t )w; w >>= 8; 78 | *p++ = ( uint8_t )w; w >>= 8; 79 | *p++ = ( uint8_t )w; w >>= 8; 80 | *p++ = ( uint8_t )w; w >>= 8; 81 | *p++ = ( uint8_t )w; 82 | #endif 83 | } 84 | 85 | static inline uint64_t load48( const void *src ) 86 | { 87 | const uint8_t *p = ( const uint8_t * )src; 88 | uint64_t w = *p++; 89 | w |= ( uint64_t )( *p++ ) << 8; 90 | w |= ( uint64_t )( *p++ ) << 16; 91 | w |= ( uint64_t )( *p++ ) << 24; 92 | w |= ( uint64_t )( *p++ ) << 32; 93 | w |= ( uint64_t )( *p++ ) << 40; 94 | return w; 95 | } 96 | 97 | static inline void store48( void *dst, uint64_t w ) 98 | { 99 | uint8_t *p = ( uint8_t * )dst; 100 | *p++ = ( uint8_t )w; w >>= 8; 101 | *p++ = ( uint8_t )w; w >>= 8; 102 | *p++ = ( uint8_t )w; w >>= 8; 103 | *p++ = ( uint8_t )w; w >>= 8; 104 | *p++ = ( uint8_t )w; w >>= 8; 105 | *p++ = ( uint8_t )w; 106 | } 107 | 108 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 109 | { 110 | return ( w << c ) | ( w >> ( 32 - c ) ); 111 | } 112 | 113 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 114 | { 115 | return ( w << c ) | ( w >> ( 64 - c ) ); 116 | } 117 | 118 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 119 | { 120 | return ( w >> c ) | ( w << ( 32 - c ) ); 121 | } 122 | 123 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 124 | { 125 | return ( w >> c ) | ( w << ( 64 - c ) ); 126 | } 127 | 128 | /* prevents compiler optimizing out memset() */ 129 | static inline void secure_zero_memory( void *v, size_t n ) 130 | { 131 | volatile uint8_t *p = ( volatile uint8_t * )v; 132 | while( n-- ) *p++ = 0; 133 | } 134 | 135 | #endif 136 | 137 | -------------------------------------------------------------------------------- /Source/C99/Argon2/kat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * 7 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 8 | * 9 | * You should have received a copy of the CC0 Public Domain Dedication along with 10 | * this software. If not, see . 11 | */ 12 | 13 | 14 | #include "stdio.h" 15 | #include "inttypes.h" 16 | 17 | #include "argon2.h" 18 | #include "argon2-core.h" 19 | 20 | 21 | 22 | void InitialKat(const uint8_t* blockhash, const Argon2_Context* context, Argon2_type type) { 23 | FILE* fp = fopen(ARGON2_KAT_FILENAME, "a+"); 24 | 25 | if (fp && blockhash != NULL && context != NULL) { 26 | fprintf(fp, "======================================="); 27 | 28 | switch (type) { 29 | case Argon2_d: 30 | fprintf(fp, "Argon2d\n"); 31 | break; 32 | case Argon2_i: 33 | fprintf(fp, "Argon2i\n"); 34 | break; 35 | case Argon2_id: 36 | fprintf(fp, "Argon2id\n"); 37 | break; 38 | case Argon2_ds: 39 | fprintf(fp, "Argon2ds\n"); 40 | break; 41 | default: 42 | break; 43 | } 44 | 45 | fprintf(fp, "Iterations: %d, Memory: %d KBytes, Parallelism: %d lanes, Tag length: %d bytes\n", 46 | context->t_cost, context->m_cost, context->lanes, context->outlen); 47 | 48 | 49 | fprintf(fp, "Password[%d]: ", context->pwdlen); 50 | if (context->clear_password) { 51 | fprintf(fp, "CLEARED\n"); 52 | } else { 53 | for (unsigned i = 0; i < context->pwdlen; ++i) { 54 | fprintf(fp, "%2.2x ", ((unsigned char*) context->pwd)[i]); 55 | } 56 | fprintf(fp, "\n"); 57 | } 58 | 59 | 60 | fprintf(fp, "Salt[%d]: ", context->saltlen); 61 | for (unsigned i = 0; i < context->saltlen; ++i) { 62 | fprintf(fp, "%2.2x ", ((unsigned char*) context->salt)[i]); 63 | } 64 | fprintf(fp, "\n"); 65 | 66 | fprintf(fp, "Secret[%d]: ", context->secretlen); 67 | 68 | if (context->clear_secret) { 69 | fprintf(fp, "CLEARED\n"); 70 | } else { 71 | for (unsigned i = 0; i < context->secretlen; ++i) { 72 | fprintf(fp, "%2.2x ", ((unsigned char*) context->secret)[i]); 73 | } 74 | fprintf(fp, "\n"); 75 | } 76 | 77 | fprintf(fp, "Associated data[%d]: ", context->adlen); 78 | for (unsigned i = 0; i < context->adlen; ++i) { 79 | fprintf(fp, "%2.2x ", ((unsigned char*) context->ad)[i]); 80 | } 81 | fprintf(fp, "\n"); 82 | 83 | 84 | 85 | fprintf(fp, "Pre-hashing digest: "); 86 | for (unsigned i = 0; i < ARGON2_PREHASH_DIGEST_LENGTH; ++i) { 87 | fprintf(fp, "%2.2x ", ((unsigned char*) blockhash)[i]); 88 | } 89 | fprintf(fp, "\n"); 90 | 91 | fclose(fp); 92 | } 93 | } 94 | 95 | void PrintTag(const void* out, uint32_t outlen) { 96 | FILE* fp = fopen(ARGON2_KAT_FILENAME, "a+"); 97 | 98 | if (fp && out != NULL) { 99 | fprintf(fp, "Tag: "); 100 | for (unsigned i = 0; i < outlen; ++i) { 101 | fprintf(fp, "%2.2x ", ((uint8_t*) out)[i]); 102 | } 103 | fprintf(fp, "\n"); 104 | 105 | fclose(fp); 106 | } 107 | } 108 | 109 | void InternalKat(const Argon2_instance_t* instance, uint32_t pass) { 110 | FILE* fp = fopen(ARGON2_KAT_FILENAME, "a+"); 111 | if (fp && instance != NULL) { 112 | fprintf(fp, "\n After pass %d:\n", pass); 113 | for (uint32_t i = 0; i < instance->memory_blocks; ++i) { 114 | uint32_t how_many_words = (instance->memory_blocks > ARGON2_WORDS_IN_BLOCK) ? 1 : ARGON2_WORDS_IN_BLOCK; 115 | for (uint32_t j = 0; j < how_many_words; ++j) 116 | fprintf(fp, "Block %.4d [%3d]: %016" PRIx64 "\n", i, j, instance->memory[i].v[j]); 117 | } 118 | 119 | fclose(fp); 120 | } 121 | } -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/argon2d.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARGON2_ 2 | #define _ARGON2_ 3 | 4 | const uint8_t MIN_LANES = 1; //Minimum number of lanes (degree of parallelism) 5 | const uint8_t MAX_LANES = 255; //Maximum number of lanes (degree of parallelism) 6 | const uint32_t SYNC_POINTS = 4; //Number of synchronization points between lanes per pass 7 | const uint32_t MAX_OUTLEN = 0xFFFFFFFF; //Maximum digest length in bytes 8 | const uint32_t MIN_OUTLEN = 4; //Minimum digest size 9 | const uint32_t MIN_MEMORY = 2 * SYNC_POINTS; //Minimum number of memory blocks: 2 per slice 10 | const uint32_t MAX_MEMORY = 0xFFFFFFFF;//Maximum number of memory blocks: 2^32-1 KB-blocks 11 | const uint32_t MIN_TIME = 1; //Minimum number of passes 12 | const uint32_t MIN_PWD_LENGTH = 0;// Minimum password length in bytes 13 | const uint32_t MAX_PWD_LENGTH = 0xFFFFFFFF; //Maximum password length in bytes 14 | const uint32_t MIN_AD_LENGTH = 0; //Minimum associated data length in bytes 15 | const uint32_t MAX_AD_LENGTH = 0xFFFFFFFF; //Maximum associated data length in bytes 16 | const uint32_t MAX_SALT_LENGTH = 0xFFFFFFFF;//Maximum salt length in bytes 17 | const uint32_t MIN_SALT_LENGTH = 8; //Minimum salt length in bytes 18 | const uint32_t MIN_SECRET = 0; //Minimum key length in bytes 19 | const uint32_t MAX_SECRET = 0xFFFFFFFF; //Maximum key length in bytes 20 | const size_t BLOCK_SIZE_KILOBYTE = 1;//Memory block size 21 | const size_t BYTES_IN_BLOCK = (1024 * BLOCK_SIZE_KILOBYTE); //The same as above 22 | const size_t BLOCK_SIZE = BYTES_IN_BLOCK; 23 | const uint8_t VERSION_NUMBER = 0x10;//Version number 24 | const uint32_t ADDRESSES_IN_BLOCK = (BYTES_IN_BLOCK / 4); // Number of memory addresses generated by one call to Blake in Argon2i 25 | 26 | const uint32_t ALIGN_ARGON = 16;//Alignment parameter 27 | 28 | const uint32_t INPUT_INITIAL_HASH_LENGTH = 64; //The inputs are first hashed with full Blake and put into the first memory blocks -- the length of this digest. 29 | 30 | /*****************ERROR CODES*********/ 31 | 32 | const int NULL_OUTPUT_PTR = -1; 33 | const int TOO_SHORT_OUTPUT = -2; 34 | const int TOO_LONG_OUTPUT = -3; 35 | const int TOO_SHORT_PWD = -4; 36 | const int TOO_LONG_PWD = -5; 37 | const int TOO_SHORT_SALT = -6; 38 | const int TOO_LONG_SALT = -7; 39 | const int TOO_SHORT_AD = -8; 40 | const int TOO_LONG_AD = -9; 41 | const int TOO_SHORT_SECRET = -10; 42 | const int TOO_LONG_SECRET = -11; 43 | const int TOO_SMALL_TIME = -12; 44 | const int TOO_LARGE_TIME = -13; 45 | const int TOO_LITTLE_MEMORY = -14; 46 | const int TOO_MUCH_MEMORY = -15; 47 | const int TOO_FEW_LANES = -16; 48 | const int TOO_MANY_LANES = -17; 49 | 50 | 51 | #define USEC_TO_SEC (1000 * 1000 * 1.0) 52 | #define BYTES_TO_GIGABYTES (1024 * 1024 * 1024 * 1.0) 53 | 54 | 55 | struct scheme_info_t 56 | { 57 | uint8_t *state; 58 | uint32_t mem_size; 59 | uint32_t passes; 60 | uint8_t lanes; 61 | scheme_info_t(uint8_t* s, uint32_t m, uint32_t p, uint8_t l){ state = s; mem_size = m; passes = p; lanes = l; } 62 | }; 63 | 64 | struct position_info_t { 65 | 66 | uint32_t pass; 67 | uint8_t slice; 68 | uint8_t lane; 69 | uint32_t index; 70 | position_info_t(uint32_t p = 0, uint8_t s = 0, uint8_t l = 0, uint32_t i = 0){ pass = p; slice = s; lane = l; index = i; } 71 | }; 72 | 73 | 74 | #define KAT_FILENAME "kat-argon2d-opt.log" 75 | 76 | 77 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 78 | unsigned int t_cost, unsigned int m_cost); 79 | 80 | extern int Argon2d(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 81 | uint8_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 82 | extern int ValidateInputs(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 83 | uint32_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 84 | extern void InitialHash(uint8_t* blockhash, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 85 | uint32_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 86 | #endif -------------------------------------------------------------------------------- /Source/C++11/Test/bench.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 source code package 3 | * 4 | * Written by Daniel Dinu and Dmitry Khovratovich, 2015 5 | * 6 | * This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 7 | * 8 | * You should have received a copy of the CC0 Public Domain Dedication along with 9 | * this software. If not, see . 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #ifdef _MSC_VER 20 | #include 21 | #endif 22 | 23 | #include "argon2.h" 24 | 25 | static uint64_t rdtsc(void) { 26 | #ifdef _MSC_VER 27 | return __rdtsc(); 28 | #else 29 | #if defined(__amd64__) || defined(__x86_64__) 30 | uint64_t rax, rdx; 31 | __asm__ __volatile__("rdtsc" : "=a"(rax), "=d"(rdx) : :); 32 | return (rdx << 32) | rax; 33 | #elif defined(__i386__) || defined(__i386) || defined(__X86__) 34 | uint64_t rax; 35 | __asm__ __volatile__("rdtsc" : "=A"(rax) : :); 36 | return rax; 37 | #else 38 | #error "Not implemented!" 39 | #endif 40 | #endif 41 | } 42 | 43 | /* 44 | * Benchmarks Argon2 with salt length 16, password length 32, t_cost 3, and different threads and m_cost 45 | */ 46 | void Benchmark() { 47 | const uint32_t inlen = 16; 48 | const unsigned outlen=16; 49 | unsigned char out[outlen]; 50 | unsigned char pwd_array[inlen]; 51 | unsigned char salt_array[inlen]; 52 | 53 | uint32_t t_cost = 1; 54 | 55 | memset(pwd_array, 0, inlen); 56 | memset(salt_array, 1, inlen); 57 | std::vector thread_test = {1, 2, 4, 6, 8, 16}; 58 | 59 | for (uint32_t m_cost = (uint32_t) 1 << 18; m_cost <= (uint32_t) 1 << 22; m_cost *= 2) { 60 | for (uint32_t thread_n : thread_test) { 61 | 62 | uint64_t start_cycles, stop_cycles, stop_cycles_i, stop_cycles_di, stop_cycles_ds; 63 | 64 | clock_t start_time = clock(); 65 | start_cycles = rdtsc(); 66 | 67 | Argon2_Context context(out, outlen, pwd_array, inlen, salt_array, inlen, NULL, 0, NULL, 0, 68 | t_cost, m_cost, thread_n, thread_n,NULL,NULL,false,false, false,false); 69 | Argon2d(&context); 70 | stop_cycles = rdtsc(); 71 | Argon2i(&context); 72 | stop_cycles_i = rdtsc(); 73 | Argon2id(&context); 74 | stop_cycles_di = rdtsc(); 75 | Argon2ds(&context); 76 | stop_cycles_ds = rdtsc(); 77 | clock_t stop_time = clock(); 78 | 79 | uint64_t delta_d = (stop_cycles - start_cycles) / (m_cost); 80 | uint64_t delta_i = (stop_cycles_i - stop_cycles) / (m_cost); 81 | uint64_t delta_id = (stop_cycles_di - stop_cycles_i) / m_cost; 82 | uint64_t delta_ds = (stop_cycles_ds - stop_cycles_di) / m_cost; 83 | float mcycles_d = (float) (stop_cycles - start_cycles) / (1 << 20); 84 | float mcycles_i = (float) (stop_cycles_i - stop_cycles) / (1 << 20); 85 | float mcycles_id = (float) (stop_cycles_di - stop_cycles_i) / (1 << 20); 86 | float mcycles_ds = (float) (stop_cycles_ds - stop_cycles_di) / (1 << 20); 87 | printf("Argon2d %d pass(es) %d Mbytes %d lanes/threads: %2.2f cpb %2.2f Mcycles \n", t_cost, m_cost >> 10, thread_n, (float) delta_d / 1024, mcycles_d); 88 | printf("Argon2i %d pass(es) %d Mbytes %d lanes/threads: %2.2f cpb %2.2f Mcycles \n", t_cost, m_cost >> 10, thread_n, (float) delta_i / 1024, mcycles_i); 89 | printf("Argon2id %d pass(es) %d Mbytes %d lanes/threads: %2.2f cpb %2.2f Mcycles \n", t_cost, m_cost >> 10, thread_n, (float) delta_id / 1024, mcycles_id); 90 | printf("Argon2ds %d pass(es) %d Mbytes %d lanes/threads: %2.2f cpb %2.2f Mcycles \n", t_cost, m_cost >> 10, thread_n, (float) delta_ds / 1024, mcycles_ds); 91 | 92 | float run_time = ((float) stop_time - start_time) / (CLOCKS_PER_SEC); 93 | printf("%2.4f seconds\n\n", run_time); 94 | } 95 | } 96 | } 97 | 98 | 99 | int main() { 100 | Benchmark(); 101 | return ARGON2_OK; 102 | } -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/ref/argon2d.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARGON2_ 2 | #define _ARGON2_ 3 | 4 | const uint8_t MIN_LANES = 1; //Minimum number of lanes (degree of parallelism) 5 | const uint8_t MAX_LANES = 255; //Maximum number of lanes (degree of parallelism) 6 | const uint32_t SYNC_POINTS = 4; //Number of synchronization points between lanes per pass 7 | const uint32_t MAX_OUTLEN = 0xFFFFFFFF; //Maximum digest length in bytes 8 | const uint32_t MIN_OUTLEN = 4; //Minimum digest size 9 | const uint32_t MIN_MEMORY = 2*SYNC_POINTS; //Minimum number of memory blocks: 2 per slice 10 | const uint32_t MAX_MEMORY = 0xFFFFFFFF;//Maximum number of memory blocks: 2^32-1 KB-blocks 11 | const uint32_t MIN_TIME = 1; //Minimum number of passes 12 | const uint32_t MIN_PWD_LENGTH = 0;// Minimum password length in bytes 13 | const uint32_t MAX_PWD_LENGTH = 0xFFFFFFFF; //Maximum password length in bytes 14 | const uint32_t MIN_AD_LENGTH = 0; //Minimum associated data length in bytes 15 | const uint32_t MAX_AD_LENGTH = 0xFFFFFFFF; //Maximum associated data length in bytes 16 | const uint32_t MAX_SALT_LENGTH =0xFFFFFFFF;//Maximum salt length in bytes 17 | const uint32_t MIN_SALT_LENGTH = 8; //Minimum salt length in bytes 18 | const uint32_t MIN_SECRET = 0; //Minimum key length in bytes 19 | const uint32_t MAX_SECRET = 0xFFFFFFFF; //Maximum key length in bytes 20 | const size_t BLOCK_SIZE_KILOBYTE = 1;//Memory block size 21 | const size_t BYTES_IN_BLOCK = (1024 * BLOCK_SIZE_KILOBYTE); //The same as above 22 | const size_t BLOCK_SIZE = BYTES_IN_BLOCK; 23 | const uint8_t VERSION_NUMBER = 0x10;//Version number 24 | const uint32_t ADDRESSES_IN_BLOCK = (BYTES_IN_BLOCK / 4); // Number of memory addresses generated by one call to Blake in Argon2i 25 | 26 | const uint32_t ALIGN_ARGON = 16;//Alignment parameter 27 | 28 | const uint32_t INPUT_INITIAL_HASH_LENGTH = 64; //The inputs are first hashed with full Blake and put into the first memory blocks -- the length of this digest. 29 | 30 | /*****************ERROR CODES*********/ 31 | 32 | const int NULL_OUTPUT_PTR = -1; 33 | const int TOO_SHORT_OUTPUT = -2; 34 | const int TOO_LONG_OUTPUT = -3; 35 | const int TOO_SHORT_PWD = -4; 36 | const int TOO_LONG_PWD = -5; 37 | const int TOO_SHORT_SALT = -6; 38 | const int TOO_LONG_SALT = -7; 39 | const int TOO_SHORT_AD = -8; 40 | const int TOO_LONG_AD = -9; 41 | const int TOO_SHORT_SECRET = -10; 42 | const int TOO_LONG_SECRET = -11; 43 | const int TOO_SMALL_TIME = -12; 44 | const int TOO_LARGE_TIME = -13; 45 | const int TOO_LITTLE_MEMORY = -14; 46 | const int TOO_MUCH_MEMORY = -15; 47 | const int TOO_FEW_LANES = -16; 48 | const int TOO_MANY_LANES = -17; 49 | 50 | 51 | //#define KAT 52 | //#define KAT_INTERNAL 53 | const char* KAT_FILENAME = "kat-argon2d.log"; 54 | 55 | 56 | #define _MEASURE //Whether we measure timings 57 | 58 | /* 59 | Structure for the (1KB) memory block. 60 | Memory blocks can be copied, XORed 61 | */ 62 | struct block{ 63 | uint8_t v[BYTES_IN_BLOCK]; 64 | 65 | block(){ memset(v, 0, BYTES_IN_BLOCK); } 66 | uint64_t& operator[](uint8_t i){ return *(uint64_t*)(v + 8 * i); } 67 | block& operator=(const block& r){ memcpy(v, r.v, BYTES_IN_BLOCK); return *this; } 68 | block operator^(const block& r){static block a; for (unsigned j = 0; j < BYTES_IN_BLOCK; ++j) a.v[j] = v[j] ^ r.v[j]; return a; } 69 | }; 70 | 71 | /** 72 | * Function to hash the inputs in the memory-hard fashion 73 | * @param out Pointer to the memory where the hash digest will be written 74 | * @param outlen Digest length in bytes 75 | * @param in Pointer to the input (password) 76 | * @param inlen Input length in bytes 77 | * @param salt Pointer to the salt 78 | * @param saltlen Salt length in bytes 79 | * @pre @a out must have at least @a outlen bytes allocated 80 | * @pre @a in must be at least @inlen bytes long 81 | * @pre @a saltlen must be at least @saltlen bytes long 82 | * @return Zero if successful, 1 otherwise. 83 | */ 84 | 85 | extern "C" int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, 86 | unsigned int t_cost, unsigned int m_cost); 87 | 88 | extern int Argon2d(uint8_t *out, uint32_t outlen, const uint8_t *msg, uint32_t msglen, const uint8_t *nonce, uint32_t noncelen, const uint8_t *secret, 89 | uint32_t secretlen, const uint8_t *ad, uint32_t adlen, uint32_t t_cost, uint32_t m_cost, uint8_t lanes); 90 | 91 | #endif -------------------------------------------------------------------------------- /Source/C++11/Blake2/blake2-impl.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLE_BLAKE2_IMPL_H 2 | #define PORTABLE_BLAKE2_IMPL_H 3 | 4 | #include 5 | #include 6 | 7 | #if defined(_MSC_VER) 8 | #define BLAKE2_INLINE __inline 9 | #elif defined(__GNUC__) || defined(__clang__) 10 | #define BLAKE2_INLINE __inline__ 11 | #else 12 | #define BLAKE2_INLINE 13 | #endif 14 | 15 | /* Argon2 Team - Begin Code */ 16 | /* 17 | Not an exhaustive list, but should cover the majority of modern platforms 18 | Additionally, the code will always be correct---this is only a performance 19 | tweak. 20 | */ 21 | #if (defined(__BYTE_ORDER__) && \ 22 | (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \ 23 | defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__MIPSEL__) || \ 24 | defined(__AARCH64EL__) || defined(__amd64__) || defined(__i386__) || \ 25 | defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \ 26 | defined(_M_ARM) 27 | #define NATIVE_LITTLE_ENDIAN 28 | #endif 29 | /* Argon2 Team - End Code */ 30 | 31 | static BLAKE2_INLINE uint32_t load32(const void *src) { 32 | #if defined(NATIVE_LITTLE_ENDIAN) 33 | uint32_t w; 34 | memcpy(&w, src, sizeof w); 35 | return w; 36 | #else 37 | const uint8_t *p = (const uint8_t *)src; 38 | uint32_t w = *p++; 39 | w |= (uint32_t)(*p++) << 8; 40 | w |= (uint32_t)(*p++) << 16; 41 | w |= (uint32_t)(*p++) << 24; 42 | return w; 43 | #endif 44 | } 45 | 46 | static BLAKE2_INLINE uint64_t load64(const void *src) { 47 | #if defined(NATIVE_LITTLE_ENDIAN) 48 | uint64_t w; 49 | memcpy(&w, src, sizeof w); 50 | return w; 51 | #else 52 | const uint8_t *p = (const uint8_t *)src; 53 | uint64_t w = *p++; 54 | w |= (uint64_t)(*p++) << 8; 55 | w |= (uint64_t)(*p++) << 16; 56 | w |= (uint64_t)(*p++) << 24; 57 | w |= (uint64_t)(*p++) << 32; 58 | w |= (uint64_t)(*p++) << 40; 59 | w |= (uint64_t)(*p++) << 48; 60 | w |= (uint64_t)(*p++) << 56; 61 | return w; 62 | #endif 63 | } 64 | 65 | static BLAKE2_INLINE void store32(void *dst, uint32_t w) { 66 | #if defined(NATIVE_LITTLE_ENDIAN) 67 | memcpy(dst, &w, sizeof w); 68 | #else 69 | uint8_t *p = (uint8_t *)dst; 70 | *p++ = (uint8_t)w; 71 | w >>= 8; 72 | *p++ = (uint8_t)w; 73 | w >>= 8; 74 | *p++ = (uint8_t)w; 75 | w >>= 8; 76 | *p++ = (uint8_t)w; 77 | #endif 78 | } 79 | 80 | static BLAKE2_INLINE void store64(void *dst, uint64_t w) { 81 | #if defined(NATIVE_LITTLE_ENDIAN) 82 | memcpy(dst, &w, sizeof w); 83 | #else 84 | uint8_t *p = (uint8_t *)dst; 85 | *p++ = (uint8_t)w; 86 | w >>= 8; 87 | *p++ = (uint8_t)w; 88 | w >>= 8; 89 | *p++ = (uint8_t)w; 90 | w >>= 8; 91 | *p++ = (uint8_t)w; 92 | w >>= 8; 93 | *p++ = (uint8_t)w; 94 | w >>= 8; 95 | *p++ = (uint8_t)w; 96 | w >>= 8; 97 | *p++ = (uint8_t)w; 98 | w >>= 8; 99 | *p++ = (uint8_t)w; 100 | #endif 101 | } 102 | 103 | static BLAKE2_INLINE uint64_t load48(const void *src) { 104 | const uint8_t *p = (const uint8_t *)src; 105 | uint64_t w = *p++; 106 | w |= (uint64_t)(*p++) << 8; 107 | w |= (uint64_t)(*p++) << 16; 108 | w |= (uint64_t)(*p++) << 24; 109 | w |= (uint64_t)(*p++) << 32; 110 | w |= (uint64_t)(*p++) << 40; 111 | return w; 112 | } 113 | 114 | static BLAKE2_INLINE void store48(void *dst, uint64_t w) { 115 | uint8_t *p = (uint8_t *)dst; 116 | *p++ = (uint8_t)w; 117 | w >>= 8; 118 | *p++ = (uint8_t)w; 119 | w >>= 8; 120 | *p++ = (uint8_t)w; 121 | w >>= 8; 122 | *p++ = (uint8_t)w; 123 | w >>= 8; 124 | *p++ = (uint8_t)w; 125 | w >>= 8; 126 | *p++ = (uint8_t)w; 127 | } 128 | 129 | static BLAKE2_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) { 130 | return (w >> c) | (w << (32 - c)); 131 | } 132 | 133 | static BLAKE2_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) { 134 | return (w >> c) | (w << (64 - c)); 135 | } 136 | 137 | /* prevents compiler optimizing out memset() */ 138 | static BLAKE2_INLINE void burn(void *v, size_t n) { 139 | static void *(*const volatile memset_v)(void *, int, size_t) = &memset; 140 | memset_v(v, 0, n); 141 | } 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake2-impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_IMPL_H__ 15 | #define __BLAKE2_IMPL_H__ 16 | 17 | #include 18 | 19 | /* Argon2 Team - Begin Code */ 20 | #include "brg-endian.h" 21 | 22 | #if defined(PLATFORM_BYTE_ORDER) && (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) && !defined(NATIVE_LITTLE_ENDIAN) 23 | #define NATIVE_LITTLE_ENDIAN 24 | #endif 25 | /* Argon2 Team - End Code */ 26 | 27 | 28 | static inline uint32_t load32( const void *src ) 29 | { 30 | #if defined(NATIVE_LITTLE_ENDIAN) 31 | uint32_t w; 32 | memcpy(&w, src, sizeof w); 33 | return w; 34 | #else 35 | const uint8_t *p = ( const uint8_t * )src; 36 | uint32_t w = *p++; 37 | w |= ( uint32_t )( *p++ ) << 8; 38 | w |= ( uint32_t )( *p++ ) << 16; 39 | w |= ( uint32_t )( *p++ ) << 24; 40 | return w; 41 | #endif 42 | } 43 | 44 | static inline uint64_t load64( const void *src ) 45 | { 46 | #if defined(NATIVE_LITTLE_ENDIAN) 47 | uint64_t w; 48 | memcpy(&w, src, sizeof w); 49 | return w; 50 | #else 51 | const uint8_t *p = ( const uint8_t * )src; 52 | uint64_t w = *p++; 53 | w |= ( uint64_t )( *p++ ) << 8; 54 | w |= ( uint64_t )( *p++ ) << 16; 55 | w |= ( uint64_t )( *p++ ) << 24; 56 | w |= ( uint64_t )( *p++ ) << 32; 57 | w |= ( uint64_t )( *p++ ) << 40; 58 | w |= ( uint64_t )( *p++ ) << 48; 59 | w |= ( uint64_t )( *p++ ) << 56; 60 | return w; 61 | #endif 62 | } 63 | 64 | static inline void store32( void *dst, uint32_t w ) 65 | { 66 | #if defined(NATIVE_LITTLE_ENDIAN) 67 | memcpy(dst, &w, sizeof w); 68 | #else 69 | uint8_t *p = ( uint8_t * )dst; 70 | *p++ = ( uint8_t )w; w >>= 8; 71 | *p++ = ( uint8_t )w; w >>= 8; 72 | *p++ = ( uint8_t )w; w >>= 8; 73 | *p++ = ( uint8_t )w; 74 | #endif 75 | } 76 | 77 | static inline void store64( void *dst, uint64_t w ) 78 | { 79 | #if defined(NATIVE_LITTLE_ENDIAN) 80 | memcpy(dst, &w, sizeof w); 81 | #else 82 | uint8_t *p = ( uint8_t * )dst; 83 | *p++ = ( uint8_t )w; w >>= 8; 84 | *p++ = ( uint8_t )w; w >>= 8; 85 | *p++ = ( uint8_t )w; w >>= 8; 86 | *p++ = ( uint8_t )w; w >>= 8; 87 | *p++ = ( uint8_t )w; w >>= 8; 88 | *p++ = ( uint8_t )w; w >>= 8; 89 | *p++ = ( uint8_t )w; w >>= 8; 90 | *p++ = ( uint8_t )w; 91 | #endif 92 | } 93 | 94 | static inline uint64_t load48( const void *src ) 95 | { 96 | const uint8_t *p = ( const uint8_t * )src; 97 | uint64_t w = *p++; 98 | w |= ( uint64_t )( *p++ ) << 8; 99 | w |= ( uint64_t )( *p++ ) << 16; 100 | w |= ( uint64_t )( *p++ ) << 24; 101 | w |= ( uint64_t )( *p++ ) << 32; 102 | w |= ( uint64_t )( *p++ ) << 40; 103 | return w; 104 | } 105 | 106 | static inline void store48( void *dst, uint64_t w ) 107 | { 108 | uint8_t *p = ( uint8_t * )dst; 109 | *p++ = ( uint8_t )w; w >>= 8; 110 | *p++ = ( uint8_t )w; w >>= 8; 111 | *p++ = ( uint8_t )w; w >>= 8; 112 | *p++ = ( uint8_t )w; w >>= 8; 113 | *p++ = ( uint8_t )w; w >>= 8; 114 | *p++ = ( uint8_t )w; 115 | } 116 | 117 | static inline uint32_t rotl32( const uint32_t w, const unsigned c ) 118 | { 119 | return ( w << c ) | ( w >> ( 32 - c ) ); 120 | } 121 | 122 | static inline uint64_t rotl64( const uint64_t w, const unsigned c ) 123 | { 124 | return ( w << c ) | ( w >> ( 64 - c ) ); 125 | } 126 | 127 | static inline uint32_t rotr32( const uint32_t w, const unsigned c ) 128 | { 129 | return ( w >> c ) | ( w << ( 32 - c ) ); 130 | } 131 | 132 | static inline uint64_t rotr64( const uint64_t w, const unsigned c ) 133 | { 134 | return ( w >> c ) | ( w << ( 64 - c ) ); 135 | } 136 | 137 | /* prevents compiler optimizing out memset() */ 138 | static inline void secure_zero_memory( void *v, size_t n ) 139 | { 140 | volatile uint8_t *p = ( volatile uint8_t * )v; 141 | while( n-- ) *p++ = 0; 142 | } 143 | 144 | #endif 145 | 146 | -------------------------------------------------------------------------------- /Source/C++11/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Argon2 source code package 3 | # 4 | # This work is licensed under a Creative Commons CC0 1.0 License/Waiver. 5 | # 6 | # You should have received a copy of the CC0 Public Domain Dedication along with 7 | # this software. If not, see . 8 | # 9 | 10 | 11 | CC = g++ #clang++ 12 | REF_CFLAGS = -std=c++11 -pthread -O3 -Wall 13 | OPT_CFLAGS = -std=c++11 -pthread -O3 -Wall -march=native 14 | 15 | 16 | ARGON2_DIR = ./Argon2 17 | BLAKE2_DIR = ./Blake2 18 | TEST_DIR = ./Test 19 | 20 | ARGON2_SOURCES = argon2.cpp argon2-core.cpp kat.cpp 21 | BLAKE2_SOURCES = blake2b.c 22 | RUN_SOURCES = run.cpp 23 | BENCH_SOURCES = bench.cpp 24 | KAT_SOURCES = genkat.cpp 25 | 26 | REF_SOURCES = argon2-ref-core.cpp 27 | OPT_SOURCES = argon2-opt-core.cpp 28 | 29 | 30 | BUILD_DIR = ./../../Build 31 | 32 | 33 | LIB_NAME=argon2 34 | 35 | 36 | SCRIPTS_DIR = ./../../Scripts 37 | 38 | 39 | ARGON2_BUILD_SOURCES = $(addprefix $(ARGON2_DIR)/,$(ARGON2_SOURCES)) 40 | BLAKE2_BUILD_SOURCES = $(addprefix $(BLAKE2_DIR)/,$(BLAKE2_SOURCES)) 41 | RUN_BUILD_SOURCES = $(addprefix $(TEST_DIR)/,$(RUN_SOURCES)) 42 | BENCH_BUILD_SOURCES = $(addprefix $(TEST_DIR)/,$(BENCH_SOURCES)) 43 | KAT_BUILD_SOURCES = $(addprefix $(TEST_DIR)/,$(KAT_SOURCES)) 44 | 45 | 46 | #OPT=TRUE 47 | ifeq ($(OPT), TRUE) 48 | CFLAGS=$(OPT_CFLAGS) 49 | ARGON2_BUILD_SOURCES += $(addprefix $(ARGON2_DIR)/,$(OPT_SOURCES)) 50 | else 51 | CFLAGS=$(REF_CFLAGS) 52 | ARGON2_BUILD_SOURCES += $(addprefix $(ARGON2_DIR)/,$(REF_SOURCES)) 53 | endif 54 | 55 | 56 | SRC_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 57 | 58 | 59 | BUILD_DIR_PATH := $(shell pwd)/$(BUILD_DIR) 60 | 61 | SYSTEM_KERNEL_NAME := $(shell uname -s) 62 | 63 | ifeq ($(SYSTEM_KERNEL_NAME), Linux) 64 | LIB_EXT := so 65 | LIB_CFLAGS := -shared -fPIC 66 | LIB_PATH := -Wl,-rpath=$(BUILD_DIR_PATH) 67 | endif 68 | ifeq ($(SYSTEM_KERNEL_NAME), Darwin) 69 | LIB_EXT := dylib 70 | LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT) 71 | LIB_PATH := -Xlinker -rpath -Xlinker $(BUILD_DIR_PATH) 72 | endif 73 | ifeq ($(KERNEL_NAME), NetBSD) 74 | LIB_EXT := so 75 | LIB_CFLAGS := -shared -fPIC 76 | LIB_PATH := -Wl,-rpath=$(BUILD_PATH) 77 | endif 78 | ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW) 79 | LIB_EXT := dll 80 | LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a 81 | LIB_PATH := -Wl,-rpath=$(BUILD_PATH) 82 | endif 83 | ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),OpenBSD FreeBSD)) 84 | LIB_EXT := so 85 | LIB_CFLAGS := -shared -fPIC 86 | LIB_PATH := -Wl,-rpath=$(BUILD_PATH) 87 | endif 88 | 89 | 90 | .PHONY: all 91 | all: cleanall argon2 argon2-lib argon2-lib-test argon2-bench argon2-kat 92 | 93 | 94 | .PHONY: argon2-bench 95 | argon2-bench: 96 | $(CC) $(CFLAGS) \ 97 | $(ARGON2_BUILD_SOURCES) \ 98 | $(BLAKE2_BUILD_SOURCES) \ 99 | $(BENCH_BUILD_SOURCES) \ 100 | -I$(ARGON2_DIR) \ 101 | -I$(BLAKE2_DIR) \ 102 | -I$(TEST_DIR) \ 103 | -o $(BUILD_DIR)/$@ 104 | .PHONY: argon2 105 | argon2: 106 | $(CC) $(CFLAGS) \ 107 | $(ARGON2_BUILD_SOURCES) \ 108 | $(BLAKE2_BUILD_SOURCES) \ 109 | $(RUN_BUILD_SOURCES) \ 110 | -I$(ARGON2_DIR) \ 111 | -I$(BLAKE2_DIR) \ 112 | -I$(TEST_DIR) \ 113 | -o $(BUILD_DIR)/$@ 114 | .PHONY: argon2-kat 115 | argon2-kat: 116 | $(CC) $(CFLAGS) \ 117 | $(ARGON2_BUILD_SOURCES) \ 118 | $(BLAKE2_BUILD_SOURCES) \ 119 | $(KAT_BUILD_SOURCES) \ 120 | -I$(ARGON2_DIR) \ 121 | -I$(BLAKE2_DIR) \ 122 | -I$(TEST_DIR) \ 123 | -o $(BUILD_DIR)/$@ 124 | 125 | .PHONY: argon2-lib 126 | argon2-lib: 127 | $(CC) $(CFLAGS) \ 128 | $(LIB_CFLAGS) \ 129 | $(ARGON2_BUILD_SOURCES) \ 130 | $(BLAKE2_BUILD_SOURCES) \ 131 | -I$(ARGON2_DIR) \ 132 | -I$(BLAKE2_DIR) \ 133 | -o $(BUILD_DIR)/lib$(LIB_NAME).$(LIB_EXT) 134 | 135 | 136 | .PHONY: argon2-lib-test 137 | argon2-lib-test: argon2-lib 138 | $(CC) $(CFLAGS) \ 139 | $(RUN_BUILD_SOURCES) \ 140 | -I$(ARGON2_DIR) \ 141 | -I$(TEST_DIR) \ 142 | -L$(BUILD_DIR_PATH) \ 143 | $(LIB_PATH) \ 144 | -l$(LIB_NAME) \ 145 | -o $(BUILD_DIR)/$@ 146 | 147 | 148 | .PHONY: check-tv 149 | check-tv: 150 | $(SCRIPTS_DIR)/check_test_vectors.sh -src=$(SRC_DIR) 151 | 152 | 153 | .PHONY: clean 154 | clean: 155 | rm -f $(BUILD_DIR)/* 156 | 157 | 158 | .PHONY: cleanall 159 | cleanall: clean 160 | rm -f *~ 161 | rm -f $(ARGON2_DIR)/*~ 162 | rm -f $(BLAKE2_DIR)/*~ 163 | rm -f $(TEST_DIR)/*~ 164 | -------------------------------------------------------------------------------- /Source/C99/Blake2/blake2b-load-sse2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_LOAD_SSE2_H__ 15 | #define __BLAKE2B_LOAD_SSE2_H__ 16 | 17 | #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 18 | #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 19 | #define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 20 | #define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 21 | #define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 22 | #define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 23 | #define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 24 | #define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 25 | #define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) 26 | #define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) 27 | #define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) 28 | #define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) 29 | #define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) 30 | #define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) 31 | #define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) 32 | #define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) 33 | #define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) 34 | #define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) 35 | #define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) 36 | #define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) 37 | #define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) 38 | #define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) 39 | #define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) 40 | #define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) 41 | #define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) 42 | #define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) 43 | #define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) 44 | #define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) 45 | #define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) 46 | #define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) 47 | #define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) 48 | #define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) 49 | #define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) 50 | #define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) 51 | #define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) 52 | #define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) 53 | #define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) 54 | #define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) 55 | #define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) 56 | #define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) 57 | #define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 58 | #define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 59 | #define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 60 | #define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 61 | #define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 62 | #define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 63 | #define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 64 | #define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 65 | 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/blake2b-load-sse2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_LOAD_SSE2_H__ 15 | #define __BLAKE2B_LOAD_SSE2_H__ 16 | 17 | #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 18 | #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 19 | #define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 20 | #define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 21 | #define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 22 | #define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 23 | #define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 24 | #define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 25 | #define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) 26 | #define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) 27 | #define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) 28 | #define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) 29 | #define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) 30 | #define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) 31 | #define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) 32 | #define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) 33 | #define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) 34 | #define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) 35 | #define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) 36 | #define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) 37 | #define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) 38 | #define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) 39 | #define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) 40 | #define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) 41 | #define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) 42 | #define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) 43 | #define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) 44 | #define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) 45 | #define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) 46 | #define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) 47 | #define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) 48 | #define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) 49 | #define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) 50 | #define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) 51 | #define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) 52 | #define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) 53 | #define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) 54 | #define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) 55 | #define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) 56 | #define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) 57 | #define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 58 | #define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 59 | #define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 60 | #define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 61 | #define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 62 | #define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 63 | #define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 64 | #define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 65 | 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2b-load-sse2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_LOAD_SSE2_H__ 15 | #define __BLAKE2B_LOAD_SSE2_H__ 16 | 17 | #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 18 | #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 19 | #define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 20 | #define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 21 | #define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 22 | #define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 23 | #define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 24 | #define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 25 | #define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) 26 | #define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) 27 | #define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) 28 | #define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) 29 | #define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) 30 | #define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) 31 | #define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) 32 | #define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) 33 | #define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) 34 | #define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) 35 | #define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) 36 | #define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) 37 | #define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) 38 | #define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) 39 | #define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) 40 | #define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) 41 | #define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) 42 | #define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) 43 | #define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) 44 | #define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) 45 | #define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) 46 | #define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) 47 | #define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) 48 | #define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) 49 | #define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) 50 | #define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) 51 | #define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) 52 | #define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) 53 | #define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) 54 | #define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) 55 | #define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) 56 | #define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) 57 | #define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 58 | #define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 59 | #define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 60 | #define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 61 | #define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 62 | #define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 63 | #define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 64 | #define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 65 | 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2b-load-sse2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_LOAD_SSE2_H__ 15 | #define __BLAKE2B_LOAD_SSE2_H__ 16 | 17 | #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 18 | #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 19 | #define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 20 | #define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 21 | #define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 22 | #define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 23 | #define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 24 | #define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 25 | #define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) 26 | #define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) 27 | #define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) 28 | #define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) 29 | #define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) 30 | #define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) 31 | #define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) 32 | #define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) 33 | #define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) 34 | #define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) 35 | #define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) 36 | #define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) 37 | #define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) 38 | #define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) 39 | #define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) 40 | #define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) 41 | #define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) 42 | #define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) 43 | #define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) 44 | #define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) 45 | #define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) 46 | #define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) 47 | #define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) 48 | #define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) 49 | #define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) 50 | #define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) 51 | #define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) 52 | #define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) 53 | #define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) 54 | #define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) 55 | #define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) 56 | #define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) 57 | #define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 58 | #define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 59 | #define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 60 | #define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 61 | #define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 62 | #define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 63 | #define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 64 | #define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 65 | 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2b-load-sse2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_LOAD_SSE2_H__ 15 | #define __BLAKE2B_LOAD_SSE2_H__ 16 | 17 | #define LOAD_MSG_0_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 18 | #define LOAD_MSG_0_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 19 | #define LOAD_MSG_0_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 20 | #define LOAD_MSG_0_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 21 | #define LOAD_MSG_1_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 22 | #define LOAD_MSG_1_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 23 | #define LOAD_MSG_1_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 24 | #define LOAD_MSG_1_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 25 | #define LOAD_MSG_2_1(b0, b1) b0 = _mm_set_epi64x(m12, m11); b1 = _mm_set_epi64x(m15, m5) 26 | #define LOAD_MSG_2_2(b0, b1) b0 = _mm_set_epi64x(m0, m8); b1 = _mm_set_epi64x(m13, m2) 27 | #define LOAD_MSG_2_3(b0, b1) b0 = _mm_set_epi64x(m3, m10); b1 = _mm_set_epi64x(m9, m7) 28 | #define LOAD_MSG_2_4(b0, b1) b0 = _mm_set_epi64x(m6, m14); b1 = _mm_set_epi64x(m4, m1) 29 | #define LOAD_MSG_3_1(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m13) 30 | #define LOAD_MSG_3_2(b0, b1) b0 = _mm_set_epi64x(m1, m9); b1 = _mm_set_epi64x(m14, m12) 31 | #define LOAD_MSG_3_3(b0, b1) b0 = _mm_set_epi64x(m5, m2); b1 = _mm_set_epi64x(m15, m4) 32 | #define LOAD_MSG_3_4(b0, b1) b0 = _mm_set_epi64x(m10, m6); b1 = _mm_set_epi64x(m8, m0) 33 | #define LOAD_MSG_4_1(b0, b1) b0 = _mm_set_epi64x(m5, m9); b1 = _mm_set_epi64x(m10, m2) 34 | #define LOAD_MSG_4_2(b0, b1) b0 = _mm_set_epi64x(m7, m0); b1 = _mm_set_epi64x(m15, m4) 35 | #define LOAD_MSG_4_3(b0, b1) b0 = _mm_set_epi64x(m11, m14); b1 = _mm_set_epi64x(m3, m6) 36 | #define LOAD_MSG_4_4(b0, b1) b0 = _mm_set_epi64x(m12, m1); b1 = _mm_set_epi64x(m13, m8) 37 | #define LOAD_MSG_5_1(b0, b1) b0 = _mm_set_epi64x(m6, m2); b1 = _mm_set_epi64x(m8, m0) 38 | #define LOAD_MSG_5_2(b0, b1) b0 = _mm_set_epi64x(m10, m12); b1 = _mm_set_epi64x(m3, m11) 39 | #define LOAD_MSG_5_3(b0, b1) b0 = _mm_set_epi64x(m7, m4); b1 = _mm_set_epi64x(m1, m15) 40 | #define LOAD_MSG_5_4(b0, b1) b0 = _mm_set_epi64x(m5, m13); b1 = _mm_set_epi64x(m9, m14) 41 | #define LOAD_MSG_6_1(b0, b1) b0 = _mm_set_epi64x(m1, m12); b1 = _mm_set_epi64x(m4, m14) 42 | #define LOAD_MSG_6_2(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m10, m13) 43 | #define LOAD_MSG_6_3(b0, b1) b0 = _mm_set_epi64x(m6, m0); b1 = _mm_set_epi64x(m8, m9) 44 | #define LOAD_MSG_6_4(b0, b1) b0 = _mm_set_epi64x(m3, m7); b1 = _mm_set_epi64x(m11, m2) 45 | #define LOAD_MSG_7_1(b0, b1) b0 = _mm_set_epi64x(m7, m13); b1 = _mm_set_epi64x(m3, m12) 46 | #define LOAD_MSG_7_2(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m9, m1) 47 | #define LOAD_MSG_7_3(b0, b1) b0 = _mm_set_epi64x(m15, m5); b1 = _mm_set_epi64x(m2, m8) 48 | #define LOAD_MSG_7_4(b0, b1) b0 = _mm_set_epi64x(m4, m0); b1 = _mm_set_epi64x(m10, m6) 49 | #define LOAD_MSG_8_1(b0, b1) b0 = _mm_set_epi64x(m14, m6); b1 = _mm_set_epi64x(m0, m11) 50 | #define LOAD_MSG_8_2(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m8, m3) 51 | #define LOAD_MSG_8_3(b0, b1) b0 = _mm_set_epi64x(m13, m12); b1 = _mm_set_epi64x(m10, m1) 52 | #define LOAD_MSG_8_4(b0, b1) b0 = _mm_set_epi64x(m7, m2); b1 = _mm_set_epi64x(m5, m4) 53 | #define LOAD_MSG_9_1(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m1, m7) 54 | #define LOAD_MSG_9_2(b0, b1) b0 = _mm_set_epi64x(m4, m2); b1 = _mm_set_epi64x(m5, m6) 55 | #define LOAD_MSG_9_3(b0, b1) b0 = _mm_set_epi64x(m9, m15); b1 = _mm_set_epi64x(m13, m3) 56 | #define LOAD_MSG_9_4(b0, b1) b0 = _mm_set_epi64x(m14, m11); b1 = _mm_set_epi64x(m0, m12) 57 | #define LOAD_MSG_10_1(b0, b1) b0 = _mm_set_epi64x(m2, m0); b1 = _mm_set_epi64x(m6, m4) 58 | #define LOAD_MSG_10_2(b0, b1) b0 = _mm_set_epi64x(m3, m1); b1 = _mm_set_epi64x(m7, m5) 59 | #define LOAD_MSG_10_3(b0, b1) b0 = _mm_set_epi64x(m10, m8); b1 = _mm_set_epi64x(m14, m12) 60 | #define LOAD_MSG_10_4(b0, b1) b0 = _mm_set_epi64x(m11, m9); b1 = _mm_set_epi64x(m15, m13) 61 | #define LOAD_MSG_11_1(b0, b1) b0 = _mm_set_epi64x(m4, m14); b1 = _mm_set_epi64x(m13, m9) 62 | #define LOAD_MSG_11_2(b0, b1) b0 = _mm_set_epi64x(m8, m10); b1 = _mm_set_epi64x(m6, m15) 63 | #define LOAD_MSG_11_3(b0, b1) b0 = _mm_set_epi64x(m0, m1); b1 = _mm_set_epi64x(m5, m11) 64 | #define LOAD_MSG_11_4(b0, b1) b0 = _mm_set_epi64x(m2, m12); b1 = _mm_set_epi64x(m3, m7) 65 | 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2b-round-perm.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_ROUND_H__ 15 | #define __BLAKE2B_ROUND_H__ 16 | 17 | #define LOAD(p) _mm_load_si128( (const __m128i *)(p) ) 18 | #define STORE(p,r) _mm_store_si128((__m128i *)(p), r) 19 | 20 | #define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) ) 21 | #define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r) 22 | 23 | #define TOF(reg) _mm_castsi128_ps((reg)) 24 | #define TOI(reg) _mm_castps_si128((reg)) 25 | 26 | #define LIKELY(x) __builtin_expect((x),1) 27 | 28 | 29 | /* Microarchitecture-specific macros */ 30 | #ifndef HAVE_XOP 31 | #ifdef HAVE_SSSE3 32 | #define _mm_roti_epi64(x, c) \ 33 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1)) \ 34 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 35 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 36 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 37 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64 - (-(c)))) 38 | #else 39 | #define _mm_roti_epi64(r, c) _mm_xor_si128(_mm_srli_epi64( (r), -(c) ),_mm_slli_epi64( (r), 64-(-(c)) )) 40 | #endif 41 | #else 42 | /* ... */ 43 | #endif 44 | 45 | 46 | 47 | 48 | #define G1_NOMSG(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 49 | row1l = _mm_add_epi64(row1l, row2l); \ 50 | row1h = _mm_add_epi64(row1h, row2h); \ 51 | \ 52 | row4l = _mm_xor_si128(row4l, row1l); \ 53 | row4h = _mm_xor_si128(row4h, row1h); \ 54 | \ 55 | row4l = _mm_roti_epi64(row4l, -32); \ 56 | row4h = _mm_roti_epi64(row4h, -32); \ 57 | \ 58 | row3l = _mm_add_epi64(row3l, row4l); \ 59 | row3h = _mm_add_epi64(row3h, row4h); \ 60 | \ 61 | row2l = _mm_xor_si128(row2l, row3l); \ 62 | row2h = _mm_xor_si128(row2h, row3h); \ 63 | \ 64 | row2l = _mm_roti_epi64(row2l, -24); \ 65 | row2h = _mm_roti_epi64(row2h, -24); \ 66 | 67 | #define G2_NOMSG(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 68 | row1l = _mm_add_epi64(row1l, row2l); \ 69 | row1h = _mm_add_epi64(row1h, row2h); \ 70 | \ 71 | row4l = _mm_xor_si128(row4l, row1l); \ 72 | row4h = _mm_xor_si128(row4h, row1h); \ 73 | \ 74 | row4l = _mm_roti_epi64(row4l, -16); \ 75 | row4h = _mm_roti_epi64(row4h, -16); \ 76 | \ 77 | row3l = _mm_add_epi64(row3l, row4l); \ 78 | row3h = _mm_add_epi64(row3h, row4h); \ 79 | \ 80 | row2l = _mm_xor_si128(row2l, row3l); \ 81 | row2h = _mm_xor_si128(row2h, row3h); \ 82 | \ 83 | row2l = _mm_roti_epi64(row2l, -63); \ 84 | row2h = _mm_roti_epi64(row2h, -63); \ 85 | 86 | #if defined(HAVE_SSSE3) 87 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 88 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 89 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 90 | row2l = t0; \ 91 | row2h = t1; \ 92 | \ 93 | t0 = row3l; \ 94 | row3l = row3h; \ 95 | row3h = t0; \ 96 | \ 97 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 98 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 99 | row4l = t1; \ 100 | row4h = t0; 101 | 102 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 103 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 104 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 105 | row2l = t0; \ 106 | row2h = t1; \ 107 | \ 108 | t0 = row3l; \ 109 | row3l = row3h; \ 110 | row3h = t0; \ 111 | \ 112 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 113 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 114 | row4l = t1; \ 115 | row4h = t0; 116 | #else 117 | 118 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 119 | t0 = row4l; \ 120 | t1 = row2l; \ 121 | row4l = row3l; \ 122 | row3l = row3h; \ 123 | row3h = row4l; \ 124 | row4l = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t0, t0)); \ 125 | row4h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row4h, row4h)); \ 126 | row2l = _mm_unpackhi_epi64(row2l, _mm_unpacklo_epi64(row2h, row2h)); \ 127 | row2h = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(t1, t1)) 128 | 129 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 130 | t0 = row3l; \ 131 | row3l = row3h; \ 132 | row3h = t0; \ 133 | t0 = row2l; \ 134 | t1 = row4l; \ 135 | row2l = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(row2l, row2l)); \ 136 | row2h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row2h, row2h)); \ 137 | row4l = _mm_unpackhi_epi64(row4l, _mm_unpacklo_epi64(row4h, row4h)); \ 138 | row4h = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t1, t1)) 139 | 140 | #endif 141 | 142 | #if defined(HAVE_SSE41) 143 | #include "blake2b-load-sse41.h" 144 | #else 145 | #include "blake2b-load-sse2.h" 146 | #endif 147 | 148 | 149 | #endif 150 | 151 | #define BLAKE2_ROUND_NOMSG(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 152 | G1_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 153 | G2_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 154 | \ 155 | DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 156 | \ 157 | G1_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 158 | G2_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 159 | \ 160 | UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); 161 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2b-round-perm.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2B_ROUND_H__ 15 | #define __BLAKE2B_ROUND_H__ 16 | 17 | #define LOAD(p) _mm_load_si128( (const __m128i *)(p) ) 18 | #define STORE(p,r) _mm_store_si128((__m128i *)(p), r) 19 | 20 | #define LOADU(p) _mm_loadu_si128( (const __m128i *)(p) ) 21 | #define STOREU(p,r) _mm_storeu_si128((__m128i *)(p), r) 22 | 23 | #define TOF(reg) _mm_castsi128_ps((reg)) 24 | #define TOI(reg) _mm_castps_si128((reg)) 25 | 26 | #define LIKELY(x) __builtin_expect((x),1) 27 | 28 | 29 | /* Microarchitecture-specific macros */ 30 | #ifndef HAVE_XOP 31 | #ifdef HAVE_SSSE3 32 | #define _mm_roti_epi64(x, c) \ 33 | (-(c) == 32) ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1)) \ 34 | : (-(c) == 24) ? _mm_shuffle_epi8((x), r24) \ 35 | : (-(c) == 16) ? _mm_shuffle_epi8((x), r16) \ 36 | : (-(c) == 63) ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_add_epi64((x), (x))) \ 37 | : _mm_xor_si128(_mm_srli_epi64((x), -(c)), _mm_slli_epi64((x), 64 - (-(c)))) 38 | #else 39 | #define _mm_roti_epi64(r, c) _mm_xor_si128(_mm_srli_epi64( (r), -(c) ),_mm_slli_epi64( (r), 64-(-(c)) )) 40 | #endif 41 | #else 42 | /* ... */ 43 | #endif 44 | 45 | 46 | 47 | 48 | #define G1_NOMSG(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 49 | row1l = _mm_add_epi64(row1l, row2l); \ 50 | row1h = _mm_add_epi64(row1h, row2h); \ 51 | \ 52 | row4l = _mm_xor_si128(row4l, row1l); \ 53 | row4h = _mm_xor_si128(row4h, row1h); \ 54 | \ 55 | row4l = _mm_roti_epi64(row4l, -32); \ 56 | row4h = _mm_roti_epi64(row4h, -32); \ 57 | \ 58 | row3l = _mm_add_epi64(row3l, row4l); \ 59 | row3h = _mm_add_epi64(row3h, row4h); \ 60 | \ 61 | row2l = _mm_xor_si128(row2l, row3l); \ 62 | row2h = _mm_xor_si128(row2h, row3h); \ 63 | \ 64 | row2l = _mm_roti_epi64(row2l, -24); \ 65 | row2h = _mm_roti_epi64(row2h, -24); \ 66 | 67 | #define G2_NOMSG(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 68 | row1l = _mm_add_epi64(row1l, row2l); \ 69 | row1h = _mm_add_epi64(row1h, row2h); \ 70 | \ 71 | row4l = _mm_xor_si128(row4l, row1l); \ 72 | row4h = _mm_xor_si128(row4h, row1h); \ 73 | \ 74 | row4l = _mm_roti_epi64(row4l, -16); \ 75 | row4h = _mm_roti_epi64(row4h, -16); \ 76 | \ 77 | row3l = _mm_add_epi64(row3l, row4l); \ 78 | row3h = _mm_add_epi64(row3h, row4h); \ 79 | \ 80 | row2l = _mm_xor_si128(row2l, row3l); \ 81 | row2h = _mm_xor_si128(row2h, row3h); \ 82 | \ 83 | row2l = _mm_roti_epi64(row2l, -63); \ 84 | row2h = _mm_roti_epi64(row2h, -63); \ 85 | 86 | #if defined(HAVE_SSSE3) 87 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 88 | t0 = _mm_alignr_epi8(row2h, row2l, 8); \ 89 | t1 = _mm_alignr_epi8(row2l, row2h, 8); \ 90 | row2l = t0; \ 91 | row2h = t1; \ 92 | \ 93 | t0 = row3l; \ 94 | row3l = row3h; \ 95 | row3h = t0; \ 96 | \ 97 | t0 = _mm_alignr_epi8(row4h, row4l, 8); \ 98 | t1 = _mm_alignr_epi8(row4l, row4h, 8); \ 99 | row4l = t1; \ 100 | row4h = t0; 101 | 102 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 103 | t0 = _mm_alignr_epi8(row2l, row2h, 8); \ 104 | t1 = _mm_alignr_epi8(row2h, row2l, 8); \ 105 | row2l = t0; \ 106 | row2h = t1; \ 107 | \ 108 | t0 = row3l; \ 109 | row3l = row3h; \ 110 | row3h = t0; \ 111 | \ 112 | t0 = _mm_alignr_epi8(row4l, row4h, 8); \ 113 | t1 = _mm_alignr_epi8(row4h, row4l, 8); \ 114 | row4l = t1; \ 115 | row4h = t0; 116 | #else 117 | 118 | #define DIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 119 | t0 = row4l; \ 120 | t1 = row2l; \ 121 | row4l = row3l; \ 122 | row3l = row3h; \ 123 | row3h = row4l; \ 124 | row4l = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t0, t0)); \ 125 | row4h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row4h, row4h)); \ 126 | row2l = _mm_unpackhi_epi64(row2l, _mm_unpacklo_epi64(row2h, row2h)); \ 127 | row2h = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(t1, t1)) 128 | 129 | #define UNDIAGONALIZE(row1l,row2l,row3l,row4l,row1h,row2h,row3h,row4h) \ 130 | t0 = row3l; \ 131 | row3l = row3h; \ 132 | row3h = t0; \ 133 | t0 = row2l; \ 134 | t1 = row4l; \ 135 | row2l = _mm_unpackhi_epi64(row2h, _mm_unpacklo_epi64(row2l, row2l)); \ 136 | row2h = _mm_unpackhi_epi64(t0, _mm_unpacklo_epi64(row2h, row2h)); \ 137 | row4l = _mm_unpackhi_epi64(row4l, _mm_unpacklo_epi64(row4h, row4h)); \ 138 | row4h = _mm_unpackhi_epi64(row4h, _mm_unpacklo_epi64(t1, t1)) 139 | 140 | #endif 141 | 142 | #if defined(HAVE_SSE41) 143 | #include "blake2b-load-sse41.h" 144 | #else 145 | #include "blake2b-load-sse2.h" 146 | #endif 147 | 148 | 149 | #endif 150 | 151 | #define BLAKE2_ROUND_NOMSG(row1l,row1h,row2l,row2h,row3l,row3h,row4l,row4h) \ 152 | G1_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 153 | G2_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 154 | \ 155 | DIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 156 | \ 157 | G1_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 158 | G2_NOMSG(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); \ 159 | \ 160 | UNDIAGONALIZE(row1l, row2l, row3l, row4l, row1h, row2h, row3h, row4h); 161 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/ref/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__((aligned(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state ; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/ref/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__((aligned(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state ; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/ref/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__((aligned(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state ; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/ref/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - reference C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__((aligned(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state ; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.1/Argon2d/opt-sse/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__ ((__aligned__(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | ALIGN( 64 ) typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | ALIGN( 64 ) typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.1/Argon2i/opt-sse/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__ ((__aligned__(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | ALIGN( 64 ) typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | ALIGN( 64 ) typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2d/opt-sse/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__ ((__aligned__(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | ALIGN( 64 ) typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | ALIGN( 64 ) typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /v.1.2/v.1.2/Argon2i/opt-sse/blake2.h: -------------------------------------------------------------------------------- 1 | /* 2 | BLAKE2 reference source code package - optimized C implementations 3 | 4 | Written in 2012 by Samuel Neves 5 | 6 | To the extent possible under law, the author(s) have dedicated all copyright 7 | and related and neighboring rights to this software to the public domain 8 | worldwide. This software is distributed without any warranty. 9 | 10 | You should have received a copy of the CC0 Public Domain Dedication along with 11 | this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #define ALIGN(x) __declspec(align(x)) 22 | #else 23 | #define ALIGN(x) __attribute__ ((__aligned__(x))) 24 | #endif 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | enum blake2s_constant 31 | { 32 | BLAKE2S_BLOCKBYTES = 64, 33 | BLAKE2S_OUTBYTES = 32, 34 | BLAKE2S_KEYBYTES = 32, 35 | BLAKE2S_SALTBYTES = 8, 36 | BLAKE2S_PERSONALBYTES = 8 37 | }; 38 | 39 | enum blake2b_constant 40 | { 41 | BLAKE2B_BLOCKBYTES = 128, 42 | BLAKE2B_OUTBYTES = 64, 43 | BLAKE2B_KEYBYTES = 64, 44 | BLAKE2B_SALTBYTES = 16, 45 | BLAKE2B_PERSONALBYTES = 16 46 | }; 47 | 48 | #pragma pack(push, 1) 49 | typedef struct __blake2s_param 50 | { 51 | uint8_t digest_length; // 1 52 | uint8_t key_length; // 2 53 | uint8_t fanout; // 3 54 | uint8_t depth; // 4 55 | uint32_t leaf_length; // 8 56 | uint8_t node_offset[6];// 14 57 | uint8_t node_depth; // 15 58 | uint8_t inner_length; // 16 59 | // uint8_t reserved[0]; 60 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 61 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 62 | } blake2s_param; 63 | 64 | ALIGN( 64 ) typedef struct __blake2s_state 65 | { 66 | uint32_t h[8]; 67 | uint32_t t[2]; 68 | uint32_t f[2]; 69 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 70 | size_t buflen; 71 | uint8_t last_node; 72 | } blake2s_state; 73 | 74 | typedef struct __blake2b_param 75 | { 76 | uint8_t digest_length; // 1 77 | uint8_t key_length; // 2 78 | uint8_t fanout; // 3 79 | uint8_t depth; // 4 80 | uint32_t leaf_length; // 8 81 | uint64_t node_offset; // 16 82 | uint8_t node_depth; // 17 83 | uint8_t inner_length; // 18 84 | uint8_t reserved[14]; // 32 85 | uint8_t salt[BLAKE2B_SALTBYTES]; // 48 86 | uint8_t personal[BLAKE2B_PERSONALBYTES]; // 64 87 | } blake2b_param; 88 | 89 | ALIGN( 64 ) typedef struct __blake2b_state 90 | { 91 | uint64_t h[8]; 92 | uint64_t t[2]; 93 | uint64_t f[2]; 94 | uint8_t buf[2 * BLAKE2B_BLOCKBYTES]; 95 | size_t buflen; 96 | uint8_t last_node; 97 | } blake2b_state; 98 | 99 | ALIGN( 64 ) typedef struct __blake2sp_state 100 | { 101 | blake2s_state S[8][1]; 102 | blake2s_state R[1]; 103 | uint8_t buf[8 * BLAKE2S_BLOCKBYTES]; 104 | size_t buflen; 105 | } blake2sp_state; 106 | 107 | ALIGN( 64 ) typedef struct __blake2bp_state 108 | { 109 | blake2b_state S[4][1]; 110 | blake2b_state R[1]; 111 | uint8_t buf[4 * BLAKE2B_BLOCKBYTES]; 112 | size_t buflen; 113 | } blake2bp_state; 114 | #pragma pack(pop) 115 | 116 | // Streaming API 117 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 118 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 119 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 120 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 121 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 122 | 123 | int blake2b_init( blake2b_state *S, const uint8_t outlen ); 124 | int blake2b_init_key( blake2b_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 125 | int blake2b_init_param( blake2b_state *S, const blake2b_param *P ); 126 | int blake2b_update( blake2b_state *S, const uint8_t *in, uint64_t inlen ); 127 | int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen ); 128 | 129 | int blake2sp_init( blake2sp_state *S, const uint8_t outlen ); 130 | int blake2sp_init_key( blake2sp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 131 | int blake2sp_update( blake2sp_state *S, const uint8_t *in, uint64_t inlen ); 132 | int blake2sp_final( blake2sp_state *S, uint8_t *out, uint8_t outlen ); 133 | 134 | int blake2bp_init( blake2bp_state *S, const uint8_t outlen ); 135 | int blake2bp_init_key( blake2bp_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 136 | int blake2bp_update( blake2bp_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2bp_final( blake2bp_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 142 | int blake2b_long(uint8_t *out, const void *in, const uint32_t outlen, const uint64_t inlen); 143 | 144 | int blake2sp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 145 | int blake2bp( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 146 | 147 | static inline int blake2( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ) 148 | { 149 | return blake2b( out, in, key, outlen, inlen, keylen ); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | #endif 157 | 158 | --------------------------------------------------------------------------------