cast128.h
Go to the documentation of this file.
1 /**
2  * @file cast128.h
3  * @brief CAST-128 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 _CAST128_H
32 #define _CAST128_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //CAST-128 block size
38 #define CAST128_BLOCK_SIZE 8
39 //Common interface for encryption algorithms
40 #define CAST128_CIPHER_ALGO (&cast128CipherAlgo)
41 
42 //C++ guard
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
48 /**
49  * @brief CAST-128 algorithm context
50  **/
51 
52 typedef struct
53 {
55  uint32_t km[16];
56  uint32_t kr[16];
58 
59 
60 //CAST-128 related constants
61 extern const CipherAlgo cast128CipherAlgo;
62 
63 //CAST-128 related functions
64 error_t cast128Init(Cast128Context *context, const uint8_t *key, size_t keyLen);
65 
66 void cast128EncryptBlock(Cast128Context *context, const uint8_t *input,
67  uint8_t *output);
68 
69 void cast128DecryptBlock(Cast128Context *context, const uint8_t *input,
70  uint8_t *output);
71 
72 void cast128Deinit(Cast128Context *context);
73 
74 //C++ guard
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif
error_t cast128Init(Cast128Context *context, const uint8_t *key, size_t keyLen)
Key expansion.
Definition: cast128.c:398
void cast128EncryptBlock(Cast128Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using CAST-128 algorithm.
Definition: cast128.c:505
void cast128Deinit(Cast128Context *context)
Release CAST-128 context.
Definition: cast128.c:595
void cast128DecryptBlock(Cast128Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using CAST-128 algorithm.
Definition: cast128.c:551
const CipherAlgo cast128CipherAlgo
Definition: cast128.c:375
unsigned int uint_t
Definition: compiler_port.h:50
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
CAST-128 algorithm context.
Definition: cast128.h:53
uint_t nr
Definition: cast128.h:54
Common interface for encryption algorithms.
Definition: crypto.h:1036