Skip to content

Commit 5c75edd

Browse files
Polymorph rekey (#25)
* Added rekey_info for both pseudonyms and attributes * Upped version * Ran fmt * Fix * Fix cargo --------- Co-authored-by: Job Doesburg <job.doesburg@gmail.com>
1 parent 5f50dc9 commit 5c75edd

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "libpep"
33
edition = "2021"
4-
version = "0.10.0"
4+
version = "0.10.1"
55
authors = ["Bernard van Gastel <bvgastel@bitpowder.com>", "Job Doesburg <job@jobdoesburg.nl>"]
66
homepage = "https://github.com/NOLAI/libpep"
77
repository = "https://github.com/NOLAI/libpep"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nolai/libpep-wasm",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "Library for polymorphic encryption and pseudonymization (in WASM)",
55
"repository": {
66
"type": "git",

src/lib/factors/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//! - [`contexts`]: Context types (PseudonymizationDomain, EncryptionContext)
1111
//! - [`secrets`]: Secret types (PseudonymizationSecret, EncryptionSecret)
1212
//! - [`types`]: Factor types and Info type aliases
13-
//! - [`derivation`]: Functions for deriving factors from contexts and secrets
1413
1514
pub mod contexts;
1615
pub mod secrets;
@@ -30,6 +29,6 @@ pub use secrets::{
3029
};
3130
pub use types::{
3231
AttributeRekeyFactor, AttributeRekeyInfo, PseudonymRSKFactors, PseudonymRekeyFactor,
33-
PseudonymRekeyInfo, PseudonymizationInfo, RekeyFactor, RerandomizeFactor, ReshuffleFactor,
34-
TranscryptionInfo,
32+
PseudonymRekeyInfo, PseudonymizationInfo, RekeyFactor, RekeyInfoProvider, RerandomizeFactor,
33+
ReshuffleFactor, TranscryptionInfo,
3534
};

src/lib/factors/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Cryptographic factor types for rerandomization, reshuffling, and rekeying operations.
22
33
use crate::arithmetic::scalars::ScalarNonZero;
4+
use crate::factors::EncryptionContext;
45
use derive_more::From;
56

67
/// High-level type for the factor used to [`rerandomize`](crate::core::primitives::rerandomize) an [ElGamal](crate::core::elgamal::ElGamal) ciphertext.
@@ -106,3 +107,20 @@ impl TranscryptionInfo {
106107
}
107108
}
108109
}
110+
111+
/// A trait for types that can provide rekey information for a specific rekey info type.
112+
///
113+
/// This trait is parameterized by the rekey info type, allowing different implementations
114+
/// for different encrypted types (e.g., `AttributeRekeyInfo` vs `PseudonymRekeyInfo`).
115+
///
116+
/// # Examples
117+
///
118+
/// ```rust,ignore
119+
/// // Transcryptor implements RekeyInfoProvider for both types
120+
/// let attr_info: AttributeRekeyInfo = transcryptor.rekey_info(&from_ctx, &to_ctx);
121+
/// let pseudo_info: PseudonymRekeyInfo = transcryptor.rekey_info(&from_ctx, &to_ctx);
122+
/// ```
123+
pub trait RekeyInfoProvider<Info> {
124+
/// Get the rekey information for transcryption between encryption contexts.
125+
fn rekey_info(&self, session_from: &EncryptionContext, session_to: &EncryptionContext) -> Info;
126+
}

src/lib/transcryptor/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
33
pub use super::{pseudonymize, rekey, rerandomize, rerandomize_known, transcrypt, Transcryptor};
44
pub use crate::data::simple::{Attribute, EncryptedAttribute, EncryptedPseudonym, Pseudonym};
5+
pub use crate::data::traits::Rekeyable;
56
pub use crate::factors::contexts::{EncryptionContext, PseudonymizationDomain};
67
pub use crate::factors::{EncryptionSecret, PseudonymizationSecret, TranscryptionInfo};

src/lib/transcryptor/types.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::data::traits::{Pseudonymizable, Rekeyable, Transcryptable};
44
use crate::factors::contexts::*;
5+
use crate::factors::types::RekeyInfoProvider;
56
use crate::factors::{
67
AttributeRekeyInfo, EncryptionSecret, PseudonymRekeyInfo, PseudonymizationInfo,
78
PseudonymizationSecret, TranscryptionInfo,
@@ -184,3 +185,23 @@ impl Transcryptor {
184185
super::batch::transcrypt_batch(encrypted, transcryption_info, rng)
185186
}
186187
}
188+
189+
impl RekeyInfoProvider<AttributeRekeyInfo> for Transcryptor {
190+
fn rekey_info(
191+
&self,
192+
session_from: &EncryptionContext,
193+
session_to: &EncryptionContext,
194+
) -> AttributeRekeyInfo {
195+
self.attribute_rekey_info(session_from, session_to)
196+
}
197+
}
198+
199+
impl RekeyInfoProvider<PseudonymRekeyInfo> for Transcryptor {
200+
fn rekey_info(
201+
&self,
202+
session_from: &EncryptionContext,
203+
session_to: &EncryptionContext,
204+
) -> PseudonymRekeyInfo {
205+
self.pseudonym_rekey_info(session_from, session_to)
206+
}
207+
}

0 commit comments

Comments
 (0)