Commit 33541e75 by Abseil Team Committed by Andy Getz

Export of internal Abseil changes

--
c3b926ea986eea9d416ef57ee67a1041b70257fd by Martijn Vels <mvels@google.com>:

Remove internal absl_internal_cordz_disabled check.

PiperOrigin-RevId: 384225993

--
2863c56ad5c86dd9c207a796e65d5bc968f77755 by Benjamin Barenblat <bbaren@google.com>:

Make randen_slow endian-correct

Pay attention to the platform endianness when pulling bytes out of each
AES block, and use platform-endian round keys.

PiperOrigin-RevId: 383878281
GitOrigin-RevId: c3b926ea986eea9d416ef57ee67a1041b70257fd
Change-Id: I0d48f4fd560b3e320260ef05790727756ffead02
parent b06e719e
...@@ -297,6 +297,7 @@ cc_library( ...@@ -297,6 +297,7 @@ cc_library(
":platform", ":platform",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/base:endian",
"//absl/numeric:int128", "//absl/numeric:int128",
], ],
) )
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cstring> #include <cstring>
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/base/internal/endian.h"
#include "absl/numeric/int128.h" #include "absl/numeric/int128.h"
#include "absl/random/internal/platform.h" #include "absl/random/internal/platform.h"
#include "absl/random/internal/randen_traits.h" #include "absl/random/internal/randen_traits.h"
...@@ -40,7 +41,7 @@ namespace { ...@@ -40,7 +41,7 @@ namespace {
// AES portions based on rijndael-alg-fst.c, // AES portions based on rijndael-alg-fst.c,
// https://fastcrypto.org/front/misc/rijndael-alg-fst.c, and modified for // https://fastcrypto.org/front/misc/rijndael-alg-fst.c, and modified for
// little-endianness. // platform-endianness.
// //
// Implementation of // Implementation of
// http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf // http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf
...@@ -251,6 +252,7 @@ inline ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE void Vector128Store( ...@@ -251,6 +252,7 @@ inline ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE void Vector128Store(
inline ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE Vector128 inline ABSL_RANDOM_INTERNAL_ATTRIBUTE_ALWAYS_INLINE Vector128
AesRound(const Vector128& state, const Vector128& round_key) { AesRound(const Vector128& state, const Vector128& round_key) {
Vector128 result; Vector128 result;
#ifdef ABSL_IS_LITTLE_ENDIAN
result.s[0] = round_key.s[0] ^ // result.s[0] = round_key.s[0] ^ //
te0[uint8_t(state.s[0])] ^ // te0[uint8_t(state.s[0])] ^ //
te1[uint8_t(state.s[1] >> 8)] ^ // te1[uint8_t(state.s[1] >> 8)] ^ //
...@@ -271,6 +273,28 @@ AesRound(const Vector128& state, const Vector128& round_key) { ...@@ -271,6 +273,28 @@ AesRound(const Vector128& state, const Vector128& round_key) {
te1[uint8_t(state.s[0] >> 8)] ^ // te1[uint8_t(state.s[0] >> 8)] ^ //
te2[uint8_t(state.s[1] >> 16)] ^ // te2[uint8_t(state.s[1] >> 16)] ^ //
te3[uint8_t(state.s[2] >> 24)]; te3[uint8_t(state.s[2] >> 24)];
#else
result.s[0] = round_key.s[0] ^ //
te0[uint8_t(state.s[0])] ^ //
te1[uint8_t(state.s[3] >> 8)] ^ //
te2[uint8_t(state.s[2] >> 16)] ^ //
te3[uint8_t(state.s[1] >> 24)];
result.s[1] = round_key.s[1] ^ //
te0[uint8_t(state.s[1])] ^ //
te1[uint8_t(state.s[0] >> 8)] ^ //
te2[uint8_t(state.s[3] >> 16)] ^ //
te3[uint8_t(state.s[2] >> 24)];
result.s[2] = round_key.s[2] ^ //
te0[uint8_t(state.s[2])] ^ //
te1[uint8_t(state.s[1] >> 8)] ^ //
te2[uint8_t(state.s[0] >> 16)] ^ //
te3[uint8_t(state.s[3] >> 24)];
result.s[3] = round_key.s[3] ^ //
te0[uint8_t(state.s[3])] ^ //
te1[uint8_t(state.s[2] >> 8)] ^ //
te2[uint8_t(state.s[1] >> 16)] ^ //
te3[uint8_t(state.s[0] >> 24)];
#endif
return result; return result;
} }
...@@ -380,7 +404,11 @@ namespace random_internal { ...@@ -380,7 +404,11 @@ namespace random_internal {
const void* RandenSlow::GetKeys() { const void* RandenSlow::GetKeys() {
// Round keys for one AES per Feistel round and branch. // Round keys for one AES per Feistel round and branch.
// The canonical implementation uses first digits of Pi. // The canonical implementation uses first digits of Pi.
#ifdef ABSL_IS_LITTLE_ENDIAN
return kRandenRoundKeys; return kRandenRoundKeys;
#else
return kRandenRoundKeysBE;
#endif
} }
void RandenSlow::Absorb(const void* seed_void, void* state_void) { void RandenSlow::Absorb(const void* seed_void, void* state_void) {
......
...@@ -24,13 +24,6 @@ ...@@ -24,13 +24,6 @@
#include "absl/base/internal/exponential_biased.h" #include "absl/base/internal/exponential_biased.h"
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
// TODO(b/162942788): weak 'cordz_disabled' value.
// A strong version is in the 'cordz_disabled_hack_for_odr' library which can
// be linked in to disable cordz at compile time.
extern "C" {
bool absl_internal_cordz_disabled ABSL_ATTRIBUTE_WEAK = false;
}
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
namespace cord_internal { namespace cord_internal {
...@@ -54,13 +47,6 @@ ABSL_CONST_INIT thread_local int64_t cordz_next_sample = kInitCordzNextSample; ...@@ -54,13 +47,6 @@ ABSL_CONST_INIT thread_local int64_t cordz_next_sample = kInitCordzNextSample;
constexpr int64_t kIntervalIfDisabled = 1 << 16; constexpr int64_t kIntervalIfDisabled = 1 << 16;
ABSL_ATTRIBUTE_NOINLINE bool cordz_should_profile_slow() { ABSL_ATTRIBUTE_NOINLINE bool cordz_should_profile_slow() {
// TODO(b/162942788): check if profiling is disabled at compile time.
if (absl_internal_cordz_disabled) {
ABSL_RAW_LOG(WARNING, "Cordz info disabled at compile time");
// We are permanently disabled: set counter to highest possible value.
cordz_next_sample = std::numeric_limits<int64_t>::max();
return false;
}
thread_local absl::base_internal::ExponentialBiased thread_local absl::base_internal::ExponentialBiased
exponential_biased_generator; exponential_biased_generator;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment