Skip to content

Commit bc2d839

Browse files
committed
Expose RSA_PKCS1_SHA1 for RSA signing
1 parent 0f3bf00 commit bc2d839

6 files changed

+218
-19
lines changed

src/rsa/convert_nist_rsa_test_vectors.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ def print_verify_test(case, n, e):
143143
print('Result = %s' % case['Result'])
144144
print('')
145145

146-
def main(fn, test_type, padding_alg):
146+
def main(fn, test_type, padding_alg, alg):
147147
input_file_digest = hashlib.sha384(open(fn, 'rb').read()).hexdigest()
148148
# File header
149149
print("# RSA %(padding_alg)s Test Vectors for FIPS 186-4 from %(fn)s in" % \
150150
{ "fn": fn, "padding_alg": padding_alg })
151+
print("# http://csrc.nist.gov/groups/STM/cavp/documents/dss/186-2rsatestvectors.zip")
151152
print("# http://csrc.nist.gov/groups/STM/cavp/documents/dss/186-3rsatestvectors.zip")
152153
print("# accessible from")
153154
print("# http://csrc.nist.gov/groups/STM/cavp/digital-signatures.html#test-vectors")
@@ -180,6 +181,10 @@ def main(fn, test_type, padding_alg):
180181
last_field = "S"
181182

182183
for case in parse(fn, last_field):
184+
if alg is not None and case['SHAAlg'] != alg:
185+
debug("Skipping filtered algorithm", DEBUG)
186+
continue
187+
183188
if case['SHAAlg'] == 'SHA224':
184189
# SHA224 not supported in *ring*.
185190
debug("Skipping due to use of SHA224", DEBUG)
@@ -223,10 +228,11 @@ def main(fn, test_type, padding_alg):
223228
debug("%d test cases output." % num_cases, True)
224229

225230
if __name__ == '__main__':
226-
if len(sys.argv) != 2:
227-
print("Usage:\n python %s <filename>" % sys.argv[0])
231+
if len(sys.argv) not in [2, 3]:
232+
print("Usage:\n python %s <filename> [algorithm]" % sys.argv[0])
228233
else:
229234
fn = sys.argv[1]
235+
alg = sys.argv[2] if len(sys.argv) > 2 else None
230236
if 'PSS' in fn:
231237
pad_alg = 'PSS'
232238
elif '15' in fn:
@@ -243,4 +249,4 @@ def main(fn, test_type, padding_alg):
243249
print("Could not determine test type.")
244250
quit()
245251

246-
main(sys.argv[1], test_type, pad_alg)
252+
main(sys.argv[1], test_type, pad_alg, alg)

src/rsa/padding.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ mod pkcs1;
1919
mod pss;
2020

2121
pub use self::{
22-
pkcs1::{PKCS1, RSA_PKCS1_SHA256, RSA_PKCS1_SHA384, RSA_PKCS1_SHA512},
22+
pkcs1::{
23+
PKCS1, RSA_PKCS1_SHA1_FOR_LEGACY_USE_ONLY, RSA_PKCS1_SHA256, RSA_PKCS1_SHA384,
24+
RSA_PKCS1_SHA512,
25+
},
2326
pss::{PSS, RSA_PSS_SHA256, RSA_PSS_SHA384, RSA_PSS_SHA512},
2427
};
25-
pub(super) use pkcs1::RSA_PKCS1_SHA1_FOR_LEGACY_USE_ONLY;
2628

2729
/// Common features of both RSA padding encoding and RSA padding verification.
2830
pub trait Padding: 'static + Sync + crate::sealed::Sealed + core::fmt::Debug {

src/rsa/padding/pkcs1.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ macro_rules! rsa_pkcs1_padding {
103103
};
104104
}
105105

106-
// Intentionally not exposed except internally for signature verification. At a
107-
// minimum, we'd need to create test vectors for signing with it, which we
108-
// don't currently have. But, it's a bad idea to use SHA-1 anyway, so perhaps
109-
// we just won't ever expose it.
110106
rsa_pkcs1_padding!(
111-
pub(in super::super) RSA_PKCS1_SHA1_FOR_LEGACY_USE_ONLY,
107+
pub RSA_PKCS1_SHA1_FOR_LEGACY_USE_ONLY,
112108
&digest::SHA1_FOR_LEGACY_USE_ONLY,
113109
&SHA1_PKCS1_DIGESTINFO_PREFIX,
114110
"PKCS#1 1.5 padding using SHA-1 for RSA signatures."

src/signature.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ pub use crate::ec::{
280280
#[cfg(feature = "alloc")]
281281
pub use crate::rsa::{
282282
padding::{
283-
RsaEncoding, RSA_PKCS1_SHA256, RSA_PKCS1_SHA384, RSA_PKCS1_SHA512, RSA_PSS_SHA256,
284-
RSA_PSS_SHA384, RSA_PSS_SHA512,
283+
RsaEncoding, RSA_PKCS1_SHA1_FOR_LEGACY_USE_ONLY, RSA_PKCS1_SHA256, RSA_PKCS1_SHA384,
284+
RSA_PKCS1_SHA512, RSA_PSS_SHA256, RSA_PSS_SHA384, RSA_PSS_SHA512,
285285
},
286286
verification::{
287287
RsaPublicKeyComponents, RSA_PKCS1_1024_8192_SHA1_FOR_LEGACY_USE_ONLY,

0 commit comments

Comments
 (0)