25 #include "utility/EndianUtil.h"
70 memcpy(state.H, key, 16);
71 #if defined(CRYPTO_LITTLE_ENDIAN)
72 state.H[0] = be32toh(state.H[0]);
73 state.H[1] = be32toh(state.H[1]);
74 state.H[2] = be32toh(state.H[2]);
75 state.H[3] = be32toh(state.H[3]);
79 memset(state.Y, 0,
sizeof(state.Y));
97 const uint8_t *d = (
const uint8_t *)data;
99 uint8_t size = 16 - state.posn;
102 uint8_t *y = ((uint8_t *)state.Y) + state.posn;
103 for (uint8_t i = 0; i < size; ++i)
108 if (state.posn == 16) {
138 memcpy(token, state.Y, len);
148 if (state.posn != 0) {
164 void GHASH::processChunk()
170 uint32_t V0 = state.H[0];
171 uint32_t V1 = state.H[1];
172 uint32_t V2 = state.H[2];
173 uint32_t V3 = state.H[3];
178 for (uint8_t posn = 0; posn < 16; ++posn) {
179 uint8_t value = ((
const uint8_t *)state.Y)[posn];
180 for (uint8_t bit = 0; bit < 8; ++bit, value <<= 1) {
182 uint32_t mask = (~((uint32_t)(value >> 7))) + 1;
191 mask = ((~(V3 & 0x01)) + 1) & 0xE1000000;
192 V3 = (V3 >> 1) | (V2 << 31);
193 V2 = (V2 >> 1) | (V1 << 31);
194 V1 = (V1 >> 1) | (V0 << 31);
195 V0 = (V0 >> 1) ^ mask;
200 state.Y[0] = htobe32(Z0);
201 state.Y[1] = htobe32(Z1);
202 state.Y[2] = htobe32(Z2);
203 state.Y[3] = htobe32(Z3);
void finalize(void *token, size_t len)
Finalizes the authentication process and returns the token.
void update(const void *data, size_t len)
Updates the message authenticator with more data.
~GHASH()
Destroys this GHASH message authenticator.
void pad()
Pads the input stream with zero bytes to a multiple of 16.
void clear()
Clears the authenticator's state, removing all sensitive data.
GHASH()
Constructs a new GHASH message authenticator.
void reset(const void *key)
Resets the GHASH message authenticator for a new session.