Skinny-C
 All Data Structures Files Functions Variables Groups Pages
Skinny64.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_SKINNY64_h
24 #define CRYPTO_SKINNY64_h
25 
26 #include "BlockCipher.h"
27 
28 class Skinny64 : public BlockCipher
29 {
30 public:
31  virtual ~Skinny64();
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  Skinny64(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 
53 class Skinny64_Tweaked : public Skinny64
54 {
55 public:
56  virtual ~Skinny64_Tweaked();
57 
58  bool setTweak(const uint8_t *tweak, size_t len);
59 
60  void clear();
61 
62 protected:
63  Skinny64_Tweaked(uint32_t *schedule, uint8_t rounds);
64 
65  void resetTweak();
66 
67 private:
68  uint8_t t[8];
69 };
70 
71 class Skinny64_64 : public Skinny64
72 {
73 public:
74  Skinny64_64();
75  virtual ~Skinny64_64();
76 
77  size_t keySize() const;
78 
79  bool setKey(const uint8_t *key, size_t len);
80 
81 private:
82  uint32_t sched[32];
83 };
84 
85 class Skinny64_128 : public Skinny64
86 {
87 public:
88  Skinny64_128();
89  virtual ~Skinny64_128();
90 
91  size_t keySize() const;
92 
93  bool setKey(const uint8_t *key, size_t len);
94 
95 private:
96  uint32_t sched[36];
97 };
98 
100 {
101 public:
103  virtual ~Skinny64_128_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[36];
111 };
112 
113 class Skinny64_192 : public Skinny64
114 {
115 public:
116  Skinny64_192();
117  virtual ~Skinny64_192();
118 
119  size_t keySize() const;
120 
121  bool setKey(const uint8_t *key, size_t len);
122 
123 private:
124  uint32_t sched[40];
125 };
126 
128 {
129 public:
131  virtual ~Skinny64_192_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[40];
139 };
140 
141 #endif
void encryptBlock(uint8_t *output, const uint8_t *input)
Encrypts a single block using this cipher.
Definition: Skinny64.cpp:359
void resetTweak()
Resets the tweak to all-zeroes.
Definition: Skinny64.cpp:1094
SKINNY block cipher with a 64-bit block and a 128-bit key.
Definition: Skinny64.h:85
SKINNY block cipher with a 64-bit block and a 64-bit key.
Definition: Skinny64.h:71
size_t keySize() const
Size of a Skinny64_128_Tweaked key in bytes.
Definition: Skinny64.cpp:1191
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny64.cpp:1268
Skinny64_128_Tweaked()
Constructs a tweakable Skinny-64 block cipher with a 64-bit key and a 64-bit tweak.
Definition: Skinny64.cpp:1173
void clear()
Clears all security-sensitive state from this block cipher.
Definition: Skinny64.cpp:1083
size_t keySize() const
Size of a Skinny64_128 key in bytes.
Definition: Skinny64.cpp:1155
Abstract base class for block ciphers.
Definition: BlockCipher.h:29
size_t keySize() const
Size of a Skinny64_192 key in bytes.
Definition: Skinny64.cpp:1226
virtual ~Skinny64_64()
Destroys this Skinny-64 block cipher object after clearing sensitive information. ...
Definition: Skinny64.cpp:1112
void xorTK1(const uint8_t *key)
XOR's the key schedule with the schedule for TK1.
Definition: Skinny64.cpp:796
virtual ~Skinny64_192_Tweaked()
Destroys this tweakable Skinny-64 block cipher object after clearing sensitive information.
Definition: Skinny64.cpp:1254
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny64.cpp:1126
virtual ~Skinny64_192()
Destroys this Skinny-64 block cipher object after clearing sensitive information. ...
Definition: Skinny64.cpp:1217
SKINNY block cipher with a 64-bit block, a 128-bit key, and a 64-bit tweak.
Definition: Skinny64.h:127
size_t blockSize() const
Size of a Skinny-64 block in bytes.
Definition: Skinny64.cpp:126
size_t keySize() const
Size of a Skinny64_64 key in bytes.
Definition: Skinny64.cpp:1121
Abstract base class for SKINNY block ciphers with 64-bit blocks.
Definition: Skinny64.h:28
Skinny64_Tweaked(uint32_t *schedule, uint8_t rounds)
Constructs a tweakable Skinny-64 block cipher object.
Definition: Skinny64.cpp:1040
size_t keySize() const
Size of a Skinny64_192_Tweaked key in bytes.
Definition: Skinny64.cpp:1263
void setTK3(const uint8_t *key)
XOR's the key schedule with the schedule for TK3.
Definition: Skinny64.cpp:967
Skinny64_192_Tweaked()
Constructs a tweakable Skinny-64 block cipher with a 128-bit key and a 64-bit tweak.
Definition: Skinny64.cpp:1245
Skinny64_128()
Constructs a Skinny-64 block cipher with a 128-bit key.
Definition: Skinny64.cpp:1137
virtual ~Skinny64_128_Tweaked()
Destroys this tweakable Skinny-64 block cipher object after clearing sensitive information.
Definition: Skinny64.cpp:1182
Skinny64(uint32_t *schedule, uint8_t rounds)
Constructs a Skinny-64 block cipher object.
Definition: Skinny64.cpp:109
void setTK1(const uint8_t *key, bool tweaked=false)
Clears the key schedule and sets it to the schedule for TK1.
Definition: Skinny64.cpp:701
bool setTweak(const uint8_t *tweak, size_t len)
Sets the 64-bit tweak value for this block cipher.
Definition: Skinny64.cpp:1069
Skinny64_64()
Constructs a Skinny-64 block cipher with a 64-bit key.
Definition: Skinny64.cpp:1103
virtual ~Skinny64()
Destroys this Skinny-64 block cipher object after clearing sensitive information. ...
Definition: Skinny64.cpp:118
void clear()
Clears all security-sensitive state from this block cipher.
Definition: Skinny64.cpp:639
virtual ~Skinny64_Tweaked()
Destroys this tweakable Skinny-64 block cipher object after clearing sensitive information.
Definition: Skinny64.cpp:1049
SKINNY block cipher with a 64-bit block, a 64-bit key, and a 64-bit tweak.
Definition: Skinny64.h:99
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny64.cpp:1196
void decryptBlock(uint8_t *output, const uint8_t *input)
Decrypts a single block using this cipher.
Definition: Skinny64.cpp:499
Skinny64_192()
Constructs a Skinny-64 block cipher with a 192-bit key.
Definition: Skinny64.cpp:1208
SKINNY block cipher with a 64-bit block and a 192-bit key.
Definition: Skinny64.h:113
virtual ~Skinny64_128()
Destroys this Skinny-64 block cipher object after clearing sensitive information. ...
Definition: Skinny64.cpp:1146
Abstract base class for SKINNY tweakable block ciphers with 64-bit blocks.
Definition: Skinny64.h:53
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny64.cpp:1160
void setTK2(const uint8_t *key)
XOR's the key schedule with the schedule for TK2.
Definition: Skinny64.cpp:895
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: Skinny64.cpp:1231