Remove lib/crc.c - users updated to use gcrypt implementation.
* grub-core/commands/crc.c: Removed.
* grub-core/Makefile.core.def (crc): Module removed.
* grub-core/commands/hashsum.c (aliases[]): Add crc alias.
* grub-core/commands/hashsum.c (GRUB_MOD_INIT): Register crc command.
* grub-core/commands/hashsum.c (GRUB_MOD_FINI): Unregister crc command.
* grub-core/lib/crc.c: Removed.
* include/grub/lib/crc.h: Removed.
* Makefile.util.def (crc): Remove lib/crc.c
* grub-core/Makefile.core.def (libgrub.a): Remove grub-core/lib/crc.c.
* util/grub-fstest.c (cmd_crd): Use libgcrypt crc implementation.
* Makefile.util.def (libgrub.a): Add grub-core/lib/libgcrypt-grub/cipher/crc.c.
* Makefile.util.def (grub-fstest): Add CFLAGS_GCRY to cflags.
* Makefile.util.def (grub-fstest): Add CPPFLAGS_GCRY to cppflags.
* grub-core/efiemu/prepare.c (grub_efiemu_crc): Use libgcrypt crc implementation.
+2010-09-20 Szymon Janc <szymon@janc.net.pl>
+
+ Remove crc.mod and move crc command to hashsum.mod.
+ Remove lib/crc.c - users updated to use gcrypt implementation.
+
+ * grub-core/commands/crc.c: Removed.
+ * grub-core/Makefile.core.def (crc): Module removed.
+ * grub-core/commands/hashsum.c (aliases[]): Add crc alias.
+ * grub-core/commands/hashsum.c (GRUB_MOD_INIT): Register crc command.
+ * grub-core/commands/hashsum.c (GRUB_MOD_FINI): Unregister crc command.
+ * grub-core/lib/crc.c: Removed.
+ * include/grub/lib/crc.h: Removed.
+ * Makefile.util.def (crc): Remove lib/crc.c
+ * grub-core/Makefile.core.def (libgrub.a): Remove grub-core/lib/crc.c.
+ * util/grub-fstest.c (cmd_crd): Use libgcrypt crc implementation.
+ * Makefile.util.def (libgrub.a): Add grub-core/lib/libgcrypt-grub/cipher/crc.c.
+ * Makefile.util.def (grub-fstest): Add CFLAGS_GCRY to cflags.
+ * Makefile.util.def (grub-fstest): Add CPPFLAGS_GCRY to cppflags.
+ * grub-core/efiemu/prepare.c (grub_efiemu_crc): Use libgcrypt crc implementation.
+
2010-09-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/boot/i386/pc/boot.S: Ignore %dl if it's not in a sane range.
common = grub-core/kern/list.c;
common = grub-core/kern/partition.c;
common = grub-core/lib/arg.c;
- common = grub-core/lib/crc.c;
common = grub-core/lib/crypto.c;
common = grub-core/lib/envblk.c;
common = grub-core/lib/hexdump.c;
common = grub-core/lib/libgcrypt-grub/cipher/sha512.c;
+ common = grub-core/lib/libgcrypt-grub/cipher/crc.c;
common = grub-core/lib/LzFind.c;
common = grub-core/lib/LzmaEnc.c;
common = grub-core/lib/pbkdf2.c;
ldadd = libgrub.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER)';
+ cflags = '$(CFLAGS_GCRY)';
+ cppflags = '$(CPPFLAGS_GCRY)';
};
program = {
enable = x86;
};
-module = {
- name = crc;
- common = commands/crc.c;
- common = lib/crc.c;
-};
-
module = {
name = date;
common = commands/date.c;
+++ /dev/null
-/* crc.c - command to calculate the crc32 checksum of a file */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2008,2010 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/dl.h>
-#include <grub/disk.h>
-#include <grub/file.h>
-#include <grub/misc.h>
-#include <grub/lib/crc.h>
-#include <grub/command.h>
-#include <grub/i18n.h>
-
-static grub_err_t
-grub_cmd_crc (grub_command_t cmd __attribute__ ((unused)),
- int argc, char **args)
-
-{
- grub_file_t file;
- char buf[GRUB_DISK_SECTOR_SIZE];
- grub_ssize_t size;
- grub_uint32_t crc;
-
- if (argc != 1)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
-
- grub_file_filter_disable_compression ();
- file = grub_file_open (args[0]);
- if (! file)
- return 0;
-
- crc = 0;
- while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
- crc = grub_getcrc32 (crc, buf, size);
-
- if (grub_errno)
- goto fail;
-
- grub_printf ("%08x\n", crc);
-
- fail:
- grub_file_close (file);
- return 0;
-}
-
-static grub_command_t cmd;
-
-GRUB_MOD_INIT(crc)
-{
- cmd = grub_register_command ("crc", grub_cmd_crc,
- N_("FILE"),
- N_("Calculate the crc32 checksum of a file."));
-}
-
-GRUB_MOD_FINI(crc)
-{
- grub_unregister_command (cmd);
-}
{"sha256sum", "sha256"},
{"sha512sum", "sha512"},
{"md5sum", "md5"},
+ {"crc", "crc32"},
};
static inline int
return GRUB_ERR_NONE;
}
-static grub_extcmd_t cmd, cmd_md5, cmd_sha256, cmd_sha512;
+static grub_extcmd_t cmd, cmd_md5, cmd_sha256, cmd_sha512 , cmd_crc;
GRUB_MOD_INIT(hashsum)
{
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
+
+ cmd_crc = grub_register_extcmd ("crc", grub_cmd_hashsum, 0,
+ N_("[-c FILE [-p PREFIX]] "
+ "[FILE1 [FILE2 ...]]"),
+ N_("Compute or check hash checksum."),
+ options);
}
GRUB_MOD_FINI(hashsum)
grub_unregister_extcmd (cmd_md5);
grub_unregister_extcmd (cmd_sha256);
grub_unregister_extcmd (cmd_sha512);
+ grub_unregister_extcmd (cmd_crc);
}
#include <grub/err.h>
#include <grub/mm.h>
-#include <grub/misc.h>
+#include <grub/types.h>
#include <grub/efiemu/efiemu.h>
-#include <grub/lib/crc.h>
+#include <grub/crypto.h>
grub_err_t
SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
int handle;
grub_off_t off;
struct SUFFIX (grub_efiemu_runtime_services) *runtime_services;
+ grub_uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
/* compute CRC32 of runtime_services */
err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
runtime_services = (struct SUFFIX (grub_efiemu_runtime_services) *)
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
- runtime_services->hdr.crc32 = 0;
- runtime_services->hdr.crc32 = grub_getcrc32
- (0, runtime_services, runtime_services->hdr.header_size);
+
+ GRUB_MD_CRC32->init(crc32_context);
+ GRUB_MD_CRC32->write(crc32_context, runtime_services, runtime_services->hdr.header_size);
+ GRUB_MD_CRC32->final(crc32_context);
+
+ runtime_services->hdr.crc32 =
+ grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context));
err = grub_efiemu_resolve_symbol ("efiemu_system_table", &handle, &off);
if (err)
return err;
/* compute CRC32 of system table */
- SUFFIX (grub_efiemu_system_table)->hdr.crc32 = 0;
- SUFFIX (grub_efiemu_system_table)->hdr.crc32
- = grub_getcrc32 (0, SUFFIX (grub_efiemu_system_table),
- SUFFIX (grub_efiemu_system_table)->hdr.header_size);
+ GRUB_MD_CRC32->init(crc32_context);
+ GRUB_MD_CRC32->write(crc32_context, SUFFIX (grub_efiemu_system_table),
+ SUFFIX (grub_efiemu_system_table)->hdr.header_size);
+ GRUB_MD_CRC32->final(crc32_context);
+ SUFFIX (grub_efiemu_system_table)->hdr.crc32 =
+ grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context));
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p\n",
SUFFIX (grub_efiemu_system_table), runtime_services);
+++ /dev/null
-/* crc.c - crc function */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2008 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/lib/crc.h>
-
-static grub_uint32_t crc32_table [256];
-
-static void
-init_crc32_table (void)
-{
- auto grub_uint32_t reflect (grub_uint32_t ref, int len);
- grub_uint32_t reflect (grub_uint32_t ref, int len)
- {
- grub_uint32_t result = 0;
- int i;
-
- for (i = 1; i <= len; i++)
- {
- if (ref & 1)
- result |= 1 << (len - i);
- ref >>= 1;
- }
-
- return result;
- }
-
- grub_uint32_t polynomial = 0x04c11db7;
- int i, j;
-
- for(i = 0; i < 256; i++)
- {
- crc32_table[i] = reflect(i, 8) << 24;
- for (j = 0; j < 8; j++)
- crc32_table[i] = (crc32_table[i] << 1) ^
- (crc32_table[i] & (1 << 31) ? polynomial : 0);
- crc32_table[i] = reflect(crc32_table[i], 32);
- }
-}
-
-grub_uint32_t
-grub_getcrc32 (grub_uint32_t crc, void *buf, int size)
-{
- int i;
- grub_uint8_t *data = buf;
-
- if (! crc32_table[1])
- init_crc32_table ();
-
- crc^= 0xffffffff;
-
- for (i = 0; i < size; i++)
- {
- crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ *data];
- data++;
- }
-
- return crc ^ 0xffffffff;
-}
+++ /dev/null
-/* crc.h - prototypes for crc */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2008 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_CRC_H
-#define GRUB_CRC_H 1
-
-grub_uint32_t grub_getcrc32 (grub_uint32_t crc, void *buf, int size);
-
-#endif /* ! GRUB_CRC_H */
#include <grub/term.h>
#include <grub/mm.h>
#include <grub/lib/hexdump.h>
-#include <grub/lib/crc.h>
+#include <grub/crypto.h>
#include <grub/command.h>
#include <grub/i18n.h>
static void
cmd_crc (char *pathname)
{
- grub_uint32_t crc = 0;
+ grub_uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
+ GRUB_MD_CRC32->init(crc32_context);
auto int crc_hook (grub_off_t ofs, char *buf, int len);
int crc_hook (grub_off_t ofs, char *buf, int len)
{
(void) ofs;
- crc = grub_getcrc32 (crc, buf, len);
+ GRUB_MD_CRC32->write(crc32_context, buf, len);
return 0;
}
read_file (pathname, crc_hook);
- printf ("%08x\n", crc);
+ GRUB_MD_CRC32->final(crc32_context);
+ printf ("%08x\n",
+ grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context)));
}
static void