xtea.h
Go to the documentation of this file.
1 /**
2  * @file xtea.h
3  * @brief XTEA (eXtended TEA)
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  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _XTEA_H
32 #define _XTEA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef XTEA_PRIVATE_CONTEXT
39  #define XTEA_PRIVATE_CONTEXT
40 #endif
41 
42 //XTEA block size
43 #define XTEA_BLOCK_SIZE 8
44 //XTEA number of rounds
45 #define XTEA_NB_ROUNDS 32
46 //Common interface for encryption algorithms
47 #define XTEA_CIPHER_ALGO (&xteaCipherAlgo)
48 
49 //C++ guard
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /**
56  * @brief XTEA algorithm context
57  **/
58 
59 typedef struct
60 {
61  uint32_t k[4];
63 } XteaContext;
64 
65 
66 //XTEA related constants
67 extern const CipherAlgo xteaCipherAlgo;
68 
69 //XTEA related functions
70 error_t xteaInit(XteaContext *context, const uint8_t *key, size_t keyLen);
71 
72 void xteaEncryptBlock(XteaContext *context, const uint8_t *input,
73  uint8_t *output);
74 
75 void xteaDecryptBlock(XteaContext *context, const uint8_t *input,
76  uint8_t *output);
77 
78 void xteaDeinit(XteaContext *context);
79 
80 //C++ guard
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
Common interface for encryption algorithms.
Definition: crypto.h:1036
XTEA algorithm context.
Definition: xtea.h:60
const CipherAlgo xteaCipherAlgo
Definition: xtea.c:46
void xteaDecryptBlock(XteaContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using XTEA algorithm.
Definition: xtea.c:134
void xteaEncryptBlock(XteaContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using XTEA algorithm.
Definition: xtea.c:98
#define XTEA_PRIVATE_CONTEXT
Definition: xtea.h:39
void xteaDeinit(XteaContext *context)
Release XTEA context.
Definition: xtea.c:168
error_t xteaInit(XteaContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: xtea.c:69