// Copyright 2017 The Abseil Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "absl/random/internal/randen_traits.h" // This file contains only the round keys for randen. // // "Nothing up my sleeve" numbers from the first hex digits of Pi, obtained // from http://hexpi.sourceforge.net/. The array was generated by following // Python script: /* python >tmp.cc << EOF """Generates Randen round keys array from pi-hex.62500.txt file.""" import binascii KEYS = 17 * 8 def chunks(l, n): """Yield successive n-sized chunks from l.""" for i in range(0, len(l), n): yield l[i:i + n] def pairwise(t): """Transforms sequence into sequence of pairs.""" it = iter(t) return zip(it,it) def digits_from_pi(): """Reads digits from hexpi.sourceforge.net file.""" with open("pi-hex.62500.txt") as file: return file.read() def digits_from_urandom(): """Reads digits from /dev/urandom.""" with open("/dev/urandom") as file: return binascii.hexlify(file.read(KEYS * 16)) def print_row(b) print(" 0x{0}, 0x{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11}, 0x{12}, 0x{13}, 0x{14}, 0x{15},".format(*b)) digits = digits_from_pi() #digits = digits_from_urandom() print("namespace {") print("static constexpr size_t kKeyBytes = {0};\n".format(KEYS * 16)) print("}") print("alignas(16) const unsigned char kRandenRoundKeysBE[kKeyBytes] = {") for i, u16 in zip(range(KEYS), chunks(digits, 32)): b = list(chunks(u16, 2)) print_row(b) print("};") print("alignas(16) const unsigned char kRandenRoundKeys[kKeyBytes] = {") for i, u16 in zip(range(KEYS), chunks(digits, 32)): b = list(chunks(u16, 2)) b.reverse() print_row(b) print("};") EOF */ namespace absl { ABSL_NAMESPACE_BEGIN namespace random_internal { namespace { static constexpr size_t kKeyBytes = …; } alignas(16) const unsigned char kRandenRoundKeysBE[kKeyBytes] = …; alignas(16) const unsigned char kRandenRoundKeys[kKeyBytes] = …; } // namespace random_internal ABSL_NAMESPACE_END } // namespace absl