digestpp 1.0
C++11 header-only message digest library
Loading...
Searching...
No Matches
absorb_data.hpp
Go to the documentation of this file.
1/*
2This code is written by kerukuro and released into public domain.
3*/
4
5#ifndef DIGESTPP_DETAIL_ABSORB_DATA_HPP
6#define DIGESTPP_DETAIL_ABSORB_DATA_HPP
7
8namespace digestpp
9{
10
11namespace detail
12{
13
14// Accumulate data and call the transformation function for full blocks.
15template<typename T, typename TF>
16inline void absorb_bytes(const unsigned char* data, size_t len, size_t bs, size_t bschk,
17 unsigned char* m, size_t& pos, T& total, TF transform)
18{
19 if (pos && pos + len >= bschk)
20 {
21 memcpy(m + pos, data, bs - pos);
22 transform(m, 1);
23 len -= bs - pos;
24 data += bs - pos;
25 total += bs * 8;
26 pos = 0;
27 }
28 if (len >= bschk)
29 {
30 size_t blocks = (len + bs - bschk) / bs;
31 size_t bytes = blocks * bs;
32 transform(data, blocks);
33 len -= bytes;
34 data += bytes;
35 total += (bytes)* 8;
36 }
37 memcpy(m + pos, data, len);
38 pos += len;
39}
40
41
42} // namespace detail
43
44} // namespace digestpp
45
46#endif // DIGESTPP_DETAIL_ABSORB_DATA_HPP
void absorb_bytes(const unsigned char *data, size_t len, size_t bs, size_t bschk, unsigned char *m, size_t &pos, T &total, TF transform)
Definition absorb_data.hpp:16
digestpp namespace
Definition ascon.hpp:14