Botan  1.11.15
src/lib/stream/chacha/chacha.h
Go to the documentation of this file.
00001 /*
00002 * ChaCha20
00003 * (C) 2014 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_CHACHA_H__
00009 #define BOTAN_CHACHA_H__
00010 
00011 #include <botan/stream_cipher.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * DJB's ChaCha (http://cr.yp.to/chacha.html)
00017 */
00018 class BOTAN_DLL ChaCha : public StreamCipher
00019    {
00020    public:
00021       void cipher(const byte in[], byte out[], size_t length);
00022 
00023       void set_iv(const byte iv[], size_t iv_len);
00024 
00025       bool valid_iv_length(size_t iv_len) const
00026          { return (iv_len == 8 || iv_len == 12); }
00027 
00028       Key_Length_Specification key_spec() const
00029          {
00030          return Key_Length_Specification(16, 32, 16);
00031          }
00032 
00033       void clear();
00034       std::string name() const { return "ChaCha"; }
00035 
00036       StreamCipher* clone() const { return new ChaCha; }
00037    protected:
00038       virtual void chacha(byte output[64], const u32bit input[16]);
00039    private:
00040       void key_schedule(const byte key[], size_t key_len);
00041 
00042       secure_vector<u32bit> m_state;
00043       secure_vector<byte> m_buffer;
00044       size_t m_position = 0;
00045    };
00046 
00047 }
00048 
00049 #endif