Skip to content

Commit

Permalink
Merge pull request #100 from dusk-network/bytecheck
Browse files Browse the repository at this point in the history
Add `CheckBytes` implementations to `rkyv`ed structures
  • Loading branch information
ureeves authored Aug 16, 2022
2 parents 52deacc + feea5fb commit f0a3367
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `CheckBytes` implementations on `rkyv`ed structures
- Add `rkyv` implementations on structures [#95]

## Changed

- Update `dusk-bls12_381` to version `0.10`
- Update `dusk-bls12_381` to version `0.11`

## [0.11.1] - 2022-04-06

Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = "https://github.com/dusk-network/jubjub"
license = "MIT/Apache-2.0"
name = "dusk-jubjub"
repository = "https://github.com/dusk-network/jubjub"
version = "0.12.0-rc.0"
version = "0.12.0-rc.1"
keywords = ["cryptography", "jubjub", "zk-snarks", "ecc", "elliptic-curve"]
categories =["algorithms", "cryptography", "science", "no-std"]
edition = "2021"
Expand All @@ -20,12 +20,13 @@ exclude = [".github/workflows/ci.yml", "github/workflows/rust.yml",

[dependencies]
dusk-bytes = "0.1"
dusk-bls12_381 = {version="0.10", default-features=false}
dusk-bls12_381 = {version="0.11.0-rc", default-features=false}
subtle = {version="^2.3", default-features = false}
rand_core = {version = "0.6", default-features=false}
canonical = {version = "0.7", optional = true}
canonical_derive = {version = "0.7", optional = true}
rkyv = {version = "0.7", optional = true}
bytecheck = {version = "0.6", optional=true}

[dev-dependencies]
rand_xorshift = {version="0.3", default-features = false}
Expand All @@ -35,4 +36,4 @@ blake2 = "0.9"
default = ["std"]
std = ["dusk-bls12_381/default"]
canon = ["canonical", "canonical_derive", "dusk-bls12_381/canon"]
rkyv-impl = ["dusk-bls12_381/rkyv", "rkyv"]
rkyv-impl = ["bytecheck", "dusk-bls12_381/rkyv-impl", "rkyv"]
3 changes: 3 additions & 0 deletions src/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::{JubJubAffine, JubJubExtended, JubJubScalar};
use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
use dusk_bytes::{DeserializableSlice, Error as BytesError, Serializable};

#[cfg(feature = "rkyv-impl")]
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{Archive, Deserialize, Serialize};

Expand Down Expand Up @@ -69,6 +71,7 @@ use rkyv::{Archive, Deserialize, Serialize};
/// example: `D{E[x * (a + b)]} == D{x * [E(a) + E(b)]}`
#[derive(Debug, Copy, Clone, PartialEq, Default)]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct ElgamalCipher {
gamma: JubJubExtended,
delta: JubJubExtended,
Expand Down
3 changes: 3 additions & 0 deletions src/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use rand_core::{CryptoRng, RngCore};

use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "rkyv-impl")]
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{Archive, Deserialize, Serialize};

Expand All @@ -28,6 +30,7 @@ use crate::BlsScalar;
#[derive(Clone, Copy, Eq)]
#[cfg_attr(feature = "canon", derive(Canon))]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct Fr(pub(crate) [u64; 4]);

impl fmt::Debug for Fr {
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use dusk_bytes::{Error as BytesError, Serializable};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

#[cfg(feature = "rkyv-impl")]
use bytecheck::CheckBytes;
#[cfg(feature = "rkyv-impl")]
use rkyv::{Archive, Deserialize, Serialize};

Expand Down Expand Up @@ -72,6 +74,7 @@ const FR_MODULUS_BYTES: [u8; 32] = [
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "canon", derive(Canon))]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct JubJubAffine {
x: BlsScalar,
y: BlsScalar,
Expand Down Expand Up @@ -196,6 +199,7 @@ pub const GENERATOR_NUMS_EXTENDED: JubJubExtended = JubJubExtended {
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "canon", derive(Canon))]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct JubJubExtended {
x: BlsScalar,
y: BlsScalar,
Expand Down Expand Up @@ -287,6 +291,7 @@ impl From<JubJubExtended> for JubJubAffine {
/// [`JubJubExtended`](crate::JubJubExtended).
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct AffineNielsPoint {
y_plus_x: BlsScalar,
y_minus_x: BlsScalar,
Expand Down Expand Up @@ -369,6 +374,7 @@ impl ConditionallySelectable for AffineNielsPoint {
/// in the form `(Y + X, Y - X, Z, T1 * T2 * 2d)`.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "rkyv-impl", derive(Archive, Serialize, Deserialize))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(derive(CheckBytes)))]
pub struct ExtendedNielsPoint {
y_plus_x: BlsScalar,
y_minus_x: BlsScalar,
Expand Down

0 comments on commit f0a3367

Please sign in to comment.