Skip to content

Commit

Permalink
feat: mark several internal functions as private
Browse files Browse the repository at this point in the history
There is no need to export some the functions from internals.rs. Mark
them as private.

Signed-off-by: Dmitry Baryshkov <[email protected]>
  • Loading branch information
lumag committed Apr 19, 2023
1 parent 5e2768a commit 5b83a69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn encrypt<K: PublicKeyParts>(key: &K, m: &BigUint) -> BigUint {
/// Performs raw RSA decryption with no padding, resulting in a plaintext `BigUint`.
/// Peforms RSA blinding if an `Rng` is passed.
#[inline]
pub fn decrypt<R: CryptoRngCore + ?Sized>(
fn decrypt<R: CryptoRngCore + ?Sized>(
mut rng: Option<&mut R>,
priv_key: &RsaPrivateKey,
c: &BigUint,
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn decrypt_and_check<R: CryptoRngCore + ?Sized>(
}

/// Returns the blinded c, along with the unblinding factor.
pub fn blind<R: CryptoRngCore, K: PublicKeyParts>(
fn blind<R: CryptoRngCore, K: PublicKeyParts>(
rng: &mut R,
key: &K,
c: &BigUint,
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn blind<R: CryptoRngCore, K: PublicKeyParts>(
}

/// Given an m and and unblinding factor, unblind the m.
pub fn unblind(key: &impl PublicKeyParts, m: &BigUint, unblinder: &BigUint) -> BigUint {
fn unblind(key: &impl PublicKeyParts, m: &BigUint, unblinder: &BigUint) -> BigUint {
(m * unblinder) % key.n()
}

Expand Down
11 changes: 7 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ fn check_public_with_max_size(public_key: &impl PublicKeyParts, max_size: usize)
#[cfg(test)]
mod tests {
use super::*;
use crate::internals;

use hex_literal::hex;
use num_traits::{FromPrimitive, ToPrimitive};
Expand Down Expand Up @@ -525,12 +524,16 @@ mod tests {

let pub_key: RsaPublicKey = private_key.clone().into();
let m = BigUint::from_u64(42).expect("invalid 42");
let c = internals::encrypt(&pub_key, &m);
let m2 = internals::decrypt::<ChaCha8Rng>(None, private_key, &c)
let c = pub_key
.raw_int_encryption_primitive(&m)
.expect("encryption successfull");
let m2 = private_key
.raw_int_decryption_primitive::<ChaCha8Rng>(None, &c)
.expect("unable to decrypt without blinding");
assert_eq!(m, m2);
let mut rng = ChaCha8Rng::from_seed([42; 32]);
let m3 = internals::decrypt(Some(&mut rng), private_key, &c)
let m3 = private_key
.raw_int_decryption_primitive(Some(&mut rng), &c)
.expect("unable to decrypt with blinding");
assert_eq!(m, m3);
}
Expand Down

0 comments on commit 5b83a69

Please sign in to comment.