From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/neqo-transport/tests/sim/rng.rs | 81 ------------------------ 1 file changed, 81 deletions(-) delete mode 100644 third_party/rust/neqo-transport/tests/sim/rng.rs (limited to 'third_party/rust/neqo-transport/tests/sim/rng.rs') diff --git a/third_party/rust/neqo-transport/tests/sim/rng.rs b/third_party/rust/neqo-transport/tests/sim/rng.rs deleted file mode 100644 index af4f70eb5f..0000000000 --- a/third_party/rust/neqo-transport/tests/sim/rng.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::{convert::TryFrom, ops::Range}; - -use neqo_common::Decoder; - -/// An implementation of a xoshiro256** pseudorandom generator. -pub struct Random { - state: [u64; 4], -} - -impl Random { - pub fn new(seed: [u8; 32]) -> Self { - assert!(seed.iter().any(|&x| x != 0)); - let mut dec = Decoder::from(&seed); - Self { - state: [ - dec.decode_uint(8).unwrap(), - dec.decode_uint(8).unwrap(), - dec.decode_uint(8).unwrap(), - dec.decode_uint(8).unwrap(), - ], - } - } - - pub fn random(&mut self) -> u64 { - let result = (self.state[1].overflowing_mul(5).0) - .rotate_right(7) - .overflowing_mul(9) - .0; - let t = self.state[1] << 17; - - self.state[2] ^= self.state[0]; - self.state[3] ^= self.state[1]; - self.state[1] ^= self.state[2]; - self.state[0] ^= self.state[3]; - - self.state[2] ^= t; - self.state[3] = self.state[3].rotate_right(45); - - result - } - - /// Generate a random value from the range. - /// If the range is empty or inverted (`range.start > range.end`), then - /// this returns the value of `range.start` without generating any random values. - pub fn random_from(&mut self, range: Range) -> u64 { - let max = range.end.saturating_sub(range.start); - if max == 0 { - return range.start; - } - - let shift = (max - 1).leading_zeros(); - assert_ne!(max, 0); - loop { - let r = self.random() >> shift; - if r < max { - return range.start + r; - } - } - } - - /// Get the seed necessary to continue from this point. - pub fn seed_str(&self) -> String { - format!( - "{:8x}{:8x}{:8x}{:8x}", - self.state[0], self.state[1], self.state[2], self.state[3], - ) - } -} - -impl Default for Random { - fn default() -> Self { - let buf = neqo_crypto::random(32); - Random::new(<[u8; 32]>::try_from(&buf[..]).unwrap()) - } -} -- cgit v1.2.3