diff --git a/ChangeLog b/ChangeLog index 1bde1bc8f..0207c9d2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2010-09-20 Szymon Janc + + 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 * grub-core/boot/i386/pc/boot.S: Ignore %dl if it's not in a sane range. diff --git a/Makefile.util.def b/Makefile.util.def index 191938efd..34b3648b1 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -72,11 +72,11 @@ library = { 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; @@ -186,6 +186,8 @@ program = { ldadd = libgrub.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER)'; + cflags = '$(CFLAGS_GCRY)'; + cppflags = '$(CPPFLAGS_GCRY)'; }; program = { diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index efd3fec8d..8e6b82ca5 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -486,12 +486,6 @@ module = { enable = x86; }; -module = { - name = crc; - common = commands/crc.c; - common = lib/crc.c; -}; - module = { name = date; common = commands/date.c; diff --git a/grub-core/commands/crc.c b/grub-core/commands/crc.c deleted file mode 100644 index f165e1aaf..000000000 --- a/grub-core/commands/crc.c +++ /dev/null @@ -1,72 +0,0 @@ -/* 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 . - */ - -#include -#include -#include -#include -#include -#include -#include - -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); -} diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c index e926c0435..df297b585 100644 --- a/grub-core/commands/hashsum.c +++ b/grub-core/commands/hashsum.c @@ -41,6 +41,7 @@ struct { const char *name; const char *hashname; } aliases[] = {"sha256sum", "sha256"}, {"sha512sum", "sha512"}, {"md5sum", "md5"}, + {"crc", "crc32"}, }; static inline int @@ -248,7 +249,7 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt, 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) { @@ -272,6 +273,12 @@ 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) @@ -280,4 +287,5 @@ GRUB_MOD_FINI(hashsum) grub_unregister_extcmd (cmd_md5); grub_unregister_extcmd (cmd_sha256); grub_unregister_extcmd (cmd_sha512); + grub_unregister_extcmd (cmd_crc); } diff --git a/grub-core/efiemu/prepare.c b/grub-core/efiemu/prepare.c index 620260049..171e092c9 100644 --- a/grub-core/efiemu/prepare.c +++ b/grub-core/efiemu/prepare.c @@ -20,9 +20,9 @@ #include #include -#include +#include #include -#include +#include grub_err_t SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks, @@ -123,6 +123,7 @@ SUFFIX (grub_efiemu_crc) (void) 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", @@ -132,19 +133,25 @@ SUFFIX (grub_efiemu_crc) (void) 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); diff --git a/grub-core/lib/crc.c b/grub-core/lib/crc.c deleted file mode 100644 index bc0d8aa8d..000000000 --- a/grub-core/lib/crc.c +++ /dev/null @@ -1,75 +0,0 @@ -/* 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 . - */ - -#include -#include - -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; -} diff --git a/include/grub/lib/crc.h b/include/grub/lib/crc.h deleted file mode 100644 index ff7284dc8..000000000 --- a/include/grub/lib/crc.h +++ /dev/null @@ -1,25 +0,0 @@ -/* 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 . - */ - -#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 */ diff --git a/util/grub-fstest.c b/util/grub-fstest.c index eb7981d3a..bcc9ea942 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -239,19 +239,22 @@ cmd_hex (char *pathname) 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