Skinny-C
 All Data Structures Files Functions Variables Groups Pages
Skinny128.h
1 /*
2  * Copyright (C) 2017 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_SKINNY128_h
24 #define CRYPTO_SKINNY128_h
25 
26 #include "BlockCipher.h"
27 
28 class Skinny128 : public BlockCipher
29 {
30 public:
31  virtual ~Skinny128();
32 
33  size_t blockSize() const;
34 
35  void encryptBlock(uint8_t *output, const uint8_t *input);
36  void decryptBlock(uint8_t *output, const uint8_t *input);
37 
38  void clear();
39 
40 protected:
41  Skinny128(uint32_t *schedule, uint8_t rounds);
42 
43  void setTK1(const uint8_t *key, bool tweaked = false);
44  void xorTK1(const uint8_t *key);
45  void setTK2(const uint8_t *key);
46  void setTK3(const uint8_t *key);
47 
48 private:
49  uint32_t *s;
50  uint8_t r;
51 };
52 
54 {
55 public:
56  virtual ~Skinny128_Tweaked();
57 
58  bool setTweak(const uint8_t *tweak, size_t len);
59 
60  void clear();
61 
62 protected:
63  Skinny128_Tweaked(uint32_t *schedule, uint8_t rounds);
64 
65  void resetTweak();
66 
67 private:
68  uint8_t t[16];
69 };
70 
71 class Skinny128_128 : public Skinny128
72 {
73 public:
74  Skinny128_128();
75  virtual ~Skinny128_128();
76 
77  size_t keySize() const;
78 
79  bool setKey(const uint8_t *key, size_t len);
80 
81 private:
82  uint32_t sched[40 * 2];
83 };
84 
85 class Skinny128_256 : public Skinny128
86 {
87 public:
88  Skinny128_256();
89  virtual ~Skinny128_256();
90 
91  size_t keySize() const;
92 
93  bool setKey(const uint8_t *key, size_t len);
94 
95 private:
96  uint32_t sched[48 * 2];
97 };
98 
100 {
101 public:
103  virtual ~Skinny128_256_Tweaked();
104 
105  size_t keySize() const;
106 
107  bool setKey(const uint8_t *key, size_t len);
108 
109 private:
110  uint32_t sched[48 * 2];
111 };
112 
113 class Skinny128_384 : public Skinny128
114 {
115 public:
116  Skinny128_384();
117  virtual ~Skinny128_384();
118 
119  size_t keySize() const;
120 
121  bool setKey(const uint8_t *key, size_t len);
122 
123 private:
124  uint32_t sched[56 * 2];
125 };
126 
128 {
129 public:
131  virtual ~Skinny128_384_Tweaked();
132 
133  size_t keySize() const;
134 
135  bool setKey(const uint8_t *key, size_t len);
136 
137 private:
138  uint32_t sched[56 * 2];
139 };
140 
141 #endif
Skinny128_Tweaked(uint32_t *schedule, uint8_t rounds)
Constructs a tweakable Skinny-128 block cipher object.
Definition: Skinny128.cpp:1231
SKINNY block cipher with a 128-bit block and a 256-bit key.
Definition: Skinny128.h:85
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny128.cpp:1387
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny128.cpp:1317
size_t keySize() const
Size of a Skinny128_256 key in bytes.
Definition: Skinny128.cpp:1346
void xorTK1(const uint8_t *key)
XOR's the key schedule with the schedule for TK1.
Definition: Skinny128.cpp:891
Abstract base class for block ciphers.
Definition: BlockCipher.h:29
size_t keySize() const
Size of a Skinny128_384 key in bytes.
Definition: Skinny128.cpp:1417
virtual ~Skinny128_256_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1373
size_t keySize() const
Size of a Skinny128_256_Tweaked key in bytes.
Definition: Skinny128.cpp:1382
void encryptBlock(uint8_t *output, const uint8_t *input)
Encrypts a single block using this cipher.
Definition: Skinny128.cpp:343
SKINNY block cipher with a 128-bit block, a 128-bit key, and a 128-bit tweak.
Definition: Skinny128.h:99
void setTK3(const uint8_t *key)
XOR's the key schedule with the schedule for TK3.
Definition: Skinny128.cpp:1122
virtual ~Skinny128_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1240
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny128.cpp:1422
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny128.cpp:1459
SKINNY block cipher with a 128-bit block and a 384-bit key.
Definition: Skinny128.h:113
virtual ~Skinny128()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:118
void clear()
Clears all security-sensitive state from this block cipher.
Definition: Skinny128.cpp:717
size_t keySize() const
Size of a Skinny128_128 key in bytes.
Definition: Skinny128.cpp:1312
Abstract base class for SKINNY tweakable block ciphers with 128-bit blocks.
Definition: Skinny128.h:53
virtual ~Skinny128_384()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1408
Skinny128_256()
Constructs a Skinny-128 block cipher with a 256-bit key.
Definition: Skinny128.cpp:1328
SKINNY block cipher with a 128-bit block and a 128-bit key.
Definition: Skinny128.h:71
Skinny128_384_Tweaked()
Constructs a tweakable Skinny-128 block cipher with a 256-bit key and a 128-bit tweak.
Definition: Skinny128.cpp:1436
Skinny128_256_Tweaked()
Constructs a tweakable Skinny-128 block cipher with a 128-bit key and a 128-bit tweak.
Definition: Skinny128.cpp:1364
void setTK2(const uint8_t *key)
XOR's the key schedule with the schedule for TK2.
Definition: Skinny128.cpp:1014
Abstract base class for SKINNY block ciphers with 128-bit blocks.
Definition: Skinny128.h:28
SKINNY block cipher with a 128-bit block, a 256-bit key, and a 128-bit tweak.
Definition: Skinny128.h:127
Skinny128_128()
Constructs a Skinny-128 block cipher with a 128-bit key.
Definition: Skinny128.cpp:1294
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny128.cpp:1351
Skinny128(uint32_t *schedule, uint8_t rounds)
Constructs a Skinny-128 block cipher object.
Definition: Skinny128.cpp:109
void setTK1(const uint8_t *key, bool tweaked=false)
Clears the key schedule and sets it to the schedule for TK1.
Definition: Skinny128.cpp:773
virtual ~Skinny128_384_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1445
size_t blockSize() const
Size of a Skinny-128 block in bytes.
Definition: Skinny128.cpp:126
void resetTweak()
Resets the tweak to all-zeroes.
Definition: Skinny128.cpp:1285
virtual ~Skinny128_256()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1337
size_t keySize() const
Size of a Skinny128_384_Tweaked key in bytes.
Definition: Skinny128.cpp:1454
void decryptBlock(uint8_t *output, const uint8_t *input)
Decrypts a single block using this cipher.
Definition: Skinny128.cpp:531
virtual ~Skinny128_128()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Definition: Skinny128.cpp:1303
Skinny128_384()
Constructs a Skinny-128 block cipher with a 384-bit key.
Definition: Skinny128.cpp:1399
bool setTweak(const uint8_t *tweak, size_t len)
Sets the 128-bit tweak value for this block cipher.
Definition: Skinny128.cpp:1260
void clear()
Clears all security-sensitive state from this block cipher.
Definition: Skinny128.cpp:1274