tea.h
Go to the documentation of this file.
1 /**
2  * @file tea.h
3  * @brief TEA (Tiny 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  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _TEA_H
32 #define _TEA_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef TEA_PRIVATE_CONTEXT
39  #define TEA_PRIVATE_CONTEXT
40 #endif
41 
42 //TEA block size
43 #define TEA_BLOCK_SIZE 8
44 //TEA number of rounds
45 #define TEA_NB_ROUNDS 32
46 //Common interface for encryption algorithms
47 #define TEA_CIPHER_ALGO (&teaCipherAlgo)
48 
49 //C++ guard
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /**
56  * @brief TEA algorithm context
57  **/
58 
59 typedef struct
60 {
61  uint32_t k[4];
63 } TeaContext;
64 
65 
66 //TEA related constants
67 extern const CipherAlgo teaCipherAlgo;
68 
69 //TEA related functions
70 error_t teaInit(TeaContext *context, const uint8_t *key, size_t keyLen);
71 
72 void teaEncryptBlock(TeaContext *context, const uint8_t *input,
73  uint8_t *output);
74 
75 void teaDecryptBlock(TeaContext *context, const uint8_t *input,
76  uint8_t *output);
77 
78 void teaDeinit(TeaContext *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
TEA algorithm context.
Definition: tea.h:60
const CipherAlgo teaCipherAlgo
Definition: tea.c:46
void teaDeinit(TeaContext *context)
Release TEA context.
Definition: tea.c:167
void teaEncryptBlock(TeaContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using TEA algorithm.
Definition: tea.c:97
error_t teaInit(TeaContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: tea.c:69
#define TEA_PRIVATE_CONTEXT
Definition: tea.h:39
void teaDecryptBlock(TeaContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using TEA algorithm.
Definition: tea.c:133