MCPcopy Create free account
hub / github.com/LUX-Core/lux / initCache

Function initCache

src/crypto/RandomX/dataset.cpp:71–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 template void deallocCache<LargePageAllocator>(randomx_cache* cache);
70
71 void initCache(randomx_cache* cache, const void* key, size_t keySize) {
72 uint32_t memory_blocks, segment_length;
73 argon2_instance_t instance;
74 argon2_context context;
75
76 context.out = nullptr;
77 context.outlen = 0;
78 context.pwd = CONST_CAST(uint8_t *)key;
79 context.pwdlen = (uint32_t)keySize;
80 context.salt = CONST_CAST(uint8_t *)RANDOMX_ARGON_SALT;
81 context.saltlen = (uint32_t)randomx::ArgonSaltSize;
82 context.secret = NULL;
83 context.secretlen = 0;
84 context.ad = NULL;
85 context.adlen = 0;
86 context.t_cost = RANDOMX_ARGON_ITERATIONS;
87 context.m_cost = RANDOMX_ARGON_MEMORY;
88 context.lanes = RANDOMX_ARGON_LANES;
89 context.threads = 1;
90 context.allocate_cbk = NULL;
91 context.free_cbk = NULL;
92 context.flags = ARGON2_DEFAULT_FLAGS;
93 context.version = ARGON2_VERSION_NUMBER;
94
95 int inputsValid = randomx_argon2_validate_inputs(&context);
96 assert(inputsValid == ARGON2_OK);
97
98 /* 2. Align memory size */
99 /* Minimum memory_blocks = 8L blocks, where L is the number of lanes */
100 memory_blocks = context.m_cost;
101
102 segment_length = memory_blocks / (context.lanes * ARGON2_SYNC_POINTS);
103
104 instance.version = context.version;
105 instance.memory = NULL;
106 instance.passes = context.t_cost;
107 instance.memory_blocks = memory_blocks;
108 instance.segment_length = segment_length;
109 instance.lane_length = segment_length * ARGON2_SYNC_POINTS;
110 instance.lanes = context.lanes;
111 instance.threads = context.threads;
112 instance.type = Argon2_d;
113 instance.memory = (block*)cache->memory;
114 instance.impl = cache->argonImpl;
115
116 if (instance.threads > instance.lanes) {
117 instance.threads = instance.lanes;
118 }
119
120 /* 3. Initialization: Hashing inputs, allocating memory, filling first
121 * blocks
122 */
123 randomx_argon2_initialize(&instance, &context);
124
125 randomx_argon2_fill_memory_blocks(&instance);
126
127 cache->reciprocalCache.clear();
128 randomx::Blake2Generator gen(key, keySize);

Callers 1

initCacheCompileFunction · 0.70

Calls 11

generateSuperscalarFunction · 0.85
randomx_reciprocalFunction · 0.85
getImm32Method · 0.80
setImm32Method · 0.80
clearMethod · 0.45
getSizeMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected