2009-12-23 16:41:32 +00:00
|
|
|
/* xnu_uuid.c - transform 64-bit serial number
|
2009-06-15 22:57:39 +00:00
|
|
|
to 128-bit uuid suitable for xnu. */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 1995,1996,1998,1999,2001,2002,
|
|
|
|
* 2003, 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/device.h>
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/fs.h>
|
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/env.h>
|
|
|
|
#include <grub/command.h>
|
2010-01-03 18:24:22 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-11-10 19:47:06 +00:00
|
|
|
#include <grub/crypto.h>
|
2009-06-15 22:57:39 +00:00
|
|
|
|
2009-12-23 16:41:32 +00:00
|
|
|
/* This prefix is used by xnu and boot-132 to hash
|
2009-06-15 22:57:39 +00:00
|
|
|
together with volume serial. */
|
2009-12-23 16:41:32 +00:00
|
|
|
static grub_uint8_t hash_prefix[16]
|
|
|
|
= {0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6,
|
2009-06-15 22:57:39 +00:00
|
|
|
0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC};
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
|
|
|
|
int argc, char **args)
|
|
|
|
{
|
2009-11-10 19:47:06 +00:00
|
|
|
grub_uint64_t serial;
|
|
|
|
grub_uint8_t *xnu_uuid;
|
2009-06-15 22:57:39 +00:00
|
|
|
char uuid_string[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
|
|
|
|
char *ptr;
|
2009-11-12 17:08:44 +00:00
|
|
|
grub_uint8_t ctx[GRUB_MD_MD5->contextsize];
|
2009-06-15 22:57:39 +00:00
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "UUID required");
|
|
|
|
|
2009-11-10 19:47:06 +00:00
|
|
|
serial = grub_cpu_to_be64 (grub_strtoull (args[0], 0, 16));
|
|
|
|
|
2009-11-12 17:08:44 +00:00
|
|
|
GRUB_MD_MD5->init (&ctx);
|
|
|
|
GRUB_MD_MD5->write (&ctx, hash_prefix, sizeof (hash_prefix));
|
|
|
|
GRUB_MD_MD5->write (&ctx, &serial, sizeof (serial));
|
|
|
|
GRUB_MD_MD5->final (&ctx);
|
|
|
|
xnu_uuid = GRUB_MD_MD5->read (&ctx);
|
2009-06-15 22:57:39 +00:00
|
|
|
|
|
|
|
grub_sprintf (uuid_string,
|
|
|
|
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
(unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1],
|
|
|
|
(unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],
|
|
|
|
(unsigned int) xnu_uuid[4], (unsigned int) xnu_uuid[5],
|
|
|
|
(unsigned int) ((xnu_uuid[6] & 0xf) | 0x30),
|
|
|
|
(unsigned int) xnu_uuid[7],
|
|
|
|
(unsigned int) ((xnu_uuid[8] & 0x3f) | 0x80),
|
|
|
|
(unsigned int) xnu_uuid[9],
|
|
|
|
(unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
|
|
|
|
(unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
|
|
|
|
(unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
|
|
|
|
for (ptr = uuid_string; *ptr; ptr++)
|
|
|
|
*ptr = grub_toupper (*ptr);
|
|
|
|
if (argc == 1)
|
|
|
|
grub_printf ("%s", uuid_string);
|
|
|
|
if (argc > 1)
|
|
|
|
grub_env_set (args[1], uuid_string);
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_command_t cmd;
|
|
|
|
|
|
|
|
|
|
|
|
GRUB_MOD_INIT (xnu_uuid)
|
|
|
|
{
|
|
|
|
cmd = grub_register_command ("xnu_uuid", grub_cmd_xnu_uuid,
|
2010-01-03 18:24:22 +00:00
|
|
|
N_("GRUBUUID [VARNAME]"),
|
|
|
|
N_("Transform 64-bit UUID to format "
|
2010-01-03 18:50:51 +00:00
|
|
|
"suitable for XNU."));
|
2009-06-15 22:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GRUB_MOD_FINI (xnu_uuid)
|
|
|
|
{
|
|
|
|
grub_unregister_command (cmd);
|
|
|
|
}
|