-
+ 936D9785BC02F35A58AC415074D9A7DAA857D24AF3093BAEA9BBF082D71E83EDB881EFCD2FCE95F774F600C6A99E8FE8F3C2C2EF7553C1E72556C31F6C7B7C3A
smg_comms/src/crc32.adb
(0 . 0)(1 . 52)
13 ------------------------------------------------------------------------------
14 ------------------------------------------------------------------------------
15 -- This file is part of 'CRC32' --
16 -- --
17 -- You do not have, nor can you ever acquire the right to use, copy or --
18 -- distribute this software ; Should you use this software for any purpose, --
19 -- or copy and distribute it to anyone or in any manner, you are breaking --
20 -- the laws of whatever soi-disant jurisdiction, and you promise to --
21 -- continue doing so for the indefinite future. In any case, please --
22 -- always : read and understand any software ; verify any PGP signatures --
23 -- that you use - for any purpose. --
24 -- --
25 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
26 ------------------------------------------------------------------------------
27 ------------------------------------------------------------------------------
28
29 -- CRC32 implementation
30 -- S.MG, 2018
31
32 package body CRC32 is
33 function CRC( S: in String ) return CRC32 is
34 Result : CRC32 := Init_Value;
35 Value : CRC32;
36 begin
37 -- process input character by character
38 for C of S loop
39 Value := CRC32( Character'Pos( C ) );
40 Result := Shift_Right(Result, 8) xor
41 Lookup( Value xor (Result and LSB_MASK));
42 end loop;
43 -- reflect result
44 Result := Result xor Xor_Out;
45
46 return Result;
47 end CRC;
48
49 function CRC( Data: in Octet_Array ) return CRC32 is
50 Result : CRC32 := Init_Value;
51 begin
52 -- process input octet by octet
53 for C of Data loop
54 Result := Shift_Right(Result, 8) xor
55 Lookup( CRC32(C) xor (Result and LSB_MASK));
56 end loop;
57 -- reflect result
58 Result := Result xor Xor_Out;
59
60 return Result;
61 end CRC;
62
63 end CRC32;
64