Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please design the code only in C++ programing using crypto libraries I also have the reference codes which I have written but these codes are

Please design the code only in C++ programing using crypto libraries I also have the reference codes which I have written but these codes are not working throwing errors.

Note: Please dont just copy paste from any AI tools like chat Gpt design own code its a request.

I am also providing the reference codes which I have written but these codes are not working please write a code according to the each task asked below read complete description before answering me give clear commands for each code line maintain proper format make sure the programs are compiled and tested provide me the code test results after execution:

Note******* Task questions are mentioned below scroll and read each line***

Reference codes:

Task 1)

//Task 1 #include #include #include #include #include #include #include #include

using namespace std;

int main(int argc, char* argv[]) { //Check for 3 arguments if(argc != 4) { cerr << "Usage: hmac [input file] [output file] [key]" << endl; return -1; }

//Read the input file string inputFileName = argv[1]; ifstream inputFile(inputFileName, ios::binary);

//Check if input file is open if(!inputFile.is_open()) { cerr << "Error: Could not open input file: " << inputFileName << endl; return -1; }

//Read the output file string outputFileName = argv[2]; ofstream outputFile(outputFileName, ios::binary);

//Check if output file is open if(!outputFile.is_open()) { cerr << "Error: Could not open output file: " << outputFileName << endl; return -1; }

//Read the key string key = argv[3];

//Compute HMAC CryptoPP::HMAC hmac((const unsigned char*)key.data(), key.size()); CryptoPP::FileSource(inputFileName.c_str(), true, new CryptoPP::HashFilter(hmac, new CryptoPP::FileSink(outputFileName.c_str())));

//Print HMAC CryptoPP::HexEncoder encoder; string hmacOutput; encoder.Attach(new CryptoPP::StringSink(hmacOutput)); encoder.Put((const byte*)hmac.Mac(), hmac.DigestSize()); encoder.MessageEnd();

cout << "HMAC: " << hmacOutput << endl;

return 0; } --------------

Task 2:

//Task 2 #include #include #include #include #include #include #include #include #include

using namespace std;

int main(int argc, char* argv[]) { //Check for 3 arguments if(argc != 4) { cerr << "Usage: hmac [input file] [output file] [key]" << endl; return -1; }

//Read the input file string inputFileName = argv[1]; ifstream inputFile(inputFileName, ios::binary);

//Check if input file is open if(!inputFile.is_open()) { cerr << "Error: Could not open input file: " << inputFileName << endl; return -1; }

//Read the output file string outputFileName = argv[2]; ofstream outputFile(outputFileName, ios::binary);

//Check if output file is open if(!outputFile.is_open()) { cerr << "Error: Could not open output file: " << outputFileName << endl; return -1; }

//Read the key string key = argv[3];

//Compute HMAC CryptoPP::HMAC hmac((const unsigned char*)key.data(), key.size()); CryptoPP::FileSource(inputFileName.c_str(), true, new CryptoPP::HashFilter(hmac, new CryptoPP::FileSink(outputFileName.c_str())));

//Print HMAC CryptoPP::HexEncoder encoder; string hmacOutput; encoder.Attach(new CryptoPP::StringSink(hmacOutput)); encoder.Put(hmac.Mac(), hmac.DigestSize()); encoder.MessageEnd();

cout << "HMAC: " << hmacOutput << endl;

//Compute OpenSSL HMAC unsigned char * digest = HMAC(EVP_sha512(), key.data(), key.length(), (unsigned char *)inputFileName.data(), inputFileName.length(), NULL, NULL);

//Print OpenSSL HMAC string opensslOutput; for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) { char buf[3]; snprintf(buf, 3, "%02x", (unsigned)digest[i]); opensslOutput.append(buf); } cout << "OpenSSL HMAC: " << opensslOutput << endl;

//Compare if (hmacOutput == opensslOutput) { cout << "HMACs match!" << endl; } else { cout << "HMACs do not match!" << endl; }

return 0; }

--

//Task 3 #include #include #include #include #include #include #include #include

using namespace std;

