Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement in Go lang AES encryption mode CBC with providing the packages name for Go lang. You can implement AES-ECB Mode (the basic AES) from

Implement in Go lang AES encryption mode CBC with providing the packages name for Go lang. You can implement AES-ECB Mode (the basic AES) from crypto/aes package and crypto/cipher.Block. You can also get the SHA-256 hash function from crypto/sha256. You can get the secure random numbers generator from crypto/rand package. However, the you will implement both CBC mode and HMAC from scratch. You are NOT allowed to use any libraries or packages to implement these two things for you. You are permitted to use any packages for anything else provided that it is part of the language itself.

I will expect that your code is run as follows:

encrypt-auth -k <32-byte key in hexadecimal> -i -o

Where is either encrypt or decrypt, the input/output files contain raw binary data.

You should parse the first 16 bytes of the key as the encryption key Kenc and the second 16 bytes as the MAC key Kmac.

To make things clear, I mean concatenation when I say ||, and I mean the length of M in bytes when I say |M|. M is a notation for the plaintext message. Remember, AES has a fixed block size of 16 bytes (128 bits). Obviously, the Kenc is the key for the AES, and Kmac is the key for MAC. The parameters for the encryption and decryption functions are all you need to accept for EACH function.

Encryption(Kenc,Kmac,M). Given a 16-byte secret key Kenc, a 16-bytes secret key Kmac, and any length string M (if a variable length is difficult for you assume that the maximum is 50), encrypt M by doing the following (make sure to finish things by order or you will have a hard time finding any bug in your code!):

1- Produce a random 16 bytes Initialization Vector (IV) and encrypt the padded plaintext M with AES-128 in CBC mode with the Kenc:

C = AES-CBC-ENC(Kenc,IV,M) (REMEMBER: you will implement CBC mode yourself but you can use a library to do the AES-ECB encryption for you)

2- The ciphertext would be: C= (IV||C)

Again, make sure that your encryption is working BEFORE going to decryption. Confirm it by checking a website that will do the CBC mode OR simply use a library compare your answer with the librarys result.

Decryption(Kenc,Kmac,C). Given a 16-byte key Kenc, a 16-byte key Kmac, and a ciphertext C, you will decrypt as follows:

a - First parse C = (IV||C) and decrypt using AES-128 in CBC mode to obtain M:

M = AES-CBC-DEC(Kenc,IV,C) (REMEMBER: you will implement CBC mode yourself but you can use a library to do the AES-ECB decryption for you)

b - Now it is time to validate the padding as follows: let n be the value of the last byte in M. Ensure that each of the final n bytes in M is equal to the value of n. If this check fails, print the following: INVALID PADDING and stop. Otherwise, remove the last n bytes from M to get M.

3- Parse M as M||T where T is a 32-byte HMAC-SHA256 tag.

4- Apply the same HMAC-SHA256 algorithm on input (Kmac,M) to get T. If T != T print

INVALID MAC and stop. Otherwise, output the plaintext message M.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago