OpenSSL Blowfish -- 2
Budget: $25 – $75 USD
Project
OpenSSL Blowfish
1 Introduction
Blowfish is a symmetric-key block cipher that provides good encryption rate with
no disclosed effective cryptanalysis. Blowfish uses 64-bit blocks and typically
128-bit keys; you can find a description of the Blowfish algorithm at https://
www.schneier.com/academic/blowfish/ and http://www.counterpane.com/
blowfish.html. OpenSSL is a community-maintained general-purpose cryptography and secure communication library, arguably the most popular in the world.
In this assignment, you will use OpenSSL’s libcrypto to implement the Blowfish block cipher. You can find a current description of all the OpenSSL functions at https://www.openssl.org/docs/man1.1.1/man3/, but we will specifically be using the BF cbc encrypt, BF ecb encrypt, and BF set key functions,
which are described at https://www.openssl.org/docs/man1.1.1/man3/BF_
encrypt.html.
2 Directions
2.1 CBC-mode Encryption/Decryption using BF ecb encrypt
Using OpenSSL version 1.1.1k
implement the Blowfish block cipher for encryption and decryption using CBC
mode of encryption in fscrypt.c, calling BF ecb encrypt and BF set key. The
two functions you will implement have the following signatures:
void * fs_encrypt ( void * plaintext , int bufsize , char *
↩→ keystr , int * resultlen );
void * fs_decrypt ( void * ciphertext , int bufsize , char
↩→ * keystr , int * resultlen );
2.2 CBC-mode Encryption/Decryption using BF cbc encrypt
For an additional 20 bonus points, implement the following functions in fscrypt2.c
with the same functionality as above. However this time, use BF cbc encrypt
and BF set key. Note that you will have to modify the provided files (see below).
void * fs_encrypt2 ( void * plaintext , int bufsize , char
↩→ * keystr , int * resultlen );
void * fs_decrypt2 ( void * ciphertext , int bufsize , char
↩→ * keystr , int * resultlen );
2.3 Assumptions
You will be provided with three files:
– fscrypt.h, which contains a block size definition, and the two function prototypes.
– main.c, which contains a driver program.
– Makefile to compile the driver executable(s).
We will make the following design decisions and assumptions:
– Use CBC mode of encryption and decryption.
– Pad the plaintext with length of the added padding in all the padded characters.
• For our example below, if plaintext input is “hello world”, your padded
plaintext buffer would be “hello world\x00\x04\x04\x04\x04”. This reflects a string constant of length 12 –don’t forget the null terminator –
plus four bytes of 0x4.
• If the final block is already a complete block, add an additional block of
plaintext (in this case, since BLOCKSIZE is 8 bytes, you would pad the
plaintext with 8 bytes of 0x08).
– The initialization vector must be comprised of a full block of all null characters.
– Both functions must allocate the result buffer of at least the required size
(using malloc() or new).
– Both functions also return the number of valid bytes in the result buffer
pointed to by resultlen.
– The application “caller” code is responsible for subsequently freeing the
buffer pointed to by plaintext or ciphertext, but not to free any of the
“callee” locally-allocated buffers. We will check your code for memory leaks
using Valgrind.
OpenSSL Blowfish
1 Introduction
Blowfish is a symmetric-key block cipher that provides good encryption rate with
no disclosed effective cryptanalysis. Blowfish uses 64-bit blocks and typically
128-bit keys; you can find a description of the Blowfish algorithm at https://
www.schneier.com/academic/blowfish/ and http://www.counterpane.com/
blowfish.html. OpenSSL is a community-maintained general-purpose cryptography and secure communication library, arguably the most popular in the world.
In this assignment, you will use OpenSSL’s libcrypto to implement the Blowfish block cipher. You can find a current description of all the OpenSSL functions at https://www.openssl.org/docs/man1.1.1/man3/, but we will specifically be using the BF cbc encrypt, BF ecb encrypt, and BF set key functions,
which are described at https://www.openssl.org/docs/man1.1.1/man3/BF_
encrypt.html.
2 Directions
2.1 CBC-mode Encryption/Decryption using BF ecb encrypt
Using OpenSSL version 1.1.1k
implement the Blowfish block cipher for encryption and decryption using CBC
mode of encryption in fscrypt.c, calling BF ecb encrypt and BF set key. The
two functions you will implement have the following signatures:
void * fs_encrypt ( void * plaintext , int bufsize , char *
↩→ keystr , int * resultlen );
void * fs_decrypt ( void * ciphertext , int bufsize , char
↩→ * keystr , int * resultlen );
2.2 CBC-mode Encryption/Decryption using BF cbc encrypt
For an additional 20 bonus points, implement the following functions in fscrypt2.c
with the same functionality as above. However this time, use BF cbc encrypt
and BF set key. Note that you will have to modify the provided files (see below).
void * fs_encrypt2 ( void * plaintext , int bufsize , char
↩→ * keystr , int * resultlen );
void * fs_decrypt2 ( void * ciphertext , int bufsize , char
↩→ * keystr , int * resultlen );
2.3 Assumptions
You will be provided with three files:
– fscrypt.h, which contains a block size definition, and the two function prototypes.
– main.c, which contains a driver program.
– Makefile to compile the driver executable(s).
We will make the following design decisions and assumptions:
– Use CBC mode of encryption and decryption.
– Pad the plaintext with length of the added padding in all the padded characters.
• For our example below, if plaintext input is “hello world”, your padded
plaintext buffer would be “hello world\x00\x04\x04\x04\x04”. This reflects a string constant of length 12 –don’t forget the null terminator –
plus four bytes of 0x4.
• If the final block is already a complete block, add an additional block of
plaintext (in this case, since BLOCKSIZE is 8 bytes, you would pad the
plaintext with 8 bytes of 0x08).
– The initialization vector must be comprised of a full block of all null characters.
– Both functions must allocate the result buffer of at least the required size
(using malloc() or new).
– Both functions also return the number of valid bytes in the result buffer
pointed to by resultlen.
– The application “caller” code is responsible for subsequently freeing the
buffer pointed to by plaintext or ciphertext, but not to free any of the
“callee” locally-allocated buffers. We will check your code for memory leaks
using Valgrind.