• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 4834822395

28 Apr 2023 09:55PM UTC coverage: 92.132% (-0.01%) from 92.146%
4834822395

push

github

77584 of 84210 relevant lines covered (92.13%)

12129586.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/lib/stream/chacha/chacha.h
1
/*
2
* ChaCha20
3
* (C) 2014,2018 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#ifndef BOTAN_CHACHA_H_
9
#define BOTAN_CHACHA_H_
10

11
#include <botan/stream_cipher.h>
12

13
namespace Botan {
14

15
/**
16
* DJB's ChaCha (https://cr.yp.to/chacha.html)
17
*/
18
class ChaCha final : public StreamCipher
×
19
   {
20
   public:
21
      /**
22
      * @param rounds number of rounds
23
      * @note Currently only 8, 12 or 20 rounds are supported, all others
24
      * will throw an exception
25
      */
26
      explicit ChaCha(size_t rounds = 20);
27

28
      std::string provider() const override;
29

30
      /*
31
      * ChaCha accepts 0, 8, 12 or 24 byte IVs.
32
      * The default IV is a 8 zero bytes.
33
      * An IV of length 0 is treated the same as the default zero IV.
34
      * An IV of length 24 selects XChaCha mode
35
      */
36
      bool valid_iv_length(size_t iv_len) const override;
37

38
      size_t default_iv_length() const override;
39

40
      Key_Length_Specification key_spec() const override;
41

42
      void clear() override;
43

44
      std::unique_ptr<StreamCipher> new_object() const override;
45

46
      std::string name() const override;
47

48
      void seek(uint64_t offset) override;
49

50
      bool has_keying_material() const override;
51

52
      size_t buffer_size() const override;
53
   private:
54
      void key_schedule(const uint8_t key[], size_t key_len) override;
55

56
      void cipher_bytes(const uint8_t in[], uint8_t out[], size_t length) override;
57

58
      void generate_keystream(uint8_t out[], size_t len) override;
59

60
      void set_iv_bytes(const uint8_t iv[], size_t iv_len) override;
61

62
      void initialize_state();
63

64
      static size_t parallelism();
65

66
      static void chacha(uint8_t output[],
67
                         size_t output_blocks,
68
                         uint32_t state[16],
69
                         size_t rounds);
70

71
#if defined(BOTAN_HAS_CHACHA_SIMD32)
72
      static void chacha_simd32_x4(uint8_t output[64*4], uint32_t state[16], size_t rounds);
73
#endif
74

75
#if defined(BOTAN_HAS_CHACHA_AVX2)
76
      static void chacha_avx2_x8(uint8_t output[64*8], uint32_t state[16], size_t rounds);
77
#endif
78

79
      size_t m_rounds;
80
      secure_vector<uint32_t> m_key;
81
      secure_vector<uint32_t> m_state;
82
      secure_vector<uint8_t> m_buffer;
83
      size_t m_position = 0;
84
   };
85

86
}
87

88
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc