139void*
hash_bs(
const void* input_bs, uint64_t input_size) {
140 auto* input =
static_cast<const uint8_t*
>(input_bs);
144 std::array<uint32_t, 64> s = {
145 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
146 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
147 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
148 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21};
162 std::array<uint32_t, 64> K = {
163 3614090360, 3905402710, 606105819, 3250441966, 4118548399, 1200080426,
164 2821735955, 4249261313, 1770035416, 2336552879, 4294925233, 2304563134,
165 1804603682, 4254626195, 2792965006, 1236535329, 4129170786, 3225465664,
166 643717713, 3921069994, 3593408605, 38016083, 3634488961, 3889429448,
167 568446438, 3275163606, 4107603335, 1163531501, 2850285829, 4243563512,
168 1735328473, 2368359562, 4294588738, 2272392833, 1839030562, 4259657740,
169 2763975236, 1272893353, 4139469664, 3200236656, 681279174, 3936430074,
170 3572445317, 76029189, 3654602809, 3873151461, 530742520, 3299628645,
171 4096336452, 1126891415, 2878612391, 4237533241, 1700485571, 2399980690,
172 4293915773, 2240044497, 1873313359, 4264355552, 2734768916, 1309151649,
173 4149444226, 3174756917, 718787259, 3951481745};
176 uint32_t a0 = 0x67452301, A = 0;
177 uint32_t b0 = 0xefcdab89, B = 0;
178 uint32_t c0 = 0x98badcfe, C = 0;
179 uint32_t d0 = 0x10325476, D = 0;
185 uint64_t padded_message_size = 0;
186 if (input_size % 64 < 56) {
187 padded_message_size = input_size + 64 - (input_size % 64);
189 padded_message_size = input_size + 128 - (input_size % 64);
192 std::vector<uint8_t> padded_message(padded_message_size);
195 std::copy(input, input + input_size, padded_message.begin());
198 padded_message[input_size] = 1 << 7;
199 for (uint64_t i = input_size; i % 64 != 56; i++) {
200 if (i == input_size) {
203 padded_message[i] = 0;
210 for (uint8_t i = 0; i < 8; i++) {
211 padded_message[padded_message_size - 8 + i] =
212 (input_bitsize_le >> (56 - 8 * i)) & 0xFF;
216 std::array<uint32_t, 16> blocks{};
219 for (uint64_t chunk = 0; chunk * 64 < padded_message_size; chunk++) {
221 for (uint8_t bid = 0; bid < 16; bid++) {
226 for (uint8_t cid = 0; cid < 4; cid++) {
227 blocks[bid] = (blocks[bid] << 8) +
228 padded_message[chunk * 64 + bid * 4 + cid];
238 for (uint8_t i = 0; i < 64; i++) {
239 uint32_t F = 0, g = 0;
241 F = (B & C) | ((~B) & D);
244 F = (D & B) | ((~D) & C);
245 g = (5 * i + 1) % 16;
248 g = (3 * i + 5) % 16;
273 auto* sig =
new uint8_t[16];
274 for (uint8_t i = 0; i < 4; i++) {
275 sig[i] = (a0 >> (8 * i)) & 0xFF;
276 sig[i + 4] = (b0 >> (8 * i)) & 0xFF;
277 sig[i + 8] = (c0 >> (8 * i)) & 0xFF;
278 sig[i + 12] = (d0 >> (8 * i)) & 0xFF;