blob: f2bc58138e8f77b3bbf371afdf49990e888f6081 [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
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
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010031#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#endif
Gilles Peskine7b8571f2021-07-07 21:02:36 +020035#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020036
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020038#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000039
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#define MBEDTLS_DES_ENCRYPT 1
41#define MBEDTLS_DES_DECRYPT 0
Paul Bakker5121ce52009-01-03 21:22:43 +000042
Gilles Peskinea3974432021-07-26 18:48:10 +020043/** The data input has an invalid length. */
44#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
Ron Eldor9924bdc2018-10-04 10:59:13 +030045
46/* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020047/** DES hardware accelerator failed. */
48#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
Paul Bakkerf3ccc682010-03-18 21:21:02 +000049
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#define MBEDTLS_DES_KEY_SIZE 8
Paul Bakker1f87fb62011-01-15 17:32:24 +000051
Paul Bakker407a0da2013-06-27 14:29:21 +020052#ifdef __cplusplus
53extern "C" {
54#endif
55
Ron Eldorb2aacec2017-05-18 16:53:08 +030056#if !defined(MBEDTLS_DES_ALT)
57// Regular implementation
58//
59
Paul Bakker5121ce52009-01-03 21:22:43 +000060/**
61 * \brief DES context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010062 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000063 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010064 * 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_des_context {
Paul Bakker5c2364c2012-10-01 14:41:15 +000068 uint32_t sk[32]; /*!< DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000069}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070mbedtls_des_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000071
72/**
73 * \brief Triple-DES context structure
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000074 *
75 * \warning DES/3DES are considered weak ciphers and their use constitutes a
76 * security risk. We recommend considering stronger ciphers
77 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +000078 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010079typedef struct mbedtls_des3_context {
Paul Bakker5c2364c2012-10-01 14:41:15 +000080 uint32_t sk[96]; /*!< 3DES subkeys */
Paul Bakker5121ce52009-01-03 21:22:43 +000081}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082mbedtls_des3_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000083
Ron Eldor05d0e512018-04-16 17:40:04 +030084#else /* MBEDTLS_DES_ALT */
85#include "des_alt.h"
86#endif /* MBEDTLS_DES_ALT */
87
Paul Bakker5121ce52009-01-03 21:22:43 +000088/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020089 * \brief Initialize DES context
90 *
91 * \param ctx DES context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010092 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +000093 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +010094 * security risk. We recommend considering stronger ciphers
95 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020096 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010097void mbedtls_des_init(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020098
99/**
100 * \brief Clear DES context
101 *
102 * \param ctx DES context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100103 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000104 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100105 * security risk. We recommend considering stronger ciphers
106 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200107 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100108void mbedtls_des_free(mbedtls_des_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200109
110/**
111 * \brief Initialize Triple-DES context
112 *
113 * \param ctx DES3 context to be initialized
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000114 *
115 * \warning DES/3DES are considered weak ciphers and their use constitutes a
116 * security risk. We recommend considering stronger ciphers
117 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100119void mbedtls_des3_init(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200120
121/**
122 * \brief Clear Triple-DES context
123 *
124 * \param ctx DES3 context to be cleared
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000125 *
126 * \warning DES/3DES are considered weak ciphers and their use constitutes a
127 * security risk. We recommend considering stronger ciphers
128 * instead.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200129 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100130void mbedtls_des3_free(mbedtls_des3_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200131
132/**
Paul Bakker1f87fb62011-01-15 17:32:24 +0000133 * \brief Set key parity on the given key to odd.
134 *
135 * DES keys are 56 bits long, but each byte is padded with
136 * a parity bit to allow verification.
137 *
138 * \param key 8-byte secret key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100139 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000140 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100141 * security risk. We recommend considering stronger ciphers
142 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000143 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100144void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000145
146/**
147 * \brief Check that key parity on the given key is odd.
148 *
149 * DES keys are 56 bits long, but each byte is padded with
150 * a parity bit to allow verification.
151 *
152 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000153 *
154 * \return 0 is parity was ok, 1 if parity was not correct.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100155 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000156 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100157 * security risk. We recommend considering stronger ciphers
158 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000159 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200160MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100161int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000162
Paul Bakker1f87fb62011-01-15 17:32:24 +0000163/**
164 * \brief Check that key is not a weak or semi-weak DES key
165 *
166 * \param key 8-byte secret key
Paul Bakker73206952011-07-06 14:37:33 +0000167 *
Paul Bakker4793cc42011-08-17 09:40:55 +0000168 * \return 0 if no weak key was found, 1 if a weak key was identified.
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100169 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000170 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100171 * security risk. We recommend considering stronger ciphers
172 * instead.
Paul Bakker1f87fb62011-01-15 17:32:24 +0000173 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200174MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100175int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker1f87fb62011-01-15 17:32:24 +0000176
177/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000178 * \brief DES key schedule (56-bit, encryption)
179 *
180 * \param ctx DES context to be initialized
181 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000182 *
183 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100184 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000185 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100186 * security risk. We recommend considering stronger ciphers
187 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000188 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200189MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100190int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000191
192/**
193 * \brief DES key schedule (56-bit, decryption)
194 *
195 * \param ctx DES context to be initialized
196 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000197 *
198 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100199 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000200 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100201 * security risk. We recommend considering stronger ciphers
202 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000203 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200204MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100205int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000206
207/**
208 * \brief Triple-DES key schedule (112-bit, encryption)
209 *
210 * \param ctx 3DES context to be initialized
211 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000212 *
213 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000214 *
215 * \warning DES/3DES are considered weak ciphers and their use constitutes a
216 * security risk. We recommend considering stronger ciphers
217 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000218 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200219MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100220int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
221 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000222
223/**
224 * \brief Triple-DES key schedule (112-bit, decryption)
225 *
226 * \param ctx 3DES context to be initialized
227 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000228 *
229 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000230 *
231 * \warning DES/3DES are considered weak ciphers and their use constitutes a
232 * security risk. We recommend considering stronger ciphers
233 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000234 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200235MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100236int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
237 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000238
239/**
240 * \brief Triple-DES key schedule (168-bit, encryption)
241 *
242 * \param ctx 3DES context to be initialized
243 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000244 *
245 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000246 *
247 * \warning DES/3DES are considered weak ciphers and their use constitutes a
248 * security risk. We recommend considering stronger ciphers
249 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000250 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200251MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100252int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
253 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000254
255/**
256 * \brief Triple-DES key schedule (168-bit, decryption)
257 *
258 * \param ctx 3DES context to be initialized
259 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000260 *
261 * \return 0
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000262 *
263 * \warning DES/3DES are considered weak ciphers and their use constitutes a
264 * security risk. We recommend considering stronger ciphers
265 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000266 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200267MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
269 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000270
271/**
272 * \brief DES-ECB block encryption/decryption
273 *
274 * \param ctx DES context
275 * \param input 64-bit input block
276 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000277 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000278 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100279 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000280 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100281 * security risk. We recommend considering stronger ciphers
282 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000283 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200284MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100285int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
286 const unsigned char input[8],
287 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000290/**
291 * \brief DES-CBC buffer encryption/decryption
292 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000293 * \note Upon exit, the content of the IV is updated so that you can
294 * call the function same function again on the following
295 * block(s) of data and get the same result as if it was
296 * encrypted in one call. This allows a "streaming" usage.
297 * If on the other hand you need to retain the contents of the
298 * IV, you should either save it manually or use the cipher
299 * module instead.
300 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000301 * \param ctx DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000303 * \param length length of the input data
304 * \param iv initialization vector (updated after use)
305 * \param input buffer holding the input data
306 * \param output buffer holding the output data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100307 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000308 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100309 * security risk. We recommend considering stronger ciphers
310 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000311 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200312MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100313int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
314 int mode,
315 size_t length,
316 unsigned char iv[8],
317 const unsigned char *input,
318 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000320
321/**
322 * \brief 3DES-ECB block encryption/decryption
323 *
324 * \param ctx 3DES context
325 * \param input 64-bit input block
326 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000327 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000328 * \return 0 if successful
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000329 *
330 * \warning DES/3DES are considered weak ciphers and their use constitutes a
331 * security risk. We recommend considering stronger ciphers
332 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000333 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200334MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100335int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
336 const unsigned char input[8],
337 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000340/**
341 * \brief 3DES-CBC buffer encryption/decryption
342 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000343 * \note Upon exit, the content of the IV is updated so that you can
344 * call the function same function again on the following
345 * block(s) of data and get the same result as if it was
346 * encrypted in one call. This allows a "streaming" usage.
347 * If on the other hand you need to retain the contents of the
348 * IV, you should either save it manually or use the cipher
349 * module instead.
350 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000351 * \param ctx 3DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000353 * \param length length of the input data
354 * \param iv initialization vector (updated after use)
355 * \param input buffer holding the input data
356 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000357 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358 * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000359 *
360 * \warning DES/3DES are considered weak ciphers and their use constitutes a
361 * security risk. We recommend considering stronger ciphers
362 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000363 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200364MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100365int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
366 int mode,
367 size_t length,
368 unsigned char iv[8],
369 const unsigned char *input,
370 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200371#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000372
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200373/**
374 * \brief Internal function for key expansion.
375 * (Only exposed to allow overriding it,
376 * see MBEDTLS_DES_SETKEY_ALT)
377 *
378 * \param SK Round keys
379 * \param key Base key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100380 *
Dave Rodgmanb43d5e72023-02-02 10:47:58 +0000381 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100382 * security risk. We recommend considering stronger ciphers
383 * instead.
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200384 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100385void mbedtls_des_setkey(uint32_t SK[32],
386 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker90995b52013-06-24 19:20:35 +0200387
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500388#if defined(MBEDTLS_SELF_TEST)
389
Paul Bakker9a736322012-11-14 12:39:52 +0000390/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000391 * \brief Checkup routine
392 *
393 * \return 0 if successful, or 1 if the test failed
394 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200395MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100396int mbedtls_des_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000397
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500398#endif /* MBEDTLS_SELF_TEST */
399
Paul Bakker5121ce52009-01-03 21:22:43 +0000400#ifdef __cplusplus
401}
402#endif
403
404#endif /* des.h */