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_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 25 #include "absl/base/config.h" 26 27 namespace absl { 28 ABSL_NAMESPACE_BEGIN 29 namespace random_internal { 30 31 // RANDen = RANDom generator or beetroots in Swiss German. 32 // 'Strong' (well-distributed, unpredictable, backtracking-resistant) random 33 // generator, faster in some benchmarks than std::mt19937_64 and pcg64_c32. 34 // 35 // RandenTraits contains the basic algorithm traits, such as the size of the 36 // state, seed, sponge, etc. 37 struct RandenTraits { 38 // Size of the entire sponge / state for the randen PRNG. 39 static constexpr size_t kStateBytes = 256; // 2048-bit 40 41 // Size of the 'inner' (inaccessible) part of the sponge. Larger values would 42 // require more frequent calls to RandenGenerate. 43 static constexpr size_t kCapacityBytes = 16; // 128-bit 44 45 // Size of the default seed consumed by the sponge. 46 static constexpr size_t kSeedBytes = kStateBytes - kCapacityBytes; 47 48 // Largest size for which security proofs are known. 49 static constexpr size_t kFeistelBlocks = 16; 50 51 // Type-2 generalized Feistel => one round function for every two blocks. 52 static constexpr size_t kFeistelFunctions = kFeistelBlocks / 2; // = 8 53 54 // Ensures SPRP security and two full subblock diffusions. 55 // Must be > 4 * log2(kFeistelBlocks). 56 static constexpr size_t kFeistelRounds = 16 + 1; 57 }; 58 59 } // namespace random_internal 60 ABSL_NAMESPACE_END 61 } // namespace absl 62 63 #endif // ABSL_RANDOM_INTERNAL_RANDEN_TRAITS_H_ 64