Coverage Report

Created: 2020-05-23 13:54

/src/botan/build/include/botan/sym_algo.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Symmetric Algorithm Base Class
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_SYMMETRIC_ALGORITHM_H_
9
#define BOTAN_SYMMETRIC_ALGORITHM_H_
10
11
#include <botan/key_spec.h>
12
#include <botan/symkey.h>
13
#include <botan/types.h>
14
15
namespace Botan {
16
17
/**
18
* This class represents a symmetric algorithm object.
19
*/
20
class BOTAN_PUBLIC_API(2,0) SymmetricAlgorithm
21
   {
22
   public:
23
32.1k
      virtual ~SymmetricAlgorithm() = default;
24
25
      /**
26
      * Reset the state.
27
      */
28
      virtual void clear() = 0;
29
30
      /**
31
      * @return object describing limits on key size
32
      */
33
      virtual Key_Length_Specification key_spec() const = 0;
34
35
      /**
36
      * @return minimum allowed key length
37
      */
38
      size_t maximum_keylength() const
39
0
         {
40
0
         return key_spec().maximum_keylength();
41
0
         }
42
43
      /**
44
      * @return maximum allowed key length
45
      */
46
      size_t minimum_keylength() const
47
0
         {
48
0
         return key_spec().minimum_keylength();
49
0
         }
50
51
      /**
52
      * Check whether a given key length is valid for this algorithm.
53
      * @param length the key length to be checked.
54
      * @return true if the key length is valid.
55
      */
56
      bool valid_keylength(size_t length) const
57
45.7k
         {
58
45.7k
         return key_spec().valid_keylength(length);
59
45.7k
         }
60
61
      /**
62
      * Set the symmetric key of this object.
63
      * @param key the SymmetricKey to be set.
64
      */
65
      void set_key(const SymmetricKey& key)
66
7.00k
         {
67
7.00k
         set_key(key.begin(), key.length());
68
7.00k
         }
69
70
      template<typename Alloc>
71
      void set_key(const std::vector<uint8_t, Alloc>& key)
72
3.67k
         {
73
3.67k
         set_key(key.data(), key.size());
74
3.67k
         }
void Botan::SymmetricAlgorithm::set_key<std::__1::allocator<unsigned char> >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
Line
Count
Source
72
7
         {
73
7
         set_key(key.data(), key.size());
74
7
         }
void Botan::SymmetricAlgorithm::set_key<Botan::secure_allocator<unsigned char> >(std::__1::vector<unsigned char, Botan::secure_allocator<unsigned char> > const&)
Line
Count
Source
72
3.66k
         {
73
3.66k
         set_key(key.data(), key.size());
74
3.66k
         }
75
76
      /**
77
      * Set the symmetric key of this object.
78
      * @param key the to be set as a byte array.
79
      * @param length in bytes of key param
80
      */
81
      void set_key(const uint8_t key[], size_t length);
82
83
      /**
84
      * @return the algorithm name
85
      */
86
      virtual std::string name() const = 0;
87
88
   protected:
89
      void verify_key_set(bool cond) const
90
876k
         {
91
876k
         if(cond == false)
92
0
            throw_key_not_set_error();
93
876k
         }
94
95
   private:
96
      void throw_key_not_set_error() const;
97
98
      /**
99
      * Run the key schedule
100
      * @param key the key
101
      * @param length of key
102
      */
103
      virtual void key_schedule(const uint8_t key[], size_t length) = 0;
104
   };
105
106
}
107
108
#endif