#include "crypto_aead.h" /** * Designers: Daniel Penazzi, Miguel Montes This codification: Daniel Penazzi. * This code is hereby placed in the public domain. */ typedef unsigned long long u64; typedef unsigned int u32; #define Sbox(S0,S1,S2,S3,S4) {\ unsigned long long xx=S0;\ unsigned long long yy=S1;\ unsigned long long zz=S2;\ unsigned long long uu=S3;\ unsigned long long vv=S4;\ unsigned long long or0=(zz|(uu^yy));\ unsigned long long or1=(uu|(vv^zz));\ unsigned long long or2=(vv|(xx^uu));\ unsigned long long or3=(xx|(yy^vv));\ unsigned long long or4=(yy|(zz^xx));\ S1=xx^or0;S2=yy^or1;S3=zz^or2;S4=(~uu)^or3;S0=vv^or4;\ or0=(yy|vv);\ or1=(zz|xx);\ or2=(uu|yy);\ or3=(vv|zz);\ or4=(xx|uu);\ S1^=or0;S2^=or1;S3^=or2;S4^=or3;S0^=or4;\ } #define ROTR(x,n) (((x)>>(n))|((x)<<(64-(n)))) #define Difusion(x,y,z,u,v) {\ u^= ROTR(u,57)^ROTR(u,63);\ v^= ROTR(v,3)^ROTR(v,26);\ x^= ROTR(x,43)^ROTR(x,62);\ y^= ROTR(y,21)^ROTR(y,46);\ z^= ROTR(z,58)^ROTR(z,61);\ x^=u^v;y^=u^v;z^=u^v;\ u^=z^x^y;v^=z^x^y;\ x=ROTR(x,8);\ y=ROTR(y,24);\ z=ROTR(z,40);\ u=ROTR(u,56);\ } //number of rounds of initialization, times 11 (12x11) #define NRINIT 132 //number of rounds of processing ad and message, times 11 #define NRMID 99 //extra number of rounds of finalization (after NRMID rounds are done), times 11 #define NREND 33 //increase of i for the round constants #define STEP 11 //R7R6....R1R0 void LESTOREu64in8bytearray(u64 Rv,unsigned char* R){ for(u32 i=0;i<8;i++) { R[i]=(Rv&0xff); Rv=(Rv>>8); } } void PartialLESTOREu64inbytearray(u64 Rv,unsigned char* R,u64 Top){ for(u32 i=0;i>8); } } u64 LELOAD8bytearrayinu64(const unsigned char* R){ u64 Rv=0; for(u32 i=0;i<8;i++) { Rv|=((u64)(R[i])<<(8*i)); } return Rv; } //should only be used if Top<8. u64 PartialLELOADbytearrayinu64(const unsigned char* R,u64 Top){ u64 Rv=(u64)R[0]; for(u64 i=1;i>32))^((y<<32)^(y>>32))^0xff; for(unsigned int i=0;i=16){ u^=LELOAD8bytearrayinu64(ad); ad+=8; z^=LELOAD8bytearrayinu64(ad); for(unsigned int i=0;i=16){ u^=LELOAD8bytearrayinu64(m); LESTOREu64in8bytearray(u,c);m+=8;c+=8; z^=LELOAD8bytearrayinu64(m); LESTOREu64in8bytearray(z,c); for(unsigned int i=0;i>32))^((y<<32)^(y>>32))^0xff; for(unsigned int i=0;i=16){ u^=LELOAD8bytearrayinu64(ad); ad+=8; z^=LELOAD8bytearrayinu64(ad); for(unsigned int i=0;i=16){ LESTOREu64in8bytearray(u,m); for(u32 sk=0;sk<8;sk++) m[sk]^=c[sk]; u=LELOAD8bytearrayinu64(c);m+=8;c+=8; LESTOREu64in8bytearray(z,m); for(u32 sk=0;sk<8;sk++) m[sk]^=c[sk]; z=LELOAD8bytearrayinu64(c); for(unsigned int i=0;i