• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 
11 /* FIPS PUB 46-3 "Data Encryption Standard (DES)" */
12 
13 #ifndef GMSSL_DES_H
14 #define GMSSL_DES_H
15 
16 
17 #include <stdint.h>
18 #include <stdlib.h>
19 
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 
26 #define DES_KEY_BITS	56
27 #define DES_BLOCK_BITS	64
28 #define DES_KEY_SIZE	((DES_KEY_BITS)/7)
29 #define DES_BLOCK_SIZE	(DES_BLOCK_BITS/8)
30 
31 #define DES_RK_BITS	48
32 #define DES_RK_SIZE	(DES_RK_BITS/8)
33 #define DES_ROUNDS	16
34 
35 #define DES_EDE_KEY_SIZE	(DES_KEY_SIZE * 3)
36 
37 typedef struct {
38 	uint64_t rk[DES_ROUNDS];
39 } DES_KEY;
40 
41 void des_set_encrypt_key(DES_KEY *key, const uint8_t raw_key[DES_KEY_SIZE]);
42 void des_set_decrypt_key(DES_KEY *key, const uint8_t raw_key[DES_KEY_SIZE]);
43 void des_encrypt(DES_KEY *key, const uint8_t in[DES_BLOCK_SIZE], uint8_t out[DES_BLOCK_SIZE]);
44 
45 
46 typedef struct {
47 	DES_KEY K[3];
48 } DES_EDE_KEY;
49 
50 void des_ede_set_encrypt_key(DES_EDE_KEY *key, const uint8_t raw_key[DES_EDE_KEY_SIZE]);
51 void des_ede_set_decrypt_key(DES_EDE_KEY *key, const uint8_t raw_key[DES_EDE_KEY_SIZE]);
52 void des_ede_encrypt(DES_EDE_KEY *key, const uint8_t in[DES_BLOCK_SIZE], uint8_t out[DES_BLOCK_SIZE]);
53 
54 
55 #ifdef __cplusplus
56 }
57 #endif
58 #endif
59