2011-04-23 22:00:29 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRUB_CRYPTODISK_HEADER
|
|
|
|
#define GRUB_CRYPTODISK_HEADER 1
|
|
|
|
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/crypto.h>
|
2011-04-25 12:52:07 +00:00
|
|
|
#include <grub/list.h>
|
2013-09-23 09:58:19 +00:00
|
|
|
#ifdef GRUB_UTIL
|
|
|
|
#include <grub/emu/hostdisk.h>
|
|
|
|
#endif
|
2011-04-23 22:00:29 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GRUB_CRYPTODISK_MODE_ECB,
|
|
|
|
GRUB_CRYPTODISK_MODE_CBC,
|
|
|
|
GRUB_CRYPTODISK_MODE_PCBC,
|
|
|
|
GRUB_CRYPTODISK_MODE_XTS,
|
|
|
|
GRUB_CRYPTODISK_MODE_LRW
|
|
|
|
} grub_cryptodisk_mode_t;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GRUB_CRYPTODISK_MODE_IV_NULL,
|
|
|
|
GRUB_CRYPTODISK_MODE_IV_PLAIN,
|
|
|
|
GRUB_CRYPTODISK_MODE_IV_PLAIN64,
|
|
|
|
GRUB_CRYPTODISK_MODE_IV_ESSIV,
|
|
|
|
GRUB_CRYPTODISK_MODE_IV_BENBI,
|
2011-04-24 15:41:50 +00:00
|
|
|
GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64,
|
2011-04-23 22:00:29 +00:00
|
|
|
GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH
|
|
|
|
} grub_cryptodisk_mode_iv_t;
|
|
|
|
|
2011-04-24 19:11:14 +00:00
|
|
|
#define GRUB_CRYPTODISK_MAX_UUID_LENGTH 71
|
2011-04-23 22:00:29 +00:00
|
|
|
|
2011-04-24 12:59:38 +00:00
|
|
|
#define GRUB_CRYPTODISK_GF_LOG_SIZE 7
|
|
|
|
#define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE)
|
|
|
|
#define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3)
|
|
|
|
#define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES)
|
2013-03-24 12:05:59 +00:00
|
|
|
#define GRUB_CRYPTODISK_MAX_KEYLEN 128
|
2011-04-23 22:00:29 +00:00
|
|
|
|
2011-04-24 15:15:55 +00:00
|
|
|
struct grub_cryptodisk;
|
|
|
|
|
|
|
|
typedef gcry_err_code_t
|
|
|
|
(*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev,
|
|
|
|
grub_uint64_t zoneno);
|
|
|
|
|
2011-04-23 22:00:29 +00:00
|
|
|
struct grub_cryptodisk
|
|
|
|
{
|
2011-04-25 12:52:07 +00:00
|
|
|
struct grub_cryptodisk *next;
|
2012-01-24 12:31:12 +00:00
|
|
|
struct grub_cryptodisk **prev;
|
2011-04-25 12:52:07 +00:00
|
|
|
|
2011-04-23 22:00:29 +00:00
|
|
|
char *source;
|
|
|
|
grub_disk_addr_t offset;
|
|
|
|
grub_disk_addr_t total_length;
|
|
|
|
grub_disk_t source_disk;
|
|
|
|
int ref;
|
|
|
|
grub_crypto_cipher_handle_t cipher;
|
|
|
|
grub_crypto_cipher_handle_t secondary_cipher;
|
|
|
|
grub_crypto_cipher_handle_t essiv_cipher;
|
|
|
|
const gcry_md_spec_t *essiv_hash, *hash, *iv_hash;
|
|
|
|
grub_cryptodisk_mode_t mode;
|
|
|
|
grub_cryptodisk_mode_iv_t mode_iv;
|
|
|
|
int benbi_log;
|
|
|
|
unsigned long id, source_id;
|
|
|
|
enum grub_disk_dev_id source_dev_id;
|
|
|
|
char uuid[GRUB_CRYPTODISK_MAX_UUID_LENGTH + 1];
|
|
|
|
grub_uint8_t lrw_key[GRUB_CRYPTODISK_GF_BYTES];
|
|
|
|
grub_uint8_t *lrw_precalc;
|
|
|
|
grub_uint8_t iv_prefix[64];
|
|
|
|
grub_size_t iv_prefix_len;
|
2013-03-24 12:05:59 +00:00
|
|
|
grub_uint8_t key[GRUB_CRYPTODISK_MAX_KEYLEN];
|
|
|
|
grub_size_t keysize;
|
2011-04-23 22:00:29 +00:00
|
|
|
#ifdef GRUB_UTIL
|
|
|
|
char *cheat;
|
2013-09-23 09:58:19 +00:00
|
|
|
grub_util_fd_t cheat_fd;
|
2011-04-23 22:00:29 +00:00
|
|
|
#endif
|
2013-03-24 12:05:59 +00:00
|
|
|
const char *modname;
|
2011-04-24 12:59:38 +00:00
|
|
|
int log_sector_size;
|
2011-04-24 15:15:55 +00:00
|
|
|
grub_cryptodisk_rekey_func_t rekey;
|
|
|
|
int rekey_shift;
|
|
|
|
grub_uint8_t rekey_key[64];
|
|
|
|
grub_uint64_t last_rekey;
|
|
|
|
int rekey_derived_size;
|
2015-11-07 15:52:59 +00:00
|
|
|
grub_disk_addr_t partition_start;
|
2011-04-23 22:00:29 +00:00
|
|
|
};
|
|
|
|
typedef struct grub_cryptodisk *grub_cryptodisk_t;
|
|
|
|
|
2011-04-25 12:52:07 +00:00
|
|
|
struct grub_cryptodisk_dev
|
|
|
|
{
|
|
|
|
struct grub_cryptodisk_dev *next;
|
2012-01-24 12:31:12 +00:00
|
|
|
struct grub_cryptodisk_dev **prev;
|
2011-04-25 12:52:07 +00:00
|
|
|
|
|
|
|
grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid,
|
|
|
|
int boot_only);
|
|
|
|
grub_err_t (*recover_key) (grub_disk_t disk, grub_cryptodisk_t dev);
|
|
|
|
};
|
|
|
|
typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t;
|
|
|
|
|
|
|
|
extern grub_cryptodisk_dev_t EXPORT_VAR (grub_cryptodisk_list);
|
|
|
|
|
|
|
|
#ifndef GRUB_LST_GENERATOR
|
|
|
|
static inline void
|
|
|
|
grub_cryptodisk_dev_register (grub_cryptodisk_dev_t cr)
|
|
|
|
{
|
|
|
|
grub_list_push (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr)
|
|
|
|
{
|
2012-01-24 12:31:12 +00:00
|
|
|
grub_list_remove (GRUB_AS_LIST (cr));
|
2011-04-25 12:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list))
|
|
|
|
|
2011-04-23 22:00:29 +00:00
|
|
|
gcry_err_code_t
|
|
|
|
grub_cryptodisk_setkey (grub_cryptodisk_t dev,
|
|
|
|
grub_uint8_t *key, grub_size_t keysize);
|
|
|
|
gcry_err_code_t
|
2011-04-24 15:15:55 +00:00
|
|
|
grub_cryptodisk_decrypt (struct grub_cryptodisk *dev,
|
2011-04-23 22:00:29 +00:00
|
|
|
grub_uint8_t * data, grub_size_t len,
|
|
|
|
grub_disk_addr_t sector);
|
|
|
|
grub_err_t
|
|
|
|
grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name,
|
|
|
|
grub_disk_t source);
|
|
|
|
#ifdef GRUB_UTIL
|
|
|
|
grub_err_t
|
|
|
|
grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name,
|
|
|
|
grub_disk_t source, const char *cheat);
|
|
|
|
void
|
2013-10-03 23:43:47 +00:00
|
|
|
grub_util_cryptodisk_get_abstraction (grub_disk_t disk,
|
Fix partmap, cryptodisk, and abstraction handling in grub-mkconfig.
Commit 588744d0dc655177d5883bdcb8f72ff5160109ed caused grub-mkconfig
no longer to be forgiving of trailing spaces on grub-probe output
lines, which among other things means that util/grub.d/10_linux.in
no longer detects LVM. To fix this, make grub-probe's output
delimiting more consistent. As a bonus, this improves the coverage
of the -0 option.
Fixes Debian bug #735935.
* grub-core/disk/cryptodisk.c
(grub_util_cryptodisk_get_abstraction): Add a user-data argument.
* grub-core/disk/diskfilter.c (grub_diskfilter_get_partmap):
Likewise.
* include/grub/cryptodisk.h (grub_util_cryptodisk_get_abstraction):
Update prototype.
* include/grub/diskfilter.h (grub_diskfilter_get_partmap): Likewise.
* util/grub-install.c (push_partmap_module, push_cryptodisk_module,
probe_mods): Adjust for extra user-data arguments.
* util/grub-probe.c (do_print, probe_partmap, probe_cryptodisk_uuid,
probe_abstraction): Use configured delimiter. Update callers.
2014-03-31 13:48:33 +00:00
|
|
|
void (*cb) (const char *val, void *data),
|
|
|
|
void *data);
|
2013-10-03 23:43:47 +00:00
|
|
|
|
2011-04-25 12:52:07 +00:00
|
|
|
char *
|
|
|
|
grub_util_get_geli_uuid (const char *dev);
|
2011-04-23 22:00:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid);
|
|
|
|
grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
|
|
|
|
|
|
|
|
#endif
|