VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (n

by Patterson Programming (5 Submissions)
Category: Math/Dates
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 31st December 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (no shifts/no unsigned ints) This is

Rate The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (n



Designed and published in 1996, the LeapFrog cipher design is for implementations that require a cipher which does not use any shifts/rotates. The user-entered key is expanded into S-boxes using a non-linear method somewhat similar to the stream cipher RC4. The diffusion is provided by compound lookups into the S-boxes. The cipher is implemented with a Feistel-like structure. Three bytes on the left are mixed through the S-box function and combined with a target byte on the right using the Xor operator. This is used for each of the four target bytes on the right. Using asymmetry in the function, groups of two and three are selected to provide maximal diffusion. Also, each byte on the left is added to its opposite on the right. Thus, the round function consists of four parallel functions which look like the parity function in MD5, but using the noted lookups, and also the add operations. Note that the Xor/Add combination create a Feistel cipher that is NOT self-inverse with an odd number of rounds. Also, the cipher uses distinct S-boxes for each half of the Feistel network, and halves are not actually swapped.

How the LeapFrog2 cipher differs from the LeapFrog cipher:

    1) Instead of simple whitening Xors LeapFrog2 uses
       pseudo-random round keys like Blowfish, etc.
    2) The structural symmetry is broken up by using
       a different ordering in rounds 0-3 and rounds 4-7.
       (the hash function MD5 uses something similar)

This is commentary regarding the LeapFrog2 cipher. The origin of the cipher is of a graphical nature. Consider a Blowfish-like function where four 8x32 lookups are Xored together. Ignore the fact that Blowfish also employs a 32-bit add. In that case, rather than Xoring the four 32-bit values together, you could (using groups of four bytes) Xor four bytes together, and Xor them with the other half. (using 16-bytes per round) You could think of it like Blowfish structured "backwards". You could then build a cipher to have more non-linearity than a Blowfish design. The LeapFrog design builds on this idea using compound (chained) substitutions. This function is similar to the key-expansion function in Twofish. (Although it is used for an entirely different purpose.) The LeapFrog design may look somewhat similar to a Skipjack-like or RC2-like design, except that LeapFrog uses S-boxes, not pure math, as the diffusion element. Also, LeapFrog uses a balanced Feistel network, not an unbalanced one like those ciphers or MacGuffin. LeapFrog diffusion is complete at 3 rounds like Blowfish. Note that the LeapFrog design blurs the destinction between nonlinear substitution and diffusion. To diffuse a block, why would you restrict the design to use only 2-in/2-out diffusion blocks. Why not make it cubic, or use even more dimensions? As stated, LeapFrog accomplishes this using compound or "chained" S-boxes. Unlike the original work of Ritter, the S-box diffusion in LeapFrog is all non-linear. Using the Feistel design, LeapFrog decryption does not need to employ inverse S-boxes. Also, some key-independent diffusion is provided by the add operation across the block halves. The add operation also has the effect of making a Feistel cipher not self-inverse with an odd number of rounds. Key-expansion: You could view the key-expansion code in LeapFrog as combining elements from ones employed in RC4 and Diamond2. The key entropy is mainly expressed in the S-boxes, not the subkeys. Although in LeapFrog2, the "subkeys" are non-cyclical like the ones employed in Blowfish. It should be noted that this analysis is entirely retrospective. I did not know of most of these cipher designs when I designed LeapFrog. I am not providing any differential or linear analysis here, you can do that for yourself. You might trust your own abilities more than my own.

This is a TYPO-CORRECTED pseudo-code example showing the
LeapFrog2 block-cipher. It uses a 64-bit block and a variable-bit key.

T1, T2, T3, T4 are signed integers
p1....p8 are signed integers

