Skip to content

Instantly share code, notes, and snippets.

@mdukat
Created November 24, 2020 11:24
Show Gist options
  • Save mdukat/08add234c136490ea5b2b210faed90e9 to your computer and use it in GitHub Desktop.
Save mdukat/08add234c136490ea5b2b210faed90e9 to your computer and use it in GitHub Desktop.
Quick aes reference
// Based on https://github.com/clarus/phd-experiments/blob/master/embedded-compcert/test/c/aes.c
// For quick reference
// rijndael-alg-fst.{h,c} source:
// https://fastcrypto.org/vmac/rijndael-alg-fst.c
// https://fastcrypto.org/vmac/rijndael-alg-fst.h
// build with:
// gcc main.c rijndael-alg-fst.c
#include "rijndael-alg-fst.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
u8* encrypt256(u8 *key, u8 plain[16]){
u32 ckey[4*(MAXNR+1)];
u8* temp = malloc(16); // or u8 temp[16]
int nr;
nr = rijndaelKeySetupEnc(ckey, key, 256);
// ^ 256 as in 256 bit key
rijndaelEncrypt(ckey, nr, plain, temp);
return temp;
}
int main(int argc, char ** argv)
{
u8* ext = encrypt256((u8 *)"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", (u8 *)"dupadupadupadupa");
// ^ 256 bit key ^ 16 byte block
for(int a = 0; a<16; a++){
printf("%x", ext[a]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment