2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2012 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #include <grub/crypto.h>
23 GRUB_MOD_LICENSE ("GPLv3+");
25 struct adler32_context
32 adler32_init (void *context
)
34 struct adler32_context
*ctx
= context
;
43 mod_add (grub_uint16_t a
, grub_uint16_t b
)
45 if ((grub_uint32_t
) a
+ (grub_uint32_t
) b
>= MOD
)
51 adler32_write (void *context
, const void *inbuf
, grub_size_t inlen
)
53 struct adler32_context
*ctx
= context
;
54 const grub_uint8_t
*ptr
= inbuf
;
58 ctx
->a
= mod_add (ctx
->a
, *ptr
);
59 ctx
->b
= mod_add (ctx
->a
, ctx
->b
);
66 adler32_final (void *context
__attribute__ ((unused
)))
71 adler32_read (void *context
)
73 struct adler32_context
*ctx
= context
;
78 ctx
->c
= grub_cpu_to_be32 (ctx
->a
| (ctx
->b
<< 16));
79 return (grub_uint8_t
*) &ctx
->c
;
82 static gcry_md_spec_t spec_adler32
=
84 "ADLER32", 0, 0, 0, 4,
85 adler32_init
, adler32_write
, adler32_final
, adler32_read
,
86 sizeof (struct adler32_context
),
94 GRUB_MOD_INIT(adler32
)
96 grub_md_register (&spec_adler32
);
99 GRUB_MOD_FINI(adler32
)
101 grub_md_unregister (&spec_adler32
);