Welcome to securityCRUSH

Welcome to the securityCRUSH blog, a place where you can find random musings as well as postings relevant to information security, penetration testing, and my latest projects - Daniel Wood.
Showing posts with label cryptography. Show all posts
Showing posts with label cryptography. Show all posts

Thursday, March 8, 2012

Intro to Cryptography (Part 3)

XOR, otherwise known as the logical operation exclusive disjunction or just “exclusive or” in short; is a type of logical operation for two operands that will always result in the value of TRUE if at least one of the operands holds a TRUE value.  If you've taken algebra, this should be somewhat familiar to you…at least in principle.

A XOR cipher (additive) encryption is extremely resistant to brute force attacks which makes it a great method, however, it does have some inherent weaknesses due to the use of patterns.  Compression can help prevent pattern susceptibility.

To demonstrate this, we can look at what we would call a Truth Table (related to what is called a Cayley Table).

XOR Truth Table
Input Output
 A B
 0 0    0
 0 1    1
 1 0    1
 1 1    0

The XOR of A and B can be written out several ways; A⊗B, A XOR B, or A≠B

Binary XOR has two operands (or inputs) like the above Truth Table; where the inputs to a binary XOR table can only be 0 or 1.  The singular output of the combination of each pair of inputs likewise can only be a 0 or 1 (this is binary).To demonstrate this, let’s take two inputs, A and B, and denote the output as C below.

A     B C
0 XOR 0 0
0 XOR 1 1
1 XOR 0 1
1 XOR 1 0

As mentioned above, we are of course using only 0’s and 1’s for carrying out this binary operation.  If we have two binary numbers that we want to conduct a XOR for we would have something like the following:

binary 1 - 10110110
              XOR
binary 2 - 11001101
Result     01111011

Applying XOR to real world use.  A string of text can be used as an input into the XOR operation by applying bitwise XOR to every character within the string using an encryption key.  Decrypting the XOR’d string, you reapply the XOR with the encryption key used and it will remove the cipher from your string - thus decrypting your plain-text.

Example:
Let’s say we have our password, which will be “password”

Converting our password to 8-bit ASCII binary:

01110000 01100001 01110011 01110011 01110111 01101111 01110010 01100100

Our password (sic) is made up of 8 characters, as you can see in the above binary, there are 8 groupings of 8 digits.  As we know, 8-bits = 1 byte.  This gives us an 8-byte password (64-bits).  Now we want to encrypt our password with our encryption key.  For the sake of this example, I will inverse our password, making our encryption key “drowssap”:

Converting our key to 8-bit ASCII binary:

01100100 01110010 01101111 01110111 01110011 01110011 01100001 01110000

Now that we have our plain-text password string to encrypt with our key, we will use XOR to encrypt it:


Input:  01110000 01100001 01110011 01110011 01110111 01101111 01110010 01100100
Key:    01100100 01110010 01101111 01110111 01110011 01110011 01100001 01110000
Result: 00010100 00010011 00011100 00000100 00000100 00011100 00010011 00010100

The result is now our encrypted text.  To decrypt our text we will just carry out the XOR again against the key, this time our Input will be our encrypted string:


Input:  00010100 00010011 00011100 00000100 00000100 00011100 00010011 00010100
Key:    01100100 01110010 01101111 01110111 01110011 01110011 01100001 01110000
Result: 01110000 01100001 01110011 01110011 01110111 01101111 01110010 01100100

Resulting in -bit ASCII that when converted back to plaintext = “password”

As you should be able to deduce, the XOR operator is vulnerable to attack using a know-plaintext attack of plaintext XOR ciphertext = encryption key.

This concludes part 3 of Intro to Cryptography.  In part 4, we will go into the basics of Public Key Infrastructure (PKI), implementations of PKI and perhaps introduce another topic.  If there’s anything you want to see in this series, please leave a comment and let me know if you need help understanding anything I’m covering.

Tuesday, February 28, 2012

Intro to Cryptography (Part 2)

Last time I introduced cryptography, how it works, as well as some basic algorithms.  I don’t want to spend too much time on the basics, as I figure that knowing what plaintext and ciphertext are should be good enough to get you started.  Part 2 is going to focus on more advanced topics that may be complicated at first, but are generally easy to understand.  Now that we understand what encryption is, we need to know that cryptography can be either strong or weak.  To determine the strength of a type of encryption, we measure how long and how many resources it would take to break the encryption.  

