Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/scryptjane/scrypt-jane-romix-basic.h
1201 views
1
#if !defined(SCRYPT_CHOOSE_COMPILETIME)
2
/* function type returned by scrypt_getROMix, used with cpu detection */
3
typedef 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);
4
#endif
5
6
/* romix pre/post nop function */
7
static void /* asm_calling_convention */
8
scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) {
9
}
10
11
/* romix pre/post endian conversion function */
12
static void /* asm_calling_convention */
13
scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) {
14
#if !defined(CPU_LE)
15
static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}};
16
size_t i;
17
if (endian_test.w == 0x100) {
18
nblocks *= SCRYPT_BLOCK_WORDS;
19
for (i = 0; i < nblocks; i++) {
20
SCRYPT_WORD_ENDIAN_SWAP(blocks[i]);
21
}
22
}
23
#endif
24
}
25
26
/* chunkmix test function */
27
typedef void (*chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r);
28
typedef void (*blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks);
29
30
static int
31
scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) {
32
/* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */
33
const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS;
34
scrypt_mix_word_t MM16 chunk[2][4 * SCRYPT_BLOCK_WORDS], v;
35
uint8_t final[16];
36
size_t i;
37
38
for (i = 0; i < words; i++) {
39
v = (scrypt_mix_word_t)i;
40
v = (v << 8) | v;
41
v = (v << 16) | v;
42
chunk[0][i] = v;
43
}
44
45
prefn(chunk[0], blocks);
46
mixfn(chunk[1], chunk[0], NULL, r);
47
postfn(chunk[1], blocks);
48
49
/* grab the last 16 bytes of the final block */
50
for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) {
51
SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]);
52
}
53
54
return scrypt_verify(expected, final, 16);
55
}
56
57
/* returns a pointer to item i, where item is len scrypt_mix_word_t's long */
58
static scrypt_mix_word_t *
59
scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) {
60
return base + (i * len);
61
}
62
63
/* returns a pointer to block i */
64
static scrypt_mix_word_t *
65
scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) {
66
return base + (i * SCRYPT_BLOCK_WORDS);
67
}
68
69