MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CompressArray

Function CompressArray

src/crypto/equihash.cpp:120–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void CompressArray(const unsigned char* in, size_t in_len,
121 unsigned char* out, size_t out_len,
122 size_t bit_len, size_t byte_pad)
123{
124 assert(bit_len >= 8);
125 assert(8*sizeof(uint32_t) >= 7+bit_len);
126
127 size_t in_width { (bit_len+7)/8 + byte_pad };
128 assert(out_len == bit_len*in_len/(8*in_width));
129
130 uint32_t bit_len_mask { ((uint32_t)1 << bit_len) - 1 };
131
132 // The acc_bits least-significant bits of acc_value represent a bit sequence
133 // in big-endian order.
134 size_t acc_bits = 0;
135 uint32_t acc_value = 0;
136
137 size_t j = 0;
138 for (size_t i = 0; i < out_len; i++) {
139 // When we have fewer than 8 bits left in the accumulator, read the next
140 // input element.
141 if (acc_bits < 8) {
142 acc_value = acc_value << bit_len;
143 for (size_t x = byte_pad; x < in_width; x++) {
144 acc_value = acc_value | (
145 (
146 // Apply bit_len_mask across byte boundaries
147 in[j+x] & ((bit_len_mask >> (8*(in_width-x-1))) & 0xFF)
148 ) << (8*(in_width-x-1))); // Big-endian
149 }
150 j += in_width;
151 acc_bits += bit_len;
152 }
153
154 acc_bits -= 8;
155 out[i] = (acc_value >> acc_bits) & 0xFF;
156 }
157}
158
159// Big-endian so that lexicographic array comparison is equivalent to integer
160// comparison

Callers 2

GetMinimalFromIndicesFunction · 0.85
GetIndicesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected