1. package body Zip.CRC is 
  2.  
  3.    CRC32_Table : array (Unsigned_32'(0) .. 255) of Unsigned_32; 
  4.  
  5.    procedure Prepare_table is 
  6.  
  7.       -- CRC - 32 algorithm, ISO - 3309 
  8.       Seed : constant := 16#EDB88320#; 
  9.       l : Unsigned_32; 
  10.  
  11.    begin 
  12.       for i in CRC32_Table'Range loop 
  13.          l := i; 
  14.          for bit in 0 .. 7 loop 
  15.             if (l and 1) = 0 then 
  16.                l := Shift_Right (l, 1); 
  17.             else 
  18.                l := Shift_Right (l, 1) xor Seed; 
  19.             end if; 
  20.          end loop; 
  21.          CRC32_Table (i) := l; 
  22.       end loop; 
  23.    end Prepare_table; 
  24.  
  25.    procedure Update (Current_CRC : in out Unsigned_32; InBuf : Zip.Byte_Buffer) is 
  26.  
  27.       local_CRC : Unsigned_32 := Current_CRC; 
  28.  
  29.    begin 
  30.       for i in InBuf'Range loop 
  31.          local_CRC := CRC32_Table (16#FF# and 
  32.                                      (local_CRC xor Unsigned_32 (InBuf (i)))) xor Shift_Right (local_CRC, 8); 
  33.       end loop; 
  34.       Current_CRC := local_CRC; 
  35.    end Update; 
  36.  
  37.    table_empty : Boolean := True; 
  38.  
  39.    procedure Init (Current_CRC : out Unsigned_32) is 
  40.  
  41.    begin 
  42.       if table_empty then 
  43.          Prepare_table; 
  44.          table_empty := False; 
  45.       end if; 
  46.       Current_CRC := 16#FFFF_FFFF#; 
  47.    end Init; 
  48.  
  49.    function Final (Current_CRC : Unsigned_32) return Unsigned_32 is (not Current_CRC); 
  50.  
  51. end Zip.CRC;