Boost logo

Boost :

Subject: [boost] [crypto] Finalisation
From: Kasra (kasra_n500_at_[hidden])
Date: 2009-01-03 09:57:18


Dear Kevin Sopp,

I know you are interested in this library I have looked at your code and have decided to use considerable amount of your library's concepts.

Dear All,

You may know that I have been working on a crypto library for boost. I think at this time the design and concepts for the library is finished and implementation could be started.

However, I decided to check with interested parties before I begin the implementation. Currently the concepts is as follows:
[Note] C++0x features has been used but there is a work around library which allows pre-C++0x compilers to compile the code.

auto concept BlockCipherTraits
{
    enum cipher_type { feistle, substitution_permutation, square, };
    static constexpr size_t block_size;
    static constexpr size_t min_key_size;
    static constexpr size_t max_key_size;
    static constexpr cipher_type type();
    static constexpr bool timming_attack_resistant;
};

template<typename T=byte_t>
auto concept PaddingTraits
{
    static constexpr size_t block_size;
    static constexpr size_t min_block_size; /* = sizeof(T) * 2; */
    static constexpr size_t max_block_size; /* = detail::pow<2,sizeof(T)*8>::value; */
    static constexpr const char* name();
};

class crypto_exception;
class cipher_state;
class invalid_length;
class invalid_key_size;
class invalid_iv_size;
class bad_padding;

template<typename T>
auto concept Padding requires PaddingTraits<T>
{
    typename size_type;
    typename value_type;

    static constexpr size_t output_size(size_t );
    static constexpr size_t pad(value_type* output, const value_type* input, size_t input_size) throw(invalid_length);
    static constexpr size_t unpad(value_type* output, const value_type* input, size_t input_size) throw(bad_padding);
};

template<typename T>
auto concept BlockCipher
{
    typename value_type;
    typename size_type;
    const void setkey(const value_type* key, size_type key_size) throw(invalid_key_size);
    const void encrypt(value_type* ctxt, const value_type* ptxt);
    const void decrypt(value_type* ptxt, const value_type* ctxt);
};

template<typename T = byte_t>
auto concept StreamCipherTraits
{
    typename value_type;
    static constexpr size_t min_stream_size;
    static constexpr size_t max_stream_size;
    static constexpr size_t transform_size;
    static constexpr size_t min_key_size;
    static constexpr size_t max_key_size;
    static constexpr size_t min_iv_size;
    static constexpr size_t max_iv_size;
    static constexpr bool seekable_stream;
    static constexpr bool synchronous;
    static constexpr bool asynchronous;
};

template<StreamCipherTraits StreamCipherT>
auto concept StreamCipher : StreamCipherT
{
    typedef value_type;
    typedef StreamCipherT traits_type;
    const void setkey(const value_type* key, size_type key_size) throw(invalid_key_size);
    const void setivconst value_type* iv, size_type iv_size) throw(invalid_iv_size);

    const void encrypt(value_type* output, const value_type* input, size_type input_size);
    const void decrypt(value_type* output, const value_type* input,size_type input_size);
};

// mode of operation + block cipher == stream_cipher
template<typename T=byte_t, BlockCipher Cipher>
auto concept ModeOfOperation: public StreamCipher
{
    typedef Cipher block_cipher_type;
};

template<typename T=byte_t>
auto concept HashFunctionTraits: StreamCipherTraits
{
    static constexpr size_t transform_size;
    static constexpr size_t digest_size;
};

template<typename T=byte_t, HashFunctionTraits HashFunctionT>
auto concept HashFunction : public HashFunctionT
{
    typedef HashFunctionT traits_type;
    size_t digest_size() const;
    constexpr create();
    template<size_t N> constexpr update(const crypto_buffer_t<N>& input);
    constexpr finalise();
    template<size_t N>
    constexpr compute(crypto_buffer_t<traits_type::digest_size>& digest, const crypto_buffer_t <N>& input);
};

class crypto_streambuf;
class crypto_istream;
class crypto_ostream;
class crypto_iostream;

Also I would like to make this library compatible with boost.iostream so that an encryption algorithm could be used as a filter for the boost.iostream.

The library tries to do most of the computation at compile time. I would welcome all comments.

With Best regards

Kasra

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk