Initial checking of what was revision 56 on http://luks.endorphin.org/svn/cryptsetup
[platform/upstream/cryptsetup.git] / luks / luks.h
1 #ifndef INCLUDED_CRYPTSETUP_LUKS_LUKS_H
2 #define INCLUDED_CRYPTSETUP_LUKS_LUKS_H
3
4 /*
5  * LUKS partition header
6  */
7
8 #include <stddef.h>
9 #include <netinet/in.h>
10 #include "libcryptsetup.h"
11 #include "internal.h"
12
13 #define LUKS_CIPHERNAME_L 32
14 #define LUKS_CIPHERMODE_L 32
15 #define LUKS_HASHSPEC_L 32
16 #define LUKS_DIGESTSIZE 20 // since SHA1
17 #define LUKS_HMACSIZE 32
18 #define LUKS_SALTSIZE 32
19 #define LUKS_NUMKEYS 8
20
21 // Numbers of iterations for the master key digest
22 #define LUKS_MKD_ITER 10
23
24 // LUKS_KT defines Key types
25
26 #define LUKS_KEY_DISABLED_OLD 0
27 #define LUKS_KEY_ENABLED_OLD 0xCAFE
28
29 #define LUKS_KEY_DISABLED 0x0000DEAD
30 #define LUKS_KEY_ENABLED  0x00AC71F3
31
32 #define LUKS_STRIPES 4000
33
34 // partition header starts with magic
35
36 #define LUKS_MAGIC {'L','U','K','S', 0xba, 0xbe};
37 #define LUKS_MAGIC_L 6
38
39 #define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
40
41 /* Actually we need only 37, but we don't want struct autoaligning to kick in */
42 #define UUID_STRING_L 40
43
44 /* We don't have gettext support in LUKS */
45
46 #define _(Text) Text 
47
48 /* Any integer values are stored in network byte order on disk and must be
49 converted */
50
51 struct luks_phdr {
52         char            magic[LUKS_MAGIC_L];
53         uint16_t        version;
54         char            cipherName[LUKS_CIPHERNAME_L];
55         char            cipherMode[LUKS_CIPHERMODE_L];
56         char            hashSpec[LUKS_HASHSPEC_L];
57         uint32_t        payloadOffset;
58         uint32_t        keyBytes;
59         char            mkDigest[LUKS_DIGESTSIZE];
60         char            mkDigestSalt[LUKS_SALTSIZE];
61         uint32_t        mkDigestIterations;
62         char            uuid[UUID_STRING_L];
63
64         struct {
65                 uint32_t active;
66         
67                 /* parameters used for password processing */
68                 uint32_t passwordIterations;
69                 char     passwordSalt[LUKS_SALTSIZE];
70                 
71                 /* parameters used for AF store/load */         
72                 uint32_t keyMaterialOffset;
73                 uint32_t stripes;               
74         } keyblock[LUKS_NUMKEYS];
75 };
76
77 struct luks_masterkey {
78         size_t keyLength;
79         char key[];
80 };
81
82 struct luks_masterkey *LUKS_alloc_masterkey(int keylength);
83
84 void LUKS_dealloc_masterkey(struct luks_masterkey *mk);
85
86 struct luks_masterkey *LUKS_generate_masterkey(int keylength);
87
88 int LUKS_generate_phdr(struct luks_phdr *header,
89                        const struct luks_masterkey *mk, const char *cipherName,
90                        const char *cipherMode, unsigned int stripes,
91                        unsigned int alignPayload);
92
93 int LUKS_read_phdr(const char *device, struct luks_phdr *hdr);
94
95 int LUKS_write_phdr(const char *device, struct luks_phdr *hdr);
96
97 int LUKS_set_key(const char *device, 
98                                         unsigned int keyIndex, 
99                                         const char *password, 
100                                         size_t passwordLen, 
101                                         struct luks_phdr *hdr, 
102                                         struct luks_masterkey *mk,
103                                         struct setup_backend *backend);
104
105 int LUKS_open_key(const char *device, 
106                                         unsigned int keyIndex, 
107                                         const char *password, 
108                                         size_t passwordLen, 
109                                         struct luks_phdr *hdr, 
110                                         struct luks_masterkey *mk,
111                                         struct setup_backend *backend);
112
113 int LUKS_open_any_key(const char *device, 
114                                         const char *password, 
115                                         size_t passwordLen, 
116                                         struct luks_phdr *hdr, 
117                                         struct luks_masterkey **mk,
118                                         struct setup_backend *backend);
119
120 int LUKS_del_key(const char *device, unsigned int keyIndex);
121 int LUKS_is_last_keyslot(const char *device, unsigned int keyIndex);
122 int LUKS_benchmarkt_iterations();
123
124 int LUKS_encrypt_to_storage(char *src, size_t srcLength,
125                             struct luks_phdr *hdr,
126                             char *key, size_t keyLength,
127                             const char *device,
128                             unsigned int sector, struct setup_backend *backend);
129         
130 int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
131                               struct luks_phdr *hdr,
132                               char *key, size_t keyLength,
133                               const char *device,
134                               unsigned int sector, struct setup_backend *backend);
135 int LUKS_device_ready(const char *device, int mode);
136 #endif