Move varint to crypto since a few of these utils will be useful everywhere.

This commit is contained in:
Adam Ierymenko 2021-11-03 12:20:02 -04:00
parent 6c504af012
commit cd62b6a932
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
3 changed files with 4 additions and 3 deletions

View file

@ -16,6 +16,7 @@ pub mod kbkdf;
pub mod random;
pub mod secret;
pub mod hex;
pub mod varint;
pub use aes_gmac_siv;
pub use rand_core;

View file

@ -7,7 +7,6 @@
*/
use std::io::{Read, Write};
use crate::vl1::buffer::Buffer;
/// Write a variable length integer, which can consume up to 10 bytes.
pub fn write<W: Write>(w: &mut W, mut v: u64) -> std::io::Result<()> {
@ -49,7 +48,7 @@ pub fn read<R: Read>(r: &mut R) -> std::io::Result<(u64, usize)> {
#[cfg(test)]
mod tests {
use crate::util::varint::*;
use crate::varint::*;
#[test]
fn varint() {

View file

@ -8,9 +8,9 @@
pub mod pool;
pub mod gate;
pub mod varint;
pub use zerotier_core_crypto::hex;
pub use zerotier_core_crypto::varint;
pub(crate) const ZEROES: [u8; 64] = [0_u8; 64];
@ -109,6 +109,7 @@ pub(crate) fn load_u64_be(d: &[u8]) -> u64 {
/// Mix bits in a 64-bit integer.
/// https://nullprogram.com/blog/2018/07/31/
#[inline(always)]
pub(crate) fn hash64(mut x: u64) -> u64 {
x ^= x.wrapping_shr(30);
x = x.wrapping_mul(0xbf58476d1ce4e5b9);