/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc.
*
* 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/>.
*/
#include <grub/cryptodisk.h>
#ifdef GRUB_UTIL
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#endif
GRUB_MOD_LICENSE ("GPLv3+");
{
{0, 0, 0, 0, 0, 0}
};
/* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: */
{
}
static grub_uint8_t n = 0;
static void
{
unsigned j;
for (j = 0; j < GRUB_CRYPTODISK_GF_BYTES; j++)
{
over2 = !!(g[j] & 0x80);
g[j] <<= 1;
g[j] |= over;
}
if (over)
g[0] ^= GF_POLYNOM;
}
static void
{
int j;
for (j = (int) GRUB_CRYPTODISK_GF_BYTES - 1; j >= 0; j--)
{
over2 = !!(g[j] & 0x80);
g[j] <<= 1;
g[j] |= over;
}
if (over)
}
static void
{
unsigned i;
grub_memset (o, 0, GRUB_CRYPTODISK_GF_BYTES);
grub_memcpy (t, b, GRUB_CRYPTODISK_GF_BYTES);
for (i = 0; i < GRUB_CRYPTODISK_GF_SIZE; i++)
{
grub_crypto_xor (o, o, t, GRUB_CRYPTODISK_GF_BYTES);
gf_mul_x_be (t);
}
}
static gcry_err_code_t
void *iv)
{
return GPG_ERR_NOT_SUPPORTED;
return GPG_ERR_INV_ARG;
{
}
return GPG_ERR_NO_ERROR;
}
struct lrw_sector
{
};
static void
const struct grub_cryptodisk *dev,
const grub_uint8_t *iv)
{
int j;
return;
if (c & 0x100)
{
for (j = GRUB_CRYPTODISK_GF_BYTES - 2; j >= 0; j--)
{
idx[j]++;
if (idx[j] != 0)
break;
}
}
}
static void __attribute__ ((unused))
const struct grub_cryptodisk *dev,
grub_uint8_t *b)
{
unsigned i;
i += GRUB_CRYPTODISK_GF_BYTES)
return;
}
{
grub_size_t i;
/* The only mode without IV. */
{
+ sizeof (grub_uint32_t) - 1)
/ sizeof (grub_uint32_t));
{
{
if (err)
return err;
}
}
{
break;
{
}
break;
break;
& 0xFFFFFFFF);
break;
{
}
break;
if (err)
return err;
}
{
case GRUB_CRYPTODISK_MODE_CBC:
if (err)
return err;
break;
if (err)
return err;
break;
case GRUB_CRYPTODISK_MODE_XTS:
{
unsigned j;
if (err)
return err;
{
data + i + j,
if (err)
return err;
}
}
break;
case GRUB_CRYPTODISK_MODE_LRW:
{
data + i,
if (err)
return err;
}
break;
case GRUB_CRYPTODISK_MODE_ECB:
break;
default:
return GPG_ERR_NOT_IMPLEMENTED;
}
sector++;
}
return GPG_ERR_NO_ERROR;
}
{
int real_keysize;
real_keysize /= 2;
/* Set the PBKDF2 output as the cipher key. */
if (err)
return err;
/* Configure ESSIV if necessary. */
{
if (err)
return err;
}
{
key + real_keysize,
keysize / 2);
if (err)
return err;
}
{
unsigned i;
if (!dev->lrw_precalc)
return GPG_ERR_OUT_OF_MEMORY;
i += GRUB_CRYPTODISK_GF_BYTES)
{
}
}
return GPG_ERR_NO_ERROR;
}
static int
{
if (pull != GRUB_DISK_PULL_NONE)
return 0;
{
return 1;
}
return GRUB_ERR_NONE;
}
static grub_err_t
{
{
break;
}
else
{
if (grub_errno)
/* Search for requested device in the list of CRYPTODISK devices. */
break;
}
if (!dev)
#ifdef GRUB_UTIL
{
}
#endif
if (!dev->source_disk)
{
/* Try to open the source disk and populate the requested disk. */
if (!dev->source_disk)
return grub_errno;
}
return GRUB_ERR_NONE;
}
static void
{
return;
#ifdef GRUB_UTIL
{
}
#endif
}
static grub_err_t
{
#ifdef GRUB_UTIL
{
if (err)
return err;
return GRUB_ERR_NONE;
}
#endif
grub_dprintf ("cryptodisk",
if (err)
{
return err;
}
sector);
return grub_crypto_gcry_error (gcry_err);
}
static grub_err_t
{
return GRUB_ERR_NOT_IMPLEMENTED_YET;
}
#ifdef GRUB_UTIL
static grub_disk_memberlist_t
{
if (list)
{
}
return list;
}
#endif
static void
cryptodisk_cleanup (void)
{
{
}
}
{
{
return grub_errno;
}
return GRUB_ERR_NONE;
}
{
return dev;
return NULL;
}
{
return dev;
return NULL;
}
#ifdef GRUB_UTIL
{
{
return grub_errno;
}
return GRUB_ERR_NONE;
}
void
{
if (dev->secondary_cipher)
if (dev->essiv_cipher)
if (dev->essiv_hash)
}
void
{
}
#endif
static char *search_uuid;
static void
{
}
static grub_err_t
{
if (dev)
return GRUB_ERR_NONE;
{
if (grub_errno)
return grub_errno;
if (!dev)
continue;
if (err)
{
return err;
}
have_it = 1;
return GRUB_ERR_NONE;
}
return GRUB_ERR_NONE;
}
#ifdef GRUB_UTIL
{
/* Try to open disk. */
if (!source)
return grub_errno;
if (dev)
{
return GRUB_ERR_NONE;
}
{
if (grub_errno)
return grub_errno;
if (!dev)
continue;
cheat);
if (err)
return GRUB_ERR_NONE;
}
return GRUB_ERR_NONE;
}
#endif
static int
{
/* Try to open disk. */
if (!source)
return grub_errno;
if (err)
grub_print_error ();
}
static grub_err_t
{
have_it = 0;
{
if (dev)
{
grub_dprintf ("cryptodisk",
return GRUB_ERR_NONE;
}
search_uuid = args[0];
search_uuid = NULL;
if (!have_it)
return GRUB_ERR_NONE;
}
{
search_uuid = NULL;
search_uuid = NULL;
return GRUB_ERR_NONE;
}
else
{
search_uuid = NULL;
if (!disk)
return grub_errno;
if (dev)
{
return GRUB_ERR_NONE;
}
return err;
}
}
.name = "cryptodisk",
#ifdef GRUB_UTIL
#endif
.next = 0
};
{
N_("SOURCE|-u UUID|-a|-b"),
}
{
}