-
+ E065ABB2672AB869629579C4566ECFF5872E15FC06EB95D54B3AD29785BAD951EB1126B0AC5E40185EB3D24320445E3AB3AB3C25E424243D79AA295621CD1F33eucrypt/crc32/crc32.ads(0 . 0)(1 . 85)
169 ------------------------------------------------------------------------------
170 ------------------------------------------------------------------------------
171 -- This file is part of 'CRC32'                                             --
172 --                                                                          --
173 -- You do not have, nor can you ever acquire the right to use, copy or      --
174 -- distribute this software ; Should you use this software for any purpose, -- 
175 -- or copy and distribute it to anyone or in any manner, you are breaking   --
176 -- the laws of whatever soi-disant jurisdiction, and you promise to         --
177 -- continue doing so for the indefinite future. In any case, please         --
178 -- always : read and understand any software ; verify any PGP signatures    --
179 -- that you use - for any purpose.                                          --
180 --                                                                          --
181 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm .     --
182 ------------------------------------------------------------------------------
183 ------------------------------------------------------------------------------
184 
185   -- CRC32, modulo 2 based implementation
186   -- S.MG, 2018
187   --
188   -- The CRC32 is a checksum calculated as the remainder of dividing
189   -- the input data by the 0x04C11DB7 polynomial. Specifications:
190   -- Name   : "CRC-32"
191   -- Width  : 32        (number of bits)
192   -- Poly   : 04C11DB7  (generator polynomial)
193   -- Init   : FFFFFFFF
194   -- RefIn  : True      (input is reflected)  
195   -- RefOut : True      (output is reflected)
196   -- XorOut : FFFFFFFF
197   -- Check  : CBF43926  (expected value for input "123456789")
198   --
199   -- This implementation is based on the CRC32 example in:
200   -- Ross N. Williams, A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS
201   -- version 3, 1993
202   -- http://ross.net/crc/download/crc_v3.txt
203 
204 with Interfaces; use Interfaces;
205 
206 package CRC32 is
207   -- local, shorthand version of Interfaces. types
208   subtype CRC32 is Interfaces.Unsigned_32;
209   subtype Octet is Interfaces.Unsigned_8;
210 
211   type Octet_Array is array( Integer range <> ) of Octet;
212 
213   -- interface for external callers
214     -- calculate CRC32 for the given string
215   function CRC( S: in String ) return CRC32;
216 
217     -- calculate CRC32 for the given array of octets
218   function CRC( Data: in Octet_Array ) return CRC32;
219   
220   -- internal constants and helper methods
221 private
222   -- These functions need to be imported to get to the shift operators. 
223   -- (Specific for GNAT)
224   function Shift_Left ( Value  : CRC32; 
225                         Amount : Natural )
226                         return CRC32;
227   function Shift_Right ( Value  : CRC32; 
228                          Amount : Natural )
229                          return CRC32;
230   function Rotate_Left ( Value  : CRC32; 
231                          Amount : Natural )
232                          return CRC32;
233   function Rotate_Right ( Value  : CRC32; 
234                          Amount : Natural )
235                          return CRC32;
236   
237   pragma Import ( Intrinsic, Rotate_Left );
238   pragma Import ( Intrinsic, Rotate_Right );
239   pragma Import ( Intrinsic, Shift_Left  );
240   pragma Import ( Intrinsic, Shift_Right ); 
241   
242   
243   -- The Shift_Left instruction does not return the bit that was shifted
244   -- We need a mask for this last bit
245   -- Bits are counted from right to left, starting at 0
246   Bit31 : constant CRC32 := 16#80_00_00_00#;
247   
248   procedure CRC_Step(C : in out CRC32; R : in out CRC32);
249   pragma Inline_Always(CRC_Step);
250   
251   function Bits_Reverse(A : in CRC32) return CRC32;
252   
253 end CRC32;