Ремонт принтеров, сканнеров, факсов и остальной офисной техники


назад Оглавление вперед




[195]

gost key(&gc,k);

/* Try some test vectors. */

data[0] = 0; data[1] = 0;

gostcrypt(&gc,data);

printf("Enc of zero vector: %08lx %08lx\n",data[0],data[1]);

gostcrypt(&gc,data);

printf("Enc of above:%08lx %08lx\n",data[0],data[1]);

data[0] = 0xffffffff; data[1] = 0xffffffff;

gostcrypt(&gc,data);

printf("Enc of ones vector: %08lx %08lx\n",data[0],data[1]);

gostcrypt(&gc,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(&gc,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(&gc,data,1);

gost dec(&gc,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(&gc);

BLOWFISH

#include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h>

#ifdef little endian /* Eg: Intel */ #include <alloc.h>

#include <ctype.h>

#ifdef little endian /* Eg: Intel */ #include <dir.h> #include <bios.h>


#ifdef big endian

#include <Types.h>

typedef struct {

unsigned long S[4][256],P[18]; } blf ctx;

#define MAXKEYBYTES 56/* 448 bits */

#define little endian 1/* Eg: Intel */

#define big endian 1/* 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 N16

#define noErr0

#define DATAERROR-1

#define KEYBYTES8

FILE*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 & 0x00FF;

x >>= 8;

c = x & 0x00FF;

x >>= 8;

b = x & 0x00FF;

x >>= 8;

a =x & 0x00FF;

y= ((S[0][a] + S[1][b]) a S[2][c]) + S[3][d];

y =bc->S[0][a] + bc->S[1][b];

y =y a 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 longXl;

unsigned longXr;

unsigned longtemp;

shorti;

Xl = *xl;

Xr = *xr;

for (i = 0; i < N;{

Xl = Xl A c->P[i]; Xr = F(c,Xl) A Xr;

temp = Xl;


Xl = Xr;

Xr = temp;

temp = Xl;

Xl = Xr;

Xr = temp;

Xr = Xr л c->P[N];

Xl = Xl л c->P[N + 1];

*xl = Xl;

*xr = Xr;

void Blowfish decipher(blf ctx *c, unsigned long *xl, unsigned long *xr)

unsigned longXl;

unsigned longXr;

unsigned longtemp;

shorti;

Xl = *xl;

Xr = *xr;

for (i = N + 1; i > 1; -i) { Xl = Xl л c->P[i]; Xr = F(c,Xl) л Xr;

/* Exchange Xl and Xr */ temp = Xl;

Xl = Xr;

Xr = temp;

/* Exchange Xl and Xr */ temp = Xl;

Xl = Xr;

Xr = temp;

Xr = Xr л c->P[1]; Xl = Xl л c->P[0];

*xl = Xl;

*xr = Xr;

short InitializeBlowfish(blf ctx *c, char key[], short keybytes)

shorti;

shortj;

shortk;

shorterror;

shortnumread;

unsigned longdata;

unsigned longdatal;

unsigned longdatar;

unsigned long ks0[] = {

0xd1310ba6, 0x98dfb5ac,0x2ffd72db,0xd01adfb7,0xb8e1afed,0x6a267e96,

0xba7c9045, 0xf12c7f99,0x24a19947,0xb3916cf7,0x0801f2e2,0x858efc16,

0x636920d8, 0x71574e69,0xa458fea3,0xf4933d7e,0x0d95748f,0x728eb658,



[стр.Начало] [стр.1] [стр.2] [стр.3] [стр.4] [стр.5] [стр.6] [стр.7] [стр.8] [стр.9] [стр.10] [стр.11] [стр.12] [стр.13] [стр.14] [стр.15] [стр.16] [стр.17] [стр.18] [стр.19] [стр.20] [стр.21] [стр.22] [стр.23] [стр.24] [стр.25] [стр.26] [стр.27] [стр.28] [стр.29] [стр.30] [стр.31] [стр.32] [стр.33] [стр.34] [стр.35] [стр.36] [стр.37] [стр.38] [стр.39] [стр.40] [стр.41] [стр.42] [стр.43] [стр.44] [стр.45] [стр.46] [стр.47] [стр.48] [стр.49] [стр.50] [стр.51] [стр.52] [стр.53] [стр.54] [стр.55] [стр.56] [стр.57] [стр.58] [стр.59] [стр.60] [стр.61] [стр.62] [стр.63] [стр.64] [стр.65] [стр.66] [стр.67] [стр.68] [стр.69] [стр.70] [стр.71] [стр.72] [стр.73] [стр.74] [стр.75] [стр.76] [стр.77] [стр.78] [стр.79] [стр.80] [стр.81] [стр.82] [стр.83] [стр.84] [стр.85] [стр.86] [стр.87] [стр.88] [стр.89] [стр.90] [стр.91] [стр.92] [стр.93] [стр.94] [стр.95] [стр.96] [стр.97] [стр.98] [стр.99] [стр.100] [стр.101] [стр.102] [стр.103] [стр.104] [стр.105] [стр.106] [стр.107] [стр.108] [стр.109] [стр.110] [стр.111] [стр.112] [стр.113] [стр.114] [стр.115] [стр.116] [стр.117] [стр.118] [стр.119] [стр.120] [стр.121] [стр.122] [стр.123] [стр.124] [стр.125] [стр.126] [стр.127] [стр.128] [стр.129] [стр.130] [стр.131] [стр.132] [стр.133] [стр.134] [стр.135] [стр.136] [стр.137] [стр.138] [стр.139] [стр.140] [стр.141] [стр.142] [стр.143] [стр.144] [стр.145] [стр.146] [стр.147] [стр.148] [стр.149] [стр.150] [стр.151] [стр.152] [стр.153] [стр.154] [стр.155] [стр.156] [стр.157] [стр.158] [стр.159] [стр.160] [стр.161] [стр.162] [стр.163] [стр.164] [стр.165] [стр.166] [стр.167] [стр.168] [стр.169] [стр.170] [стр.171] [стр.172] [стр.173] [стр.174] [стр.175] [стр.176] [стр.177] [стр.178] [стр.179] [стр.180] [стр.181] [стр.182] [стр.183] [стр.184] [стр.185] [стр.186] [стр.187] [стр.188] [стр.189] [стр.190] [стр.191] [стр.192] [стр.193] [стр.194] [стр.195] [стр.196] [стр.197] [стр.198] [стр.199] [стр.200] [стр.201] [стр.202] [стр.203]