blob: 031b9cf271823d29b2420403ff3fa58cdfe7575a [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file des.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerf3b86c12011-01-27 15:24:17 +00004 * \brief DES block cipher
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +00006 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +01007 * security risk. We recommend considering stronger ciphers
8 * instead.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakkerb96f1542010-07-18 20:36:00 +000013 *
Paul Bakker5121ce52009-01-03 21:22:43 +000014 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015#ifndef MBEDTLS_DES_H
16#define MBEDTLS_DES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020018#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010019#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020020#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020021#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020022#endif
Gilles Peskine7b8571f2021-07-07 21:02:36 +020023#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020024
Rich Evans00ab4702015-02-06 13:43:58 +000025#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020026#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#define MBEDTLS_DES_ENCRYPT 1
29#define MBEDTLS_DES_DECRYPT 0
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Gilles Peskinea3974432021-07-26 18:48:10 +020031/** The data input has an invalid length. */
32#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
Ron Eldor9924bdc2018-10-04 10:59:13 +030033
34/* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020035/** DES hardware accelerator failed. */
36#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
Paul Bakkerf3ccc682010-03-18 21:21:02 +000037
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020038#define MBEDTLS_DES_KEY_SIZE 8
Paul Bakker1f87fb62011-01-15 17:32:24 +000039
Paul Bakker407a0da2013-06-27 14:29:21 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Ron Eldorb2aacec2017-05-18 16:53:08 +030044#if !defined(MBEDTLS_DES_ALT)
45// Regular implementation
46//
47
Paul Bakker5121ce52009-01-03 21:22:43 +000048/**
49 * \brief DES context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010050 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000051 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010052 * security risk. We recommend considering stronger ciphers
53 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000054 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010055typedef struct mbedtls_des_context {
Paul Bakker5c2364c2012-10-01 14:41:15 +000056 uint32_t sk[32]; /*!< DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000057}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058mbedtls_des_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000059
60/**
61 * \brief Triple-DES context structure
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000062 *
63 * \warning DES/3DES are considered weak ciphers and their use constitutes a
64 * security risk. We recommend considering stronger ciphers
65 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000066 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010067typedef struct mbedtls_des3_context {
Paul Bakker5c2364c2012-10-01 14:41:15 +000068 uint32_t sk[96]; /*!< 3DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000069}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070mbedtls_des3_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Ron Eldor05d0e512018-04-16 17:40:04 +030072#else /* MBEDTLS_DES_ALT */
73#include "des_alt.h"
74#endif /* MBEDTLS_DES_ALT */
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020077 * \brief Initialize DES context
78 *
79 * \param ctx DES context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010080 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000081 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010082 * security risk. We recommend considering stronger ciphers
83 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020084 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010085void mbedtls_des_init(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020086
87/**
88 * \brief Clear DES context
89 *
90 * \param ctx DES context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010091 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000092 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010093 * security risk. We recommend considering stronger ciphers
94 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020095 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010096void mbedtls_des_free(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020097
98/**
99 * \brief Initialize Triple-DES context
100 *
101 * \param ctx DES3 context to be initialized
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000102 *
103 * \warning DES/3DES are considered weak ciphers and their use constitutes a
104 * security risk. We recommend considering stronger ciphers
105 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200106 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100107void mbedtls_des3_init(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200108
109/**
110 * \brief Clear Triple-DES context
111 *
112 * \param ctx DES3 context to be cleared
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000113 *
114 * \warning DES/3DES are considered weak ciphers and their use constitutes a
115 * security risk. We recommend considering stronger ciphers
116 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200117 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100118void mbedtls_des3_free(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200119
120/**
Paul Bakker1f87fb62011-01-15 17:32:24 +0000121 * \brief Set key parity on the given key to odd.
122 *
123 * DES keys are 56 bits long, but each byte is padded with
124 * a parity bit to allow verification.
125 *
126 * \param key 8-byte secret key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100127 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000128 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100129 * security risk. We recommend considering stronger ciphers
130 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000131 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100132void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000133
134/**
135 * \brief Check that key parity on the given key is odd.
136 *
137 * DES keys are 56 bits long, but each byte is padded with
138 * a parity bit to allow verification.
139 *
140 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000141 *
142 * \return 0 is parity was ok, 1 if parity was not correct.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100143 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000144 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100145 * security risk. We recommend considering stronger ciphers
146 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000147 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200148MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100149int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000150
Paul Bakker1f87fb62011-01-15 17:32:24 +0000151/**
152 * \brief Check that key is not a weak or semi-weak DES key
153 *
154 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000155 *
Paul Bakker4793cc42011-08-17 09:40:55 +0000156 * \return 0 if no weak key was found, 1 if a weak key was identified.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100157 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000158 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100159 * security risk. We recommend considering stronger ciphers
160 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000161 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200162MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100163int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000164
165/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000166 * \brief DES key schedule (56-bit, encryption)
167 *
168 * \param ctx DES context to be initialized
169 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000170 *
171 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100172 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000173 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100174 * security risk. We recommend considering stronger ciphers
175 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000176 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200177MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100178int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000179
180/**
181 * \brief DES key schedule (56-bit, decryption)
182 *
183 * \param ctx DES context to be initialized
184 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000185 *
186 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100187 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000188 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100189 * security risk. We recommend considering stronger ciphers
190 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000191 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200192MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100193int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000194
195/**
196 * \brief Triple-DES key schedule (112-bit, encryption)
197 *
198 * \param ctx 3DES context to be initialized
199 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000200 *
201 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000202 *
203 * \warning DES/3DES are considered weak ciphers and their use constitutes a
204 * security risk. We recommend considering stronger ciphers
205 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200207MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100208int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
209 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000210
211/**
212 * \brief Triple-DES key schedule (112-bit, decryption)
213 *
214 * \param ctx 3DES context to be initialized
215 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000216 *
217 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000218 *
219 * \warning DES/3DES are considered weak ciphers and their use constitutes a
220 * security risk. We recommend considering stronger ciphers
221 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000222 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200223MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100224int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
225 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000226
227/**
228 * \brief Triple-DES key schedule (168-bit, encryption)
229 *
230 * \param ctx 3DES context to be initialized
231 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000232 *
233 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000234 *
235 * \warning DES/3DES are considered weak ciphers and their use constitutes a
236 * security risk. We recommend considering stronger ciphers
237 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000238 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200239MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100240int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
241 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000242
243/**
244 * \brief Triple-DES key schedule (168-bit, decryption)
245 *
246 * \param ctx 3DES context to be initialized
247 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000248 *
249 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000250 *
251 * \warning DES/3DES are considered weak ciphers and their use constitutes a
252 * security risk. We recommend considering stronger ciphers
253 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000254 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200255MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100256int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
257 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000258
259/**
260 * \brief DES-ECB block encryption/decryption
261 *
262 * \param ctx DES context
263 * \param input 64-bit input block
264 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000265 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000266 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100267 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000268 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100269 * security risk. We recommend considering stronger ciphers
270 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000271 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200272MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100273int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
274 const unsigned char input[8],
275 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000278/**
279 * \brief DES-CBC buffer encryption/decryption
280 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000281 * \note Upon exit, the content of the IV is updated so that you can
282 * call the function same function again on the following
283 * block(s) of data and get the same result as if it was
284 * encrypted in one call. This allows a "streaming" usage.
285 * If on the other hand you need to retain the contents of the
286 * IV, you should either save it manually or use the cipher
287 * module instead.
288 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000289 * \param ctx DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000291 * \param length length of the input data
292 * \param iv initialization vector (updated after use)
293 * \param input buffer holding the input data
294 * \param output buffer holding the output data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100295 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000296 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100297 * security risk. We recommend considering stronger ciphers
298 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000299 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200300MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100301int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
302 int mode,
303 size_t length,
304 unsigned char iv[8],
305 const unsigned char *input,
306 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000308
309/**
310 * \brief 3DES-ECB block encryption/decryption
311 *
312 * \param ctx 3DES context
313 * \param input 64-bit input block
314 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000315 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000316 * \return 0 if successful
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000317 *
318 * \warning DES/3DES are considered weak ciphers and their use constitutes a
319 * security risk. We recommend considering stronger ciphers
320 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000321 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200322MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100323int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
324 const unsigned char input[8],
325 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000326
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200327#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000328/**
329 * \brief 3DES-CBC buffer encryption/decryption
330 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000331 * \note Upon exit, the content of the IV is updated so that you can
332 * call the function same function again on the following
333 * block(s) of data and get the same result as if it was
334 * encrypted in one call. This allows a "streaming" usage.
335 * If on the other hand you need to retain the contents of the
336 * IV, you should either save it manually or use the cipher
337 * module instead.
338 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000339 * \param ctx 3DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000341 * \param length length of the input data
342 * \param iv initialization vector (updated after use)
343 * \param input buffer holding the input data
344 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000345 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346 * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000347 *
348 * \warning DES/3DES are considered weak ciphers and their use constitutes a
349 * security risk. We recommend considering stronger ciphers
350 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000351 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200352MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100353int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
354 int mode,
355 size_t length,
356 unsigned char iv[8],
357 const unsigned char *input,
358 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200359#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000360
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200361/**
362 * \brief Internal function for key expansion.
363 * (Only exposed to allow overriding it,
364 * see MBEDTLS_DES_SETKEY_ALT)
365 *
366 * \param SK Round keys
367 * \param key Base key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100368 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000369 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100370 * security risk. We recommend considering stronger ciphers
371 * instead.
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200372 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100373void mbedtls_des_setkey(uint32_t SK[32],
374 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker90995b52013-06-24 19:20:35 +0200375
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500376#if defined(MBEDTLS_SELF_TEST)
377
Paul Bakker9a736322012-11-14 12:39:52 +0000378/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000379 * \brief Checkup routine
380 *
381 * \return 0 if successful, or 1 if the test failed
382 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200383MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100384int mbedtls_des_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000385
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500386#endif /* MBEDTLS_SELF_TEST */
387
Paul Bakker5121ce52009-01-03 21:22:43 +0000388#ifdef __cplusplus
389}
390#endif
391
392#endif /* des.h */