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

Function ExpandArray

src/crypto/equihash.cpp:77–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77void ExpandArray(const unsigned char* in, size_t in_len,
78 unsigned char* out, size_t out_len,
79 size_t bit_len, size_t byte_pad)
80{
81 assert(bit_len >= 8);
82 assert(8*sizeof(uint32_t) >= 7+bit_len);
83
84 size_t out_width { (bit_len+7)/8 + byte_pad };
85 assert(out_len == 8*out_width*in_len/bit_len);
86
87 uint32_t bit_len_mask { ((uint32_t)1 << bit_len) - 1 };
88
89 // The acc_bits least-significant bits of acc_value represent a bit sequence
90 // in big-endian order.
91 size_t acc_bits = 0;
92 uint32_t acc_value = 0;
93
94 size_t j = 0;
95 for (size_t i = 0; i < in_len; i++) {
96 acc_value = (acc_value << 8) | in[i];
97 acc_bits += 8;
98
99 // When we have bit_len or more bits in the accumulator, write the next
100 // output element.
101 if (acc_bits >= bit_len) {
102 acc_bits -= bit_len;
103 for (size_t x = 0; x < byte_pad; x++) {
104 out[j+x] = 0;
105 }
106 for (size_t x = byte_pad; x < out_width; x++) {
107 out[j+x] = (
108 // Big-endian
109 acc_value >> (acc_bits+(8*(out_width-x-1)))
110 ) & (
111 // Apply bit_len_mask across byte boundaries
112 (bit_len_mask >> (8*(out_width-x-1))) & 0xFF
113 );
114 }
115 j += out_width;
116 }
117 }
118}
119
120void CompressArray(const unsigned char* in, size_t in_len,
121 unsigned char* out, size_t out_len,

Callers 2

GetIndicesFromMinimalFunction · 0.85
StepRowMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected