Einzelnen Beitrag anzeigen

qwertz543221
(Gast)

n/a Beiträge
 
#5

AW: Advanced Encryption Standard 128 bit Eigenimplementierung - key schedule

  Alt 28. Dez 2012, 23:06
Habe es hinbekommen:

Delphi-Quellcode:
Function Taes.Expandkey(Key: Tinput; Var Expandedkey: Tkey128): Byte;
//expands given key (128,192,256 bit, determined by bitlen variable) to (176,208,240 bytes)
//blocksize=16=>keysize 128 bit
//result:= the number of rounds (10,12,14) determined by new keylength
//SRC= http://www.samiam.org/key-schedule.html
//http://cboard.cprogramming.com/c-programming/87805-%5Btutorial%5D-implementing-advanced-encryption-standard.html
Var
  I, Rconiterator, A, C: Integer;
  Temp: Tword;
Begin
  I := 1;
  While I <= Length(Key) Do
  Begin
    Expandedkey[I] := Key[I];
    Inc(I);
  End;
  { inc(i);
    while i<=length(expandedkey) do
    begin
    expandedkey[i]:=0;
    inc(i);
    end; }


  Rconiterator := 1;

  C := Length(Key) + 1; //17
  While C <= 176 Do
  Begin
    { Copy the temporary variable over from the last 4-byte- block }
    A := 1;
    While A <= 4 Do
    Begin
      //showmessage(inttostr(a)+';'+inttostr(c));
      Temp[A] := Expandedkey[A + C - 5]; //ok
      Inc(A);
    End;
    //Every four blocks (of four bytes) do a complex calculation
    If ((C - 1) Mod 16 = 0) Then
    Begin
      Keyschedule_core(Temp, Rconiterator, 0);
      Inc(Rconiterator);
    End;
    A := 1;
    While A <= 4 Do
    Begin
      //Expandedkey[C+1] := Expandedkey[C - 16] Xor Temp[A];
      Expandedkey[C] := Expandedkey[C - 16] Xor Temp[A];
      Inc(C);
      Inc(A);
    End;

  End;

  Result := 11; //number of rounds for 128 bit keys
End;
  Mit Zitat antworten Zitat