#include "photon.h" /*################################################################################################################ Circular Left Shift Function (Any direction any number of bits for any number of total Bytes) ################################################################################################################*/ int gcd( int a, int b){ if(b== 0) return a; return gcd(b, a%b); } int inbytelshift(u8 value, int pos) { u8 temp1 = value, temp2 = value; if(pos > 0) { return (((temp1 << pos) & 0xff) | temp2 >> (8 - pos)); } else if(pos < 0) { return (((temp1 << (8 + pos)) & 0xff) | temp2 >> - pos); } else return value; } int byte_wise_lshift(u8 * value, int pos_byte,int byte_shift_period) { int no_cycle = gcd(byte_shift_period, pos_byte); for(int i = 0; i < no_cycle; i++) { for(int j=0; j> (8 - pos); value[i] = inbytelshift(value[i], pos) ^temp2^ temp1; temp1 = temp2; } value[0] = value[0] ^ temp1; return 0; } /*################################################################################################################ Finite Field Multiplication ################################################################################################################*/ int alpha_mult(u8 * value) { u8 temp1; temp1 = value[15]>> 7; interbytelshift(value, 1, 16); u8 alpha_128[16]; for(int j=0; j<16;j++) { if(j==0) //alpha_128 = x^128 + x^7 + x^2 + x + 1 . alpha_128[j]=0x87; else alpha_128[j]= 0x00; } if(temp1==1) { value[0] = value[0]^ 0x01; for(int i=0;i<16;i++) value[i] = value[i]^alpha_128[i]; } return 0; } int mult(int c , u8 * value) { for(int i=0 ; i