Skip to content

Commit

Permalink
aes_gcm_plug.c: Fix and add self-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
solardiz committed May 17, 2024
1 parent 323b322 commit 97a023b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/aes_gcm_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* See https://w1.fi/hostapd/ for more information.
*
* For self-test use the following command,
* gcc -DTEST -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib aes_gcm_plug.c -lcrypt
* gcc -DTEST aes_gcm_plug.c aes/aes.a -lcrypt -O2 -Wall -W -fstack-protector-all -fsanitize=address -o aes_gcm_plug-test
*/

#include <stdio.h>
Expand Down Expand Up @@ -293,7 +293,7 @@ static void aes_gcm_ghash(const uint8_t *H, const uint8_t *aad, size_t aad_len,
}


#if 0
#ifdef TEST
/**
* aes_gcm_ae - GCM-AE_K(IV, P, A)
*/
Expand Down Expand Up @@ -408,17 +408,26 @@ static const unsigned char gcm_tag[] = {
};


int main()
int main(void)
{
unsigned char tag[16];
unsigned char crypt[32];
unsigned char crypt[16];
unsigned char plain[16];
int retval;

aes_gcm_ae(gcm_key, 32, gcm_iv, 12, gcm_pt, 16, gcm_aad, 16, crypt, tag);
retval = aes_gcm_ae(gcm_key, 32, gcm_iv, 12, gcm_pt, 16, gcm_aad, 16, crypt, tag);

if (!memcmp(tag, gcm_tag, 16)) {
if (!retval && !memcmp(crypt, gcm_ct, 16) && !memcmp(tag, gcm_tag, 16)) {
printf("PASS\n");
} else {
printf("FAIL\n");
}
else {

retval = aes_gcm_ad(gcm_key, 32, gcm_iv, 12, crypt, 16, gcm_aad, 16, tag, plain, 0);

if (!retval && !memcmp(plain, gcm_pt, 16)) {
printf("PASS\n");
} else {
printf("FAIL\n");
}

Expand Down

0 comments on commit 97a023b

Please sign in to comment.