Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / cryptodisk.h
blobf2ad2a79ab21ec3288a11804cb8728cca8d2d98c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_CRYPTODISK_HEADER
20 #define GRUB_CRYPTODISK_HEADER 1
22 #include <grub/disk.h>
23 #include <grub/crypto.h>
24 #include <grub/list.h>
25 #ifdef GRUB_UTIL
26 #include <grub/emu/hostdisk.h>
27 #endif
29 typedef enum
31 GRUB_CRYPTODISK_MODE_ECB,
32 GRUB_CRYPTODISK_MODE_CBC,
33 GRUB_CRYPTODISK_MODE_PCBC,
34 GRUB_CRYPTODISK_MODE_XTS,
35 GRUB_CRYPTODISK_MODE_LRW
36 } grub_cryptodisk_mode_t;
38 typedef enum
40 GRUB_CRYPTODISK_MODE_IV_NULL,
41 GRUB_CRYPTODISK_MODE_IV_PLAIN,
42 GRUB_CRYPTODISK_MODE_IV_PLAIN64,
43 GRUB_CRYPTODISK_MODE_IV_ESSIV,
44 GRUB_CRYPTODISK_MODE_IV_BENBI,
45 GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64,
46 GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH
47 } grub_cryptodisk_mode_iv_t;
49 #define GRUB_CRYPTODISK_MAX_UUID_LENGTH 71
51 #define GRUB_CRYPTODISK_GF_LOG_SIZE 7
52 #define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE)
53 #define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3)
54 #define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES)
55 #define GRUB_CRYPTODISK_MAX_KEYLEN 128
57 struct grub_cryptodisk;
59 typedef gcry_err_code_t
60 (*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev,
61 grub_uint64_t zoneno);
63 struct grub_cryptodisk
65 struct grub_cryptodisk *next;
66 struct grub_cryptodisk **prev;
68 char *source;
69 grub_disk_addr_t offset;
70 grub_disk_addr_t total_length;
71 grub_disk_t source_disk;
72 int ref;
73 grub_crypto_cipher_handle_t cipher;
74 grub_crypto_cipher_handle_t secondary_cipher;
75 grub_crypto_cipher_handle_t essiv_cipher;
76 const gcry_md_spec_t *essiv_hash, *hash, *iv_hash;
77 grub_cryptodisk_mode_t mode;
78 grub_cryptodisk_mode_iv_t mode_iv;
79 int benbi_log;
80 unsigned long id, source_id;
81 enum grub_disk_dev_id source_dev_id;
82 char uuid[GRUB_CRYPTODISK_MAX_UUID_LENGTH + 1];
83 grub_uint8_t lrw_key[GRUB_CRYPTODISK_GF_BYTES];
84 grub_uint8_t *lrw_precalc;
85 grub_uint8_t iv_prefix[64];
86 grub_size_t iv_prefix_len;
87 grub_uint8_t key[GRUB_CRYPTODISK_MAX_KEYLEN];
88 grub_size_t keysize;
89 #ifdef GRUB_UTIL
90 char *cheat;
91 grub_util_fd_t cheat_fd;
92 #endif
93 const char *modname;
94 int log_sector_size;
95 grub_cryptodisk_rekey_func_t rekey;
96 int rekey_shift;
97 grub_uint8_t rekey_key[64];
98 grub_uint64_t last_rekey;
99 int rekey_derived_size;
101 typedef struct grub_cryptodisk *grub_cryptodisk_t;
103 struct grub_cryptodisk_dev
105 struct grub_cryptodisk_dev *next;
106 struct grub_cryptodisk_dev **prev;
108 grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid,
109 int boot_only);
110 grub_err_t (*recover_key) (grub_disk_t disk, grub_cryptodisk_t dev);
112 typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t;
114 extern grub_cryptodisk_dev_t EXPORT_VAR (grub_cryptodisk_list);
116 #ifndef GRUB_LST_GENERATOR
117 static inline void
118 grub_cryptodisk_dev_register (grub_cryptodisk_dev_t cr)
120 grub_list_push (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr));
122 #endif
124 static inline void
125 grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr)
127 grub_list_remove (GRUB_AS_LIST (cr));
130 #define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list))
132 gcry_err_code_t
133 grub_cryptodisk_setkey (grub_cryptodisk_t dev,
134 grub_uint8_t *key, grub_size_t keysize);
135 gcry_err_code_t
136 grub_cryptodisk_decrypt (struct grub_cryptodisk *dev,
137 grub_uint8_t * data, grub_size_t len,
138 grub_disk_addr_t sector);
139 grub_err_t
140 grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name,
141 grub_disk_t source);
142 #ifdef GRUB_UTIL
143 grub_err_t
144 grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name,
145 grub_disk_t source, const char *cheat);
146 void
147 grub_util_cryptodisk_get_abstraction (grub_disk_t disk,
148 void (*cb) (const char *val, void *data),
149 void *data);
151 char *
152 grub_util_get_geli_uuid (const char *dev);
153 #endif
155 grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid);
156 grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
158 #endif