#include #include #include /* Append a new messages onto the end of a MAC Author: Tim Pierson, Dartmouth CS55, Winter 2021 based example from Du: https://github.com/kevin-w-du/BookCode/blob/master/One_Way_Hash/sha256_padding.c compile: gcc sha256_padding.c -o sha256_padding -lcrypto run: ./sha256_padding will output the SHA-256 hash of an original message with an additional message appended. */ int main(int argc, const char *argv[]) { SHA256_CTX c; unsigned char buffer[SHA256_DIGEST_LENGTH]; int i; char *orig_msg = "Launch a missile at Target A"; char *key = "theKey"; char *append_msg = " and at Cambridge"; SHA256_Init(&c); SHA256_Update(&c, "theKey:Launch a missile at Target A" "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x18" " and at Cambridge", 64+17); SHA256_Final(buffer, &c); printf("New MAC\n"); for (i = 0; i < 32; i++) { printf("%02x", buffer[i]); } printf("\n"); return 0; }