blob: 4f1f408d1917f6e1722ae2f4c6ca16cff0bb2f31 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001// 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_TRAITS_H_
16#define ABSL_RANDOM_INTERNAL_RANDEN_TRAITS_H_
17
18// HERMETIC NOTE: The randen_hwaes target must not introduce duplicate
19// symbols from arbitrary system and other headers, since it may be built
20// with different flags from other targets, using different levels of
21// optimization, potentially introducing ODR violations.
22
23#include <cstddef>
24
25namespace absl {
26namespace random_internal {
27
28// RANDen = RANDom generator or beetroots in Swiss German.
29// 'Strong' (well-distributed, unpredictable, backtracking-resistant) random
30// generator, faster in some benchmarks than std::mt19937_64 and pcg64_c32.
31//
32// RandenTraits contains the basic algorithm traits, such as the size of the
33// state, seed, sponge, etc.
34struct RandenTraits {
35 // Size of the entire sponge / state for the randen PRNG.
36 static constexpr size_t kStateBytes = 256; // 2048-bit
37
38 // Size of the 'inner' (inaccessible) part of the sponge. Larger values would
39 // require more frequent calls to RandenGenerate.
40 static constexpr size_t kCapacityBytes = 16; // 128-bit
41
42 // Size of the default seed consumed by the sponge.
43 static constexpr size_t kSeedBytes = kStateBytes - kCapacityBytes;
44
45 // Largest size for which security proofs are known.
46 static constexpr size_t kFeistelBlocks = 16;
47
48 // Type-2 generalized Feistel => one round function for every two blocks.
49 static constexpr size_t kFeistelFunctions = kFeistelBlocks / 2; // = 8
50
51 // Ensures SPRP security and two full subblock diffusions.
52 // Must be > 4 * log2(kFeistelBlocks).
53 static constexpr size_t kFeistelRounds = 16 + 1;
54};
55
56} // namespace random_internal
57} // namespace absl
58
59#endif // ABSL_RANDOM_INTERNAL_RANDEN_TRAITS_H_