Subroutine LeapFrogEncrypt

    For BlockNumber = 1 To Blocks

        * read plaintext block into p1....p8

        * LeapFrogRounds are 8
        For x = 0 To (LeapFrogRounds / 2) - 1

            * create the T variables
            T1 = A1(p1 Xor SK(x, 0))
            T2 = A2(p2 Xor SK(x, 1))
            T3 = A3(p3 Xor SK(x, 2))
            T4 = A4(p4 Xor SK(x, 3))

            * T variable order "A"
            p5 = p5 Xor A1(A1(T2 Xor T3) Xor T4)
            p6 = p6 Xor A2(A2(T1 Xor T4) Xor T3)
            p7 = p7 Xor A3(A3(T4 Xor T2) Xor T1)
            p8 = p8 Xor A4(A4(T3 Xor T1) Xor T2)
            p5 = (p5 + T1) And HFF
            p6 = (p6 + T2) And HFF
            p7 = (p7 + T3) And HFF
            p8 = (p8 + T4) And HFF

            * do other half without swapping
            T1 = A5(p5 Xor SK(x, 4))
            T2 = A6(p6 Xor SK(x, 5))
            T3 = A7(p7 Xor SK(x, 6))
            T4 = A8(p8 Xor SK(x, 7))

            p1 = p1 Xor A5(A5(T2 Xor T3) Xor T4)
            p2 = p2 Xor A6(A6(T1 Xor T4) Xor T3)
            p3 = p3 Xor A7(A7(T4 Xor T2) Xor T1)
            p4 = p4 Xor A8(A8(T3 Xor T1) Xor T2)
            p1 = (p1 + T1) And HFF
            p2 = (p2 + T2) And HFF
            p3 = (p3 + T3) And HFF
            p4 = (p4 + T4) And HFF

        Next

        For x = (LeapFrogRounds / 2) To (LeapFrogRounds - 1)

            * create the T variables
            T1 = A1(p1 Xor SK(x, 0))
            T2 = A2(p2 Xor SK(x, 1))
            T3 = A3(p3 Xor SK(x, 2))
            T4 = A4(p4 Xor SK(x, 3))

            * T variable order "B"
            p5 = p5 Xor A1(A1(T2 Xor T3) Xor T4)
            p6 = p6 Xor A2(A2(T3 Xor T4) Xor T1)
            p7 = p7 Xor A3(A3(T4 Xor T1) Xor T2)
            p8 = p8 Xor A4(A4(T1 Xor T2) Xor T3)
            p5 = (p5 + T1) And HFF
            p6 = (p6 + T2) And HFF
            p7 = (p7 + T3) And HFF
            p8 = (p8 + T4) And HFF

            * do other half without swapping
            T1 = A5(p5 Xor SK(x, 4))
            T2 = A6(p6 Xor SK(x, 5))
            T3 = A7(p7 Xor SK(x, 6))
            T4 = A8(p8 Xor SK(x, 7))

            p1 = p1 Xor A5(A5(T2 Xor T3) Xor T4)
            p2 = p2 Xor A6(A6(T3 Xor T4) Xor T1)
            p3 = p3 Xor A7(A7(T4 Xor T1) Xor T2)
            p4 = p4 Xor A8(A8(T1 Xor T2) Xor T3)
            p1 = (p1 + T1) And HFF
            p2 = (p2 + T2) And HFF
            p3 = (p3 + T3) And HFF
            p4 = (p4 + T4) And HFF

        Next

        * whiten data
        p1 = p1 Xor SK(LeapFrogRounds, 0)
        p2 = p2 Xor SK(LeapFrogRounds, 1)
        p3 = p3 Xor SK(LeapFrogRounds, 2)
        p4 = p4 Xor SK(LeapFrogRounds, 3)

        p5 = p5 Xor SK(LeapFrogRounds, 4)
        p6 = p6 Xor SK(LeapFrogRounds, 5)
        p7 = p7 Xor SK(LeapFrogRounds, 6)
        p8 = p8 Xor SK(LeapFrogRounds, 7)

        * write ciphertext block from p1....p8

    Next

End Subroutine LeapFrogEncrypt

