blob: 2b097a13dd248c16d3384a98d41a5cf20f536248 [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 Rodgmanc04515b2023-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 Rodgman16799db2023-11-02 19:47:20 +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
Mateusz Starzyk846f0212021-05-19 19:44:07 +020017#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000018
Bence Szépkútic662b362021-05-27 11:25:03 +020019#include "mbedtls/build_info.h"
Mateusz Starzyke35f8f62021-08-04 15:38:09 +020020#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020021
Rich Evans00ab4702015-02-06 13:43:58 +000022#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020023#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000024
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#define MBEDTLS_DES_ENCRYPT 1
26#define MBEDTLS_DES_DECRYPT 0
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Gilles Peskined2971572021-07-26 18:48:10 +020028/** The data input has an invalid length. */
29#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
Ron Eldor9924bdc2018-10-04 10:59:13 +030030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#define MBEDTLS_DES_KEY_SIZE 8
Paul Bakker1f87fb62011-01-15 17:32:24 +000032
Paul Bakker407a0da2013-06-27 14:29:21 +020033#ifdef __cplusplus
34extern "C" {
35#endif
36
Ron Eldorb2aacec2017-05-18 16:53:08 +030037#if !defined(MBEDTLS_DES_ALT)
38// Regular implementation
39//
40
Paul Bakker5121ce52009-01-03 21:22:43 +000041/**
42 * \brief DES context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010043 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000044 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010045 * security risk. We recommend considering stronger ciphers
46 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000047 */
Gilles Peskine449bd832023-01-11 14:50:10 +010048typedef struct mbedtls_des_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020049 uint32_t MBEDTLS_PRIVATE(sk)[32]; /*!< DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000050}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051mbedtls_des_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000052
53/**
54 * \brief Triple-DES context structure
Dave Rodgmanc04515b2023-02-02 10:47:58 +000055 *
56 * \warning DES/3DES are considered weak ciphers and their use constitutes a
57 * security risk. We recommend considering stronger ciphers
58 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000059 */
Gilles Peskine449bd832023-01-11 14:50:10 +010060typedef struct mbedtls_des3_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020061 uint32_t MBEDTLS_PRIVATE(sk)[96]; /*!< 3DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000062}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063mbedtls_des3_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000064
Ron Eldor05d0e512018-04-16 17:40:04 +030065#else /* MBEDTLS_DES_ALT */
66#include "des_alt.h"
67#endif /* MBEDTLS_DES_ALT */
68
Paul Bakker5121ce52009-01-03 21:22:43 +000069/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020070 * \brief Initialize DES context
71 *
72 * \param ctx DES context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010073 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000074 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010075 * security risk. We recommend considering stronger ciphers
76 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020077 */
Gilles Peskine449bd832023-01-11 14:50:10 +010078void mbedtls_des_init(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020079
80/**
81 * \brief Clear DES context
82 *
83 * \param ctx DES context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010084 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000085 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010086 * security risk. We recommend considering stronger ciphers
87 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020088 */
Gilles Peskine449bd832023-01-11 14:50:10 +010089void mbedtls_des_free(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020090
91/**
92 * \brief Initialize Triple-DES context
93 *
94 * \param ctx DES3 context to be initialized
Dave Rodgmanc04515b2023-02-02 10:47:58 +000095 *
96 * \warning DES/3DES are considered weak ciphers and their use constitutes a
97 * security risk. We recommend considering stronger ciphers
98 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020099 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100100void mbedtls_des3_init(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200101
102/**
103 * \brief Clear Triple-DES context
104 *
105 * \param ctx DES3 context to be cleared
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000106 *
107 * \warning DES/3DES are considered weak ciphers and their use constitutes a
108 * security risk. We recommend considering stronger ciphers
109 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200110 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100111void mbedtls_des3_free(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200112
113/**
Paul Bakker1f87fb62011-01-15 17:32:24 +0000114 * \brief Set key parity on the given key to odd.
115 *
116 * DES keys are 56 bits long, but each byte is padded with
117 * a parity bit to allow verification.
118 *
119 * \param key 8-byte secret key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100120 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000121 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100122 * security risk. We recommend considering stronger ciphers
123 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000124 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100125void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000126
127/**
128 * \brief Check that key parity on the given key is odd.
129 *
130 * DES keys are 56 bits long, but each byte is padded with
131 * a parity bit to allow verification.
132 *
133 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000134 *
135 * \return 0 is parity was ok, 1 if parity was not correct.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100136 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000137 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100138 * security risk. We recommend considering stronger ciphers
139 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000140 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200141MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100142int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000143
Paul Bakker1f87fb62011-01-15 17:32:24 +0000144/**
145 * \brief Check that key is not a weak or semi-weak DES key
146 *
147 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000148 *
Paul Bakker4793cc42011-08-17 09:40:55 +0000149 * \return 0 if no weak key was found, 1 if a weak key was identified.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100150 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000151 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100152 * security risk. We recommend considering stronger ciphers
153 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000154 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200155MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100156int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000157
158/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000159 * \brief DES key schedule (56-bit, encryption)
160 *
161 * \param ctx DES context to be initialized
162 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000163 *
164 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100165 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000166 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100167 * security risk. We recommend considering stronger ciphers
168 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000169 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200170MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100171int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000172
173/**
174 * \brief DES key schedule (56-bit, decryption)
175 *
176 * \param ctx DES context to be initialized
177 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000178 *
179 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100180 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000181 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100182 * security risk. We recommend considering stronger ciphers
183 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000184 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200185MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100186int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000187
188/**
189 * \brief Triple-DES key schedule (112-bit, encryption)
190 *
191 * \param ctx 3DES context to be initialized
192 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000193 *
194 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000195 *
196 * \warning DES/3DES are considered weak ciphers and their use constitutes a
197 * security risk. We recommend considering stronger ciphers
198 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000199 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200200MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100201int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
202 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000203
204/**
205 * \brief Triple-DES key schedule (112-bit, decryption)
206 *
207 * \param ctx 3DES context to be initialized
208 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000209 *
210 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000211 *
212 * \warning DES/3DES are considered weak ciphers and their use constitutes a
213 * security risk. We recommend considering stronger ciphers
214 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000215 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200216MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100217int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
218 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000219
220/**
221 * \brief Triple-DES key schedule (168-bit, encryption)
222 *
223 * \param ctx 3DES context to be initialized
224 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000225 *
226 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000227 *
228 * \warning DES/3DES are considered weak ciphers and their use constitutes a
229 * security risk. We recommend considering stronger ciphers
230 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000231 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200232MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100233int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
234 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000235
236/**
237 * \brief Triple-DES key schedule (168-bit, decryption)
238 *
239 * \param ctx 3DES context to be initialized
240 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000241 *
242 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000243 *
244 * \warning DES/3DES are considered weak ciphers and their use constitutes a
245 * security risk. We recommend considering stronger ciphers
246 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000247 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200248MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100249int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
250 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000251
252/**
253 * \brief DES-ECB block encryption/decryption
254 *
255 * \param ctx DES context
256 * \param input 64-bit input block
257 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000258 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000259 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100260 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000261 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100262 * security risk. We recommend considering stronger ciphers
263 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000264 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200265MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100266int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
267 const unsigned char input[8],
268 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000271/**
272 * \brief DES-CBC buffer encryption/decryption
273 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000274 * \note Upon exit, the content of the IV is updated so that you can
275 * call the function same function again on the following
276 * block(s) of data and get the same result as if it was
277 * encrypted in one call. This allows a "streaming" usage.
278 * If on the other hand you need to retain the contents of the
279 * IV, you should either save it manually or use the cipher
280 * module instead.
281 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 * \param ctx DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000284 * \param length length of the input data
285 * \param iv initialization vector (updated after use)
286 * \param input buffer holding the input data
287 * \param output buffer holding the output data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100288 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000289 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100290 * security risk. We recommend considering stronger ciphers
291 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000292 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200293MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100294int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
295 int mode,
296 size_t length,
297 unsigned char iv[8],
298 const unsigned char *input,
299 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000301
302/**
303 * \brief 3DES-ECB block encryption/decryption
304 *
305 * \param ctx 3DES context
306 * \param input 64-bit input block
307 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000308 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000309 * \return 0 if successful
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000310 *
311 * \warning DES/3DES are considered weak ciphers and their use constitutes a
312 * security risk. We recommend considering stronger ciphers
313 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000314 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200315MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100316int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
317 const unsigned char input[8],
318 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000319
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000321/**
322 * \brief 3DES-CBC buffer encryption/decryption
323 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000324 * \note Upon exit, the content of the IV is updated so that you can
325 * call the function same function again on the following
326 * block(s) of data and get the same result as if it was
327 * encrypted in one call. This allows a "streaming" usage.
328 * If on the other hand you need to retain the contents of the
329 * IV, you should either save it manually or use the cipher
330 * module instead.
331 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000332 * \param ctx 3DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000334 * \param length length of the input data
335 * \param iv initialization vector (updated after use)
336 * \param input buffer holding the input data
337 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000338 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339 * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000340 *
341 * \warning DES/3DES are considered weak ciphers and their use constitutes a
342 * security risk. We recommend considering stronger ciphers
343 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000344 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200345MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100346int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
347 int mode,
348 size_t length,
349 unsigned char iv[8],
350 const unsigned char *input,
351 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000353
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200354/**
355 * \brief Internal function for key expansion.
356 * (Only exposed to allow overriding it,
357 * see MBEDTLS_DES_SETKEY_ALT)
358 *
359 * \param SK Round keys
360 * \param key Base key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100361 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000362 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100363 * security risk. We recommend considering stronger ciphers
364 * instead.
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200365 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100366void mbedtls_des_setkey(uint32_t SK[32],
367 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker90995b52013-06-24 19:20:35 +0200368
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500369#if defined(MBEDTLS_SELF_TEST)
370
Paul Bakker9a736322012-11-14 12:39:52 +0000371/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000372 * \brief Checkup routine
373 *
374 * \return 0 if successful, or 1 if the test failed
375 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200376MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100377int mbedtls_des_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000378
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500379#endif /* MBEDTLS_SELF_TEST */
380
Paul Bakker5121ce52009-01-03 21:22:43 +0000381#ifdef __cplusplus
382}
383#endif
384
385#endif /* des.h */