28147-89 - 4


n1 ^= f(n2+key[5]);

n2 ^= f(n1+key[6]);

n1 ^= f(n2+key[7]);

}

n2 ^= f(n1+key[7]);

n1 ^= f(n2+key[6]);

n2 ^= f(n1+key[5]);

n1 ^= f(n2+key[4]);

n2 ^= f(n1+key[3]);

n1 ^= f(n2+key[2]);

n2 ^= f(n1+key[1]);

n1 ^= f(n2+key[0]);

Block::Put(xorBlock, outBlock)(n2)(n1);

}

void GOST::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const

{

word32 n1, n2, t;

Block::Get(inBlock)(n1)(n2);

18.5

n2 ^= f(n1+key[0]);

n1 ^= f(n2+key[1]);

n2 ^= f(n1+key[2]);

n1 ^= f(n2+key[3]);

n2 ^= f(n1+key[4]);

n1 ^= f(n2+key[5]);

n2 ^= f(n1+key[6]);

n1 ^= f(n2+key[7]);

for (unsigned int i=0; i<3; i++)

{

n2 ^= f(n1+key[7]);

n1 ^= f(n2+key[6]);

n2 ^= f(n1+key[5]);

n1 ^= f(n2+key[4]);

n2 ^= f(n1+key[3]);

n1 ^= f(n2+key[2]);

n2 ^= f(n1+key[1]);

n1 ^= f(n2+key[0]);

}

Block::Put(xorBlock, outBlock)(n2)(n1);

}

NAMESPACE_END

18.6. gost.h,


C++ ( Crypto++ 5.1)

#ifndef CRYPTOPP_GOST_H

#define CRYPTOPP_GOST_H

#include "seckey.h"

#include "secblock.h"

NAMESPACE_BEGIN(CryptoPP)

struct GOST_Info : public FixedBlockSize<8>,

public FixedKeyLength<32>

{ static const char *StaticAlgorithmName() {return "GOST";}};

18.6

{

class Base : public BlockCipherBaseTemplate<GOST_Info>

{

public:

void UncheckedSetKey(CipherDir direction,

const byte *userKey, unsigned int length);

protected:

static void PrecalculateSTable();

static const byte sBox[8][16];

static bool sTableCalculated;

static word32 sTable[4][256];

FixedSizeSecBlock<word32, 8> key;

};

class Enc : public Base

{

public:

void ProcessAndXorBlock(const byte *inBlock,

const byte *xorBlock, byte *outBlock) const;