Skip to content

Commit 6c72cdd

Browse files
committed
Move copy_with_left_pad to algorithms
1 parent 8f161de commit 6c72cdd

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/algorithms.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,13 @@ pub fn generate_multi_prime_key<R: Rng>(
110110
primes,
111111
))
112112
}
113+
114+
#[inline]
115+
pub fn copy_with_left_pad(dest: &mut [u8], src: &[u8]) {
116+
// left pad with zeros
117+
let padding_bytes = dest.len() - src.len();
118+
for el in dest.iter_mut().take(padding_bytes) {
119+
*el = 0;
120+
}
121+
dest[padding_bytes..].copy_from_slice(src);
122+
}

src/pkcs1v15.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rand::Rng;
33
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
44
use zeroize::Zeroize;
55

6+
use crate::algorithms::copy_with_left_pad;
67
use crate::errors::{Error, Result};
78
use crate::hash::Hash;
89
use crate::internals;
@@ -170,16 +171,6 @@ fn hash_info<H: Hash>(hash: Option<&H>, digest_len: usize) -> Result<(usize, &'s
170171
}
171172
}
172173

173-
#[inline]
174-
pub fn copy_with_left_pad(dest: &mut [u8], src: &[u8]) {
175-
// left pad with zeros
176-
let padding_bytes = dest.len() - src.len();
177-
for el in dest.iter_mut().take(padding_bytes) {
178-
*el = 0;
179-
}
180-
dest[padding_bytes..].copy_from_slice(src);
181-
}
182-
183174
/// Decrypts ciphertext using `priv_key` and blinds the operation if
184175
/// `rng` is given. It returns one or zero in valid that indicates whether the
185176
/// plaintext was correctly structured. In either case, the plaintext is

src/pss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::pkcs1v15::copy_with_left_pad;
1+
use crate::algorithms::copy_with_left_pad;
22
use crate::internals;
33
use crate::key::{RSAPrivateKey, RSAPublicKey};
44
use crate::errors::{Error, Result};

0 commit comments

Comments
 (0)