Path: blob/linux/scryptjane/scrypt-jane-salsa64.h
1201 views
#define SCRYPT_MIX_BASE "Salsa64/8"12typedef uint64_t scrypt_mix_word_t;34#define SCRYPT_WORDTO8_LE U64TO8_LE5#define SCRYPT_WORD_ENDIAN_SWAP U64_SWAP67#define SCRYPT_BLOCK_BYTES 1288#define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t))910/* must have these here in case block bytes is ever != 64 */11#include "scrypt-jane-romix-basic.h"1213#include "scrypt-jane-mix_salsa64-avx.h"14#include "scrypt-jane-mix_salsa64-ssse3.h"15#include "scrypt-jane-mix_salsa64-sse2.h"16#include "scrypt-jane-mix_salsa64.h"1718#if defined(SCRYPT_SALSA64_AVX)19#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx20#define SCRYPT_ROMIX_FN scrypt_ROMix_avx21#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse222#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse223#include "scrypt-jane-romix-template.h"24#endif2526#if defined(SCRYPT_SALSA64_SSSE3)27#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse328#define SCRYPT_ROMIX_FN scrypt_ROMix_ssse329#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse230#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse231#include "scrypt-jane-romix-template.h"32#endif3334#if defined(SCRYPT_SALSA64_SSE2)35#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse236#define SCRYPT_ROMIX_FN scrypt_ROMix_sse237#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse238#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse239#include "scrypt-jane-romix-template.h"40#endif4142/* cpu agnostic */43#define SCRYPT_ROMIX_FN scrypt_ROMix_basic44#define SCRYPT_MIX_FN salsa64_core_basic45#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian46#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian47#include "scrypt-jane-romix-template.h"4849#if !defined(SCRYPT_CHOOSE_COMPILETIME)50static scrypt_ROMixfn51scrypt_getROMix() {52size_t cpuflags = detect_cpu();5354#if defined(SCRYPT_SALSA64_AVX)55if (cpuflags & cpu_avx)56return scrypt_ROMix_avx;57else58#endif5960#if defined(SCRYPT_SALSA64_SSSE3)61if (cpuflags & cpu_ssse3)62return scrypt_ROMix_ssse3;63else64#endif6566#if defined(SCRYPT_SALSA64_SSE2)67if (cpuflags & cpu_sse2)68return scrypt_ROMix_sse2;69else70#endif7172return scrypt_ROMix_basic;73}74#endif757677#if defined(SCRYPT_TEST_SPEED)78static size_t79available_implementations() {80size_t cpuflags = detect_cpu();81size_t flags = 0;8283#if defined(SCRYPT_SALSA64_AVX)84if (cpuflags & cpu_avx)85flags |= cpu_avx;86#endif8788#if defined(SCRYPT_SALSA64_SSSE3)89if (cpuflags & cpu_ssse3)90flags |= cpu_ssse3;91#endif9293#if defined(SCRYPT_SALSA64_SSE2)94if (cpuflags & cpu_sse2)95flags |= cpu_sse2;96#endif9798return flags;99}100#endif101102static int103scrypt_test_mix() {104static const uint8_t expected[16] = {1050xf8,0x92,0x9b,0xf8,0xcc,0x1d,0xce,0x2e,0x13,0x82,0xac,0x96,0xb2,0x6c,0xee,0x2c,106};107108int ret = 1;109size_t cpuflags = detect_cpu();110111#if defined(SCRYPT_SALSA64_AVX)112if (cpuflags & cpu_avx)113ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);114#endif115116#if defined(SCRYPT_SALSA64_SSSE3)117if (cpuflags & cpu_ssse3)118ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);119#endif120121#if defined(SCRYPT_SALSA64_SSE2)122if (cpuflags & cpu_sse2)123ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);124#endif125126#if defined(SCRYPT_SALSA64_BASIC)127ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected);128#endif129130return ret;131}132133134135