summaryrefslogtreecommitdiffstats
path: root/old/botan/src/stream/stream_cipher.h
blob: 8ea359131088b3432e4b09eaf1344a37db4d7202 (plain)
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
/**
* Stream Cipher
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_STREAM_CIPHER_H__
#define BOTAN_STREAM_CIPHER_H__

#include <botan/sym_algo.h>

namespace Botan {

/*
* Stream Cipher
*/
class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
   {
   public:
      const u32bit IV_LENGTH;

      /**
      * Encrypt a message.
      * @param i the plaintext
      * @param o the byte array to hold the output, i.e. the ciphertext
      * @param len the length of both i and o
      */
      void encrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }

      /**
      * Decrypt a message.
      * @param i the ciphertext to decrypt
      * @param o the byte array to hold the output, i.e. the plaintext
      * @param len the length of both i and o
      */
      void decrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }

      /**
      * Encrypt a message.
      * @param in the plaintext as input, after the function has
      * returned it will hold the ciphertext

      * @param len the length of in
      */
      void encrypt(byte in[], u32bit len) { cipher(in, in, len); }

      /**
      * Decrypt a message.
      * @param in the ciphertext as input, after the function has
      * returned it will hold the plaintext
      * @param len the length of in
      */
      void decrypt(byte in[], u32bit len) { cipher(in, in, len); }

      /**
      * Resync the cipher using the IV
      * @param iv the initialization vector
      * @param iv_len the length of the IV in bytes
      */
      virtual void resync(const byte iv[], u32bit iv_len);

      /**
      * Seek ahead in the stream.
      * @param len the length to seek ahead.
      */
      virtual void seek(u32bit len);

      /**
      * Get a new object representing the same algorithm as *this
      */
      virtual StreamCipher* clone() const = 0;

      /**
      * Zeroize internal state
      */
      virtual void clear() throw() = 0;

      StreamCipher(u32bit key_min, u32bit key_max = 0,
                   u32bit key_mod = 1,
                   u32bit iv_len = 0) :
         SymmetricAlgorithm(key_min, key_max, key_mod),
         IV_LENGTH(iv_len) {}

      virtual ~StreamCipher() {}
   private:
      virtual void cipher(const byte[], byte[], u32bit) = 0;
   };

}

#endif