When reading about encryption elsewhere, you may have heard of bits, bytes and words. Measuring an encryption standard for strength is noted by the amount of cryptographic bits used to encrypt the data.

Here are a few more definitions you should get acquainted with:

Hashing: or the process of running data as an input through a hash function returns a fixed-size string, also known as the hash value.

Within cryptography, hash functions have the following basic requirements:
  • Input can be of any length
  • Output (the hash) has a fixed length
  • Hashing is one way, collision-free and is easy to compute for any given x; where H(x).
 (where F = a compression function)

Common Hashes
Hashing algorithm       Hash size
MD5                     16 bytes (128 bits)
SHA-1                   20 bytes (160 bits)
SHA-256                 32 bytes (256 bits)
SHA-384                 48 bytes (384 bits)
SHA-512                 64 bytes (512 bits)

Block ciphers
A type of symmetric encryption, rely on manipulating larger blocks of data (hence the name) during the encryption phase than stream ciphers.  by design, block ciphers are inherently slower than stream ciphers.

Block ciphers work by taking a fixed-length block of plaintext and encrypting it into a block of ciphertext.  These blocks are measured by their fixed length, or block size.  Blocks are usually 64 bits in length, however, they will be increasing to 128 bits in the future.

The most commonly used block ciphers are DES and AES, the successor to DES.

Stream ciphers
Also a symmetric encryption algorithm that are much faster than block ciphers. During encryption, a stream cipher will generate a key or keystream using a specific sequence of bits.  In order to encrypt the plaintext, the stream cipher will combine the keystream with the plaintext that is to be encrypted.  This is usually done via bitwise XOR operations.

The most commonly used stream cipher today is RC4, also know as ARC4/ARCFOUR (Alleged RC4) or just “Rons Code” 4.

Padding
Two common methods of padding are bit and byte padding.  Zero padding is also available.  I won’t get into much details on it here, however, it is used in public key cryptography, such as OAEP with RSA.

This concludes part 2 of Intro to Cryptography.  In part 3, I will go into XOR operations and the fundamentals and math behind the encryption.  If there’s anything you want to see in this series, please leave a comment and let me know if you need help understanding anything I’m covering.

Thursday, February 23, 2012

Intro to Cryptography (Part 1)

Without getting into the history of cryptography I will do my best to explain basic cryptography and how it works.  Cryptography is essentially the science of mathematics using algorithms (or ciphers) to encrypt and decrypt plain text messages.  An original message that you want to encrypt is known as plaintext.  The message after it has been encrypted is known as ciphertext.  In order to encrypt the original message, it must be processed by a mathematical algorithm that results in the ciphertext.  Likewise, in order to decrypt the ciphertext, it must run through a mathematical algorithm to decrypt it back to the plaintext.

A very simple encryption algorithm is ROT13.  The name of this method comes from the method of the algorithm.  In order to encrypt the message, each character is rotated by 13 places, substituting the original letter by another letter 13 places down.  ROT13 is an example of a simple Caesar cipher that was developed in ancient Rome.

Since ROT13 uses the 26 letters in the English alphabet, 26 = 2 x 13, ROT13 (rotate by 13 places) is it’s own inverse.  So in order to decrypt a message encoded with ROT13, you just rotate the letters by another 13 places achieving the original plaintext message.

ROT13 character set
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm

 To understand this better, take a look at the below table:

So, if I were to take the word, password and encode it with ROT13, we would be left withcnffjbeq

There are variants of ROT13, such as ROT47 which uses the 26 character alphabet, and also includes numbers and common symbols.

ROT47 character set
!"#$%&'()*+,-./0123456789:;<
PQRSTUVWXYZ[\]^_`abcdefghijk

=>?@ABCDEFGHIJKLMN
lmnopqrstuvwxyz{|}

What would our password be when encrypted by ROT47?

This concludes part 1 of Intro to Cryptography.  In part 2 we will be diving into slightly more complicated cryptography and introduce a few new concepts.  If there’s anything you want to see in this series, please leave a comment and let me know if you need help understanding anything I’m covering.

xEVD 7F? E@ =62C? 4CJAE@8C2A9JP