Skip to content

Commit

Permalink
Merge pull request #45 from sentclose/fips-keys
Browse files Browse the repository at this point in the history
Fips keys
  • Loading branch information
joernheinemann authored Jun 23, 2024
2 parents 1591e76 + 818b058 commit 421140f
Show file tree
Hide file tree
Showing 46 changed files with 5,240 additions and 324 deletions.
93 changes: 90 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
"implementation/js/sentc_wasm_light",
"implementation/dart/sentc_flutter_rust",
"implementation/dart/sentc_flutter_rust_light",
"crypto_keys/crypto_std_keys",
"crypto_keys/crypto_std_keys", "crypto_keys/crypto_fips_keys",
]

[workspace.package]
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/group/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod group;
pub mod group;

#[cfg(feature = "export")]
mod group_export;
Expand Down
83 changes: 81 additions & 2 deletions crypto_core/src/cryptomat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub trait Sig: CryptoAlg + Into<Vec<u8>>
//__________________________________________________________________________________________________
//searchable

pub trait SearchableKey: CryptoAlg + AsRef<[u8]>
pub trait SearchableKey: CryptoAlg
{
fn encrypt_key_with_master_key<M: SymKey>(&self, master_key: &M) -> Result<Vec<u8>, Error>;

Expand All @@ -183,7 +183,7 @@ pub trait SearchableKeyComposer
//__________________________________________________________________________________________________
//sortable

pub trait SortableKey: CryptoAlg + AsRef<[u8]>
pub trait SortableKey: CryptoAlg
{
fn encrypt_key_with_master_key<M: SymKey>(&self, master_key: &M) -> Result<Vec<u8>, Error>;

Expand Down Expand Up @@ -288,3 +288,82 @@ pub trait DeriveAuthKeyForAuthComposer
}

pub trait PasswordEncryptSalt: PwPrepareExport {}

//__________________________________________________________________________________________________

#[macro_export]
macro_rules! crypto_alg_str_impl {
($st:ty,$alg:ident) => {
impl $crate::cryptomat::CryptoAlg for $st
{
fn get_alg_str(&self) -> &'static str
{
$alg
}
}
};
}

#[macro_export]
macro_rules! try_from_bytes_single_value {
($st:ty) => {
impl<'a> TryFrom<&'a [u8]> for $st
{
type Error = $crate::Error;

fn try_from(value: &'a [u8]) -> Result<Self, Self::Error>
{
Ok(Self(
value
.try_into()
.map_err(|_| $crate::Error::KeyDecryptFailed)?,
))
}
}
};
}

#[macro_export]
macro_rules! try_from_bytes_owned_single_value {
($st:ty) => {
impl TryFrom<Vec<u8>> for $st
{
type Error = $crate::Error;

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error>
{
Ok(Self(
value
.try_into()
.map_err(|_| $crate::Error::KeyDecryptFailed)?,
))
}
}
};
}

#[macro_export]
macro_rules! as_ref_bytes_single_value {
($st:ty) => {
impl AsRef<[u8]> for $st
{
fn as_ref(&self) -> &[u8]
{
&self.0
}
}
};
}

#[macro_export]
macro_rules! into_bytes_single_value {
($st:ty) => {
impl Into<Vec<u8>> for $st
{
fn into(self) -> Vec<u8>
{
Vec::from(self.0)
}
}
};
}
41 changes: 41 additions & 0 deletions crypto_keys/crypto_fips_keys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "sentc-crypto-fips-keys"
version.workspace = true
edition.workspace = true
license-file.workspace = true
authors.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
rust-version.workspace = true

include = [
"Cargo.toml",
"../LICENSE",
"src/**/*",
]

[dependencies]
sentc-crypto-core.workspace = true
sentc-crypto-utils = { workspace = true, optional = true }
sentc-crypto-common = { workspace = true, optional = true }
sentc-crypto = { workspace = true, optional = true }

openssl = { version = "0.10.64", default-features = false }

digest = "0.10.7"

base64ct = { version = "1.0.1", default-features = false, features = ["alloc"], optional = true }
pem-rfc7468 = { version = "0.3.1", features = ["alloc"], optional = true }
serde = { version = "1.0.137", features = ["derive"], optional = true }
serde_json = { version = "1.0.81", default-features = false, features = ["alloc"], optional = true }

[dev-dependencies]
sentc-crypto = { workspace = true, features = ["server"] }

[features]
wrapper = ["sentc-crypto-utils", "sentc-crypto-common", "serde", "serde_json", "pem-rfc7468"]
full = ["wrapper", "sentc-crypto-utils/encryption", "base64ct"]

sdk = ["sentc-crypto"]
sdk_full = ["sdk", "sentc-crypto/full_rustls"]
Loading

0 comments on commit 421140f

Please sign in to comment.