abseil-cpp/absl/random/internal/randen.cc
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 #include "absl/random/internal/randen.h"
16 
17 #include "absl/base/internal/raw_logging.h"
18 #include "absl/random/internal/randen_detect.h"
19 
20 // RANDen = RANDom generator or beetroots in Swiss High German.
21 // 'Strong' (well-distributed, unpredictable, backtracking-resistant) random
22 // generator, faster in some benchmarks than std::mt19937_64 and pcg64_c32.
23 //
24 // High-level summary:
25 // 1) Reverie (see "A Robust and Sponge-Like PRNG with Improved Efficiency") is
26 // a sponge-like random generator that requires a cryptographic permutation.
27 // It improves upon "Provably Robust Sponge-Based PRNGs and KDFs" by
28 // achieving backtracking resistance with only one Permute() per buffer.
29 //
30 // 2) "Simpira v2: A Family of Efficient Permutations Using the AES Round
31 // Function" constructs up to 1024-bit permutations using an improved
32 // Generalized Feistel network with 2-round AES-128 functions. This Feistel
33 // block shuffle achieves diffusion faster and is less vulnerable to
34 // sliced-biclique attacks than the Type-2 cyclic shuffle.
35 //
36 // 3) "Improving the Generalized Feistel" and "New criterion for diffusion
37 // property" extends the same kind of improved Feistel block shuffle to 16
38 // branches, which enables a 2048-bit permutation.
39 //
40 // We combine these three ideas and also change Simpira's subround keys from
41 // structured/low-entropy counters to digits of Pi.
42 
43 namespace absl {
45 namespace random_internal {
46 namespace {
47 
48 struct RandenState {
49  const void* keys;
50  bool has_crypto;
51 };
52 
53 RandenState GetRandenState() {
54  static const RandenState state = []() {
55  RandenState tmp;
56 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
57  // HW AES Dispatch.
59  tmp.has_crypto = true;
60  tmp.keys = RandenHwAes::GetKeys();
61  } else {
62  tmp.has_crypto = false;
63  tmp.keys = RandenSlow::GetKeys();
64  }
65 #elif ABSL_HAVE_ACCELERATED_AES
66  // HW AES is enabled.
67  tmp.has_crypto = true;
68  tmp.keys = RandenHwAes::GetKeys();
69 #else
70  // HW AES is disabled.
71  tmp.has_crypto = false;
72  tmp.keys = RandenSlow::GetKeys();
73 #endif
74  return tmp;
75  }();
76  return state;
77 }
78 
79 } // namespace
80 
82  auto tmp = GetRandenState();
83  keys_ = tmp.keys;
84 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
85  has_crypto_ = tmp.has_crypto;
86 #endif
87 }
88 
89 } // namespace random_internal
91 } // namespace absl
keys
const void * keys
Definition: abseil-cpp/absl/random/internal/randen.cc:49
absl::random_internal::Randen::keys_
const void * keys_
Definition: abseil-cpp/absl/random/internal/randen.h:86
absl::random_internal::HasRandenHwAesImplementation
bool HasRandenHwAesImplementation()
Definition: abseil-cpp/absl/random/internal/randen_hwaes.cc:54
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::CPUSupportsRandenHwAes
bool CPUSupportsRandenHwAes()
Definition: abseil-cpp/absl/random/internal/randen_detect.cc:131
has_crypto
bool has_crypto
Definition: abseil-cpp/absl/random/internal/randen.cc:50
absl::random_internal::RandenHwAes::GetKeys
static const void * GetKeys()
Definition: abseil-cpp/absl/random/internal/randen_hwaes.cc:57
absl::random_internal::RandenSlow::GetKeys
static const void * GetKeys()
Definition: abseil-cpp/absl/random/internal/randen_slow.cc:421
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87


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