Skip to content

Commit

Permalink
Merge branch 'main' into alt_benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Jul 29, 2024
2 parents e8bc7c0 + 657d9b4 commit f825577
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ name = "xoflib"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.21.0" }
sha3 = "0.10.8"
pyo3 = "0.21.0"
sha3 = { version = "0.10.8", features = ["asm"] }
44 changes: 31 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use sha3::{

macro_rules! impl_sponge_shaker_classes {
// hasher is tt so we can pick the right kind of methods to generate
($hasher:tt, $xof_reader:ident, $shaker_name:ident, $sponge_name:ident) => {
#[pyclass(module="xof")]
(hasher_name = $hasher:tt, pyclass_name = $class_name:literal, reader_name = $xof_reader:ident, rust_shaker_name = $shaker_name:ident, rust_sponge_name = $sponge_name:ident) => {
#[pyclass(module="xoflib", name=$class_name)]
#[doc=concat!(stringify!($shaker_name), " implements absorption and finalization for the ", stringify!($hasher), " XOF")]
struct $shaker_name {
hasher: $hasher,
}

impl_sponge_shaker_classes!(@shaker_methods $hasher, $shaker_name, $sponge_name);

#[pyclass(module="xof")]
#[pyclass(module="xoflib")]
#[doc=concat!(stringify!($sponge_name), " implements sponge expansion for the ", stringify!($hasher), " XOF")]
struct $sponge_name {
xof: XofReaderCoreWrapper<$xof_reader>,
Expand Down Expand Up @@ -140,19 +140,37 @@ macro_rules! impl_sponge_shaker_classes {
};
}

impl_sponge_shaker_classes!(Shake128, Shake128ReaderCore, Shaker128, Sponge128);
impl_sponge_shaker_classes!(Shake256, Shake256ReaderCore, Shaker256, Sponge256);
#[rustfmt::skip]
impl_sponge_shaker_classes!(
TurboShake128,
TurboShake128ReaderCore,
TurboShaker128,
TurboSponge128
hasher_name = Shake128,
pyclass_name = "Shake128",
reader_name = Shake128ReaderCore,
rust_shaker_name = Shaker128,
rust_sponge_name = Sponge128
);
#[rustfmt::skip]
impl_sponge_shaker_classes!(
TurboShake256,
TurboShake256ReaderCore,
TurboShaker256,
TurboSponge256
hasher_name = Shake256,
pyclass_name = "Shake256",
reader_name = Shake256ReaderCore,
rust_shaker_name = Shaker256,
rust_sponge_name = Sponge256
);
#[rustfmt::skip]
impl_sponge_shaker_classes!(
hasher_name = TurboShake128,
pyclass_name = "TurboShake128",
reader_name = TurboShake128ReaderCore,
rust_shaker_name = TurboShaker128,
rust_sponge_name = TurboSponge128
);
#[rustfmt::skip]
impl_sponge_shaker_classes!(
hasher_name = TurboShake256,
pyclass_name = "TurboShake256",
reader_name = TurboShake256ReaderCore,
rust_shaker_name = TurboShaker256,
rust_sponge_name = TurboSponge256
);

/// A Python package for the Shake extendable-output functions (XOFs): Shake128,
Expand Down
4 changes: 2 additions & 2 deletions xoflib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Sponge256:
def read(self, n: int) -> bytes:
...

class TurboShaker128:
class TurboShake128:
def __init__(self, domain_sep: int, input_bytes: bytes | None = None):
...

Expand All @@ -40,7 +40,7 @@ class TurboSponge128:
def read(self, n: int) -> bytes:
...

class TurboShaker256:
class TurboShake256:
def __init__(self, domain_sep: int, input_bytes: bytes | None = None):
...

Expand Down

0 comments on commit f825577

Please sign in to comment.