~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/adler32.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* Adler32 Source File                            *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/adler32.h>
7
 
#include <botan/bit_ops.h>
8
 
 
9
 
namespace Botan {
10
 
 
11
 
/*************************************************
12
 
* Adler32 Checksum                               *
13
 
*************************************************/
14
 
void Adler32::hash(const byte input[], u32bit length)
15
 
   {
16
 
   u32bit S1x = S1, S2x = S2;
17
 
   while(length >= 16)
18
 
      {
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;
35
 
      input += 16;
36
 
      length -= 16;
37
 
      }
38
 
   for(u32bit j = 0; j != length; ++j)
39
 
      {
40
 
      S1x += input[j]; S2x += S1x;
41
 
      }
42
 
   S1x %= 65521;
43
 
   S2x %= 65521;
44
 
   S1 = S1x;
45
 
   S2 = S2x;
46
 
   }
47
 
 
48
 
/*************************************************
49
 
* Update an Adler32 Checksum                     *
50
 
*************************************************/
51
 
void Adler32::add_data(const byte input[], u32bit length)
52
 
   {
53
 
   const u32bit PROCESS_AMOUNT = 5552;
54
 
   while(length >= PROCESS_AMOUNT)
55
 
      {
56
 
      hash(input, PROCESS_AMOUNT);
57
 
      input += PROCESS_AMOUNT;
58
 
      length -= PROCESS_AMOUNT;
59
 
      }
60
 
   hash(input, length);
61
 
   }
62
 
 
63
 
/*************************************************
64
 
* Finalize an Adler32 Checksum                   *
65
 
*************************************************/
66
 
void Adler32::final_result(byte output[])
67
 
   {
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);
72
 
   clear();
73
 
   }
74
 
 
75
 
}