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

Char k int len initializeblowfishcklen void

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: ta[0] = 0; data[1] = 0; gostcrypt(&ampgc,data); printf(“Enc of zero vector: %08lx %08lx\n”,data[0],data[1]); gostcrypt(&ampgc,data); printf(“Enc of above: %08lx %08lx\n”,data[0],data[1]); data[0] = 0xffffffff; data[1] = 0xffffffff; gostcrypt(&ampgc,data); printf(“Enc of ones vector: %08lx %08lx\n”,data[0],data[1]); gostcrypt(&ampgc,data); printf(“Enc of above: %08lx %08lx\n”,data[0],data[1]); /* Does gost_dec() properly reverse gost_enc()? Do we deal OK with single–block lengths passed in gost_dec()? Do we deal OK with different lengths passed in? */ /* Init data */ for(i=0;i<10;i++) data[i]=i; /* Encrypt data as 5 blocks. */ gost_enc(&ampgc,data,5); /* Display encrypted data. */ for(i=0;i<10;i+=2) printf(“Block %02d = %08lx %08lx\n”, i/2,data[i],data[i+1]); /* Decrypt in different sized chunks. */ gost_dec(&ampgc,data,1); gost_dec(&ampgc,data+2,4); printf(“\n”); /* Display decrypted data. */ for(i=0;i<10;i+=2) printf(“Block %02d = %08lx %08lx\n”, i/2,data[i],data[i+1]); gost_destroy(&ampgc); } BLOWFISH #include #include #include #include <math.h> <stdio.h> <stdlib.h> <time.h> /* Eg: Intel */ #ifdef little_endian #include <alloc.h> #endif #include <ctype.h> #ifdef little_endian /* Eg: Intel */ #include <dir.h> #include <bios.h> #endif #ifdef big_endian #include <Types.h> #endif typedef struct { unsigned long S[4][256],P[18]; } blf_ctx; #define MAXKEYBYTES 56 // #define little_endian 1 #define big_endian 1 /* 448 bits */ /* Eg: Intel */ /* Eg: Motorola */ void Blowfish_encipher(blf_ctx *,unsigned long *xl, unsigned long *xr); void Blowfish_decipher(blf_ctx *,unsigned long *xl, unsigned long *xr); #define #define #define #define FILE* N noErr DATAERROR KEYBYTES 16 0 –1 8 SubkeyFile; unsigned long F(blf_ctx *bc, unsigned long x) { unsigned short a; unsigned short b; unsigned short c; unsigned short d; unsigned long y; d = x & 0×00FF; x >>= 8; c = x & 0×00FF; x >>= 8; b = x & 0×00FF; x >>= 8; a = x & 0×00FF; //y = ((S[0][a] + S[1][b]) ^ S[2][c]) + S[3][d]; y = bc–>S[0][a] + bc–>S[1][b]; y = y ^ bc–>S[2][c]; y = y + bc–>S[3][d]; return y; } void Blowfish_encipher(blf_ctx *c,unsigned long *xl, unsigned long *xr) { unsigned long Xl; unsigned long Xr; unsigned long temp; short i; Xl = *xl; Xr = *xr; for (i = 0; i < N; ++i) { Xl = Xl ^ c–>P[i]; Xr = F(c,Xl) ^ Xr; temp = Xl;...
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