dion
May 13th, 2002, 04:02
i had got Hagen Reddmann's free TCipher package,which has Blowfish class with Init func :
procedure TCipher_Blowfish.Init(const Key; Size: Integer; IVector: Pointer);
var
I,J: Integer;
B: array[0..7] of Byte;
K: PByteArray;
P: PIntArray;
S: PBlowfish;
begin
InitBegin(Size);
K := @Key;
S := User;
P := Pointer(PChar(User) + SizeOf(Blowfish_Data));
Move(Blowfish_Data, S^, SizeOf(Blowfish_Data));
Move(Blowfish_Key, P^, Sizeof(Blowfish_Key));
J := 0;
for I := 0 to 17 do
begin
P[I] := P[I] xor (K[(J + 0) mod Size] shl 24 +
K[(J + 1) mod Size] shl 16 +
K[(J + 2) mod Size] shl 8 +
K[(J + 3) mod Size]);
J := (J + 4) mod Size;
end;
FillChar(B, SizeOf(B), 0);
for I := 0 to 8 do
begin
Encode(@B);
P[I * 2] := SwapInteger(PCipherRec(@B).A);
P[I * 2 + 1] := SwapInteger(PCipherRec(@B).B);
end;
for I := 0 to 3 do
for J := 0 to 127 do
begin
Encode(@B);
S[I, J * 2] := SwapInteger(PCipherRec(@B).A);
S[I, J * 2 +1] := SwapInteger(PCipherRec(@B).B);
end;
FillChar(B, SizeOf(B), 0);
InitEnd(IVector);
end;
i had question here, is BF_set_key in bf section of OpenSSL package is same like Init procedure here ? do the *IVector same like *Key in BF_set_key ? and then, blowfish is symetric cipher, right ? say that i'm gonna establish a connection with blowfish only. what i'm gonna do are pass our pwd to Init/BF_set_key, then i encode msg and send it to my pal in another side. now, my pal has to do the same, pass pwd to Init/set_key and then decode it. is this works ? coz i'm still not understand what Init/set_key do under the hood. i had read the counterpane tut. it said there's P & Sbox array. from Init func i see that P & Sbox array updated at the end. what i think is it's gonna be diff P & Sbox every time encode/decode gets called. and with this then i think such connection is can't be, coz the my pal's P & Sbox are diff from me since i've encode something while he do nothing yet. can anyone tell what's wrong with this ?
procedure TCipher_Blowfish.Init(const Key; Size: Integer; IVector: Pointer);
var
I,J: Integer;
B: array[0..7] of Byte;
K: PByteArray;
P: PIntArray;
S: PBlowfish;
begin
InitBegin(Size);
K := @Key;
S := User;
P := Pointer(PChar(User) + SizeOf(Blowfish_Data));
Move(Blowfish_Data, S^, SizeOf(Blowfish_Data));
Move(Blowfish_Key, P^, Sizeof(Blowfish_Key));
J := 0;
for I := 0 to 17 do
begin
P[I] := P[I] xor (K[(J + 0) mod Size] shl 24 +
K[(J + 1) mod Size] shl 16 +
K[(J + 2) mod Size] shl 8 +
K[(J + 3) mod Size]);
J := (J + 4) mod Size;
end;
FillChar(B, SizeOf(B), 0);
for I := 0 to 8 do
begin
Encode(@B);
P[I * 2] := SwapInteger(PCipherRec(@B).A);
P[I * 2 + 1] := SwapInteger(PCipherRec(@B).B);
end;
for I := 0 to 3 do
for J := 0 to 127 do
begin
Encode(@B);
S[I, J * 2] := SwapInteger(PCipherRec(@B).A);
S[I, J * 2 +1] := SwapInteger(PCipherRec(@B).B);
end;
FillChar(B, SizeOf(B), 0);
InitEnd(IVector);
end;
i had question here, is BF_set_key in bf section of OpenSSL package is same like Init procedure here ? do the *IVector same like *Key in BF_set_key ? and then, blowfish is symetric cipher, right ? say that i'm gonna establish a connection with blowfish only. what i'm gonna do are pass our pwd to Init/BF_set_key, then i encode msg and send it to my pal in another side. now, my pal has to do the same, pass pwd to Init/set_key and then decode it. is this works ? coz i'm still not understand what Init/set_key do under the hood. i had read the counterpane tut. it said there's P & Sbox array. from Init func i see that P & Sbox array updated at the end. what i think is it's gonna be diff P & Sbox every time encode/decode gets called. and with this then i think such connection is can't be, coz the my pal's P & Sbox are diff from me since i've encode something while he do nothing yet. can anyone tell what's wrong with this ?