Arduino Cryptography Library
OMAC.h
1 /*
2  * Copyright (C) 2016 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef CRYPTO_OMAC_H
24 #define CRYPTO_OMAC_H
25 
26 #include "BlockCipher.h"
27 
28 class OMAC
29 {
30 public:
31  OMAC();
32  ~OMAC();
33 
34  BlockCipher *blockCipher() const { return _blockCipher; }
35  void setBlockCipher(BlockCipher *cipher) { _blockCipher = cipher; }
36 
37  void initFirst(uint8_t omac[16]);
38  void initNext(uint8_t omac[16], uint8_t tag);
39  void update(uint8_t omac[16], const uint8_t *data, size_t size);
40  void finalize(uint8_t omac[16]);
41 
42  void clear();
43 
44 private:
45  BlockCipher *_blockCipher;
46  uint32_t b[4];
47  uint8_t posn;
48 };
49 
50 #endif
Abstract base class for block ciphers.
Definition: BlockCipher.h:30
Implementation of the OMAC message authenticator.
Definition: OMAC.h:29
void initFirst(uint8_t omac[16])
Initialises the first OMAC hashing context and creates the B value.
Definition: OMAC.cpp:101
void clear()
Clears all security-sensitive state from this object.
Definition: OMAC.cpp:197
void update(uint8_t omac[16], const uint8_t *data, size_t size)
Updates an OMAC hashing context with more data.
Definition: OMAC.cpp:143
~OMAC()
Destroys this OMAC object.
Definition: OMAC.cpp:59
BlockCipher * blockCipher() const
Gets the block cipher that is in use for this OMAC object.
Definition: OMAC.h:34
void setBlockCipher(BlockCipher *cipher)
Sets the block cipher to use for this OMAC object.
Definition: OMAC.h:35
void initNext(uint8_t omac[16], uint8_t tag)
Initialises or restarts an OMAC hashing context.
Definition: OMAC.cpp:127
void finalize(uint8_t omac[16])
Finalises an OMAC hashing context.
Definition: OMAC.cpp:172
OMAC()
Constructs a new OMAC object.
Definition: OMAC.cpp:48