Subroutine LeapFrogDecrypt

    For BlockNumber = 1 To Blocks

        * read ciphertext block into p1....p8

        * unwhiten data
        p1 = p1 Xor SK(LeapFrogRounds, 0)
        p2 = p2 Xor SK(LeapFrogRounds, 1)
        p3 = p3 Xor SK(LeapFrogRounds, 2)
        p4 = p4 Xor SK(LeapFrogRounds, 3)

        p5 = p5 Xor SK(LeapFrogRounds, 4)
        p6 = p6 Xor SK(LeapFrogRounds, 5)
        p7 = p7 Xor SK(LeapFrogRounds, 6)
        p8 = p8 Xor SK(LeapFrogRounds, 7)

        For y = 0 To (LeapFrogRounds / 2) - 1

            * invert subkeys
            x = (LeapFrogRounds - 1) - y

            * create the T variables
            T1 = A5(p5 Xor SK(x, 4))
            T2 = A6(p6 Xor SK(x, 5))
            T3 = A7(p7 Xor SK(x, 6))
            T4 = A8(p8 Xor SK(x, 7))

           * T variable order "B"
            p1 = (p1 - T1) And HFF
            p2 = (p2 - T2) And HFF
            p3 = (p3 - T3) And HFF
            p4 = (p4 - T4) And HFF
            p1 = p1 Xor A5(A5(T2 Xor T3) Xor T4)
            p2 = p2 Xor A6(A6(T3 Xor T4) Xor T1)
            p3 = p3 Xor A7(A7(T4 Xor T1) Xor T2)
            p4 = p4 Xor A8(A8(T1 Xor T2) Xor T3)

            * do other half without swapping
            T1 = A1(p1 Xor SK(x, 0))
            T2 = A2(p2 Xor SK(x, 1))
            T3 = A3(p3 Xor SK(x, 2))
            T4 = A4(p4 Xor SK(x, 3))

            p5 = (p5 - T1) And HFF
            p6 = (p6 - T2) And HFF
            p7 = (p7 - T3) And HFF
            p8 = (p8 - T4) And HFF
            p5 = p5 Xor A1(A1(T2 Xor T3) Xor T4)
            p6 = p6 Xor A2(A2(T3 Xor T4) Xor T1)
            p7 = p7 Xor A3(A3(T4 Xor T1) Xor T2)
            p8 = p8 Xor A4(A4(T1 Xor T2) Xor T3)

        Next

        For y = (LeapFrogRounds / 2) To (LeapFrogRounds - 1)

            * invert subkeys
            x = (LeapFrogRounds - 1) - y

            * create the T variables
            T1 = A5(p5 Xor SK(x, 4))
            T2 = A6(p6 Xor SK(x, 5))
            T3 = A7(p7 Xor SK(x, 6))
            T4 = A8(p8 Xor SK(x, 7))

           * T variable order "A"
            p1 = (p1 - T1) And HFF
            p2 = (p2 - T2) And HFF
            p3 = (p3 - T3) And HFF
            p4 = (p4 - T4) And HFF
            p1 = p1 Xor A5(A5(T2 Xor T3) Xor T4)
            p2 = p2 Xor A6(A6(T1 Xor T4) Xor T3)
            p3 = p3 Xor A7(A7(T4 Xor T2) Xor T1)
            p4 = p4 Xor A8(A8(T3 Xor T1) Xor T2)

            * do other half without swapping
            T1 = A1(p1 Xor SK(x, 0))
            T2 = A2(p2 Xor SK(x, 1))
            T3 = A3(p3 Xor SK(x, 2))
            T4 = A4(p4 Xor SK(x, 3))

            p5 = (p5 - T1) And HFF
            p6 = (p6 - T2) And HFF
            p7 = (p7 - T3) And HFF
            p8 = (p8 - T4) And HFF
            p5 = p5 Xor A1(A1(T2 Xor T3) Xor T4)
            p6 = p6 Xor A2(A2(T1 Xor T4) Xor T3)
            p7 = p7 Xor A3(A3(T4 Xor T2) Xor T1)
            p8 = p8 Xor A4(A4(T3 Xor T1) Xor T2)

        Next

        * write plaintext block from p1....p8

    Next

End Subroutine LeapFrogDecrypt

