srecord  1.65.0
fletcher32.h
Go to the documentation of this file.
1 //
2 // srecord - Manipulate EPROM load files
3 // Copyright (C) 2009-2011 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program 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 GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef SRECORD_FLETCHER32_H
20 #define SRECORD_FLETCHER32_H
21 
22 #include <stddef.h>
23 
24 namespace srecord
25 {
26 
27 /**
28  * The fletcher32 class is used to represent the running value of a 32-bit
29  * Fletcher's Checksum of a series of bytes.
30  *
31  * http://en.wikipedia.org/wiki/Fletcher%27s_checksum
32  *
33  * Fletcher's checksum is one of several types of checksum algorithms,
34  * which are relatively simple processes used by computers to check the
35  * integrity of data.
36  *
37  * The implementation of the Fletcher-32 is very similar to the Adler-32
38  * algorithm but several differences should be noted. Fletcher wraps around
39  * at modulo 65535 while Adler wraps at the prime 65521. In other words,
40  * Fletcher adds overflow bits (16-31) into its sum; while Adler multiplies
41  * those bits by 15, then adds the product into its sum. Fletcher-32 works
42  * on 16 bit data while Adler works on 8 bit data.
43  *
44  * It is designed to overcome some of the inadequacies of simply summing
45  * all the bytes as in the original checksum. Fletcher's checksum, unlike
46  * the original checksum, can detect the inserting/deleting of zero value
47  * bytes, the reordering of bytes, and the incrementing and decrementing of
48  * bytes in opposite directions.
49  *
50  * Fletcher's checksum is described in RFC 1146. You can also find
51  * information about generating (as well as verifying) such a checksum in
52  * Annex B of RFC 905.
53  *
54  * Fletcher-32 is slightly more reliable than Adler-32.[1]
55  */
57 {
58 public:
59  /**
60  * The destructor.
61  */
62  virtual ~fletcher32();
63 
64  /**
65  * The default constructor.
66  */
68 
69  /**
70  * The copy constructor.
71  */
73 
74  /**
75  * The assignment operator.
76  */
78 
79  /**
80  * The get method is used to obtain the running value of the cyclic
81  * redundancy check.
82  */
83  unsigned long get() const;
84 
85  /**
86  * The next method is used to advance the state by one byte.
87  */
88  void next(unsigned char);
89 
90  /**
91  * The nextbuf method is used to advance the state by a series of bytes.
92  */
93  void nextbuf(const void *, size_t);
94 
95 private:
96  /**
97  * The sum1 instance variable is used to remember the sum of the bytes.
98  */
99  unsigned long sum1;
100 
101  /**
102  * The sum2 instance variable is used to remember the sum of the
103  * sum of the bytes.
104  */
105  unsigned long sum2;
106 };
107 
108 };
109 
110 // vim: set ts=8 sw=4 et :
111 #endif // SRECORD_FLETCHER32_H
The fletcher32 class is used to represent the running value of a 32-bit Fletcher's Checksum of a seri...
Definition: fletcher32.h:57
unsigned long get() const
The get method is used to obtain the running value of the cyclic redundancy check.
fletcher32 & operator=(const fletcher32 &)
The assignment operator.
fletcher32()
The default constructor.
fletcher32(const fletcher32 &)
The copy constructor.
void nextbuf(const void *, size_t)
The nextbuf method is used to advance the state by a series of bytes.
virtual ~fletcher32()
The destructor.
void next(unsigned char)
The next method is used to advance the state by one byte.