Skip to content

Commit fbc48e2

Browse files
committed
Move copy_with_left_pad to algorithms
1 parent f5bfd00 commit fbc48e2

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
@@ -111,3 +111,13 @@ pub fn generate_multi_prime_key<R: Rng>(
111111
primes,
112112
))
113113
}
114+
115+
#[inline]
116+
pub fn copy_with_left_pad(dest: &mut [u8], src: &[u8]) {
117+
// left pad with zeros
118+
let padding_bytes = dest.len() - src.len();
119+
for el in dest.iter_mut().take(padding_bytes) {
120+
*el = 0;
121+
}
122+
dest[padding_bytes..].copy_from_slice(src);
123+
}

src/pkcs1v15.rs

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

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

174-
#[inline]
175-
pub fn copy_with_left_pad(dest: &mut [u8], src: &[u8]) {
176-
// left pad with zeros
177-
let padding_bytes = dest.len() - src.len();
178-
for el in dest.iter_mut().take(padding_bytes) {
179-
*el = 0;
180-
}
181-
dest[padding_bytes..].copy_from_slice(src);
182-
}
183-
184175
/// Decrypts ciphertext using `priv_key` and blinds the operation if
185176
/// `rng` is given. It returns one or zero in valid that indicates whether the
186177
/// 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)