blob: f10ac90d755e6ce5c231794d256f03cba39c3d55 [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
Yanray Wang9141ad12023-08-24 14:53:16 +0800185#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
Paul Bakker5121ce52009-01-03 21:22:43 +0000186/**
187 * \brief DES key schedule (56-bit, decryption)
188 *
189 * \param ctx DES context to be initialized
190 * \param key 8-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000191 *
192 * \return 0
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100193 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000194 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100195 * security risk. We recommend considering stronger ciphers
196 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000197 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200198MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100199int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Yanray Wang9141ad12023-08-24 14:53:16 +0800200#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
Paul Bakker5121ce52009-01-03 21:22:43 +0000201
202/**
203 * \brief Triple-DES key schedule (112-bit, encryption)
204 *
205 * \param ctx 3DES context to be initialized
206 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000207 *
208 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000209 *
210 * \warning DES/3DES are considered weak ciphers and their use constitutes a
211 * security risk. We recommend considering stronger ciphers
212 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000213 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200214MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100215int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
216 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000217
Yanray Wang9141ad12023-08-24 14:53:16 +0800218#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
Paul Bakker5121ce52009-01-03 21:22:43 +0000219/**
220 * \brief Triple-DES key schedule (112-bit, decryption)
221 *
222 * \param ctx 3DES context to be initialized
223 * \param key 16-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000224 *
225 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000226 *
227 * \warning DES/3DES are considered weak ciphers and their use constitutes a
228 * security risk. We recommend considering stronger ciphers
229 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000230 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200231MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100232int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
233 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
Yanray Wang9141ad12023-08-24 14:53:16 +0800234#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
Paul Bakker5121ce52009-01-03 21:22:43 +0000235
236/**
237 * \brief Triple-DES key schedule (168-bit, encryption)
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_enc(mbedtls_des3_context *ctx,
250 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000251
Yanray Wang9141ad12023-08-24 14:53:16 +0800252#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
Paul Bakker5121ce52009-01-03 21:22:43 +0000253/**
254 * \brief Triple-DES key schedule (168-bit, decryption)
255 *
256 * \param ctx 3DES context to be initialized
257 * \param key 24-byte secret key
Paul Bakker8123e9d2011-01-06 15:37:30 +0000258 *
259 * \return 0
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000260 *
261 * \warning DES/3DES are considered weak ciphers and their use constitutes a
262 * 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_des3_set3key_dec(mbedtls_des3_context *ctx,
267 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
Yanray Wang9141ad12023-08-24 14:53:16 +0800268#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
Paul Bakker5121ce52009-01-03 21:22:43 +0000269
270/**
271 * \brief DES-ECB block encryption/decryption
272 *
273 * \param ctx DES context
274 * \param input 64-bit input block
275 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000276 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000277 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100278 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000279 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100280 * security risk. We recommend considering stronger ciphers
281 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200283MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100284int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
285 const unsigned char input[8],
286 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000287
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000289/**
290 * \brief DES-CBC buffer encryption/decryption
291 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000292 * \note Upon exit, the content of the IV is updated so that you can
293 * call the function same function again on the following
294 * block(s) of data and get the same result as if it was
295 * encrypted in one call. This allows a "streaming" usage.
296 * If on the other hand you need to retain the contents of the
297 * IV, you should either save it manually or use the cipher
298 * module instead.
299 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000300 * \param ctx DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000302 * \param length length of the input data
303 * \param iv initialization vector (updated after use)
304 * \param input buffer holding the input data
305 * \param output buffer holding the output data
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100306 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000307 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100308 * security risk. We recommend considering stronger ciphers
309 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000310 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200311MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100312int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
313 int mode,
314 size_t length,
315 unsigned char iv[8],
316 const unsigned char *input,
317 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000319
320/**
321 * \brief 3DES-ECB block encryption/decryption
322 *
323 * \param ctx 3DES context
324 * \param input 64-bit input block
325 * \param output 64-bit output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000326 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000327 * \return 0 if successful
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000328 *
329 * \warning DES/3DES are considered weak ciphers and their use constitutes a
330 * security risk. We recommend considering stronger ciphers
331 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000332 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200333MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100334int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
335 const unsigned char input[8],
336 unsigned char output[8]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000337
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000339/**
340 * \brief 3DES-CBC buffer encryption/decryption
341 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000342 * \note Upon exit, the content of the IV is updated so that you can
343 * call the function same function again on the following
344 * block(s) of data and get the same result as if it was
345 * encrypted in one call. This allows a "streaming" usage.
346 * If on the other hand you need to retain the contents of the
347 * IV, you should either save it manually or use the cipher
348 * module instead.
349 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000350 * \param ctx 3DES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351 * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000352 * \param length length of the input data
353 * \param iv initialization vector (updated after use)
354 * \param input buffer holding the input data
355 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000356 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357 * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000358 *
359 * \warning DES/3DES are considered weak ciphers and their use constitutes a
360 * security risk. We recommend considering stronger ciphers
361 * instead.
Paul Bakker5121ce52009-01-03 21:22:43 +0000362 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200363MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100364int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
365 int mode,
366 size_t length,
367 unsigned char iv[8],
368 const unsigned char *input,
369 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000371
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200372/**
373 * \brief Internal function for key expansion.
374 * (Only exposed to allow overriding it,
375 * see MBEDTLS_DES_SETKEY_ALT)
376 *
377 * \param SK Round keys
378 * \param key Base key
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100379 *
Dave Rodgmanc04515b2023-02-02 10:47:58 +0000380 * \warning DES/3DES are considered weak ciphers and their use constitutes a
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100381 * security risk. We recommend considering stronger ciphers
382 * instead.
Manuel Pégourié-Gonnard70a50102015-05-12 15:02:45 +0200383 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100384void mbedtls_des_setkey(uint32_t SK[32],
385 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
Paul Bakker90995b52013-06-24 19:20:35 +0200386
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500387#if defined(MBEDTLS_SELF_TEST)
388
Paul Bakker9a736322012-11-14 12:39:52 +0000389/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000390 * \brief Checkup routine
391 *
392 * \return 0 if successful, or 1 if the test failed
393 */
Gilles Peskinee41803a2021-09-23 17:35:37 +0200394MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine449bd832023-01-11 14:50:10 +0100395int mbedtls_des_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000396
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500397#endif /* MBEDTLS_SELF_TEST */
398
Paul Bakker5121ce52009-01-03 21:22:43 +0000399#ifdef __cplusplus
400}
401#endif
402
403#endif /* des.h */