int main(int argc, char* argv[]) { //Check for 3 arguments if(argc != 4) { cerr << "Usage: cmac [input file] [output file] [key]" << endl; return -1; }

//Read the input file string inputFileName = argv[1]; ifstream inputFile(inputFileName, ios::binary);

//Check if input file is open if(!inputFile.is_open()) { cerr << "Error: Could not open input file: " << inputFileName << endl; return -1; }

//Read the output file string outputFileName = argv[2]; ofstream outputFile(outputFileName, ios::binary);

//Check if output file is open if(!outputFile.is_open()) { cerr << "Error: Could not open output file: " << outputFileName << endl; return -1; }

//Read the key string key = argv[3];

//Compute CMAC CryptoPP::CMAC cmac((const unsigned char*)key.data(), key.size()); CryptoPP::FileSource(inputFileName.c_str(), true, new CryptoPP::HashFilter(cmac, new CryptoPP::FileSink(outputFileName.c_str())));

//Print CMAC CryptoPP::HexEncoder encoder; string cmacOutput; encoder.Attach(new CryptoPP::StringSink(cmacOutput)); encoder.Put(cmac.Mac(), cmac.DigestSize()); encoder.MessageEnd();

cout << "CMAC: " << cmacOutput << endl;

return 0; }

Task 4:

//Task 4 #include #include #include #include #include #include #include #include #include

using namespace std;

int main(int argc, char* argv[]) { //Check for 3 arguments if(argc != 4) { cerr << "Usage: cmac [input file] [output file] [key]" << endl; return -1; }

//Read the input file string inputFileName = argv[1]; ifstream inputFile(inputFileName, ios::binary);

//Check if input file is open if(!inputFile.is_open()) { cerr << "Error: Could not open input file: " << inputFileName << endl; return -1; }

//Read the output file string outputFileName = argv[2]; ofstream outputFile(outputFileName, ios::binary);

//Check if output file is open if(!outputFile.is_open()) { cerr << "Error: Could not open output file: " << outputFileName << endl; return -1; }

//Read the key string key = argv[3];

//Compute CMAC CryptoPP::CMAC cmac((const unsigned char*)key.data(), key.size()); CryptoPP::FileSource(inputFileName.c_str(), true, new CryptoPP::HashFilter(cmac, new CryptoPP::FileSink(outputFileName.c_str())));

//Print CMAC CryptoPP::HexEncoder encoder; string cmacOutput; encoder.Attach(new CryptoPP::StringSink(cmacOutput)); encoder.Put(cmac.Mac(), cmac.DigestSize()); encoder.MessageEnd();

cout << "CMAC: " << cmacOutput << endl;

//Compute OpenSSL CMAC unsigned char * digest = CMAC(EVP_aes_128_cbc(), key.data(), key.length(), (unsigned char *)inputFileName.data(), inputFileName.length(), NULL, NULL);

//Print OpenSSL CMAC string opensslOutput; for (int i = 0; i < AES_BLOCK_SIZE; i++) { char buf[3]; snprintf(buf, 3, "%02x", (unsigned)digest[i]); opensslOutput.append(buf); } cout << "OpenSSL CMAC: " << opensslOutput << endl;

//Compare if (cmacOutput == opensslOutput) { cout << "CMACs match!" << endl; } else { cout << "CMACs do not match!" << endl; }

return 0; }

Note I have 5 Test files for testing the codes written

Task -1

: Please compute theHMAC (Keyed-hash Message Authentication Code) of the input file using SHA-512 using the library functions provided by cryptopp libraries. After computing the HMAC with key K of an input message M, print it on the screen in hexadecimal format, also store the HMAC output in the output file. Your program should take three arguments: an input file name, an output HMAC file, and a key. Task 2

Using openssl to generate the HMAC of the input messages. Please compare the output HMAC generated in the first task with the HMAC computed using openssl for the same file with the same key.

Task 3

Task 3 (For graduate students): Please compute the CMAC (Cipher-based Message Authentication Code) using AES with 128 bits of the input message. You can use the library functions provided by cryptopp. After computing the CMAC of an input message M, print it on the screen in hexadecimal format, also store the CMAC output in the output file. Your program should take three arguments: an input file name, an output CMAC file, and a key.

Task 4

Task 4 (For graduate students): Using openssl command lines to generate the CMAC of the input messages. Compare the CMAC computed by your program in task3 and the CMAC computed by openssl command lines for the same file with the same key.

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

Step: 3

blur-text-image

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

Solve for the Nash equilibria in one-shot games and repeated games.

Answered: 1 week ago

Question

a . L = { Set of all Strings that end with 0 1 }

Answered: 1 week ago

Question

Write a note on Historical Development of clinical Trials?

Answered: 1 week ago