51 EAXCommon::~EAXCommon()
75 return blockCipher->
setKey(key, len);
85 omacInitFirst(state.counter);
86 omacUpdate(state.counter, iv, len);
87 omacFinal(state.counter);
91 memcpy(state.tag, state.counter, 16);
94 omacInit(state.hash, 1);
106 encryptCTR(output, input, len);
107 omacUpdate(state.hash, output, len);
114 omacUpdate(state.hash, input, len);
115 encryptCTR(output, input, len);
121 omacUpdate(state.hash, (
const uint8_t *)data, len);
129 memcpy(tag, state.tag, len);
140 return secure_compare(state.tag, tag, len);
149 static void gfDouble(uint8_t value[16])
152 for (uint8_t index = 16; index > 0; ) {
154 temp |= (((uint16_t)(value[index])) << 1);
155 value[index] = (uint8_t)temp;
158 value[15] ^= (uint8_t)((-temp) & 0x87);
166 void EAXCommon::omacInitFirst(uint8_t omac[16])
177 memcpy(state.b, omac, 16);
187 void EAXCommon::omacInit(uint8_t omac[16], uint8_t t)
201 void EAXCommon::omacUpdate(uint8_t omac[16],
const uint8_t *data,
size_t len)
205 if (state.authPosn == 16) {
211 uint8_t size = 16 - state.authPosn;
214 for (uint8_t index = 0; index < size; ++index)
215 omac[(state.authPosn)++] ^= data[index];
228 void EAXCommon::omacFinal(uint8_t omac[16])
231 if (state.authPosn != 16) {
234 memcpy(p, state.b, 16);
236 omac[state.authPosn] ^= 0x80;
237 for (uint8_t index = 0; index < 16; ++index)
238 omac[index] ^= p[index];
242 for (uint8_t index = 0; index < 16; ++index)
243 omac[index] ^= state.b[index];
254 void EAXCommon::closeAuthData()
257 omacFinal(state.hash);
258 for (uint8_t index = 0; index < 16; ++index)
259 state.tag[index] ^= state.hash[index];
263 omacInit(state.hash, 2);
275 void EAXCommon::encryptCTR(uint8_t *output,
const uint8_t *input,
size_t len)
279 if (state.encPosn == 16) {
292 temp += state.counter[index];
293 state.counter[index] = (uint8_t)temp;
299 uint8_t size = 16 - state.encPosn;
302 for (uint8_t index = 0; index < size; ++index)
303 output[index] = input[index] ^ state.stream[(state.encPosn)++];
312 void EAXCommon::closeTag()
319 omacFinal(state.hash);
320 for (uint8_t index = 0; index < 16; ++index)
321 state.tag[index] ^= state.hash[index];
bool setIV(const uint8_t *iv, size_t len)
Sets the initialization vector to use for future encryption and decryption operations.
void decrypt(uint8_t *output, const uint8_t *input, size_t len)
Decrypts an input buffer and writes the plaintext to an output buffer.
size_t tagSize() const
Returns the size of the authentication tag.
EAXCommon()
Constructs a new cipher in EAX mode.
bool checkTag(const void *tag, size_t len)
Finalizes the decryption process and checks the authentication tag.
virtual void encryptBlock(uint8_t *output, const uint8_t *input)=0
Encrypts a single block using this cipher.
void encrypt(uint8_t *output, const uint8_t *input, size_t len)
Encrypts an input buffer and writes the ciphertext to an output buffer.
void clear()
Clears all security-sensitive state from this cipher.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
void computeTag(void *tag, size_t len)
Finalizes the encryption process and computes the authentication tag.
virtual bool setKey(const uint8_t *key, size_t len)=0
Sets the key to use for future encryption and decryption operations.
size_t ivSize() const
Size of the initialization vector for this cipher, in bytes.
void addAuthData(const void *data, size_t len)
Adds extra data that will be authenticated but not encrypted.
size_t keySize() const
Default size of the key for this cipher, in bytes.
virtual size_t keySize() const =0
Default size of the key for this block cipher, in bytes.