mbed TLS v2.16.1
des.h
Go to the documentation of this file.
1 
10 /*
11  * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
12  * SPDX-License-Identifier: GPL-2.0
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  *
28  * This file is part of mbed TLS (https://tls.mbed.org)
29  *
30  */
31 #ifndef MBEDTLS_DES_H
32 #define MBEDTLS_DES_H
33 
34 #if !defined(MBEDTLS_CONFIG_FILE)
35 #include "config.h"
36 #else
37 #include MBEDTLS_CONFIG_FILE
38 #endif
39 
40 #include <stddef.h>
41 #include <stdint.h>
42 
43 #define MBEDTLS_DES_ENCRYPT 1
44 #define MBEDTLS_DES_DECRYPT 0
45 
46 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
48 /* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */
49 #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
51 #define MBEDTLS_DES_KEY_SIZE 8
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 #if !defined(MBEDTLS_DES_ALT)
58 // Regular implementation
59 //
60 
68 typedef struct mbedtls_des_context
69 {
70  uint32_t sk[32];
71 }
73 
77 typedef struct mbedtls_des3_context
78 {
79  uint32_t sk[96];
80 }
82 
83 #else /* MBEDTLS_DES_ALT */
84 #include "des_alt.h"
85 #endif /* MBEDTLS_DES_ALT */
86 
97 
108 
115 
122 
135 void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
136 
151 int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
152 
164 int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
165 
178 int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
179 
192 int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
193 
203  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
204 
214  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
215 
225  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
226 
236  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
237 
252  const unsigned char input[8],
253  unsigned char output[8] );
254 
255 #if defined(MBEDTLS_CIPHER_MODE_CBC)
256 
279  int mode,
280  size_t length,
281  unsigned char iv[8],
282  const unsigned char *input,
283  unsigned char *output );
284 #endif /* MBEDTLS_CIPHER_MODE_CBC */
285 
296  const unsigned char input[8],
297  unsigned char output[8] );
298 
299 #if defined(MBEDTLS_CIPHER_MODE_CBC)
300 
321  int mode,
322  size_t length,
323  unsigned char iv[8],
324  const unsigned char *input,
325  unsigned char *output );
326 #endif /* MBEDTLS_CIPHER_MODE_CBC */
327 
340 void mbedtls_des_setkey( uint32_t SK[32],
341  const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
342 
343 #if defined(MBEDTLS_SELF_TEST)
344 
350 int mbedtls_des_self_test( int verbose );
351 
352 #endif /* MBEDTLS_SELF_TEST */
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* des.h */
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_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Check that key is not a weak or semi-weak DES key.
void mbedtls_des3_init(mbedtls_des3_context *ctx)
Initialize 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)
#define MBEDTLS_DES_KEY_SIZE
Definition: des.h:51
DES context structure.
Definition: des.h:68
Configuration options (set of defines)
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)
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)
Triple-DES context structure.
Definition: des.h:77
int mbedtls_des_self_test(int verbose)
Checkup routine.
int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
struct mbedtls_des3_context mbedtls_des3_context
Triple-DES context structure.
void mbedtls_des_free(mbedtls_des_context *ctx)
Clear DES context.
struct mbedtls_des_context mbedtls_des_context
DES context structure.
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
void mbedtls_des_init(mbedtls_des_context *ctx)
Initialize DES context.
uint32_t sk[96]
Definition: des.h:79
uint32_t sk[32]
Definition: des.h:70
void mbedtls_des3_free(mbedtls_des3_context *ctx)
Clear Triple-DES context.
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_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_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_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_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_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, decryption)