Path: blob/linux/scryptjane/scrypt-jane-romix-basic.h
1201 views
#if !defined(SCRYPT_CHOOSE_COMPILETIME)1/* function type returned by scrypt_getROMix, used with cpu detection */2typedef void (FASTCALL *scrypt_ROMixfn)(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r);3#endif45/* romix pre/post nop function */6static void /* asm_calling_convention */7scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) {8}910/* romix pre/post endian conversion function */11static void /* asm_calling_convention */12scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) {13#if !defined(CPU_LE)14static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}};15size_t i;16if (endian_test.w == 0x100) {17nblocks *= SCRYPT_BLOCK_WORDS;18for (i = 0; i < nblocks; i++) {19SCRYPT_WORD_ENDIAN_SWAP(blocks[i]);20}21}22#endif23}2425/* chunkmix test function */26typedef void (*chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r);27typedef void (*blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks);2829static int30scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) {31/* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */32const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS;33scrypt_mix_word_t MM16 chunk[2][4 * SCRYPT_BLOCK_WORDS], v;34uint8_t final[16];35size_t i;3637for (i = 0; i < words; i++) {38v = (scrypt_mix_word_t)i;39v = (v << 8) | v;40v = (v << 16) | v;41chunk[0][i] = v;42}4344prefn(chunk[0], blocks);45mixfn(chunk[1], chunk[0], NULL, r);46postfn(chunk[1], blocks);4748/* grab the last 16 bytes of the final block */49for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) {50SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]);51}5253return scrypt_verify(expected, final, 16);54}5556/* returns a pointer to item i, where item is len scrypt_mix_word_t's long */57static scrypt_mix_word_t *58scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) {59return base + (i * len);60}6162/* returns a pointer to block i */63static scrypt_mix_word_t *64scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) {65return base + (i * SCRYPT_BLOCK_WORDS);66}676869