Path: blob/master/scryptjane/scrypt-jane-salsa.h
1301 views
#define SCRYPT_MIX_BASE "Salsa20/8"12typedef uint32_t scrypt_mix_word_t;34#define SCRYPT_WORDTO8_LE U32TO8_LE5#define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP67#define SCRYPT_BLOCK_BYTES 648#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_salsa-avx.h"14#include "scrypt-jane-mix_salsa-sse2.h"15#include "scrypt-jane-mix_salsa.h"1617#if defined(SCRYPT_SALSA_AVX)18#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx19#define SCRYPT_ROMIX_FN scrypt_ROMix_avx20#define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse221#define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse222#include "scrypt-jane-romix-template.h"23#endif2425#if defined(SCRYPT_SALSA_SSE2)26#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse227#define SCRYPT_ROMIX_FN scrypt_ROMix_sse228#define SCRYPT_MIX_FN salsa_core_sse229#define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse230#define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse231#include "scrypt-jane-romix-template.h"32#endif3334/* cpu agnostic */35#define SCRYPT_ROMIX_FN scrypt_ROMix_basic36#define SCRYPT_MIX_FN salsa_core_basic37#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian38#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian39#include "scrypt-jane-romix-template.h"4041#if !defined(SCRYPT_CHOOSE_COMPILETIME)42static scrypt_ROMixfn43scrypt_getROMix() {44size_t cpuflags = detect_cpu();4546#if defined(SCRYPT_SALSA_AVX)47if (cpuflags & cpu_avx)48return scrypt_ROMix_avx;49else50#endif5152#if defined(SCRYPT_SALSA_SSE2)53if (cpuflags & cpu_sse2)54return scrypt_ROMix_sse2;55else56#endif5758return scrypt_ROMix_basic;59}60#endif616263#if defined(SCRYPT_TEST_SPEED)64static size_t65available_implementations() {66size_t cpuflags = detect_cpu();67size_t flags = 0;6869#if defined(SCRYPT_SALSA_AVX)70if (cpuflags & cpu_avx)71flags |= cpu_avx;72#endif7374#if defined(SCRYPT_SALSA_SSE2)75if (cpuflags & cpu_sse2)76flags |= cpu_sse2;77#endif7879return flags;80}81#endif828384static int85scrypt_test_mix() {86static const uint8_t expected[16] = {870x41,0x1f,0x2e,0xa3,0xab,0xa3,0x1a,0x34,0x87,0x1d,0x8a,0x1c,0x76,0xa0,0x27,0x66,88};8990int ret = 1;91size_t cpuflags = detect_cpu();9293#if defined(SCRYPT_SALSA_AVX)94if (cpuflags & cpu_avx)95ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected);96#endif9798#if defined(SCRYPT_SALSA_SSE2)99if (cpuflags & cpu_sse2)100ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected);101#endif102103#if defined(SCRYPT_SALSA_BASIC)104ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected);105#endif106107return ret;108}109110111