des.h
Go to the documentation of this file.
1 /**
2  * @file des.h
3  * @brief DES (Data Encryption Standard)
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 _DES_H
32 #define _DES_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef DES_PRIVATE_CONTEXT
39  #define DES_PRIVATE_CONTEXT
40 #endif
41 
42 //DES block size
43 #define DES_BLOCK_SIZE 8
44 //Common interface for encryption algorithms
45 #define DES_CIPHER_ALGO (&desCipherAlgo)
46 
47 //C++ guard
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 
53 /**
54  * @brief DES algorithm context
55  **/
56 
57 typedef struct
58 {
59  uint32_t ks[32];
61 } DesContext;
62 
63 
64 //DES related constants
65 extern const uint8_t DES_CBC_OID[5];
66 extern const CipherAlgo desCipherAlgo;
67 
68 //DES related functions
69 error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen);
70 
71 void desEncryptBlock(DesContext *context, const uint8_t *input,
72  uint8_t *output);
73 
74 void desDecryptBlock(DesContext *context, const uint8_t *input,
75  uint8_t *output);
76 
77 void desDeinit(DesContext *context);
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
General definitions for cryptographic algorithms.
void desDeinit(DesContext *context)
Release DES context.
Definition: des.c:429
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
Definition: des.c:391
const CipherAlgo desCipherAlgo
Definition: des.c:273
#define DES_PRIVATE_CONTEXT
Definition: des.h:39
const uint8_t DES_CBC_OID[5]
Definition: des.c:270
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using DES algorithm.
Definition: des.c:351
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.
Definition: des.c:296
error_t
Error codes.
Definition: error.h:43
Common interface for encryption algorithms.
Definition: crypto.h:1036
DES algorithm context.
Definition: des.h:58