Results 1 to 14 of 14

Thread: Blowfish Init<>set_key

  1. #1
    dion
    Guest

    Blowfish Init<>set_key

    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 ?
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  2. #2
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    If you both know the password, then you have no need of SSL. SSL is for establishing connections between computers with no prior relationship and involves asymmetric (public-key) crypto.

    Blowfish is a 64-bit symmetric cipher. Use a hash function to convert your passphrase into a 64-bit key. Then you encrypt using that key, and he decrypts using that key.

  3. #3
    dion
    Guest
    hi Mike, i don't understand how the connection is establihed, i mean how the protocol works out. is it true when i encrypt msg with a key [init blowfish] then the s-box and p array is get updated ? if then how the other computer can decrypt it without knowing the updated s-box and p array ?
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  4. #4
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    If you both put the same key (or passphrase) into blowfish, it will synchronize itself. As your friend begins to decrypt the message, his cipher's internal state will change in the same way as yours did and everything will work fine.

    The S and P boxes are initialized before encrypting, when you supply the key. They don't change after that.

    I said to use a hash function on your passphrase to get 64 bits of key. You can do that, or you can just put the key in directly to blowfish, since the key length is variable.

    Is Delphi your language of choice? There are other easy-to-use implementations in other languages, too.
    Last edited by mike; May 18th, 2002 at 19:18.

  5. #5
    dion
    Guest
    Quote:
    "The S and P boxes are initialized before encrypting, when you supply the key. They don't change after that. "

    why is that? what's in my mind is s-box and p box are both got updated each time i encrypt/decrypt something, is that true? coz u say it in the beginning that internal's state'll changed. well, i agree with that. but after both put the key to init, and then i put my msg to encrypt and send it to him. and in this point, i think the s-box and p-box got updated again, right? what i think again is...is it true that the only one who can decrypt it is me, coz the my 1st internal state has changed and the other is not yet ?

    to be clear say like this:
    s1,p1 -----[init with my key]----> s1',p1'
    s2,p2------[init with his key,same]-----> s2',p2'
    s1',p1'-----[encrypt my msg]------>s1'',p1''
    s2',p2'-----[decrypt my msg]------>?

    yep, in this point i don't understand.
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  6. #6
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    "The S and P boxes are initialized before encrypting, when you supply the key. They don't change after that. "

    why is that? what's in my mind is s-box and p box are both got updated each time i encrypt/decrypt something, is that true?
    No, the S and P box don't change when you encrypt something. You set them up once when you provide the key and they don't change until you want a new key.

    Quoting from Applied Crypto:

    Blowfish is a Feistel network consisting of 16 rounds. The input is a 64-bit data element x. To encrypt:
    Code:
    Divide x into two 32-bit halves, xl and xr
    for i=1 to 16
        xl=xl XOR Pi
        xr=F(xl) XOR xr
        swap xl and xr
    end for
    swap xl and xr (undo the last swap)
    xr=xr XOR P17
    xl=xl XOR P18
    recombine xl and xr
    That's the code for encrypting one block. If you do that to every block, you get ECB mode encryption. Note that the S and P tables are only referenced, not modified.

  7. #7
    dion
    Guest
    ? encrypt/decrypt not change s/p box, or i'm wrong reading that s-box are session dependent ?
    um.. about Feistel network. i see that encrypt/decrypt just involve reverse subkey for input to F(). if encrypt/decrypt is not changing s/p box, is it possible to make the s/p box to earlier state, with reverse the subkey for F()?

    i see one using blowfish like this :
    s,p ----[key]---> s',p' for init
    s',p'----[xored key]--->ciphertext for encrypt

    is it a secure way ? is it known as one of four mode operation ?
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  8. #8
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    Look, it's not that hard. For a given key, you set up the S and P boxes ONCE and then they never change again. Encrypt, decrypt, it doesn't matter. They don't change as long as the key is the same.

    For decryption, you're right, you use them in reverse order, but they DON'T CHANGE.

  9. #9
    dion
    Guest
    if it really doesn't change, then am i wrong if i say the blowfish strength is at difficulty in reverse the s/pbox to earlier [phi] state ?
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  10. #10
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    if it really doesn't change, then am i wrong if i say the blowfish strength is at difficulty in reverse the s/pbox to earlier [phi] state ?
    The hard problem is deriving the S and P boxes when you don't know the password. There'd be no point in reversing the S & P boxes to the phi state. If you knew the S & P boxes, you wouldn't need to know the key, since only the S & P boxes are used for encryption.

    If all you get to see is a bunch of plaintexts and the corresponding ciphertexts, then it's very hard to figure out the S & P boxes.

  11. #11
    dion
    Guest
    ok, i got that. and thanks for all of your replies, Mike, since i see noone replying me anymore, maybe coz i'm very new-b.
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  12. #12
    dion
    Guest

    Lightbulb

    oh! Hi, Mike, you said that there are other easy-to-use implementations in other languages. i want to know that, please tell me.

    thanks
    I promise that I have read the FAQ and tried to use the Search to answer my question.

  13. #13
    הבּרוּ נשׂאי כּלי יהוה mike's Avatar
    Join Date
    Mar 2001
    Posts
    491
    Try Wei Dai's Crypto++ library

    www.eskimo.com/~weidai

    (if that doesn't work, remove the tilde)

  14. #14
    dion
    Guest
    thanks Mike
    I promise that I have read the FAQ and tried to use the Search to answer my question.

Similar Threads

  1. Blowfish and SHA-1 analysis on cacheX
    By Lbolt99 in forum RCE Cryptographics
    Replies: 18
    Last Post: May 5th, 2004, 21:18
  2. Blowfish
    By peterg70 in forum RCE Cryptographics
    Replies: 14
    Last Post: September 25th, 2002, 00:39
  3. Blowfish Bruteforce 48 bits
    By Lbolt99 in forum RCE Cryptographics
    Replies: 2
    Last Post: July 26th, 2002, 14:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •