Showing posts with label Ciphers. Show all posts
Showing posts with label Ciphers. Show all posts

Saturday, January 12, 2013

Tiny Encryption Algorithm (TEA)

TEA is an algorithm with a couple weaknesses. Still, the algorithm is a block cipher notable for its simplicity of description and a C implementation of just a few lines of code.

It was designed by David Wheeler and Roger Needham of the Cambridge Computer Laboratory, first presented at the Fast Software Encryption workshop in Leuven in 1994, and first published in the proceedings of that workshop.

It's an ideal algorithm for testing new frameworks and modes of operation. The first caveat is to make sure your installation produces the proper outputs to reference inputs. Then you can build your framework around it confident that if your output breaks, it's the framework at fault.

The authors suggest in its reference notes that anything you can do with or to DES will work just as well with TEA.

TEA operates on two 32-bit unsigned integers, uses a 128-bit key, and chunks out similar 32-bit unsigned integers. Conveniently you can feed it pointers to character strings of this size and it will cast them to longs.

The original reference implementation accepts three pointers (input,output, key) which makes the necessary CBC mode adapters easier to attach.

Standard usage calls for 64 Feistel rounds which is 32 cycles of the algorithm.
Make n = 32.

The effective key size is 126 bits which is plenty for keeping my diary secure.

Here is the ANSI C implementation I use :
void encipher(unsigned long *const v,unsigned long *const w,
   const unsigned long *const k){

   register unsigned long 
     y=v[0],z=v[1],n=32,
     sum=0,delta=0x9E3779B9,
     a=k[0],b=k[1],c=k[2],d=k[3];

   while(n-->0) {
      sum += delta;
      y += (z << 4)+a ^ z+sum ^ (z >> 5)+b;
      z += (y << 4)+c ^ y+sum ^ (y >> 5)+d;
   }
   w[0]=y; w[1]=z;
}

void decipher(unsigned long *const v,unsigned long *const w,
   const unsigned long *const k){

   register unsigned long 
     y=v[0],z=v[1],n=32,
     sum=0xC6EF3720,delta=0x9E3779B9,
     a=k[0],b=k[1], c=k[2],d=k[3];

   while(n-->0) {
      z -= (y << 4)+c ^ y+sum ^ (y >> 5)+d;
      y -= (z << 4)+a ^ z+sum ^ (z >> 5)+b;
      sum -= delta;
   }
   w[0]=y; w[1]=z;
}


Test Vectors :

Plain Text :

Cipher Key :

Cipher Text :


Tuesday, January 08, 2013

Secure Hash Algorithms (SHA-1 and SHA-256)

Secure Hash Algorithms (SHA-1 and SHA-256)

Secure Hash Algorithms, a form of symmetric encryption, is also included in VIA processors based on the ‘Esther' core.

Implementing the SHA-1 and SHA-256 variants of secure hash, the VIA Padlock SHA engine can deliver real-time data encryption peaking at 5 gigabits per second.

This algorithm is again endorsed and used at all levels of the U.S. Government and operates by compressing the data needed and encrypting it into message digests. Each message digest is created so that the information inside is computationally infeasible to be read by an outside party.

Table: An example of the message digests produced by SHA-1:

Original String SHA-1 Hash Digest
Hello World z7R8yBtZz0+eqead7UEYzPvVFjw=
VB L1SHP0uzGbMUpT4z0zlAdEzfPE=
Vb e0cnhoZRmuoC/Ed51RrW71x1CDw=
Vb e3Pa1F6tMmhPGUfGg1nrfdV31+1=
VB gzt6my3YlrzJiTiucvqBTgM6LtM=

By studying the contents of each SHA-1 secure hash digest it becomes immediately evident that a change of character case on the same word produces a completely different encrypted message.

In fact a change of just one bit within a message causes a completely different secure hash message digest to be created. This allows easy detection of message manipulation, as a message cannot be decrypted, altered even slightly and re-encrypted without producing an entirely different message digest. This is why most governments and organizations in the world now use a implementation of the secure hash algorithm.

SHA-256 is a more secure version of SHA-1, using a 256bit hash algorithm (SHA-1 uses a 160 bit algorithm), and is currently considered completely unbreakable.

Despite this advantage, SHA-1 and SHA-256 secure hash algorithms suffer from one drawback: they all require enormous consumption of processor cycles in the computation of digests, especially when a high throughput is required.

However, VIA has solved this problem by integrating the computation of secure hash algorithms SHA-1 and SHA-256 directly onto the processor die.

By incorporating secure hash into the VIA PadLock Security Engine, VIA has effectively shifted the computational process of large-scale number crunching away from the main processor to the PadLock engine.

Thus, a developer can include real-time secure hash encryption in their applications without worrying that the process will significantly affect other applications or processes running concurrently.


AES - Advanced Encryption Standard


Symmetric-Key Algorithm : Vintage - 2001

AES is based on a design principle known as a substitution-permutation network, and is fast in both software and hardware. AES does not use a Feistel network.

High speed and low RAM requirements were criteria of the AES selection process. Thus AES performs well on a wide variety of hardware, from 8-bit smart cards to high-performance computers.

The design and strength of all key lengths of the AES algorithm (i.e., 128, 192 and 256) are sufficient to protect classified information up to the SECRET level. TOP SECRET information will require use of either the 192 or 256 key lengths.

AES has a block size of 128 bits (16 bytes) and three available key lengths of 128, 192, 256 bits.

Give the algorithm a key, and then feed it 16 byte blocks and get back 16 byte blocks.

It works the same way for either encrypt or decrypt.

 

Thursday, February 10, 2011

RC-4

RC-4(w)

Key length: Minimum 8, maximum 2048, multiple of 8 bits; default 128 bits.

RC-2

RC-2(w)


Key length: Minimum 0; maximum 1024, multiple of 8 bits; default 128 bits.
Block size: 8 bytes.

IDEA

IDEA(w)

Block size: 8 bytes.
Key length: 128 bits.

DES

DES(w)

Block size: 8 bytes
Key length: 64 bits as encoded; 56 bits excluding parity bits.

RC-6

RC-6(w)

In cryptography, RC6 is a symmetric key block cipher derived from RC5.

RC6 proper has a block size of 128 bits and supports key sizes of 128, 192 and 256 bits, but, like RC5, it can be parameterized to support a wide variety of word-lengths, key sizes and number of rounds.

CAST5

CAST5

Block size: 8 bytes.
Key length: Minimum 40, maximum 128, multiple of 8 bits; default 128 bits.

Skipjack

Skipjack(w)

Block size: 8 bytes.
Key length: 80 bits.

Serpent

Serpent(w)

Block size: 16 bytes.
Key length: Minimum 0, maximum 256, multiple of 8 bits; default 128 bits.

Twofish

Twofish(w)

In cryptography, Twofish is a symmetric key block cipher with a block size of 128 bits and key sizes up to 256 bits. It was one of the five finalists of the Advanced Encryption Standard contest, but was not selected for standardisation. Twofish is related to the earlier block cipher Blowfish.

On most software platforms Twofish is slightly slower than Rijndael (the chosen algorithm for Advanced Encryption Standard) for 128-bit keys, but somewhat faster for 256-bit keys.

Twofish has a 128-bit block size, a key size ranging from 128 to 256 bits, and is optimized for 32-bit CPUs. Currently there is no successful cryptanalysis of Twofish.

Block sizes : 128 bits
Key sizes : 128, 192 or 256 bits

Blowfish

Blowfish

Blowfish is a keyed, symmetric block cipher, designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products. Blowfish provides a good encryption rate in software and no effective cryptanalysis of it has been found to date. Blowfish is a fast block cipher, except when changing keys.

Bruce Schneier notes that while Blowfish is still in use, he recommends using the more recent Twofish algorithm instead.

Block Size : 64 bits
Key Sizes : 32–448 bits in steps of 8 bits

Wednesday, November 03, 2010

Triple-DES (DESde)