present.c
Go to the documentation of this file.
1 /**
2  * @file present.c
3  * @brief PRESENT encryption algorithm
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @section Description
28  *
29  * PRESENT is an ultra-lightweight block cipher
30  *
31  * @author Oryx Embedded SARL (www.oryx-embedded.com)
32  * @version 2.4.0
33  **/
34 
35 //Switch to the appropriate trace level
36 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
37 
38 //Dependencies
39 #include "core/crypto.h"
40 #include "cipher/present.h"
41 
42 //Check crypto library configuration
43 #if (PRESENT_SUPPORT == ENABLED)
44 
45 //S-box
46 static const uint8_t sbox[16] =
47 {
48  0x0C, 0x05, 0x06, 0x0B, 0x09, 0x00, 0x0A, 0x0D, 0x03, 0x0E, 0x0F, 0x08, 0x04, 0x07, 0x01, 0x02
49 };
50 
51 //Inverse S-box
52 static const uint8_t isbox[256] =
53 {
54  0x55, 0x5E, 0x5F, 0x58, 0x5C, 0x51, 0x52, 0x5D, 0x5B, 0x54, 0x56, 0x53, 0x50, 0x57, 0x59, 0x5A,
55  0xE5, 0xEE, 0xEF, 0xE8, 0xEC, 0xE1, 0xE2, 0xED, 0xEB, 0xE4, 0xE6, 0xE3, 0xE0, 0xE7, 0xE9, 0xEA,
56  0xF5, 0xFE, 0xFF, 0xF8, 0xFC, 0xF1, 0xF2, 0xFD, 0xFB, 0xF4, 0xF6, 0xF3, 0xF0, 0xF7, 0xF9, 0xFA,
57  0x85, 0x8E, 0x8F, 0x88, 0x8C, 0x81, 0x82, 0x8D, 0x8B, 0x84, 0x86, 0x83, 0x80, 0x87, 0x89, 0x8A,
58  0xC5, 0xCE, 0xCF, 0xC8, 0xCC, 0xC1, 0xC2, 0xCD, 0xCB, 0xC4, 0xC6, 0xC3, 0xC0, 0xC7, 0xC9, 0xCA,
59  0x15, 0x1E, 0x1F, 0x18, 0x1C, 0x11, 0x12, 0x1D, 0x1B, 0x14, 0x16, 0x13, 0x10, 0x17, 0x19, 0x1A,
60  0x25, 0x2E, 0x2F, 0x28, 0x2C, 0x21, 0x22, 0x2D, 0x2B, 0x24, 0x26, 0x23, 0x20, 0x27, 0x29, 0x2A,
61  0xD5, 0xDE, 0xDF, 0xD8, 0xDC, 0xD1, 0xD2, 0xDD, 0xDB, 0xD4, 0xD6, 0xD3, 0xD0, 0xD7, 0xD9, 0xDA,
62  0xB5, 0xBE, 0xBF, 0xB8, 0xBC, 0xB1, 0xB2, 0xBD, 0xBB, 0xB4, 0xB6, 0xB3, 0xB0, 0xB7, 0xB9, 0xBA,
63  0x45, 0x4E, 0x4F, 0x48, 0x4C, 0x41, 0x42, 0x4D, 0x4B, 0x44, 0x46, 0x43, 0x40, 0x47, 0x49, 0x4A,
64  0x65, 0x6E, 0x6F, 0x68, 0x6C, 0x61, 0x62, 0x6D, 0x6B, 0x64, 0x66, 0x63, 0x60, 0x67, 0x69, 0x6A,
65  0x35, 0x3E, 0x3F, 0x38, 0x3C, 0x31, 0x32, 0x3D, 0x3B, 0x34, 0x36, 0x33, 0x30, 0x37, 0x39, 0x3A,
66  0x05, 0x0E, 0x0F, 0x08, 0x0C, 0x01, 0x02, 0x0D, 0x0B, 0x04, 0x06, 0x03, 0x00, 0x07, 0x09, 0x0A,
67  0x75, 0x7E, 0x7F, 0x78, 0x7C, 0x71, 0x72, 0x7D, 0x7B, 0x74, 0x76, 0x73, 0x70, 0x77, 0x79, 0x7A,
68  0x95, 0x9E, 0x9F, 0x98, 0x9C, 0x91, 0x92, 0x9D, 0x9B, 0x94, 0x96, 0x93, 0x90, 0x97, 0x99, 0x9A,
69  0xA5, 0xAE, 0xAF, 0xA8, 0xAC, 0xA1, 0xA2, 0xAD, 0xAB, 0xA4, 0xA6, 0xA3, 0xA0, 0xA7, 0xA9, 0xAA,
70 };
71 
72 //Inverse bit permutation
73 static const uint32_t ipbox[256] =
74 {
75  0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, 0x00000101, 0x00000110, 0x00000111,
76  0x00001000, 0x00001001, 0x00001010, 0x00001011, 0x00001100, 0x00001101, 0x00001110, 0x00001111,
77  0x00010000, 0x00010001, 0x00010010, 0x00010011, 0x00010100, 0x00010101, 0x00010110, 0x00010111,
78  0x00011000, 0x00011001, 0x00011010, 0x00011011, 0x00011100, 0x00011101, 0x00011110, 0x00011111,
79  0x00100000, 0x00100001, 0x00100010, 0x00100011, 0x00100100, 0x00100101, 0x00100110, 0x00100111,
80  0x00101000, 0x00101001, 0x00101010, 0x00101011, 0x00101100, 0x00101101, 0x00101110, 0x00101111,
81  0x00110000, 0x00110001, 0x00110010, 0x00110011, 0x00110100, 0x00110101, 0x00110110, 0x00110111,
82  0x00111000, 0x00111001, 0x00111010, 0x00111011, 0x00111100, 0x00111101, 0x00111110, 0x00111111,
83  0x01000000, 0x01000001, 0x01000010, 0x01000011, 0x01000100, 0x01000101, 0x01000110, 0x01000111,
84  0x01001000, 0x01001001, 0x01001010, 0x01001011, 0x01001100, 0x01001101, 0x01001110, 0x01001111,
85  0x01010000, 0x01010001, 0x01010010, 0x01010011, 0x01010100, 0x01010101, 0x01010110, 0x01010111,
86  0x01011000, 0x01011001, 0x01011010, 0x01011011, 0x01011100, 0x01011101, 0x01011110, 0x01011111,
87  0x01100000, 0x01100001, 0x01100010, 0x01100011, 0x01100100, 0x01100101, 0x01100110, 0x01100111,
88  0x01101000, 0x01101001, 0x01101010, 0x01101011, 0x01101100, 0x01101101, 0x01101110, 0x01101111,
89  0x01110000, 0x01110001, 0x01110010, 0x01110011, 0x01110100, 0x01110101, 0x01110110, 0x01110111,
90  0x01111000, 0x01111001, 0x01111010, 0x01111011, 0x01111100, 0x01111101, 0x01111110, 0x01111111,
91  0x10000000, 0x10000001, 0x10000010, 0x10000011, 0x10000100, 0x10000101, 0x10000110, 0x10000111,
92  0x10001000, 0x10001001, 0x10001010, 0x10001011, 0x10001100, 0x10001101, 0x10001110, 0x10001111,
93  0x10010000, 0x10010001, 0x10010010, 0x10010011, 0x10010100, 0x10010101, 0x10010110, 0x10010111,
94  0x10011000, 0x10011001, 0x10011010, 0x10011011, 0x10011100, 0x10011101, 0x10011110, 0x10011111,
95  0x10100000, 0x10100001, 0x10100010, 0x10100011, 0x10100100, 0x10100101, 0x10100110, 0x10100111,
96  0x10101000, 0x10101001, 0x10101010, 0x10101011, 0x10101100, 0x10101101, 0x10101110, 0x10101111,
97  0x10110000, 0x10110001, 0x10110010, 0x10110011, 0x10110100, 0x10110101, 0x10110110, 0x10110111,
98  0x10111000, 0x10111001, 0x10111010, 0x10111011, 0x10111100, 0x10111101, 0x10111110, 0x10111111,
99  0x11000000, 0x11000001, 0x11000010, 0x11000011, 0x11000100, 0x11000101, 0x11000110, 0x11000111,
100  0x11001000, 0x11001001, 0x11001010, 0x11001011, 0x11001100, 0x11001101, 0x11001110, 0x11001111,
101  0x11010000, 0x11010001, 0x11010010, 0x11010011, 0x11010100, 0x11010101, 0x11010110, 0x11010111,
102  0x11011000, 0x11011001, 0x11011010, 0x11011011, 0x11011100, 0x11011101, 0x11011110, 0x11011111,
103  0x11100000, 0x11100001, 0x11100010, 0x11100011, 0x11100100, 0x11100101, 0x11100110, 0x11100111,
104  0x11101000, 0x11101001, 0x11101010, 0x11101011, 0x11101100, 0x11101101, 0x11101110, 0x11101111,
105  0x11110000, 0x11110001, 0x11110010, 0x11110011, 0x11110100, 0x11110101, 0x11110110, 0x11110111,
106  0x11111000, 0x11111001, 0x11111010, 0x11111011, 0x11111100, 0x11111101, 0x11111110, 0x11111111
107 };
108 
109 //Combined S-box and bit permutation
110 static const uint64_t spbox[256] =
111 {
112  0x0003000300000000, 0x0002000300000001, 0x0002000300010000, 0x0003000200010001,
113  0x0003000200000001, 0x0002000200000000, 0x0003000200010000, 0x0003000300000001,
114  0x0002000200010001, 0x0003000300010000, 0x0003000300010001, 0x0003000200000000,
115  0x0002000300000000, 0x0002000300010001, 0x0002000200000001, 0x0002000200010000,
116  0x0001000300000002, 0x0000000300000003, 0x0000000300010002, 0x0001000200010003,
117  0x0001000200000003, 0x0000000200000002, 0x0001000200010002, 0x0001000300000003,
118  0x0000000200010003, 0x0001000300010002, 0x0001000300010003, 0x0001000200000002,
119  0x0000000300000002, 0x0000000300010003, 0x0000000200000003, 0x0000000200010002,
120  0x0001000300020000, 0x0000000300020001, 0x0000000300030000, 0x0001000200030001,
121  0x0001000200020001, 0x0000000200020000, 0x0001000200030000, 0x0001000300020001,
122  0x0000000200030001, 0x0001000300030000, 0x0001000300030001, 0x0001000200020000,
123  0x0000000300020000, 0x0000000300030001, 0x0000000200020001, 0x0000000200030000,
124  0x0003000100020002, 0x0002000100020003, 0x0002000100030002, 0x0003000000030003,
125  0x0003000000020003, 0x0002000000020002, 0x0003000000030002, 0x0003000100020003,
126  0x0002000000030003, 0x0003000100030002, 0x0003000100030003, 0x0003000000020002,
127  0x0002000100020002, 0x0002000100030003, 0x0002000000020003, 0x0002000000030002,
128  0x0003000100000002, 0x0002000100000003, 0x0002000100010002, 0x0003000000010003,
129  0x0003000000000003, 0x0002000000000002, 0x0003000000010002, 0x0003000100000003,
130  0x0002000000010003, 0x0003000100010002, 0x0003000100010003, 0x0003000000000002,
131  0x0002000100000002, 0x0002000100010003, 0x0002000000000003, 0x0002000000010002,
132  0x0001000100000000, 0x0000000100000001, 0x0000000100010000, 0x0001000000010001,
133  0x0001000000000001, 0x0000000000000000, 0x0001000000010000, 0x0001000100000001,
134  0x0000000000010001, 0x0001000100010000, 0x0001000100010001, 0x0001000000000000,
135  0x0000000100000000, 0x0000000100010001, 0x0000000000000001, 0x0000000000010000,
136  0x0003000100020000, 0x0002000100020001, 0x0002000100030000, 0x0003000000030001,
137  0x0003000000020001, 0x0002000000020000, 0x0003000000030000, 0x0003000100020001,
138  0x0002000000030001, 0x0003000100030000, 0x0003000100030001, 0x0003000000020000,
139  0x0002000100020000, 0x0002000100030001, 0x0002000000020001, 0x0002000000030000,
140  0x0003000300000002, 0x0002000300000003, 0x0002000300010002, 0x0003000200010003,
141  0x0003000200000003, 0x0002000200000002, 0x0003000200010002, 0x0003000300000003,
142  0x0002000200010003, 0x0003000300010002, 0x0003000300010003, 0x0003000200000002,
143  0x0002000300000002, 0x0002000300010003, 0x0002000200000003, 0x0002000200010002,
144  0x0001000100020002, 0x0000000100020003, 0x0000000100030002, 0x0001000000030003,
145  0x0001000000020003, 0x0000000000020002, 0x0001000000030002, 0x0001000100020003,
146  0x0000000000030003, 0x0001000100030002, 0x0001000100030003, 0x0001000000020002,
147  0x0000000100020002, 0x0000000100030003, 0x0000000000020003, 0x0000000000030002,
148  0x0003000300020000, 0x0002000300020001, 0x0002000300030000, 0x0003000200030001,
149  0x0003000200020001, 0x0002000200020000, 0x0003000200030000, 0x0003000300020001,
150  0x0002000200030001, 0x0003000300030000, 0x0003000300030001, 0x0003000200020000,
151  0x0002000300020000, 0x0002000300030001, 0x0002000200020001, 0x0002000200030000,
152  0x0003000300020002, 0x0002000300020003, 0x0002000300030002, 0x0003000200030003,
153  0x0003000200020003, 0x0002000200020002, 0x0003000200030002, 0x0003000300020003,
154  0x0002000200030003, 0x0003000300030002, 0x0003000300030003, 0x0003000200020002,
155  0x0002000300020002, 0x0002000300030003, 0x0002000200020003, 0x0002000200030002,
156  0x0003000100000000, 0x0002000100000001, 0x0002000100010000, 0x0003000000010001,
157  0x0003000000000001, 0x0002000000000000, 0x0003000000010000, 0x0003000100000001,
158  0x0002000000010001, 0x0003000100010000, 0x0003000100010001, 0x0003000000000000,
159  0x0002000100000000, 0x0002000100010001, 0x0002000000000001, 0x0002000000010000,
160  0x0001000300000000, 0x0000000300000001, 0x0000000300010000, 0x0001000200010001,
161  0x0001000200000001, 0x0000000200000000, 0x0001000200010000, 0x0001000300000001,
162  0x0000000200010001, 0x0001000300010000, 0x0001000300010001, 0x0001000200000000,
163  0x0000000300000000, 0x0000000300010001, 0x0000000200000001, 0x0000000200010000,
164  0x0001000300020002, 0x0000000300020003, 0x0000000300030002, 0x0001000200030003,
165  0x0001000200020003, 0x0000000200020002, 0x0001000200030002, 0x0001000300020003,
166  0x0000000200030003, 0x0001000300030002, 0x0001000300030003, 0x0001000200020002,
167  0x0000000300020002, 0x0000000300030003, 0x0000000200020003, 0x0000000200030002,
168  0x0001000100000002, 0x0000000100000003, 0x0000000100010002, 0x0001000000010003,
169  0x0001000000000003, 0x0000000000000002, 0x0001000000010002, 0x0001000100000003,
170  0x0000000000010003, 0x0001000100010002, 0x0001000100010003, 0x0001000000000002,
171  0x0000000100000002, 0x0000000100010003, 0x0000000000000003, 0x0000000000010002,
172  0x0001000100020000, 0x0000000100020001, 0x0000000100030000, 0x0001000000030001,
173  0x0001000000020001, 0x0000000000020000, 0x0001000000030000, 0x0001000100020001,
174  0x0000000000030001, 0x0001000100030000, 0x0001000100030001, 0x0001000000020000,
175  0x0000000100020000, 0x0000000100030001, 0x0000000000020001, 0x0000000000030000
176 };
177 
178 //Common interface for encryption algorithms
180 {
181  "PRESENT",
182  sizeof(PresentContext),
186  NULL,
187  NULL,
191 };
192 
193 
194 /**
195  * @brief Key expansion
196  * @param[in] context Pointer to the PRESENT context to initialize
197  * @param[in] key Pointer to the key
198  * @param[in] keyLen Length of the key
199  * @return Error code
200  **/
201 
202 error_t presentInit(PresentContext *context, const uint8_t *key,
203  size_t keyLen)
204 {
205  uint_t i;
206  uint64_t t;
207  uint64_t kl;
208  uint64_t kh;
209 
210  //Check parameters
211  if(context == NULL || key == NULL)
213 
214  //Check key length
215  if(keyLen != 10 && keyLen != 16)
217 
218  //PRESENT can take keys of either 80 or 128 bits
219  if(keyLen == 10)
220  {
221  //Copy the 80-bit key
222  kh = LOAD16BE(key);
223  kl = LOAD64BE(key + 2);
224 
225  //Save the 64 leftmost bits of K
226  context->ks[0] = (kh << 48) | (kl >> 16);
227 
228  //Generate round keys
229  for(i = 1; i <= 31; i++)
230  {
231  //The key register is rotated by 61 bit positions to the left
232  t = kh & 0xFFFF;
233  kh = (kl >> 3) & 0xFFFF;
234  kl = (kl << 61) | (t << 45) | (kl >> 19);
235 
236  //The left-most four bits are passed through the S-box
237  t = sbox[(kh >> 12) & 0x0F];
238  kh = (kh & 0x0FFF) | (t << 12);
239 
240  //The round counter value i is XOR-ed with bits 19, 18, 17, 16, 15 of K
241  kl ^= (uint64_t) i << 15;
242 
243  //Save the 64 leftmost bits of K
244  context->ks[i] = (kh << 48) | (kl >> 16);
245  }
246  }
247  else
248  {
249  //Copy the 128-bit key
250  kh = LOAD64BE(key);
251  kl = LOAD64BE(key + 8);
252 
253  //Save the 64 leftmost bits of K
254  context->ks[0] = kh;
255 
256  //Generate round keys
257  for(i = 1; i <= 31; i++)
258  {
259  //The key register is rotated by 61 bit positions to the left
260  t = kh;
261  kh = (t << 61) | (kl >> 3);
262  kl = (kl << 61) | (t >> 3);
263 
264  //The left-most eight bits are passed through two S-boxes
265  t = sbox[(kh >> 56) & 0x0F];
266  kh = (kh & 0xF0FFFFFFFFFFFFFF) | (t << 56);
267  t = sbox[(kh >> 60) & 0x0F];
268  kh = (kh & 0x0FFFFFFFFFFFFFFF) | (t << 60);
269 
270  //The round counter value i is XOR-ed with bits 66, 65, 64, 63, 62 of K
271  kh ^= (uint64_t) i >> 2;
272  kl ^= (uint64_t) i << 62;
273 
274  //Save the 64 leftmost bits of K
275  context->ks[i] = kh;
276  }
277  }
278 
279  //No error to report
280  return NO_ERROR;
281 }
282 
283 
284 /**
285  * @brief Encrypt a 8-byte block using PRESENT algorithm
286  * @param[in] context Pointer to the PRESENT context
287  * @param[in] input Plaintext block to encrypt
288  * @param[out] output Ciphertext block resulting from encryption
289  **/
290 
291 void presentEncryptBlock(PresentContext *context, const uint8_t *input,
292  uint8_t *output)
293 {
294  uint_t i;
295  uint64_t s;
296  uint64_t t;
297  uint64_t state;
298 
299  //Copy the plaintext to the 64-bit state
300  state = LOAD64BE(input);
301 
302  //Initial round key addition
303  state ^= context->ks[0];
304 
305  //The encryption consists of 31 rounds
306  for(i = 1; i <= 31; i++)
307  {
308  //Apply S-box and bit permutation
309  s = spbox[state & 0xFF];
310  t = spbox[(state >> 8) & 0xFF];
311  s |= ROL64(t, 2);
312  t = spbox[(state >> 16) & 0xFF];
313  s |= ROL64(t, 4);
314  t = spbox[(state >> 24) & 0xFF];
315  s |= ROL64(t, 6);
316  t = spbox[(state >> 32) & 0xFF];
317  s |= ROL64(t, 8);
318  t = spbox[(state >> 40) & 0xFF];
319  s |= ROL64(t, 10);
320  t = spbox[(state >> 48) & 0xFF];
321  s |= ROL64(t, 12);
322  t = spbox[(state >> 56) & 0xFF];
323  s |= ROL64(t, 14);
324 
325  //Add round key
326  state = s ^ context->ks[i];
327  }
328 
329  //The final state is then copied to the output
330  STORE64BE(state, output);
331 }
332 
333 
334 /**
335  * @brief Decrypt a 8-byte block using PRESENT algorithm
336  * @param[in] context Pointer to the PRESENT context
337  * @param[in] input Ciphertext block to decrypt
338  * @param[out] output Plaintext block resulting from decryption
339  **/
340 
341 void presentDecryptBlock(PresentContext *context, const uint8_t *input,
342  uint8_t *output)
343 {
344  uint_t i;
345  uint64_t s;
346  uint64_t t;
347  uint64_t state;
348 
349  //Copy the ciphertext to the 64-bit state
350  state = LOAD64BE(input);
351 
352  //The decryption consists of 31 rounds
353  for(i = 31; i > 0; i--)
354  {
355  //Add round key
356  state ^= context->ks[i];
357 
358  //Apply inverse bit permutation
359  s = ipbox[state & 0xFF];
360  t = ipbox[(state >> 8) & 0xFF];
361  s |= ROL64(t, 32);
362  t = ipbox[(state >> 16) & 0xFF];
363  s |= ROL64(t, 1);
364  t = ipbox[(state >> 24) & 0xFF];
365  s |= ROL64(t, 33);
366  t = ipbox[(state >> 32) & 0xFF];
367  s |= ROL64(t, 2);
368  t = ipbox[(state >> 40) & 0xFF];
369  s |= ROL64(t, 34);
370  t = ipbox[(state >> 48) & 0xFF];
371  s |= ROL64(t, 3);
372  t = ipbox[(state >> 56) & 0xFF];
373  s |= ROL64(t, 35);
374 
375  //Apply inverse S-box
376  state = isbox[s & 0xFF];
377  t = isbox[(s >> 8) & 0xFF];
378  state |= ROL64(t, 8);
379  t = isbox[(s >> 16) & 0xFF];
380  state |= ROL64(t, 16);
381  t = isbox[(s >> 24) & 0xFF];
382  state |= ROL64(t, 24);
383  t = isbox[(s >> 32) & 0xFF];
384  state |= ROL64(t, 32);
385  t = isbox[(s >> 40) & 0xFF];
386  state |= ROL64(t, 40);
387  t = isbox[(s >> 48) & 0xFF];
388  state |= ROL64(t, 48);
389  t = isbox[(s >> 56) & 0xFF];
390  state |= ROL64(t, 56);
391  }
392 
393  //Final round key addition
394  state ^= context->ks[0];
395 
396  //The final state is then copied to the output
397  STORE64BE(state, output);
398 }
399 
400 
401 /**
402  * @brief Release PRESENT context
403  * @param[in] context Pointer to the PRESENT context
404  **/
405 
407 {
408  //Clear PRESENT context
409  osMemset(context, 0, sizeof(PresentContext));
410 }
411 
412 #endif
unsigned int uint_t
Definition: compiler_port.h:50
#define LOAD64BE(p)
Definition: cpu_endian.h:246
#define STORE64BE(a, p)
Definition: cpu_endian.h:322
#define LOAD16BE(p)
Definition: cpu_endian.h:186
General definitions for cryptographic algorithms.
void(* CipherAlgoDeinit)(void *context)
Definition: crypto.h:983
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:980
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:968
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:977
#define ROL64(a, n)
Definition: crypto.h:777
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:932
error_t
Error codes.
Definition: error.h:43
@ ERROR_INVALID_KEY_LENGTH
Definition: error.h:107
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
uint8_t t
Definition: lldp_ext_med.h:212
uint8_t s
Definition: ndp.h:345
#define osMemset(p, value, length)
Definition: os_port.h:135
void presentDeinit(PresentContext *context)
Release PRESENT context.
Definition: present.c:406
error_t presentInit(PresentContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: present.c:202
void presentDecryptBlock(PresentContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using PRESENT algorithm.
Definition: present.c:341
void presentEncryptBlock(PresentContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using PRESENT algorithm.
Definition: present.c:291
const CipherAlgo presentCipherAlgo
Definition: present.c:179
PRESENT encryption algorithm.
#define PRESENT_BLOCK_SIZE
Definition: present.h:38
Common interface for encryption algorithms.
Definition: crypto.h:1036
PRESENT algorithm context.
Definition: present.h:53
uint64_t ks[32]
Definition: present.h:54