#include "options.h" //options.h to define BLOCKSIZE #if BLOCKSIZE == 64 # define ROUNDS 27 //size of a word in bytes //(pt and ct size = 2 words = 1 block) # define WSZ 4 //number of words for key # define M 4 #elif BLOCKSIZE == 128 # define ROUNDS 32 //size of a word in bytes //(pt and ct size = 2 words = 1 block) # define WSZ 8 //number of words for key # define M 2 #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 *K) { u8 L[(ROUNDS+M-2)*WSZ] = { 0 }; u8 RK[ROUNDS*WSZ] = { 0 }; u8 carry; u8 ct_temp[2*WSZ] = { 0 }; //RK0 = K0 for(u8 j=0; j>5) ^ L[(i+M-1)*WSZ+j]; } } //Encryption for(u8 j=0; j<2*WSZ; j++){ ct[j] = pt[j]; //copy pt to ct } for(u8 i=0; i>5) ^ ct_temp[WSZ+j]; } //copy ct from temp for(u8 j=0; j<2*WSZ; j++){ ct[j] = ct_temp[j]; } } }