MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / processBlock

Method processBlock

src/sha3.cpp:90–168  ·  view source on GitHub ↗

process a full block

Source from the content-addressed store, hash-verified

88
89/// process a full block
90void SHA3::processBlock(const void* data)
91{
92#if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN)
93#define LITTLEENDIAN(x) swap(x)
94#else
95#define LITTLEENDIAN(x) (x)
96#endif
97
98 const uint64_t* data64 = (const uint64_t*) data;
99 // mix data into state
100 for (unsigned int i = 0; i < m_blockSize / 8; i++)
101 m_hash[i] ^= LITTLEENDIAN(data64[i]);
102
103 // re-compute state
104 for (unsigned int round = 0; round < Rounds; round++)
105 {
106 // Theta
107 uint64_t coefficients[5];
108 for (unsigned int i = 0; i < 5; i++)
109 coefficients[i] = m_hash[i] ^ m_hash[i + 5] ^ m_hash[i + 10] ^ m_hash[i + 15] ^ m_hash[i + 20];
110
111 for (unsigned int i = 0; i < 5; i++)
112 {
113 uint64_t one = coefficients[mod5(i + 4)] ^ rotateLeft(coefficients[mod5(i + 1)], 1);
114 m_hash[i ] ^= one;
115 m_hash[i + 5] ^= one;
116 m_hash[i + 10] ^= one;
117 m_hash[i + 15] ^= one;
118 m_hash[i + 20] ^= one;
119 }
120
121 // temporary
122 uint64_t one;
123
124 // Rho Pi
125 uint64_t last = m_hash[1];
126 one = m_hash[10]; m_hash[10] = rotateLeft(last, 1); last = one;
127 one = m_hash[ 7]; m_hash[ 7] = rotateLeft(last, 3); last = one;
128 one = m_hash[11]; m_hash[11] = rotateLeft(last, 6); last = one;
129 one = m_hash[17]; m_hash[17] = rotateLeft(last, 10); last = one;
130 one = m_hash[18]; m_hash[18] = rotateLeft(last, 15); last = one;
131 one = m_hash[ 3]; m_hash[ 3] = rotateLeft(last, 21); last = one;
132 one = m_hash[ 5]; m_hash[ 5] = rotateLeft(last, 28); last = one;
133 one = m_hash[16]; m_hash[16] = rotateLeft(last, 36); last = one;
134 one = m_hash[ 8]; m_hash[ 8] = rotateLeft(last, 45); last = one;
135 one = m_hash[21]; m_hash[21] = rotateLeft(last, 55); last = one;
136 one = m_hash[24]; m_hash[24] = rotateLeft(last, 2); last = one;
137 one = m_hash[ 4]; m_hash[ 4] = rotateLeft(last, 14); last = one;
138 one = m_hash[15]; m_hash[15] = rotateLeft(last, 27); last = one;
139 one = m_hash[23]; m_hash[23] = rotateLeft(last, 41); last = one;
140 one = m_hash[19]; m_hash[19] = rotateLeft(last, 56); last = one;
141 one = m_hash[13]; m_hash[13] = rotateLeft(last, 8); last = one;
142 one = m_hash[12]; m_hash[12] = rotateLeft(last, 25); last = one;
143 one = m_hash[ 2]; m_hash[ 2] = rotateLeft(last, 43); last = one;
144 one = m_hash[20]; m_hash[20] = rotateLeft(last, 62); last = one;
145 one = m_hash[14]; m_hash[14] = rotateLeft(last, 18); last = one;
146 one = m_hash[22]; m_hash[22] = rotateLeft(last, 39); last = one;
147 one = m_hash[ 9]; m_hash[ 9] = rotateLeft(last, 61); last = one;

Callers

nothing calls this directly

Calls 2

mod5Function · 0.85
rotateLeftFunction · 0.85

Tested by

no test coverage detected