Browse Source

fix for issue #39333

Michaël Van Canneyt 3 năm trước cách đây
mục cha
commit
fe656ab4ef
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 5 3
      packages/hash/src/hmac.pp

+ 5 - 3
packages/hash/src/hmac.pp

@@ -142,6 +142,7 @@ var
   PKey, POPad, PIPad: PChar;
   PKey, POPad, PIPad: PChar;
   VKey, VOPad, VIPad: string;
   VKey, VOPad, VIPad: string;
 begin
 begin
+  // Set up masking block from key.
   VLength := Length(AKey);
   VLength := Length(AKey);
   if VLength > SHA1_BLOCK_SIZE then
   if VLength > SHA1_BLOCK_SIZE then
   begin
   begin
@@ -153,16 +154,17 @@ begin
   begin
   begin
     SetLength(VKey, SHA1_BLOCK_SIZE - VLength);
     SetLength(VKey, SHA1_BLOCK_SIZE - VLength);
     FillChar(Pointer(VKey)^, SHA1_BLOCK_SIZE - VLength, #0);
     FillChar(Pointer(VKey)^, SHA1_BLOCK_SIZE - VLength, #0);
-    VKey := AKey + VKey;
+    VKey := AKey + VKey; // VKEY now has length SHA1_BLOCK_SIZE
   end;
   end;
+  PKey := PChar(VKey);
+  // Padding blocks
   SetLength(VOPad, SHA1_BLOCK_SIZE);
   SetLength(VOPad, SHA1_BLOCK_SIZE);
   POPad := PChar(VOPad);
   POPad := PChar(VOPad);
   FillChar(POPad^, SHA1_BLOCK_SIZE, $5c);
   FillChar(POPad^, SHA1_BLOCK_SIZE, $5c);
   SetLength(VIPad, SHA1_BLOCK_SIZE);
   SetLength(VIPad, SHA1_BLOCK_SIZE);
   PIPad := PChar(VIPad);
   PIPad := PChar(VIPad);
   FillChar(PIPad^, SHA1_BLOCK_SIZE, $36);
   FillChar(PIPad^, SHA1_BLOCK_SIZE, $36);
-  PKey := PChar(VKey);
-  for I := 1 to VLength do
+  for I := 1 to SHA1_BLOCK_SIZE do
   begin
   begin
     POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
     POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
     PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));
     PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));