raw
eucrypt_crc32_div...    1 ------------------------------------------------------------------------------
eucrypt_crc32_div... 2 ------------------------------------------------------------------------------
eucrypt_crc32_div... 3 -- This file is part of 'CRC32' --
eucrypt_crc32_div... 4 -- --
eucrypt_crc32_div... 5 -- You do not have, nor can you ever acquire the right to use, copy or --
eucrypt_crc32_div... 6 -- distribute this software ; Should you use this software for any purpose, --
eucrypt_crc32_div... 7 -- or copy and distribute it to anyone or in any manner, you are breaking --
eucrypt_crc32_div... 8 -- the laws of whatever soi-disant jurisdiction, and you promise to --
eucrypt_crc32_div... 9 -- continue doing so for the indefinite future. In any case, please --
eucrypt_crc32_div... 10 -- always : read and understand any software ; verify any PGP signatures --
eucrypt_crc32_div... 11 -- that you use - for any purpose. --
eucrypt_crc32_div... 12 -- --
eucrypt_crc32_div... 13 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
eucrypt_crc32_div... 14 ------------------------------------------------------------------------------
eucrypt_crc32_div... 15 ------------------------------------------------------------------------------
eucrypt_crc32_div... 16
eucrypt_crc32_div... 17 -- CRC32, modulo 2 based implementation
eucrypt_crc32_div... 18 -- S.MG, 2018
eucrypt_crc32_div... 19 --
eucrypt_crc32_div... 20 -- The CRC32 is a checksum calculated as the remainder of dividing
eucrypt_crc32_div... 21 -- the input data by the 0x04C11DB7 polynomial. Specifications:
eucrypt_crc32_div... 22 -- Name : "CRC-32"
eucrypt_crc32_div... 23 -- Width : 32 (number of bits)
eucrypt_crc32_div... 24 -- Poly : 04C11DB7 (generator polynomial)
eucrypt_crc32_div... 25 -- Init : FFFFFFFF
eucrypt_crc32_div... 26 -- RefIn : True (input is reflected)
eucrypt_crc32_div... 27 -- RefOut : True (output is reflected)
eucrypt_crc32_div... 28 -- XorOut : FFFFFFFF
eucrypt_crc32_div... 29 -- Check : CBF43926 (expected value for input "123456789")
eucrypt_crc32_div... 30 --
eucrypt_crc32_div... 31 -- This implementation is based on the CRC32 example in:
eucrypt_crc32_div... 32 -- Ross N. Williams, A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS
eucrypt_crc32_div... 33 -- version 3, 1993
eucrypt_crc32_div... 34 -- http://ross.net/crc/download/crc_v3.txt
eucrypt_crc32_div... 35
eucrypt_crc32_div... 36 with Interfaces; use Interfaces;
eucrypt_crc32_div... 37
eucrypt_crc32_div... 38 package CRC32 is
eucrypt_crc32_div... 39 -- local, shorthand version of Interfaces. types
eucrypt_crc32_div... 40 subtype CRC32 is Interfaces.Unsigned_32;
eucrypt_crc32_div... 41 subtype Octet is Interfaces.Unsigned_8;
eucrypt_crc32_div... 42
eucrypt_crc32_div... 43 type Octet_Array is array( Integer range <> ) of Octet;
eucrypt_crc32_div... 44
eucrypt_crc32_div... 45 -- interface for external callers
eucrypt_crc32_div... 46 -- calculate CRC32 for the given string
eucrypt_crc32_div... 47 function CRC( S: in String ) return CRC32;
eucrypt_crc32_div... 48
eucrypt_crc32_div... 49 -- calculate CRC32 for the given array of octets
eucrypt_crc32_div... 50 function CRC( Data: in Octet_Array ) return CRC32;
eucrypt_crc32_div... 51
eucrypt_crc32_div... 52 -- internal constants and helper methods
eucrypt_crc32_div... 53 private
eucrypt_crc32_div... 54 -- These functions need to be imported to get to the shift operators.
eucrypt_crc32_div... 55 -- (Specific for GNAT)
eucrypt_crc32_div... 56 function Shift_Left ( Value : CRC32;
eucrypt_crc32_div... 57 Amount : Natural )
eucrypt_crc32_div... 58 return CRC32;
eucrypt_crc32_div... 59 function Shift_Right ( Value : CRC32;
eucrypt_crc32_div... 60 Amount : Natural )
eucrypt_crc32_div... 61 return CRC32;
eucrypt_crc32_div... 62 function Rotate_Left ( Value : CRC32;
eucrypt_crc32_div... 63 Amount : Natural )
eucrypt_crc32_div... 64 return CRC32;
eucrypt_crc32_div... 65 function Rotate_Right ( Value : CRC32;
eucrypt_crc32_div... 66 Amount : Natural )
eucrypt_crc32_div... 67 return CRC32;
eucrypt_crc32_div... 68
eucrypt_crc32_div... 69 pragma Import ( Intrinsic, Rotate_Left );
eucrypt_crc32_div... 70 pragma Import ( Intrinsic, Rotate_Right );
eucrypt_crc32_div... 71 pragma Import ( Intrinsic, Shift_Left );
eucrypt_crc32_div... 72 pragma Import ( Intrinsic, Shift_Right );
eucrypt_crc32_div... 73
eucrypt_crc32_div... 74
eucrypt_crc32_div... 75 -- The Shift_Left instruction does not return the bit that was shifted
eucrypt_crc32_div... 76 -- We need a mask for this last bit
eucrypt_crc32_div... 77 -- Bits are counted from right to left, starting at 0
eucrypt_crc32_div... 78 Bit31 : constant CRC32 := 16#80_00_00_00#;
eucrypt_crc32_div... 79
eucrypt_crc32_div... 80 procedure CRC_Step(C : in out CRC32; R : in out CRC32);
eucrypt_crc32_div... 81 pragma Inline_Always(CRC_Step);
eucrypt_crc32_div... 82
eucrypt_crc32_div... 83 function Bits_Reverse(A : in CRC32) return CRC32;
eucrypt_crc32_div... 84
eucrypt_crc32_div... 85 end CRC32;