iPXE
des.h
Go to the documentation of this file.
1 #ifndef _IPXE_DES_H
2 #define _IPXE_DES_H
3 
4 /** @file
5  *
6  * DES algorithm
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <ipxe/crypto.h>
13 
14 /** A DES 32-bit dword value
15  *
16  * DES views data as 64-bit big-endian values, typically handled as a
17  * most-significant "left" half and a least-significant "right" half.
18  */
19 union des_dword {
20  /** Raw bytes */
21  uint8_t byte[4];
22  /** 32-bit big-endian dword */
24 };
25 
26 /** A DES 64-bit block */
27 union des_block {
28  /** Raw bytes */
29  uint8_t byte[8];
30  /** 32-bit big-endian dwords */
32  /** Named left and right halves */
33  struct {
34  /** Left (most significant) half */
35  union des_dword left;
36  /** Right (least significant) half */
38  };
39  /** Named "C" and "D" halves */
40  struct {
41  /** "C" (most significant) half */
42  union des_dword c;
43  /** "D" (least significant) half */
44  union des_dword d;
45  };
46 };
47 
48 /** DES blocksize */
49 #define DES_BLOCKSIZE sizeof ( union des_block )
50 
51 /** A DES round key
52  *
53  * A DES round key is a 48-bit value, consumed as 8 groups of 6 bits.
54  * We store these as 8 separate bytes, for simplicity of consumption.
55  */
57  /** Raw bytes */
58  uint8_t byte[8];
59  /** 32-bit big-endian dwords */
61  /** 6-bit step key byte
62  *
63  * There are 8 steps within a DES round (one step per S-box).
64  * Each step requires six bits of the round key.
65  *
66  * As an optimisation, we store the least significant of the 6
67  * bits in the sign bit of a signed 8-bit value, and the
68  * remaining 5 bits in the least significant 5 bits of the
69  * 8-bit value. See the comments in des_sbox() for further
70  * details.
71  */
73 };
74 
75 /** Number of DES rounds */
76 #define DES_ROUNDS 16
77 
78 /** DES context */
79 struct des_context {
80  /** Round keys */
82 };
83 
84 /** DES context size */
85 #define DES_CTX_SIZE sizeof ( struct des_context )
86 
87 extern struct cipher_algorithm des_algorithm;
90 
91 #endif /* _IPXE_DES_H */
union des_dword d
"D" (least significant) half
Definition: des.h:44
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A DES 64-bit block.
Definition: des.h:27
A DES 32-bit dword value.
Definition: des.h:19
union des_dword right
Right (least significant) half.
Definition: des.h:37
Cryptographic API.
struct cipher_algorithm des_cbc_algorithm
DES context.
Definition: des.h:79
union des_round_key rkey[DES_ROUNDS]
Round keys.
Definition: des.h:81
#define DES_ROUNDS
Number of DES rounds.
Definition: des.h:76
signed char int8_t
Definition: stdint.h:15
struct cipher_algorithm des_ecb_algorithm
A DES round key.
Definition: des.h:56
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
uint32_t dword
32-bit big-endian dword
Definition: des.h:23
int8_t step[8]
6-bit step key byte
Definition: des.h:72
union des_dword left
Left (most significant) half.
Definition: des.h:35
A cipher algorithm.
Definition: crypto.h:49
union des_dword c
"C" (most significant) half
Definition: des.h:42
struct cipher_algorithm des_algorithm
Basic DES algorithm.
Definition: des.c:676
unsigned long int dword
Definition: smc9000.h:40