hedgewars/uSHA.pas
changeset 2157 a2fa7f594842
parent 1066 1f1b3686a2b0
child 2630 079ef82eac75
equal deleted inserted replaced
2156:3f1a19802d10 2157:a2fa7f594842
    27                     end;
    27                     end;
    28      TSHA1Digest =  array[0..4] of LongWord;
    28      TSHA1Digest =  array[0..4] of LongWord;
    29 
    29 
    30 procedure SHA1Init(var Context: TSHA1Context);
    30 procedure SHA1Init(var Context: TSHA1Context);
    31 procedure SHA1Update(var Context: TSHA1Context; Buf: PByteArray; Length: LongWord);
    31 procedure SHA1Update(var Context: TSHA1Context; Buf: PByteArray; Length: LongWord);
       
    32 procedure SHA1UpdateLongwords(var Context: TSHA1Context; Buf: PLongwordArray; Length: LongWord);
    32 function  SHA1Final(Context: TSHA1Context): TSHA1Digest;
    33 function  SHA1Final(Context: TSHA1Context): TSHA1Digest;
    33 
    34 
    34 implementation
    35 implementation
    35 
    36 
    36 function rol(x: LongWord; y: Byte): LongWord;
    37 function rol(x: LongWord; y: Byte): LongWord;
   114        Context.CurrLength:= 0
   115        Context.CurrLength:= 0
   115        end
   116        end
   116     end
   117     end
   117 end;
   118 end;
   118 
   119 
       
   120 procedure SHA1UpdateLongwords(var Context: TSHA1Context; Buf: PLongwordArray; Length: LongWord);
       
   121 var i: Longword;
       
   122 begin
       
   123 for i:= 0 to Pred(Length div 4) do
       
   124     begin
       
   125     SDLNet_Write32(Buf^[i], @Context.Buf[Context.CurrLength]);
       
   126     inc(Context.CurrLength, 4);
       
   127     if Context.CurrLength = 64 then
       
   128        begin
       
   129        SHA1Hash(Context);
       
   130        inc(Context.Length, 512);
       
   131        Context.CurrLength:= 0
       
   132        end
       
   133     end
       
   134 end;
       
   135 
   119 function  SHA1Final(Context: TSHA1Context): TSHA1Digest;
   136 function  SHA1Final(Context: TSHA1Context): TSHA1Digest;
   120 var i: LongWord;
   137 var i: LongWord;
   121 begin
   138 begin
   122 Context.Length:= Context.Length + Context.CurrLength shl 3;
   139 Context.Length:= Context.Length + Context.CurrLength shl 3;
   123 Context.Buf[Context.CurrLength]:= $80;
   140 Context.Buf[Context.CurrLength]:= $80;