Created
March 6, 2022 16:48
-
-
Save devendranaga/0d3fc84c63cd37b2f52cdb4cf90e3818 to your computer and use it in GitHub Desktop.
poly1305-aes authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdarg.h> | |
#include <unistd.h> | |
#include <openssl/evp.h> | |
#include <openssl/err.h> | |
#include <openssl/params.h> | |
int main() | |
{ | |
EVP_MAC *mac = EVP_MAC_fetch(NULL, "poly1305", NULL); | |
const unsigned char key[] = {0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33, | |
0x7f, 0x44, 0x52, 0xfe, 0x42, 0xd5, 0x06, 0xa8, | |
0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, 0xb2, 0xfd, | |
0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b}; | |
EVP_MAC_CTX *ctx = NULL; | |
unsigned char *buf = "Cryptographic Forum Research Group"; | |
size_t final_l; | |
size_t i; | |
OSSL_PARAM params[1]; | |
size_t params_n = 0; | |
params[params_n] = OSSL_PARAM_construct_end(); | |
ctx = EVP_MAC_CTX_new(mac); | |
if (!ctx) { | |
return -1; | |
} | |
if (!EVP_MAC_init(ctx, key, sizeof(key), params)) { | |
goto err; | |
} | |
if (!EVP_MAC_update(ctx, buf, strlen(buf))) | |
goto err; | |
unsigned char out[32]; | |
if (!EVP_MAC_final(ctx, out, &final_l, sizeof(out))) | |
goto err; | |
printf("Result: "); | |
for (i = 0; i < final_l; i++) | |
printf("%02X:", out[i]); | |
printf("\n"); | |
EVP_MAC_CTX_free(ctx); | |
EVP_MAC_free(mac); | |
return 0; | |
err: | |
EVP_MAC_CTX_free(ctx); | |
EVP_MAC_free(mac); | |
fprintf(stderr, "Something went wrong\n"); | |
ERR_print_errors_fp(stderr); | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment