applied cryptography - protocols, algorithms, and source code in c

fcn2ck1 fcn2ck3

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2, 9, 1, 24, 16, 8, 0 typedef short short struct { gen; exp; /* irreducible polynomial used in this field */ /* exponent used to generate this s function */ } sfn_desc; sfn_desc sfn = { { /* 101110111 { /* 110000111 { /* 110001101 { /* 110100011 { /* 110110001 { /* 111000011 { /* 111010111 { /* 111100111 { 00, 00} */ */ */ */ */ */ */ */ }; 375, 391, 397, 419, 433, 451, 471, 487, 31}, 31}, 31}, 31}, 31}, 31}, 31}, 31}, { { { { { { { { /* /* /* /* /* /* /* /* 101111011 110001011 110011111 110101001 110111101 111001111 111011101 111110011 */ */ */ */ */ */ */ */ 379, 395, 415, 425, 445, 463, 477, 499, 31}, 31}, 31}, 31}, 31}, 31}, 31}, 31}, typedef struct { Long loki_subkeys[ROUNDS]; } loki_ctx; static Long static short f(); s(); /* declare LOKI function f */ /* declare LOKI S–box fn s */ #define ROL12(b) b = ((b << 12) | (b >> 20)); #define ROL13(b) b = ((b << 13) | (b >> 19)); #ifdef LITTLE_ENDIAN #define bswap(cb) { register char c; c = cb[0]; cb[0] = c = cb[1]; cb[1] = c = cb[4]; cb[4] = c = cb[5]; cb[5] = } #endif cb[3]; cb[2]; cb[7]; cb[6]; cb[3] cb[2] cb[7] cb[6] = = = = c; c; c; c; \ \ \ \ \ \ void setlokikey(loki_ctx *c, char *key) { register i; register Long KL, KR; #ifdef LITTLE_ENDIAN bswap(key); /* swap bytes round if little–endian */ #endif KL = ((Long *)key)[0]; KR = ((Long *)key)[1]; for (i=0; i<ROUNDS; i+=4) { c–>loki_subkeys[i] = KL; ROL12 (KL); c–>loki_subkeys[i+1] = KL; ROL13 (KL); c–>loki_subkeys[i+2] = KR; ROL12 (KR); c–>loki_subkeys[i+3] = KR; ROL13 (KR); } #ifdef LITTLE_ENDIAN bswap(key); #endif } void enloki (loki_ctx *c, char *b) { register i; register Long L, R; #ifdef LITTLE_ENDIAN bswap(b); #endif L = ((Long *)b)[0]; R = ((Long *)b)[1]; /* Generate the 16 subkeys */ /* swap bytes back if little–endian */ /* left & right data halves */ /* swap bytes round if little–endian */ for (i=0; i<ROUNDS; i+=2) { /* Encrypt with the 16 subkeys */ L ^= f (R, c–>loki_subkeys[i]); R ^= f (L, c...
View Full Document

This note was uploaded on 10/18/2010 for the course MATH CS 301 taught by Professor Aliulger during the Fall '10 term at Koç University.

Ask a homework question - tutors are online