raw
eucrypt_ch14_crc32      1 ------------------------------------------------------------------------------
eucrypt_ch14_crc32 2 ------------------------------------------------------------------------------
eucrypt_ch14_crc32 3 -- This file is part of 'CRC32' --
eucrypt_ch14_crc32 4 -- --
eucrypt_ch14_crc32 5 -- You do not have, nor can you ever acquire the right to use, copy or --
eucrypt_ch14_crc32 6 -- distribute this software ; Should you use this software for any purpose, --
eucrypt_ch14_crc32 7 -- or copy and distribute it to anyone or in any manner, you are breaking --
eucrypt_ch14_crc32 8 -- the laws of whatever soi-disant jurisdiction, and you promise to --
eucrypt_ch14_crc32 9 -- continue doing so for the indefinite future. In any case, please --
eucrypt_ch14_crc32 10 -- always : read and understand any software ; verify any PGP signatures --
eucrypt_ch14_crc32 11 -- that you use - for any purpose. --
eucrypt_ch14_crc32 12 -- --
eucrypt_ch14_crc32 13 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
eucrypt_ch14_crc32 14 ------------------------------------------------------------------------------
eucrypt_ch14_crc32 15 ------------------------------------------------------------------------------
eucrypt_ch14_crc32 16
eucrypt_ch14_crc32 17 -- CRC32, lookup-based implementation
eucrypt_ch14_crc32 18 -- S.MG, 2018
eucrypt_ch14_crc32 19 --
eucrypt_ch14_crc32 20 -- The CRC32 is a checksum calculated as the remainder of dividing
eucrypt_ch14_crc32 21 -- the input data by the 0x04C11DB7 polynomial. Specifications:
eucrypt_ch14_crc32 22 -- Name : "CRC-32"
eucrypt_ch14_crc32 23 -- Width : 32 (number of bits)
eucrypt_ch14_crc32 24 -- Poly : 04C11DB7 (generator polynomial)
eucrypt_ch14_crc32 25 -- Init : FFFFFFFF
eucrypt_ch14_crc32 26 -- RefIn : True (input is reflected)
eucrypt_ch14_crc32 27 -- RefOut : True (output is reflected)
eucrypt_ch14_crc32 28 -- XorOut : FFFFFFFF
eucrypt_ch14_crc32 29 -- Check : CBF43926 (expected value for input "123456789")
eucrypt_ch14_crc32 30 --
eucrypt_ch14_crc32 31 -- This implementation is based on the CRC32 specification in:
eucrypt_ch14_crc32 32 -- Sarwate, D.V. "Computation of Cyclic Redundancy Checks via Table Look-Up"
eucrypt_ch14_crc32 33 -- in Communications of the ACM, Vol. 31 No. 8, pp.1008-1013, Aug. 1988
eucrypt_ch14_crc32 34
eucrypt_ch14_crc32 35 with Interfaces; use Interfaces;
eucrypt_ch14_crc32 36
eucrypt_ch14_crc32 37 package CRC32 is
eucrypt_ch14_crc32 38 -- local, shorthand version of Interfaces. types
eucrypt_ch14_crc32 39 subtype CRC32 is Interfaces.Unsigned_32;
eucrypt_ch14_crc32 40 subtype Octet is Interfaces.Unsigned_8;
eucrypt_ch14_crc32 41
eucrypt_ch14_crc32 42 type Octet_Array is array( Integer range <> ) of Octet;
eucrypt_ch14_crc32 43
eucrypt_ch14_crc32 44 -- interface for external callers
eucrypt_ch14_crc32 45 -- calculate CRC32 for the given string
eucrypt_ch14_crc32 46 function CRC( S: in String ) return CRC32;
eucrypt_ch14_crc32 47
eucrypt_ch14_crc32 48 -- calculate CRC32 for the given array of octets
eucrypt_ch14_crc32 49 function CRC( Data: in Octet_Array ) return CRC32;
eucrypt_ch14_crc32 50
eucrypt_ch14_crc32 51
eucrypt_ch14_crc32 52 -- internal constants and helper methods
eucrypt_ch14_crc32 53 private
eucrypt_ch14_crc32 54 function Shift_Right( Value : CRC32;
eucrypt_ch14_crc32 55 Amount : Natural)
eucrypt_ch14_crc32 56 return CRC32;
eucrypt_ch14_crc32 57 pragma Import(Intrinsic, Shift_Right);
eucrypt_ch14_crc32 58
eucrypt_ch14_crc32 59 Init_Value : constant CRC32 := 16#FFFF_FFFF#; -- Initial value
eucrypt_ch14_crc32 60 Xor_Out : constant CRC32 := 16#FFFF_FFFF#; -- For extracting result
eucrypt_ch14_crc32 61 LSB_Mask : constant CRC32 := 16#0000_00FF#; -- lsb mask for a CRC32 value
eucrypt_ch14_crc32 62
eucrypt_ch14_crc32 63 -- lookup table with precomputed values for CRC32
eucrypt_ch14_crc32 64 Lookup : constant array (CRC32 range 0 .. 255) of CRC32 :=
eucrypt_ch14_crc32 65 (16#0000_0000#, 16#7707_3096#, 16#EE0E_612C#, 16#9909_51BA#,
eucrypt_ch14_crc32 66 16#076D_C419#, 16#706A_F48F#, 16#E963_A535#, 16#9E64_95A3#,
eucrypt_ch14_crc32 67 16#0EDB_8832#, 16#79DC_B8A4#, 16#E0D5_E91E#, 16#97D2_D988#,
eucrypt_ch14_crc32 68 16#09B6_4C2B#, 16#7EB1_7CBD#, 16#E7B8_2D07#, 16#90BF_1D91#,
eucrypt_ch14_crc32 69 16#1DB7_1064#, 16#6AB0_20F2#, 16#F3B9_7148#, 16#84BE_41DE#,
eucrypt_ch14_crc32 70 16#1ADA_D47D#, 16#6DDD_E4EB#, 16#F4D4_B551#, 16#83D3_85C7#,
eucrypt_ch14_crc32 71 16#136C_9856#, 16#646B_A8C0#, 16#FD62_F97A#, 16#8A65_C9EC#,
eucrypt_ch14_crc32 72 16#1401_5C4F#, 16#6306_6CD9#, 16#FA0F_3D63#, 16#8D08_0DF5#,
eucrypt_ch14_crc32 73 16#3B6E_20C8#, 16#4C69_105E#, 16#D560_41E4#, 16#A267_7172#,
eucrypt_ch14_crc32 74 16#3C03_E4D1#, 16#4B04_D447#, 16#D20D_85FD#, 16#A50A_B56B#,
eucrypt_ch14_crc32 75 16#35B5_A8FA#, 16#42B2_986C#, 16#DBBB_C9D6#, 16#ACBC_F940#,
eucrypt_ch14_crc32 76 16#32D8_6CE3#, 16#45DF_5C75#, 16#DCD6_0DCF#, 16#ABD1_3D59#,
eucrypt_ch14_crc32 77 16#26D9_30AC#, 16#51DE_003A#, 16#C8D7_5180#, 16#BFD0_6116#,
eucrypt_ch14_crc32 78 16#21B4_F4B5#, 16#56B3_C423#, 16#CFBA_9599#, 16#B8BD_A50F#,
eucrypt_ch14_crc32 79 16#2802_B89E#, 16#5F05_8808#, 16#C60C_D9B2#, 16#B10B_E924#,
eucrypt_ch14_crc32 80 16#2F6F_7C87#, 16#5868_4C11#, 16#C161_1DAB#, 16#B666_2D3D#,
eucrypt_ch14_crc32 81 16#76DC_4190#, 16#01DB_7106#, 16#98D2_20BC#, 16#EFD5_102A#,
eucrypt_ch14_crc32 82 16#71B1_8589#, 16#06B6_B51F#, 16#9FBF_E4A5#, 16#E8B8_D433#,
eucrypt_ch14_crc32 83 16#7807_C9A2#, 16#0F00_F934#, 16#9609_A88E#, 16#E10E_9818#,
eucrypt_ch14_crc32 84 16#7F6A_0DBB#, 16#086D_3D2D#, 16#9164_6C97#, 16#E663_5C01#,
eucrypt_ch14_crc32 85 16#6B6B_51F4#, 16#1C6C_6162#, 16#8565_30D8#, 16#F262_004E#,
eucrypt_ch14_crc32 86 16#6C06_95ED#, 16#1B01_A57B#, 16#8208_F4C1#, 16#F50F_C457#,
eucrypt_ch14_crc32 87 16#65B0_D9C6#, 16#12B7_E950#, 16#8BBE_B8EA#, 16#FCB9_887C#,
eucrypt_ch14_crc32 88 16#62DD_1DDF#, 16#15DA_2D49#, 16#8CD3_7CF3#, 16#FBD4_4C65#,
eucrypt_ch14_crc32 89 16#4DB2_6158#, 16#3AB5_51CE#, 16#A3BC_0074#, 16#D4BB_30E2#,
eucrypt_ch14_crc32 90 16#4ADF_A541#, 16#3DD8_95D7#, 16#A4D1_C46D#, 16#D3D6_F4FB#,
eucrypt_ch14_crc32 91 16#4369_E96A#, 16#346E_D9FC#, 16#AD67_8846#, 16#DA60_B8D0#,
eucrypt_ch14_crc32 92 16#4404_2D73#, 16#3303_1DE5#, 16#AA0A_4C5F#, 16#DD0D_7CC9#,
eucrypt_ch14_crc32 93 16#5005_713C#, 16#2702_41AA#, 16#BE0B_1010#, 16#C90C_2086#,
eucrypt_ch14_crc32 94 16#5768_B525#, 16#206F_85B3#, 16#B966_D409#, 16#CE61_E49F#,
eucrypt_ch14_crc32 95 16#5EDE_F90E#, 16#29D9_C998#, 16#B0D0_9822#, 16#C7D7_A8B4#,
eucrypt_ch14_crc32 96 16#59B3_3D17#, 16#2EB4_0D81#, 16#B7BD_5C3B#, 16#C0BA_6CAD#,
eucrypt_ch14_crc32 97 16#EDB8_8320#, 16#9ABF_B3B6#, 16#03B6_E20C#, 16#74B1_D29A#,
eucrypt_ch14_crc32 98 16#EAD5_4739#, 16#9DD2_77AF#, 16#04DB_2615#, 16#73DC_1683#,
eucrypt_ch14_crc32 99 16#E363_0B12#, 16#9464_3B84#, 16#0D6D_6A3E#, 16#7A6A_5AA8#,
eucrypt_ch14_crc32 100 16#E40E_CF0B#, 16#9309_FF9D#, 16#0A00_AE27#, 16#7D07_9EB1#,
eucrypt_ch14_crc32 101 16#F00F_9344#, 16#8708_A3D2#, 16#1E01_F268#, 16#6906_C2FE#,
eucrypt_ch14_crc32 102 16#F762_575D#, 16#8065_67CB#, 16#196C_3671#, 16#6E6B_06E7#,
eucrypt_ch14_crc32 103 16#FED4_1B76#, 16#89D3_2BE0#, 16#10DA_7A5A#, 16#67DD_4ACC#,
eucrypt_ch14_crc32 104 16#F9B9_DF6F#, 16#8EBE_EFF9#, 16#17B7_BE43#, 16#60B0_8ED5#,
eucrypt_ch14_crc32 105 16#D6D6_A3E8#, 16#A1D1_937E#, 16#38D8_C2C4#, 16#4FDF_F252#,
eucrypt_ch14_crc32 106 16#D1BB_67F1#, 16#A6BC_5767#, 16#3FB5_06DD#, 16#48B2_364B#,
eucrypt_ch14_crc32 107 16#D80D_2BDA#, 16#AF0A_1B4C#, 16#3603_4AF6#, 16#4104_7A60#,
eucrypt_ch14_crc32 108 16#DF60_EFC3#, 16#A867_DF55#, 16#316E_8EEF#, 16#4669_BE79#,
eucrypt_ch14_crc32 109 16#CB61_B38C#, 16#BC66_831A#, 16#256F_D2A0#, 16#5268_E236#,
eucrypt_ch14_crc32 110 16#CC0C_7795#, 16#BB0B_4703#, 16#2202_16B9#, 16#5505_262F#,
eucrypt_ch14_crc32 111 16#C5BA_3BBE#, 16#B2BD_0B28#, 16#2BB4_5A92#, 16#5CB3_6A04#,
eucrypt_ch14_crc32 112 16#C2D7_FFA7#, 16#B5D0_CF31#, 16#2CD9_9E8B#, 16#5BDE_AE1D#,
eucrypt_ch14_crc32 113 16#9B64_C2B0#, 16#EC63_F226#, 16#756A_A39C#, 16#026D_930A#,
eucrypt_ch14_crc32 114 16#9C09_06A9#, 16#EB0E_363F#, 16#7207_6785#, 16#0500_5713#,
eucrypt_ch14_crc32 115 16#95BF_4A82#, 16#E2B8_7A14#, 16#7BB1_2BAE#, 16#0CB6_1B38#,
eucrypt_ch14_crc32 116 16#92D2_8E9B#, 16#E5D5_BE0D#, 16#7CDC_EFB7#, 16#0BDB_DF21#,
eucrypt_ch14_crc32 117 16#86D3_D2D4#, 16#F1D4_E242#, 16#68DD_B3F8#, 16#1FDA_836E#,
eucrypt_ch14_crc32 118 16#81BE_16CD#, 16#F6B9_265B#, 16#6FB0_77E1#, 16#18B7_4777#,
eucrypt_ch14_crc32 119 16#8808_5AE6#, 16#FF0F_6A70#, 16#6606_3BCA#, 16#1101_0B5C#,
eucrypt_ch14_crc32 120 16#8F65_9EFF#, 16#F862_AE69#, 16#616B_FFD3#, 16#166C_CF45#,
eucrypt_ch14_crc32 121 16#A00A_E278#, 16#D70D_D2EE#, 16#4E04_8354#, 16#3903_B3C2#,
eucrypt_ch14_crc32 122 16#A767_2661#, 16#D060_16F7#, 16#4969_474D#, 16#3E6E_77DB#,
eucrypt_ch14_crc32 123 16#AED1_6A4A#, 16#D9D6_5ADC#, 16#40DF_0B66#, 16#37D8_3BF0#,
eucrypt_ch14_crc32 124 16#A9BC_AE53#, 16#DEBB_9EC5#, 16#47B2_CF7F#, 16#30B5_FFE9#,
eucrypt_ch14_crc32 125 16#BDBD_F21C#, 16#CABA_C28A#, 16#53B3_9330#, 16#24B4_A3A6#,
eucrypt_ch14_crc32 126 16#BAD0_3605#, 16#CDD7_0693#, 16#54DE_5729#, 16#23D9_67BF#,
eucrypt_ch14_crc32 127 16#B366_7A2E#, 16#C461_4AB8#, 16#5D68_1B02#, 16#2A6F_2B94#,
eucrypt_ch14_crc32 128 16#B40B_BE37#, 16#C30C_8EA1#, 16#5A05_DF1B#, 16#2D02_EF8D#);
eucrypt_ch14_crc32 129
eucrypt_ch14_crc32 130 end CRC32;