blob: f445102d9d4c598e56a7ebe6ca0b28f893e88933 [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000025 *
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#ifndef MBEDTLS_DES_H
28#define MBEDTLS_DES_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020029#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Bence Szépkútic662b362021-05-27 11:25:03 +020031#include "mbedtls/build_info.h"
Mateusz Starzyke35f8f62021-08-04 15:38:09 +020032#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020033
Rich Evans00ab4702015-02-06 13:43:58 +000034#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020035#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000036
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#define MBEDTLS_DES_ENCRYPT 1
38#define MBEDTLS_DES_DECRYPT 0
Paul Bakker5121ce52009-01-03 21:22:43 +000039
Gilles Peskined2971572021-07-26 18:48:10 +020040/** The data input has an invalid length. */
41#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
Ron Eldor9924bdc2018-10-04 10:59:13 +030042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#define MBEDTLS_DES_KEY_SIZE 8
Paul Bakker1f87fb62011-01-15 17:32:24 +000044
Paul Bakker407a0da2013-06-27 14:29:21 +020045#ifdef __cplusplus
46extern "C" {
47#endif
48
Ron Eldorb2aacec2017-05-18 16:53:08 +030049#if !defined(MBEDTLS_DES_ALT)
50// Regular implementation
51//
52
Paul Bakker5121ce52009-01-03 21:22:43 +000053/**
54 * \brief DES context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010055 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000056 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010057 * 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_des_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020061 uint32_t MBEDTLS_PRIVATE(sk)[32]; /*!< DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000062}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063mbedtls_des_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000064
65/**
66 * \brief Triple-DES context structure
Dave Rodgmanc04515b2023-02-02 10:47:58 +000067 *
68 * \warning DES/3DES are considered weak ciphers and their use constitutes a
69 * security risk. We recommend considering stronger ciphers
70 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000071 */
Gilles Peskine449bd832023-01-11 14:50:10 +010072typedef struct mbedtls_des3_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020073 uint32_t MBEDTLS_PRIVATE(sk)[96]; /*!< 3DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000074}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075mbedtls_des3_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000076
Ron Eldor05d0e512018-04-16 17:40:04 +030077#else /* MBEDTLS_DES_ALT */
78#include "des_alt.h"
79#endif /* MBEDTLS_DES_ALT */
80
Paul Bakker5121ce52009-01-03 21:22:43 +000081/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020082 * \brief Initialize DES context
83 *
84 * \param ctx DES context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010085 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000086 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010087 * security risk. We recommend considering stronger ciphers
88 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020089 */
Gilles Peskine449bd832023-01-11 14:50:10 +010090void mbedtls_des_init(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020091
92/**
93 * \brief Clear DES context
94 *
95 * \param ctx DES context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010096 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +000097 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010098 * security risk. We recommend considering stronger ciphers
99 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200100 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100101void mbedtls_des_free(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200102
103/**
104 * \brief Initialize Triple-DES context
105 *
106 * \param ctx DES3 context to be initialized
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000107 *
108 * \warning DES/3DES are considered weak ciphers and their use constitutes a
109 * security risk. We recommend considering stronger ciphers
110 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200111 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100112void mbedtls_des3_init(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200113
114/**
115 * \brief Clear Triple-DES context
116 *
117 * \param ctx DES3 context to be cleared
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000118 *
119 * \warning DES/3DES are considered weak ciphers and their use constitutes a
120 * security risk. We recommend considering stronger ciphers
121 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200122 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100123void mbedtls_des3_free(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200124
125/**
Paul Bakker1f87fb62011-01-15 17:32:24 +0000126 * \brief Set key parity on the given key to odd.
127 *
128 * DES keys are 56 bits long, but each byte is padded with
129 * a parity bit to allow verification.
130 *
131 * \param key 8-byte secret key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100132 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000133 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100134 * security risk. We recommend considering stronger ciphers
135 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000136 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100137void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000138
139/**
140 * \brief Check that key parity on the given key is odd.
141 *
142 * DES keys are 56 bits long, but each byte is padded with
143 * a parity bit to allow verification.
144 *
145 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000146 *
147 * \return 0 is parity was ok, 1 if parity was not correct.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100148 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000149 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100150 * security risk. We recommend considering stronger ciphers
151 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000152 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200153MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100154int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000155
Paul Bakker1f87fb62011-01-15 17:32:24 +0000156/**
157 * \brief Check that key is not a weak or semi-weak DES key
158 *
159 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000160 *
Paul Bakker4793cc42011-08-17 09:40:55 +0000161 * \return 0 if no weak key was found, 1 if a weak key was identified.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100162 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000163 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100164 * security risk. We recommend considering stronger ciphers
165 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000166 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200167MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100168int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000169
170/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000171 * \brief DES key schedule (56-bit, encryption)
172 *
173 * \param ctx DES context to be initialized
174 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000175 *
176 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100177 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000178 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100179 * security risk. We recommend considering stronger ciphers
180 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000181 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200182MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100183int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000184
185/**
186 * \brief DES key schedule (56-bit, decryption)
187 *
188 * \param ctx DES context to be initialized
189 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000190 *
191 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100192 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000193 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100194 * security risk. We recommend considering stronger ciphers
195 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000196 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200197MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100198int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000199
200/**
201 * \brief Triple-DES key schedule (112-bit, encryption)
202 *
203 * \param ctx 3DES context to be initialized
204 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000205 *
206 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000207 *
208 * \warning DES/3DES are considered weak ciphers and their use constitutes a
209 * security risk. We recommend considering stronger ciphers
210 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000211 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200212MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100213int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
214 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000215
216/**
217 * \brief Triple-DES key schedule (112-bit, decryption)
218 *
219 * \param ctx 3DES context to be initialized
220 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000221 *
222 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000223 *
224 * \warning DES/3DES are considered weak ciphers and their use constitutes a
225 * security risk. We recommend considering stronger ciphers
226 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000227 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200228MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100229int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
230 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000231
232/**
233 * \brief Triple-DES key schedule (168-bit, encryption)
234 *
235 * \param ctx 3DES context to be initialized
236 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000237 *
238 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000239 *
240 * \warning DES/3DES are considered weak ciphers and their use constitutes a
241 * security risk. We recommend considering stronger ciphers
242 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000243 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200244MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100245int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
246 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000247
248/**
249 * \brief Triple-DES key schedule (168-bit, decryption)
250 *
251 * \param ctx 3DES context to be initialized
252 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000253 *
254 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000255 *
256 * \warning DES/3DES are considered weak ciphers and their use constitutes a
257 * security risk. We recommend considering stronger ciphers
258 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000259 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200260MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100261int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
262 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000263
264/**
265 * \brief DES-ECB block encryption/decryption
266 *
267 * \param ctx DES context
268 * \param input 64-bit input block
269 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000270 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000271 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100272 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000273 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100274 * security risk. We recommend considering stronger ciphers
275 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000276 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200277MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100278int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
279 const unsigned char input[8],
280 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000283/**
284 * \brief DES-CBC buffer encryption/decryption
285 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000286 * \note Upon exit, the content of the IV is updated so that you can
287 * call the function same function again on the following
288 * block(s) of data and get the same result as if it was
289 * encrypted in one call. This allows a "streaming" usage.
290 * If on the other hand you need to retain the contents of the
291 * IV, you should either save it manually or use the cipher
292 * module instead.
293 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000294 * \param ctx DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000296 * \param length length of the input data
297 * \param iv initialization vector (updated after use)
298 * \param input buffer holding the input data
299 * \param output buffer holding the output data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100300 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000301 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100302 * security risk. We recommend considering stronger ciphers
303 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000304 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200305MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100306int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
307 int mode,
308 size_t length,
309 unsigned char iv[8],
310 const unsigned char *input,
311 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000313
314/**
315 * \brief 3DES-ECB block encryption/decryption
316 *
317 * \param ctx 3DES context
318 * \param input 64-bit input block
319 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000320 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000321 * \return 0 if successful
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000322 *
323 * \warning DES/3DES are considered weak ciphers and their use constitutes a
324 * security risk. We recommend considering stronger ciphers
325 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000326 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200327MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100328int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
329 const unsigned char input[8],
330 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000331
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000333/**
334 * \brief 3DES-CBC buffer encryption/decryption
335 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000336 * \note Upon exit, the content of the IV is updated so that you can
337 * call the function same function again on the following
338 * block(s) of data and get the same result as if it was
339 * encrypted in one call. This allows a "streaming" usage.
340 * If on the other hand you need to retain the contents of the
341 * IV, you should either save it manually or use the cipher
342 * module instead.
343 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000344 * \param ctx 3DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000346 * \param length length of the input data
347 * \param iv initialization vector (updated after use)
348 * \param input buffer holding the input data
349 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000350 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351 * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000352 *
353 * \warning DES/3DES are considered weak ciphers and their use constitutes a
354 * security risk. We recommend considering stronger ciphers
355 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000356 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200357MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100358int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
359 int mode,
360 size_t length,
361 unsigned char iv[8],
362 const unsigned char *input,
363 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000365
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200366/**
367 * \brief Internal function for key expansion.
368 * (Only exposed to allow overriding it,
369 * see MBEDTLS_DES_SETKEY_ALT)
370 *
371 * \param SK Round keys
372 * \param key Base key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100373 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000374 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100375 * security risk. We recommend considering stronger ciphers
376 * instead.
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200377 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100378void mbedtls_des_setkey(uint32_t SK[32],
379 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker90995b52013-06-24 19:20:35 +0200380
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500381#if defined(MBEDTLS_SELF_TEST)
382
Paul Bakker9a736322012-11-14 12:39:52 +0000383/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000384 * \brief Checkup routine
385 *
386 * \return 0 if successful, or 1 if the test failed
387 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200388MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100389int mbedtls_des_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000390
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500391#endif /* MBEDTLS_SELF_TEST */
392
Paul Bakker5121ce52009-01-03 21:22:43 +0000393#ifdef __cplusplus
394}
395#endif
396
397#endif /* des.h */