From d696b236ecc88c2037d22602510d811413f7e9e6 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 5 Dec 2022 09:25:10 -0600 Subject: [PATCH] remove rand and replace with general cryptography --- Cargo.lock | 31 ++++++++++++++----- Cargo.toml | 4 ++- libraries/{rand => cryptography}/Cargo.toml | 2 +- libraries/cryptography/src/hashing/mod.rs | 10 ++++++ libraries/cryptography/src/lib.rs | 6 ++++ .../lib.rs => cryptography/src/random/mod.rs} | 5 --- 6 files changed, 43 insertions(+), 15 deletions(-) rename libraries/{rand => cryptography}/Cargo.toml (90%) create mode 100644 libraries/cryptography/src/hashing/mod.rs create mode 100644 libraries/cryptography/src/lib.rs rename libraries/{rand/src/lib.rs => cryptography/src/random/mod.rs} (97%) diff --git a/Cargo.lock b/Cargo.lock index 8aab46d..a23dd5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,13 @@ dependencies = [ "toml 0.5.9 (git+https://git.ablecorp.us/theoddgarlic/toml-rs)", ] +[[package]] +name = "cryptography" +version = "0.1.1" +dependencies = [ + "versioning", +] + [[package]] name = "delete" version = "0.1.0" @@ -152,6 +159,14 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "messaging" +version = "0.1.0" +dependencies = [ + "process", + "versioning", +] + [[package]] name = "no_video" version = "0.1.0" @@ -177,6 +192,13 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "process" +version = "0.1.0" +dependencies = [ + "versioning", +] + [[package]] name = "ps2_keyboard" version = "0.1.0" @@ -190,18 +212,11 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.1.1" -dependencies = [ - "versioning", -] - [[package]] name = "randomness_handler" version = "0.1.0" dependencies = [ - "rand", + "cryptography", "versioning", ] diff --git a/Cargo.toml b/Cargo.toml index 779fe09..d3c197f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,10 @@ members = [ "libraries/able_graphics_library", "libraries/clparse", + "libraries/cryptography", "libraries/locale-maxima", - "libraries/rand", + "libraries/messaging", + "libraries/process", "libraries/table", "libraries/tar", "libraries/time", diff --git a/libraries/rand/Cargo.toml b/libraries/cryptography/Cargo.toml similarity index 90% rename from libraries/rand/Cargo.toml rename to libraries/cryptography/Cargo.toml index 16251f3..99f599f 100644 --- a/libraries/rand/Cargo.toml +++ b/libraries/cryptography/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rand" +name = "cryptography" version = "0.1.1" edition = "2021" diff --git a/libraries/cryptography/src/hashing/mod.rs b/libraries/cryptography/src/hashing/mod.rs new file mode 100644 index 0000000..4438814 --- /dev/null +++ b/libraries/cryptography/src/hashing/mod.rs @@ -0,0 +1,10 @@ +pub fn checksum>(input: T) -> u64 { + let input_bytes = input.as_ref(); + + let mut checksum: u64 = 0; + for &byte in input_bytes { + checksum = checksum.wrapping_add(byte as u64); + } + + checksum +} diff --git a/libraries/cryptography/src/lib.rs b/libraries/cryptography/src/lib.rs new file mode 100644 index 0000000..f879f10 --- /dev/null +++ b/libraries/cryptography/src/lib.rs @@ -0,0 +1,6 @@ +#![no_std] + +pub mod random; + +use versioning::Version; +pub const VERSION: Version = Version::new(0, 1, 1); diff --git a/libraries/rand/src/lib.rs b/libraries/cryptography/src/random/mod.rs similarity index 97% rename from libraries/rand/src/lib.rs rename to libraries/cryptography/src/random/mod.rs index e696c0f..ff5a61b 100644 --- a/libraries/rand/src/lib.rs +++ b/libraries/cryptography/src/random/mod.rs @@ -1,10 +1,5 @@ -#![no_std] - use core::fmt::Display; -use versioning::Version; -pub const VERSION: Version = Version::new(0, 1, 1); - pub struct Csprng { state: [u8; 256], dirty: bool,