mbed TLS v2.7.16
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: Apache-2.0 OR GPL-2.0-or-later
13  *
14  * This file is provided under the Apache License 2.0, or the
15  * GNU General Public License v2.0 or later.
16  *
17  * **********
18  * Apache License 2.0:
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License"); you may
21  * not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  * http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  *
32  * **********
33  *
34  * **********
35  * GNU General Public License v2.0 or later:
36  *
37  * This program is free software; you can redistribute it and/or modify
38  * it under the terms of the GNU General Public License as published by
39  * the Free Software Foundation; either version 2 of the License, or
40  * (at your option) any later version.
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU General Public License for more details.
46  *
47  * You should have received a copy of the GNU General Public License along
48  * with this program; if not, write to the Free Software Foundation, Inc.,
49  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50  *
51  * **********
52  *
53  * This file is part of mbed TLS (https://tls.mbed.org)
54  *
55  */
56 #ifndef MBEDTLS_DES_H
57 #define MBEDTLS_DES_H
58 
59 #if !defined(MBEDTLS_CONFIG_FILE)
60 #include "config.h"
61 #else
62 #include MBEDTLS_CONFIG_FILE
63 #endif
64 
65 #include <stddef.h>
66 #include <stdint.h>
67 
68 #define MBEDTLS_DES_ENCRYPT 1
69 #define MBEDTLS_DES_DECRYPT 0
70 
71 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
72 #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
74 #define MBEDTLS_DES_KEY_SIZE 8
75 
76 #if !defined(MBEDTLS_DES_ALT)
77 // Regular implementation
78 //
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
91 typedef struct
92 {
93  uint32_t sk[32];
94 }
96 
100 typedef struct
101 {
102  uint32_t sk[96];
103 }
105 
116 
127 
134 
141 
154 void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
155 
170 int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
171 
183 int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
184 
197 int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
198 
211 int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
212 
222  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
223 
233  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
234 
244  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
245 
255  const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
256 
271  const unsigned char input[8],
272  unsigned char output[8] );
273 
274 #if defined(MBEDTLS_CIPHER_MODE_CBC)
275 
298  int mode,
299  size_t length,
300  unsigned char iv[8],
301  const unsigned char *input,
302  unsigned char *output );
303 #endif /* MBEDTLS_CIPHER_MODE_CBC */
304 
315  const unsigned char input[8],
316  unsigned char output[8] );
317 
318 #if defined(MBEDTLS_CIPHER_MODE_CBC)
319 
340  int mode,
341  size_t length,
342  unsigned char iv[8],
343  const unsigned char *input,
344  unsigned char *output );
345 #endif /* MBEDTLS_CIPHER_MODE_CBC */
346 
359 void mbedtls_des_setkey( uint32_t SK[32],
360  const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
361 #ifdef __cplusplus
362 }
363 #endif
364 
365 #else /* MBEDTLS_DES_ALT */
366 #include "des_alt.h"
367 #endif /* MBEDTLS_DES_ALT */
368 
369 #ifdef __cplusplus
370 extern "C" {
371 #endif
372 
378 int mbedtls_des_self_test( int verbose );
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 
384 #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:74
DES context structure.
Definition: des.h:91
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:100
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.
void mbedtls_des_free(mbedtls_des_context *ctx)
Clear DES context.
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.
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)