Mbed TLS v3.5.0
des.h
Go to the documentation of this file.
1
10/*
11 * Copyright The Mbed TLS Contributors
12 * 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.
25 *
26 */
27#ifndef MBEDTLS_DES_H
28#define MBEDTLS_DES_H
30
31#include "mbedtls/build_info.h"
33
34#include <stddef.h>
35#include <stdint.h>
36
37#define MBEDTLS_DES_ENCRYPT 1
38#define MBEDTLS_DES_DECRYPT 0
39
41#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
42
43#define MBEDTLS_DES_KEY_SIZE 8
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49#if !defined(MBEDTLS_DES_ALT)
50// Regular implementation
51//
52
60typedef struct mbedtls_des_context {
61 uint32_t MBEDTLS_PRIVATE(sk)[32];
62}
64
72typedef struct mbedtls_des3_context {
73 uint32_t MBEDTLS_PRIVATE(sk)[96];
74}
76
77#else /* MBEDTLS_DES_ALT */
78#include "des_alt.h"
79#endif /* MBEDTLS_DES_ALT */
80
91
102
113
124
138
155
169
184
199
214 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
215
230 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
231
246 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
247
262 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
263
279 const unsigned char input[8],
280 unsigned char output[8]);
281
282#if defined(MBEDTLS_CIPHER_MODE_CBC)
307 int mode,
308 size_t length,
309 unsigned char iv[8],
310 const unsigned char *input,
311 unsigned char *output);
312#endif /* MBEDTLS_CIPHER_MODE_CBC */
313
329 const unsigned char input[8],
330 unsigned char output[8]);
331
332#if defined(MBEDTLS_CIPHER_MODE_CBC)
359 int mode,
360 size_t length,
361 unsigned char iv[8],
362 const unsigned char *input,
363 unsigned char *output);
364#endif /* MBEDTLS_CIPHER_MODE_CBC */
365
378void mbedtls_des_setkey(uint32_t SK[32],
379 const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
380
381#if defined(MBEDTLS_SELF_TEST)
382
389int mbedtls_des_self_test(int verbose);
390
391#endif /* MBEDTLS_SELF_TEST */
392
393#ifdef __cplusplus
394}
395#endif
396
397#endif /* des.h */
int mbedtls_des_self_test(int verbose)
Checkup routine.
void mbedtls_des_init(mbedtls_des_context *ctx)
Initialize DES context.
struct mbedtls_des3_context mbedtls_des3_context
Triple-DES context structure.
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
void mbedtls_des3_free(mbedtls_des3_context *ctx)
Clear Triple-DES context.
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
3DES-CBC buffer encryption/decryption
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE])
Set key parity on the given key to odd.
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
DES-CBC buffer encryption/decryption.
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void mbedtls_des_setkey(uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Internal function for key expansion. (Only exposed to allow overriding it, see MBEDTLS_DES_SETKEY_ALT...
int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Check that key parity on the given key is odd.
int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Check that key is not a weak or semi-weak DES key.
struct mbedtls_des_context mbedtls_des_context
DES context structure.
void mbedtls_des3_init(mbedtls_des3_context *ctx)
Initialize Triple-DES context.
#define MBEDTLS_DES_KEY_SIZE
Definition: des.h:43
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
void mbedtls_des_free(mbedtls_des_context *ctx)
Clear DES context.
Build-time configuration info.
Common and shared functions used by multiple modules in the Mbed TLS library.
#define MBEDTLS_CHECK_RETURN_TYPICAL
#define MBEDTLS_CHECK_RETURN_CRITICAL
Definition: platform_util.h:93
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
Triple-DES context structure.
Definition: des.h:72
DES context structure.
Definition: des.h:60