Add support for adler32 checksuming.
* grub-core/lib/adler32.c: New file. * Makefile.util.def (library): Add grub-core/lib/adler32.c to common. * util/import_gcry.py (cryptolist): Add adler32.
This commit is contained in:
parent
b3e9c48799
commit
9a8d32a24f
5 changed files with 168 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
|||
2011-08-20 Szymon Janc <szymon@janc.net.pl>
|
||||
|
||||
Add support for adler32 checksuming.
|
||||
|
||||
* grub-core/lib/adler32.c: New file.
|
||||
* Makefile.util.def (library): Add grub-core/lib/adler32.c to common.
|
||||
* util/import_gcry.py (cryptolist): Add adler32.
|
||||
|
||||
2011-08-20 Szymon Janc <szymon@janc.net.pl>
|
||||
|
||||
More work on LZO for btrfs support. Some fixes and code refactoring.
|
||||
|
|
|
@ -91,6 +91,7 @@ library = {
|
|||
common = grub-core/lib/LzFind.c;
|
||||
common = grub-core/lib/LzmaEnc.c;
|
||||
common = grub-core/lib/crc.c;
|
||||
common = grub-core/lib/adler32.c;
|
||||
common = grub-core/normal/datetime.c;
|
||||
common = grub-core/normal/misc.c;
|
||||
common = grub-core/partmap/acorn.c;
|
||||
|
|
|
@ -1687,3 +1687,8 @@ module = {
|
|||
common = commands/cacheinfo.c;
|
||||
condition = COND_ENABLE_CACHE_STATS;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = adler32;
|
||||
common = lib/adler32.c;
|
||||
};
|
||||
|
|
152
grub-core/lib/adler32.c
Normal file
152
grub-core/lib/adler32.c
Normal file
|
@ -0,0 +1,152 @@
|
|||
/* adler32.c - adler32 check. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 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/dl.h>
|
||||
#include <grub/crypto.h>
|
||||
|
||||
/* Based on adler32() from adler32.c of zlib-1.2.5 library. */
|
||||
|
||||
#define BASE 65521UL
|
||||
#define NMAX 5552
|
||||
|
||||
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
static grub_uint32_t
|
||||
update_adler32 (grub_uint32_t adler, const grub_uint8_t *buf, grub_size_t len)
|
||||
{
|
||||
unsigned long sum2;
|
||||
unsigned int n;
|
||||
|
||||
sum2 = (adler >> 16) & 0xffff;
|
||||
adler &= 0xffff;
|
||||
|
||||
if (len == 1)
|
||||
{
|
||||
adler += buf[0];
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
sum2 += adler;
|
||||
if (sum2 >= BASE)
|
||||
sum2 -= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
if (len < 16)
|
||||
{
|
||||
while (len--)
|
||||
{
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
if (adler >= BASE)
|
||||
adler -= BASE;
|
||||
sum2 %= BASE;
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
while (len >= NMAX)
|
||||
{
|
||||
len -= NMAX;
|
||||
n = NMAX / 16;
|
||||
do
|
||||
{
|
||||
DO16 (buf);
|
||||
buf += 16;
|
||||
}
|
||||
while (--n);
|
||||
adler %= BASE;
|
||||
sum2 %= BASE;
|
||||
}
|
||||
|
||||
if (len)
|
||||
{
|
||||
while (len >= 16)
|
||||
{
|
||||
len -= 16;
|
||||
DO16 (buf);
|
||||
buf += 16;
|
||||
}
|
||||
while (len--)
|
||||
{
|
||||
adler += *buf++;
|
||||
sum2 += adler;
|
||||
}
|
||||
adler %= BASE;
|
||||
sum2 %= BASE;
|
||||
}
|
||||
|
||||
return adler | (sum2 << 16);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
grub_uint32_t adler;
|
||||
grub_uint8_t buf[4];
|
||||
}
|
||||
adler32_context;
|
||||
|
||||
static void
|
||||
adler32_init (void *context)
|
||||
{
|
||||
adler32_context *ctx = (adler32_context *) context;
|
||||
ctx->adler = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
adler32_write (void *context, const void *inbuf, grub_size_t inlen)
|
||||
{
|
||||
adler32_context *ctx = (adler32_context *) context;
|
||||
if (!inbuf)
|
||||
return;
|
||||
ctx->adler = update_adler32 (ctx->adler, inbuf, inlen);
|
||||
}
|
||||
|
||||
static grub_uint8_t *
|
||||
adler32_read (void *context)
|
||||
{
|
||||
adler32_context *ctx = (adler32_context *) context;
|
||||
return ctx->buf;
|
||||
}
|
||||
|
||||
static void
|
||||
adler32_final (void *context __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
gcry_md_spec_t _gcry_digest_spec_adler32 = {
|
||||
"ADLER32",0 , 0, 0 , 4,
|
||||
adler32_init, adler32_write, adler32_final, adler32_read,
|
||||
sizeof (adler32_context),
|
||||
.blocksize = 64
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(adler32)
|
||||
{
|
||||
grub_md_register (&_gcry_digest_spec_adler32);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(adler32)
|
||||
{
|
||||
grub_md_unregister (&_gcry_digest_spec_adler32);
|
||||
}
|
|
@ -81,6 +81,8 @@ cryptolist.write ("AES-128: gcry_rijndael\n");
|
|||
cryptolist.write ("AES-192: gcry_rijndael\n");
|
||||
cryptolist.write ("AES-256: gcry_rijndael\n");
|
||||
|
||||
cryptolist.write ("ADLER32: adler32\n");
|
||||
|
||||
for cipher_file in cipher_files:
|
||||
infile = os.path.join (cipher_dir_in, cipher_file)
|
||||
outfile = os.path.join (cipher_dir_out, cipher_file)
|
||||
|
|
Loading…
Reference in a new issue