Subroutine LeapFrogExpandKey

    * replicate key into array

    y = 0
    For x = 0 To 255
        LongKey(x) = k(y)
        y = (y + 1) Mod RealKeyLen
    Next

    * initialize expanded key arrays
    For i = 0 To 255
        A1(i) = i, A5(i) = i
        A2(i) = i, A6(i) = i
        A3(i) = i, A7(i) = i
        A4(i) = i, A8(i) = i
    Next

    j = 0
    * randomize array
    For i = 0 To 255
        j = (j + A1(i) + LongKey(i)) And HFF
        Exchange A1(i), A1(j)
    Next
    For i = 0 To 255
        j = (j + A1(i)) And HFF, Exchange A1(i), A1(j)
    Next

    * randomize the other arrays
    For i = 0 To 255
        j = (j + A1(A2(i)) + A1(LongKey(i))) And HFF
        Exchange A2(i), A2(j)
    Next
    For i = 0 To 255
        j = (j + A2(A3(i)) + A2(LongKey(i))) And HFF
        Exchange A3(i), A3(j)
    Next
    For i = 0 To 255
        j = (j + A3(A4(i)) + A3(LongKey(i))) And HFF
        Exchange A4(i), A4(j)
    Next

    For i = 0 To 255
        j = (j + A4(A5(i)) + A4(LongKey(i))) And HFF
        Exchange A5(i), A5(j)
    Next
    For i = 0 To 255
        j = (j + A5(A6(i)) + A5(LongKey(i))) And HFF
        Exchange A6(i), A6(j)
    Next
    For i = 0 To 255
        j = (j + A6(A7(i)) + A6(LongKey(i))) And HFF
        Exchange A7(i), A7(j)
    Next
    For i = 0 To 255
        j = (j + A7(A8(i)) + A7(LongKey(i))) And HFF
        Exchange A8(i), A8(j)
    Next

    * store zeros to SK array
    * make subkeys from S-boxes
    For i = 0 To 63
        SK(0, 0) = (SK(0, 0) + A1(i)) And HFF
        SK(0, 1) = (SK(0, 1) + A2(i)) And HFF
        SK(0, 2) = (SK(0, 2) + A3(i)) And HFF
        SK(0, 3) = (SK(0, 3) + A4(i)) And HFF
        SK(0, 4) = (SK(0, 4) + A5(i)) And HFF
        SK(0, 5) = (SK(0, 5) + A6(i)) And HFF
        SK(0, 6) = (SK(0, 6) + A7(i)) And HFF
        SK(0, 7) = (SK(0, 7) + A8(i)) And HFF
    Next
    For i = 0 To LeapFrogRounds - 1
        SK(i + 1, 0) = (SK(i, 0) + A1(64 + i)) And HFF
        SK(i + 1, 1) = (SK(i, 1) + A2(64 + i)) And HFF
        SK(i + 1, 2) = (SK(i, 2) + A3(64 + i)) And HFF
        SK(i + 1, 3) = (SK(i, 3) + A4(64 + i)) And HFF
        SK(i + 1, 4) = (SK(i, 4) + A5(64 + i)) And HFF
        SK(i + 1, 5) = (SK(i, 5) + A6(64 + i)) And HFF
        SK(i + 1, 6) = (SK(i, 6) + A7(64 + i)) And HFF
        SK(i + 1, 7) = (SK(i, 7) + A8(64 + i)) And HFF
    Next
    For i = 0 To LeapFrogRounds
        SK(i, 0) = A5(SK(i, 0))
        SK(i, 1) = A6(SK(i, 1))
        SK(i, 2) = A7(SK(i, 2))
        SK(i, 3) = A8(SK(i, 3))
    Next
    For i = 0 To LeapFrogRounds
        SK(i, 4) = A1(SK(i, 4))
        SK(i, 5) = A2(SK(i, 5))
        SK(i, 6) = A3(SK(i, 6))
        SK(i, 7) = A4(SK(i, 7))
    Next

End Sub LeapFrogExpand

Download this snippet    Add to My Saved Code

The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (n Comments

No comments have been posted about The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (n. Why not be the first to post a comment about The LeapFrog2 CIPHER that is used in StealthMail 2.1. Secure and designed for languages like VB. (n.

Post your comment

Subject:
Message:
0/1000 characters