carlos tafoya and john kaplar. block ciphers (a primitive of cryptography) require heavy use of bit...

15
Carlos Tafoya and John Kaplar

Post on 21-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Carlos Tafoya and John Kaplar

Page 2: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction of bits, rotation of bits). This is easy in hardware, but in software this requires custom functions that are tedious to code and test.

Free, formal cryptographic languages are nonexistent.

Page 3: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

A simple language called LIMP (Logical Imperative)

LIMP will simplify the bit manipulation that block ciphers require

Limp has a C-like syntax Currently Limp Can fully support the DES

block cipher The interpreter for LIMP is written in Java

Page 4: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Cryptographic languages are rare Only commercial one is called Cryptol Cryptol is a domain specific programming

language for cryptography Developed for the NSA and heavily used in

the aerospace and defense industries. Cryptol is not free! Cryptol has ML-like syntax (Yuck!! or

Yeah!!) http://www.galois.com/

Page 5: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Block Ciphers Definition for a Block Cipher B

◦ B is a function that takes an n-bit plaintext (i.e. the message), a k-bit key and produces an n-bit cipher-text (i.e. the encrypted message)

N = {0,1} , the set of all n-bit binary strings

{0,1} , the set of all k-bit binary strings

B:N K N, where B is 1-to-1 for a fixed element e K

n

k

let

K

Page 6: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

DES (Data Encryption Standard)

Page 7: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Limp Data Types Bit-Vector

◦ A Bit vector is an n-bit twos complement integer.◦ The number of bits, or Bit-Vector Width, can be

fully controlled by the programmer◦ Bit-Vectors can be declared in binary(0b), hex(0x)

or decimal Arrays

◦ Arrays of Bit-Vectors

Page 8: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

•Limp Expression Operators Expression Operators

◦ Limp Contains the normal expression operators +,-,*,/,&,|,^,!,<<,>>

Limp also has 4 special operators <<< (rotate a bit vector left)

0b0110 <<< 2 = 0b1001 >>> (rotate a bit vector right)

0b0110 >>> 1 = 0b0011 @ (Bit Vector Concatenation)

0b000 @ 0b111 = 0b000111 # (Bit Vector Width restrictor)

3 # (0b0111+0b0111) =110 (not 01110)

Page 9: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Limp Built-in Functions permute(vector, permArray)

◦ This functions takes a Bit-Vector (vector) and an array that specifies how the bits of the vector are to be permuted (permArray) and returns a new bit vector containing the permutation.

◦ The Permutation may be smaller, larger or the same size as the Bit-Vector being permuted (i.e. compression, expansion, and permutation)

◦ Example v = 0b0011 permute(v, [3,2,1,0]) = 0b1100 permute(v, [2,1]) = 0b10 Permute(v, [3,2,1,0,3]) = 0b11001

Page 10: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Limp Built-in Functions extract(vector, start, end)

◦ This function takes a Bit-Vector (vector), a start index (start), and an end index (end) and returns a new Bit-Vector whose value is the bit range [start,end] from the passed in Bit-Vector

◦ Example v = 0b000111 extract(v, 1,3) = 0b001

Page 11: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Limp Commands e (expression evaluation) r = e (assignment) c1;c2 (sequencing) loop e c (looping) print e (printing values)

Page 12: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Limp Example (Key Schedule)

keySchedule(masterKey) { p1 = [ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 ];

p2 = [ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 ];

rotate = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];

permKey = permute(masterKey, p1); left = extract(permKey,0,27); right = extract(permKey,28,55);

keys = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; count = 0; loop 16 { left = left <<< rotate[count]; right = right <<< rotate[count]; keys[count] = permute(left@right,p2); count = count + 1; } return keys;}

Page 13: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Same Functionality in Cstatic void des_key_schedule(const char * _rawkey, uint32_t * subkey){ const unsigned char *rawkey = (const unsigned char *) _rawkey; uint32_t left, right, work; int round;

READ_64BIT_DATA (rawkey, left, right) DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f) DO_PERMUTATION (right, work, left, 0, 0x10101010) left = ((leftkey_swap[(left >> 0) & 0xf] << 3) | (leftkey_swap[(left >> 8) & 0xf] << 2) | (leftkey_swap[(left >> 16) & 0xf] << 1) | (leftkey_swap[(left >> 24) & 0xf]) | (leftkey_swap[(left >> 5) & 0xf] << 7) | (leftkey_swap[(left >> 13) & 0xf] << 6) | (leftkey_swap[(left >> 21) & 0xf] << 5) | (leftkey_swap[(left >> 29) & 0xf] << 4));

left &= 0x0fffffff;

right = ((rightkey_swap[(right >> 1) & 0xf] << 3) | (rightkey_swap[(right >> 9) & 0xf] << 2) | (rightkey_swap[(right >> 17) & 0xf] << 1) | (rightkey_swap[(right >> 25) & 0xf]) | (rightkey_swap[(right >> 4) & 0xf] << 7) | (rightkey_swap[(right >> 12) & 0xf] << 6) | (rightkey_swap[(right >> 20) & 0xf] << 5) | (rightkey_swap[(right >> 28) & 0xf] << 4));

right &= 0x0fffffff;

for (round = 0; round < 16; ++round) { left = ((left << encrypt_rotate_tab[round]) | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; right = ((right << encrypt_rotate_tab[round]) | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;

*subkey++ = (((left << 4) & 0x24000000) | ((left << 28) & 0x10000000) | ((left << 14) & 0x08000000) | ((left << 18) & 0x02080000) | ((left << 6) & 0x01000000) | ((left << 9) & 0x00200000) | ((left >> 1) & 0x00100000) | ((left << 10) & 0x00040000) | ((left << 2) & 0x00020000) | ((left >> 10) & 0x00010000) | ((right >> 13) & 0x00002000) | ((right >> 4) & 0x00001000) | ((right << 6) & 0x00000800) | ((right >> 1) & 0x00000400) | ((right >> 14) & 0x00000200) | (right & 0x00000100) | ((right >> 5) & 0x00000020) | ((right >> 10) & 0x00000010) | ((right >> 3) & 0x00000008) | ((right >> 18) & 0x00000004) | ((right >> 26) & 0x00000002) | ((right >> 24) & 0x00000001));

*subkey++ = (((left << 15) & 0x20000000) | ((left << 17) & 0x10000000) | ((left << 10) & 0x08000000) | ((left << 22) & 0x04000000) | ((left >> 2) & 0x02000000) | ((left << 1) & 0x01000000) | ((left << 16) & 0x00200000) | ((left << 11) & 0x00100000) | ((left << 3) & 0x00080000) | ((left >> 6) & 0x00040000) | ((left << 15) & 0x00020000) | ((left >> 4) & 0x00010000) | ((right >> 2) & 0x00002000) | ((right << 8) & 0x00001000) | ((right >> 14) & 0x00000808) | ((right >> 9) & 0x00000400) | ((right) & 0x00000200) | ((right << 7) & 0x00000100) | ((right >> 7) & 0x00000020) | ((right >> 3) & 0x00000011) | ((right << 2) & 0x00000004) | ((right >> 21) & 0x00000002)); }}

Page 14: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

LIMP removes the complexity of dealing with bit manipulation in software.

Provides an easy and free alternative to Cryptol.

Page 15: Carlos Tafoya and John Kaplar.  Block ciphers (a primitive of cryptography) require heavy use of bit manipulation (i.e. permutation of bits, extraction

Do you have questions, concerns, or comments?