Botan  1.11.15
src/lib/block/gost_28147/gost_28147.h
Go to the documentation of this file.
00001 /*
00002 * GOST 28147-89
00003 * (C) 1999-2009 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_GOST_28147_89_H__
00009 #define BOTAN_GOST_28147_89_H__
00010 
00011 #include <botan/block_cipher.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however
00017 * the standard does not actually define these Sboxes; they are
00018 * considered a local configuration issue. Several different sets are
00019 * used.
00020 */
00021 class BOTAN_DLL GOST_28147_89_Params
00022    {
00023    public:
00024       /**
00025       * @param row the row
00026       * @param col the column
00027       * @return sbox entry at this row/column
00028       */
00029       byte sbox_entry(size_t row, size_t col) const;
00030 
00031       /**
00032       * @return name of this parameter set
00033       */
00034       std::string param_name() const { return name; }
00035 
00036       /**
00037       * Default GOST parameters are the ones given in GOST R 34.11 for
00038       * testing purposes; these sboxes are also used by Crypto++, and,
00039       * at least according to Wikipedia, the Central Bank of Russian
00040       * Federation
00041       * @param name of the parameter set
00042       */
00043       GOST_28147_89_Params(const std::string& name = "R3411_94_TestParam");
00044    private:
00045       const byte* sboxes;
00046       std::string name;
00047    };
00048 
00049 /**
00050 * GOST 28147-89
00051 */
00052 class BOTAN_DLL GOST_28147_89 : public Block_Cipher_Fixed_Params<8, 32>
00053    {
00054    public:
00055       void encrypt_n(const byte in[], byte out[], size_t blocks) const;
00056       void decrypt_n(const byte in[], byte out[], size_t blocks) const;
00057 
00058       void clear();
00059 
00060       std::string name() const;
00061       BlockCipher* clone() const { return new GOST_28147_89(SBOX); }
00062 
00063       /**
00064       * @param params the sbox parameters to use
00065       */
00066       GOST_28147_89(const GOST_28147_89_Params& params);
00067    private:
00068       GOST_28147_89(const std::vector<u32bit>& other_SBOX) :
00069          SBOX(other_SBOX), EK(8) {}
00070 
00071       void key_schedule(const byte[], size_t);
00072 
00073       /*
00074       * The sbox is not secret, this is just a larger expansion of it
00075       * which we generate at runtime for faster execution
00076       */
00077       std::vector<u32bit> SBOX;
00078 
00079       secure_vector<u32bit> EK;
00080    };
00081 
00082 }
00083 
00084 #endif