Skip to content

Commit

Permalink
Merge pull request #9 from supinie/seeds
Browse files Browse the repository at this point in the history
default behaviour seed over key for private key
  • Loading branch information
supinie authored Jan 9, 2025
2 parents 0c9eaf6 + 3993f38 commit bb8ebfb
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 92 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
env:
RUST_BACKTRACE: 1

- name: cargo test all
run: cargo test --all-features || cargo test --all-features || cargo test --all-features
env:
RUST_BACKTRACE: 1

- name: Get coverage
run: ./.github/coverage --lcov --output-path cov_report || ./.github/coverage --lcov --output-path cov_report || ./.github/coverage --lcov --output-path cov_report

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ proptest-regressions

# Flamegraph
benches/flamegraph/

.direnv/
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "enc_rust"
version = "0.1.4"
version = "0.2.0"
edition = "2021"
authors = ["supinie <[email protected]>"]

Expand All @@ -16,6 +16,10 @@ license = "GPL-3.0-or-later"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
decap_key = [] # Use the true key instead of seed for PrivateKey. Default uses seed.

[profile.release]
opt-level = "s"
lto = false
Expand Down
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
with import <nixpkgs> {};
mkShell {
buildInputs = [ rustup gcc bacon ];
}
11 changes: 9 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum CrystalsError {
InvalidSeedLength(usize, usize),
InternalError(),
InvalidK(usize),
InvalidCiphertextLength(usize, usize, K),
InvalidCiphertextLength(usize),
}

impl Display for CrystalsError {
Expand All @@ -24,7 +24,7 @@ impl Display for CrystalsError {
Self::InvalidSeedLength(seed_len, expected_seed_len) => write!(f, "Invalid seed length, expected {expected_seed_len}, got {seed_len}"),
Self::InternalError() => write!(f, "Unexpected internal error"),
Self::InvalidK(k) => write!(f, "Recieved invalid k value, {k}, expected 2, 3, or 4"),
Self::InvalidCiphertextLength(ciphertext_len, expected_ciphertext_len, sec_level) => write!(f, "Invalid ciphertext length, expected {expected_ciphertext_len}, got {ciphertext_len} (key security level: {sec_level})"),
Self::InvalidCiphertextLength(ciphertext_len) => write!(f, "Invalid ciphertext length, expected 768, 1088, or 1568, got {ciphertext_len}"),
}
}
}
Expand Down Expand Up @@ -96,6 +96,7 @@ impl From<rand_core::Error> for KeyGenerationError {
#[derive(Debug)]
pub enum EncryptionDecryptionError {
Crystals(CrystalsError),
KeyGenerationError(KeyGenerationError),
TryFromInt(TryFromIntError),
Packing(PackingError),
Rand(rand_core::Error),
Expand All @@ -107,6 +108,12 @@ impl From<CrystalsError> for EncryptionDecryptionError {
}
}

impl From<KeyGenerationError> for EncryptionDecryptionError {
fn from(error: KeyGenerationError) -> Self {
Self::KeyGenerationError(error)
}
}

impl From<TryFromIntError> for EncryptionDecryptionError {
fn from(error: TryFromIntError) -> Self {
Self::TryFromInt(error)
Expand Down
2 changes: 2 additions & 0 deletions src/indcpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ impl PrivateKey {
}

// buf should be of length indcpa_private_key_bytes
#[cfg(feature = "decap_key")]
pub(crate) fn pack(&self, buf: &mut [u8]) -> Result<(), PackingError> {
self.secret.pack(buf)
}

// buf should be of length indcpa_private_key_bytes
#[cfg(feature = "decap_key")]
pub(crate) fn unpack(buf: &[u8]) -> Result<Self, PackingError> {
let secret = PolyVec::unpack(buf)?.normalise();
Ok(Self { secret })
Expand Down
Loading

0 comments on commit bb8ebfb

Please sign in to comment.