1
/*************************************************
2
* Adler32 Source File *
3
* (C) 1999-2007 The Botan Project *
4
*************************************************/
6
#include <botan/adler32.h>
7
#include <botan/bit_ops.h>
11
/*************************************************
13
*************************************************/
14
void Adler32::hash(const byte input[], u32bit length)
16
u32bit S1x = S1, S2x = S2;
19
S1x += input[ 0]; S2x += S1x;
20
S1x += input[ 1]; S2x += S1x;
21
S1x += input[ 2]; S2x += S1x;
22
S1x += input[ 3]; S2x += S1x;
23
S1x += input[ 4]; S2x += S1x;
24
S1x += input[ 5]; S2x += S1x;
25
S1x += input[ 6]; S2x += S1x;
26
S1x += input[ 7]; S2x += S1x;
27
S1x += input[ 8]; S2x += S1x;
28
S1x += input[ 9]; S2x += S1x;
29
S1x += input[10]; S2x += S1x;
30
S1x += input[11]; S2x += S1x;
31
S1x += input[12]; S2x += S1x;
32
S1x += input[13]; S2x += S1x;
33
S1x += input[14]; S2x += S1x;
34
S1x += input[15]; S2x += S1x;
38
for(u32bit j = 0; j != length; ++j)
40
S1x += input[j]; S2x += S1x;
48
/*************************************************
49
* Update an Adler32 Checksum *
50
*************************************************/
51
void Adler32::add_data(const byte input[], u32bit length)
53
const u32bit PROCESS_AMOUNT = 5552;
54
while(length >= PROCESS_AMOUNT)
56
hash(input, PROCESS_AMOUNT);
57
input += PROCESS_AMOUNT;
58
length -= PROCESS_AMOUNT;
63
/*************************************************
64
* Finalize an Adler32 Checksum *
65
*************************************************/
66
void Adler32::final_result(byte output[])
68
output[0] = get_byte(2, S2);
69
output[1] = get_byte(3, S2);
70
output[2] = get_byte(2, S1);
71
output[3] = get_byte(3, S1);