Najwa M. AlGhamdi

advertisement
CSC 519: Computer Security
Programming Assignment 1
By
Najwa M. AlGhamdi
ID : 427220110
Najwa M. AlGhamdi , 427220110 , PA-1
Table of content
TABLE OF CONTENT ....................................................................................................... 2
1. SYMMETRIC KEY ALGORITHM ....................................................................................... 3
2. PROGRAMMING ENVIRONMENT .................................................................................... 3
3. BRUTE FORCE METHOD ............................................................................................... 3
4. OUTCOMES ............................................................................................................... 3
4.1 The decrypted message ................................................................................. 3
4.2 The Missing bytes ........................................................................................... 3
4.3 The execution time ......................................................................................... 3
4.4 Screen shot ..................................................................................................... 4
5.CONCLUSION ............................................................................................................. 4
APPENDIX ..................................................................................................................... 5
1. Decryption ......................................................................................................... 5
1.1 Cipher mode ................................................................................................... 5
1.1.1 Why? ......................................................................................................................... 5
1.1.2 Cipher mode enumeration ...................................................................................... 5
2. Brute force search ............................................................................................ 8
2.1 Basic algorithm ........................................................................................................... 8
REFERENCES ............................................................................................................... 10
Najwa M. AlGhamdi , 427220110 , PA-1
1. Symmetric key algorithm
"Symmetric-key algorithms are a class of algorithms for cryptography that use
trivially related, often identical, cryptographic keys for both decryption and
encryption. Symmetric-key algorithms can be divided into stream ciphers and
block ciphers. Stream ciphers encrypt the bits of the message one at a time, and
block ciphers take a number of bits and encrypt them as a single unit. Blocks of
64 bits have been commonly used ; Advanced Encryption Standard algorithm
approved by NIST (National Institute of Standards and Technology) in December
2001 uses 128-bit blocks." [1]
The algorithm used in this assignment is the blocks cipher that called Rijndael
(pronounced rain-dahl) which is the candidate for AES algorithm that was
selected by NITS. [2]
2. Programming Environment
The environment was Microsoft visual basic 2005 express edition. The reason
behind selecting such environment is that it supports a cryptography namespace
– system. Security. Cryptography - that dose all the cryptography services such
as encryption/ decryption, hashing, message authentication, etc...[3]
I used a symmetric algorithm class that is provided by the previous namespace to
do the decryption process.1
3. Brute Force method
I used the brute force search to find the missing bytes of the key.
"brute-force search or exhaustive search is a trivial but very general
problem-solving technique, that consists of systematically enumerating all
possible candidates for the solution and checking whether each candidate satisfies
the problem's statement" [4]
4. Outcomes
4.1 The decrypted message
Salam Abu Mohammed, CSCO stock will crash! Sell all as fast as possible!
Regards.
4.2 The Missing bytes
00-07-0B-B0.
And the key is: 01-7B-3A-EC-3C-8E-FC-8B-19-F8-23-C0-00-07-0B-B0
4.3 The execution time
44 seconds
1
See the appendix for more information about how the decryption was handled.
Najwa M. AlGhamdi , 427220110 , PA-1
4.4 Screen shot
5.Conclusion
This assignment focused on the decryption process using symmetric key
algorithm. It was implemented using symmetric algorithm class provided by the
system .security . cryptography namespace supported by VB.net , using brute
force search to search for the key.
Najwa M. AlGhamdi , 427220110 , PA-1
Appendix
In this part, I'll explain how the decryption was handled, and show little focus on the
brute force search.
1. Decryption
I wrote the following function that will encapsulate the decryption process. It
called "decrypt" with a list of parameters (key and data of type "array of bytes"
that will hold the key value and cipher text respectively).
First, a variable of type symmetric algorithm (named as AES) was declared and
initialized with an instance of Rajndeal Managed class.
SymmetricAlgorithm class represents the abstract base class from which all
implementations of symmetric algorithms must inherit , while RijndaelManaged
class will Accesses the managed version of the Rijndael (AES) algorithm
Recall from section1 , The Rijndael algorithm is a symmetric block cipher that
supports key sizes of 128, 192 and 256 bits, with data handled in 128-bit blocks.
Again, all the prevoius class are supported by system . security . cryptography
namespace.
Then I did some AES's setting , that are neccessery to enable the AES-128
algorithm , as the following
1. AES . block size= 128
2. AES . key size = 128
3. AES . key = key , where key is the decryption key.
4. AES . mode= ciphermode. ECB.
1.1 Cipher mode
Specifies the block cipher mode to use for encryption
[5]
1.1.1 Why?
The block cipher uses the same encryption algorithm for each block. Thus, every
identical block will have the same cipher text, if we use the same key and
algorithm, which ease carking it. Specifying the cipher mode will overcome this
limitation by getting feedback from earlier block encryption to modify the
encryption process.
1.1.2 Cipher mode enumeration
Member name
Description
CBC
The Cipher Block Chaining (CBC) mode
introduces feedback. Before each plain text
block is encrypted, it is combined with the
cipher text of the previous block by a bitwise
exclusive OR operation. This ensures that
even if the plain text contains many identical
blocks, they will each encrypt to a different
cipher text block. The initialization vector is
combined with the first plain text block by a
bitwise exclusive OR operation before the
block is encrypted.
If a single bit of the cipher text block is
mangled, the corresponding plain text block
will also be mangled. In addition, a bit in the
Najwa M. AlGhamdi , 427220110 , PA-1
subsequent block, in the same position as
the original mangled bit, will be mangled.
CFB
The Cipher Feedback (CFB) mode processes
small increments of plain text into cipher
text, instead of processing an entire block at
a time. This mode uses a shift register that
is one block in length and is divided into
sections. For example, if the block size is
eight bytes, with one byte processed at a
time, the shift register is divided into eight
sections.
If a bit in the cipher text is mangled, one
plain text bit is mangled and the shift
register is corrupted. This results in the next
several plain text increments being mangled
until the bad bit is shifted out of the shift
register.
CTS
The Cipher Text Stealing (CTS) mode
handles any length of plain text and
produces cipher text whose length matches
the plain text length. This mode behaves like
the CBC mode for all but the last two blocks
of the plain text.
ECB
The Electronic Codebook (ECB) mode
encrypts each block individually. This means
that any blocks of plain text that are
identical and are in the same message, or in
a different message encrypted with the
same key, will be transformed into identical
cipher text blocks.
If the plain text to be encrypted contains
substantial repetition, it is feasible for the
cipher text to be broken one block at a time.
Also, it is possible for an active adversary to
substitute and exchange individual blocks
without detection.
If a single bit of the cipher text block is
mangled, the entire corresponding plain text
block will also be mangled.
OFB
The Output Feedback (OFB) mode processes
small increments of plain text into cipher
text instead of processing an entire block at
a time. This mode is similar to CFB; the only
difference between the two modes is the
way that the shift register is filled.
If a bit in the cipher text is mangled, the
corresponding bit of plain text will be
mangled. However, if there are extra or
missing bits from the cipher text, the plain
text will be mangled from that point on
Cipher mode enumeration [5]
Unfortunatly , I was forced to use ECB , because after parctising I found that all
the prevoius mode , except the ECB, requier initialization vector.
After that, I Defined a stream that links data streams to cryptographic
transformations using cryptostream class .
The constructor of this class requires 3 parameters
1. data stream , which is a memory stream that hold a cipher text
Najwa M. AlGhamdi , 427220110 , PA-1
2. the transformation to use ,which in the case of decryption, will be "create
decryptor" , a member of symmetric algorithm class , that Creates a
symmetric decryptor object with the current Key property .
3. The mode of the stream ( read or write)
Thus , one this constructor is executed, the crypto stream will hold the decrypted
message that will be read by a stream reader to get the palin text.
The following code will express the previoius explaination as vb.net code.
Function decrypt(ByVal key() As Byte, ByVal data() As Byte) As
String
' The function objective : to handel the decryption process
of the cipher text.
' Parmetters : 1. key (array of bytes) will hold the value of
the decryption key.
'
2. data(array of bytes) will hold the cipher
text.
Dim AES As SymmetricAlgorithm = New RijndaelManaged
'SymmetricAlgorithm represents the abstract base class from
which all implementations of symmetric algorithms must inherit.
'Symmetric cryptographic algorithms have a single secret key
that is used for both encryption and decryption.
'For a symmetric algorithm to be effective, the secret key
must be known only to the sender and the receiver.
'RijndaelManaged : Accesses the managed version of the
Rijndael (AES) algorithm
'The Rijndael algorithm is a symmetric block cipher that
supports key sizes of 128, 192 and 256 bits, with data handled in
128-bit blocks
Dim memoryStream As MemoryStream
memoryStream = New MemoryStream(Data)
'prepare for decryption by copying the data to a memory
stream .
AES.Mode = CipherMode.ECB
' set the mode for operation of the symmetric algorithm.
' cipher mode enumerations could be : CBC , CBF , CTS , ECB ,
OFB
' see appendex 1 in the enclosed report for more modes
details.
AES.BlockSize = 128
AES.KeySize = 128
AES.Key = key
' set both block size and key size to 128 in bits , and
assign the key to the algorithm key
Dim plainTextstring As String = ""
' palintextsting will hold the value of the palin text
Dim encStream As New CryptoStream(memoryStream,
AES.CreateDecryptor(), CryptoStreamMode.Read)
'Defines a stream that links data streams to cryptographic
transformations
Najwa M. AlGhamdi , 427220110 , PA-1
'Initializes a new instance of the CryptoStream class with a
target data stream, the transformation to use, and the mode of the
stream.
'CreateDecyptor will decrypt the data in memory stream into
encstream
Dim strReader As New StreamReader(encStream)
Try
plainTextstring = strReader.ReadToEnd()
' read the decrypted data from the memory stream
Catch
End Try
Return plainTextstring
End Function
2. Brute force search
2.1 Basic algorithm
The following express the basic algorithm for brute force search that seeks for a
solution for data P [4]
c <- first(P) // generate a first candidate solution for p.
while c <> Λ do // Λ is null value
if valid(P,c) // check whether candidate c is a solution for P
then output(P, c) // use the solution c of P as appropriate to the
application
c <- next(P,c) // generate the next candidate for P after the
current one c
this is the code
Function findkey(ByVal cipher_text As Byte(), ByRef partial_key
As Byte()) As String
'function object : to find the missing bytes of the key using
brute force method
' the function returns the decrypted msg
' parametters: cipher text that hold the encrypted data
'
partial key the hold the incomplete key
Dim txt As String
date1 = Date.Now
' I will use 4 nested loops
to find the missing bytes
Dim i, j, k, n As Integer
For i = 0 To 255 Step 1 '---------> for byte # 12
'-----------------------i loop ------------------For j = 0 To 255 Step 1 '--------> for byte # 13
'--------------------j loop -----------------For k = 0 To 255 Step 1 '------> for byte # 14
'----------------k loop -----------------For n = 0 To 255 Step 1 '------> for byte # 15
'-------------n loop-----------------partial_key(15) = CByte(n)
partial_key(14) = CByte(k)
partial_key(13) = CByte(j)
partial_key(12) = CByte(i)
txt = decrypt(partial_key, cipher_text)
' decrypt the message with this potintial key
Najwa M. AlGhamdi , 427220110 , PA-1
If txt <> "" Then
If txt.Contains("Salam") Then
' if the decrypted msg contains the
word "Salam"
found = True
date2 = Date.Now
End If
If found Then
Exit For
End If
End If
'-----------------end of n loop--------------Next n
If found Then
Exit For
End If
'---------------------end of k loop --------------Next k
If found Then
Exit For
End If
'--------------------------end of j loop ---------------Next j
If found Then
Exit For
End If
'------------------------------end of i loop ----------------Next i
Return txt
End Function
Najwa M. AlGhamdi , 427220110 , PA-1
References
[1] http://en.wikipedia.org/wiki/Symmetric_key
[2] http://searchsecurity.techtarget.com/sDefinition/0,,sid14_gci523541,00.html
[3]http://msdn2.microsoft.com/enus/library/system.security.cryptography(VS.71
).asp
[4] http://en.wikipedia.org/wiki/Brute-force_search
[5]http://msdn2.microsoft.com/enus/library/system.security.cryptography.ciphr
mode(VS.71).asp
Najwa M. AlGhamdi , 427220110 , PA-1
Download