Coverage Report

Created: 2023-02-13 06:21

/src/botan/build/include/botan/internal/stream_mode.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2015 Jack Lloyd
3
* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_STREAM_MODE_H_
9
#define BOTAN_STREAM_MODE_H_
10
11
#include <botan/cipher_mode.h>
12
13
#if defined(BOTAN_HAS_STREAM_CIPHER)
14
   #include <botan/stream_cipher.h>
15
#endif
16
17
namespace Botan {
18
19
#if defined(BOTAN_HAS_STREAM_CIPHER)
20
21
class Stream_Cipher_Mode final : public Cipher_Mode
22
   {
23
   public:
24
      /**
25
      * @param cipher underyling stream cipher
26
      */
27
      explicit Stream_Cipher_Mode(std::unique_ptr<StreamCipher> cipher) :
28
0
         m_cipher(std::move(cipher)) {}
29
30
      size_t process(uint8_t buf[], size_t sz) override
31
0
         {
32
0
         m_cipher->cipher1(buf, sz);
33
0
         return sz;
34
0
         }
35
36
      void finish(secure_vector<uint8_t>& buf, size_t offset) override
37
0
         { return update(buf, offset); }
38
39
0
      size_t output_length(size_t input_length) const override { return input_length; }
40
41
0
      size_t update_granularity() const override { return 1; }
42
43
      // Return value is arbitrary as there is currently no way to
44
      // query a StreamCipher as to its internal block size
45
0
      size_t ideal_granularity() const override { return 64; }
46
47
0
      size_t minimum_final_size() const override { return 0; }
48
49
0
      size_t default_nonce_length() const override { return 0; }
50
51
      bool valid_nonce_length(size_t nonce_len) const override
52
0
         { return m_cipher->valid_iv_length(nonce_len); }
53
54
0
      Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); }
55
56
0
      std::string name() const override { return m_cipher->name(); }
57
58
      void clear() override
59
0
         {
60
0
         m_cipher->clear();
61
0
         reset();
62
0
         }
63
64
0
      void reset() override { /* no msg state */ }
65
66
   private:
67
      void start_msg(const uint8_t nonce[], size_t nonce_len) override
68
0
         {
69
0
         if(nonce_len > 0)
70
0
            {
71
0
            m_cipher->set_iv(nonce, nonce_len);
72
0
            }
73
0
         }
74
75
      void key_schedule(const uint8_t key[], size_t length) override
76
0
         {
77
0
         m_cipher->set_key(key, length);
78
0
         }
79
80
      std::unique_ptr<StreamCipher> m_cipher;
81
   };
82
83
#endif
84
85
}
86
87
#endif