abseil-cpp/absl/random/internal/randen.h
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_RANDOM_INTERNAL_RANDEN_H_
16 #define ABSL_RANDOM_INTERNAL_RANDEN_H_
17 
18 #include <cstddef>
19 
20 #include "absl/random/internal/platform.h"
21 #include "absl/random/internal/randen_hwaes.h"
22 #include "absl/random/internal/randen_slow.h"
23 #include "absl/random/internal/randen_traits.h"
24 
25 namespace absl {
27 namespace random_internal {
28 
29 // RANDen = RANDom generator or beetroots in Swiss High German.
30 // 'Strong' (well-distributed, unpredictable, backtracking-resistant) random
31 // generator, faster in some benchmarks than std::mt19937_64 and pcg64_c32.
32 //
33 // Randen implements the basic state manipulation methods.
34 class Randen {
35  public:
36  static constexpr size_t kStateBytes = RandenTraits::kStateBytes;
37  static constexpr size_t kCapacityBytes = RandenTraits::kCapacityBytes;
38  static constexpr size_t kSeedBytes = RandenTraits::kSeedBytes;
39 
40  ~Randen() = default;
41 
42  Randen();
43 
44  // Generate updates the randen sponge. The outer portion of the sponge
45  // (kCapacityBytes .. kStateBytes) may be consumed as PRNG state.
46  // REQUIRES: state points to kStateBytes of state.
47  inline void Generate(void* state) const {
48 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
49  // HW AES Dispatch.
50  if (has_crypto_) {
52  } else {
54  }
55 #elif ABSL_HAVE_ACCELERATED_AES
56  // HW AES is enabled.
58 #else
59  // HW AES is disabled.
61 #endif
62  }
63 
64  // Absorb incorporates additional seed material into the randen sponge. After
65  // absorb returns, Generate must be called before the state may be consumed.
66  // REQUIRES: seed points to kSeedBytes of seed.
67  // REQUIRES: state points to kStateBytes of state.
68  inline void Absorb(const void* seed, void* state) const {
69 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
70  // HW AES Dispatch.
71  if (has_crypto_) {
73  } else {
75  }
76 #elif ABSL_HAVE_ACCELERATED_AES
77  // HW AES is enabled.
79 #else
80  // HW AES is disabled.
82 #endif
83  }
84 
85  private:
86  const void* keys_;
87 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
88  bool has_crypto_;
89 #endif
90 };
91 
92 } // namespace random_internal
94 } // namespace absl
95 
96 #endif // ABSL_RANDOM_INTERNAL_RANDEN_H_
absl::random_internal::Randen::~Randen
~Randen()=default
absl::random_internal::Randen::keys_
const void * keys_
Definition: abseil-cpp/absl/random/internal/randen.h:86
seed
static const uint8_t seed[20]
Definition: dsa_test.cc:79
absl::random_internal::Randen::Generate
void Generate(void *state) const
Definition: abseil-cpp/absl/random/internal/randen.h:47
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::random_internal::Randen::Randen
Randen()
Definition: abseil-cpp/absl/random/internal/randen.cc:81
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::random_internal::RandenHwAes::Absorb
static void Absorb(const void *seed_void, void *state_void)
Definition: abseil-cpp/absl/random/internal/randen_hwaes.cc:66
absl::random_internal::Randen
Definition: abseil-cpp/absl/random/internal/randen.h:34
absl::random_internal::Randen::kCapacityBytes
static constexpr size_t kCapacityBytes
Definition: abseil-cpp/absl/random/internal/randen.h:37
absl::random_internal::Randen::kStateBytes
static constexpr size_t kStateBytes
Definition: abseil-cpp/absl/random/internal/randen.h:36
absl::random_internal::Randen::kSeedBytes
static constexpr size_t kSeedBytes
Definition: abseil-cpp/absl/random/internal/randen.h:38
absl::random_internal::RandenTraits::kStateBytes
static constexpr size_t kStateBytes
Definition: abseil-cpp/absl/random/internal/randen_traits.h:58
absl::random_internal::RandenSlow::Absorb
static void Absorb(const void *seed_void, void *state_void)
Definition: abseil-cpp/absl/random/internal/randen_slow.cc:431
absl::random_internal::RandenHwAes::Generate
static void Generate(const void *keys, void *state_void)
Definition: abseil-cpp/absl/random/internal/randen_hwaes.cc:74
absl::random_internal::RandenTraits::kCapacityBytes
static constexpr size_t kCapacityBytes
Definition: abseil-cpp/absl/random/internal/randen_traits.h:62
absl::random_internal::RandenSlow::Generate
static void Generate(const void *keys, void *state_void)
Definition: abseil-cpp/absl/random/internal/randen_slow.cc:450
absl::random_internal::RandenTraits::kSeedBytes
static constexpr size_t kSeedBytes
Definition: abseil-cpp/absl/random/internal/randen_traits.h:65
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::random_internal::Randen::Absorb
void Absorb(const void *seed, void *state) const
Definition: abseil-cpp/absl/random/internal/randen.h:68
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:50