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 */