#include "options.h" //options.h to define BLOCKSIZE #if BLOCKSIZE == 64 # define ROUNDS 80 //size of a word in bytes //(pt and ct size = 4 words = 1 block) # define WSZ 2 //number of words for key (K/W) # define M 8 #elif BLOCKSIZE == 128 # define ROUNDS 80 //size of a word in bytes //(pt and ct size = 4 words = 1 block) # define WSZ 4 //number of words for key (K/W) # define M 4 #endif #define CARRY(r, a, b) ( ((a>>7)&(b>>7)) | ((a>>7)&(!(r>>7))) | ((!(r>>7))&(b>>7)) ) typedef unsigned char u8; typedef unsigned int u32; void blockcipher_encrypt (u8 *ct, const u8 *pt, const u8 *key) { u8 rk[2*M*WSZ]; //key expansion u8 rol_1[WSZ]; //Rotation Left 1 u8 rol_8[WSZ]; //Rotation Left 8 u8 rol_11[WSZ]; //Rotation Left 11 for(u8 i=0; i> 7); rol_8[j] = key[i*WSZ+((j+WSZ-1)%WSZ)]; rol_11[j] = (key[i*WSZ+((j+WSZ-1)%WSZ)] << 3) | (key[i*WSZ+((j+WSZ-2)%WSZ)] >>5); } for(u8 j=0; j> 7); } //TMP1 = ROL_1(ct_prev[1]) XOR RK[i] for(u8 j=0; j> 7); } } //ct_prev = ct for(u8 j=0; j<4*WSZ; j++){ ct_prev[j] = ct[j]; } } return; }