1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-22 07:15:32 +00:00

rust tests

This commit is contained in:
Henry Case 2020-10-17 12:19:29 +01:00
parent 8474981cfc
commit 4dcc9b581b
3 changed files with 112 additions and 1 deletions

View File

@ -1,3 +1,3 @@
# NOBS Crypto
Cryptographic implementation of quantum-resistant primitives in Go.
Cryptographic implementation of quantum-resistant primitives in ~Go~ Rust.

22
hash/sha3/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "sha3"
version = "0.1.0"
authors = ["Kris Kwiatkowski <kris@amongbytes.com>"]
edition = "2018"
[dependencies]
phf = { version = "0.8.0", features = ["macros"] }
keccak = "0.1"
digest = "0.1^"
[[bin]]
name ="sha3"
path = "sha3.rs"
test = false
doctest = false
bench = false
doc = false
plugin = false
proc-macro = false
harness = false
edition = "2018"

89
hash/sha3/sha3.rs Normal file
View File

@ -0,0 +1,89 @@
// Copyright 2020 Kris Kwiatkowski. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
use ::phf::{phf_map, Map};
use digest::Digest;
// OZAPTF: use sponge from RustCrypto
pub enum Sha3Id {
SHA3_224,
// SHA3_256,
// SHA3_384,
// SHA3_512,
// SHAKE128,
// SHAKE256
}
pub struct spongeDesc {
r: u8,
d: u8,
name: String,
sfx: u8,
}
static SHA3MODE: phf::Map<&'static Sha3Id, spongeDesc> = phf_map! {
SHA3_224 => Sha3{r: 144, d: 244/8, name: String::from("SHA3-224"), sfx: 0x06},
};
pub struct Sha3 {
state: [u8; 25],
desc: spongeDesc,
is_squezing: bool,
idx: usize
}
impl Digest for Sha3 {
fn new() -> Self {
}
fn update(&mut self, data: impl AsRef<[u8]>) {
if (self.is_squezing) {
return;
}
let mut tlen = self.idx + data.len();
if (tlen < self.desc.r) {
}
}
fn chain(self, data: impl AsRef<[u8]>) -> Self {
}
fn finalize(self) -> Output<Self> {
}
fn finalize_reset(&mut self) -> Output<Self> {
}
fn reset(&mut self) {
self.idx = 0;
self.is_squezing = false
}
fn output_size() -> usize {
0
}
fn digest(data: &[u8]) -> Output<Self> {
}
}
impl Sha3 {
pub fn new(desc: spongeDesc) -> Sha3 {
Sha3 {
state: [0; 25],
spongeDesc: desc,
is_squezing: false,
idx: 0
}
}
pub fn sha3_224() -> Sha3 {
Sha3::new(SHA3MODE[SHA3_224])
}
}