Skip to content

Commit 744eff6

Browse files
authored
Merge pull request #332 from puiterwijk/primal-optional
Remove RSA primality test
2 parents da28f83 + b1dab1e commit 744eff6

File tree

3 files changed

+10
-39
lines changed

3 files changed

+10
-39
lines changed

tss-esapi/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ hostname-validator = "1.1.0"
2323
regex = "1.3.9"
2424
zeroize = { version = "1.1.0", features = ["zeroize_derive"] }
2525
tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.3.0" }
26-
primal = "0.3.0"
2726

2827
[dev-dependencies]
2928
env_logger = "0.9.0"

tss-esapi/src/structures/tagged/public/rsa.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,13 @@ impl RsaExponent {
232232

233233
/// Function for creating a new RsaExponent
234234
///
235+
/// # Warning
236+
/// Will not check whether the value is a valid exponent for RSA.
237+
///
235238
/// # Errors
236239
/// Will return an error if the value passed into the function
237240
/// is not a valid RSA exponent.
238241
pub fn create(value: u32) -> Result<Self> {
239-
if !RsaExponent::is_valid(value) {
240-
error!(
241-
"Received invalid value {} when creating rsa exponent",
242-
value,
243-
);
244-
return Err(Error::WrapperError(WrapperErrorKind::InvalidParam));
245-
}
246242
Ok(RsaExponent { value })
247243
}
248244

@@ -251,9 +247,9 @@ impl RsaExponent {
251247
self.value
252248
}
253249

254-
/// Function for checking if a value is valid rsa exponent.
255-
pub fn is_valid(value: u32) -> bool {
256-
(value > 2 && primal::is_prime(value.into())) || value == 0
250+
/// No-op. Does not check whether the value is a valid exponent for RSA.
251+
pub fn is_valid(_: u32) -> bool {
252+
true
257253
}
258254
}
259255

@@ -267,17 +263,9 @@ impl TryFrom<UINT32> for RsaExponent {
267263
type Error = Error;
268264

269265
fn try_from(tpm_uint32_value: UINT32) -> Result<Self> {
270-
if RsaExponent::is_valid(tpm_uint32_value) {
271-
Ok(RsaExponent {
272-
value: tpm_uint32_value,
273-
})
274-
} else {
275-
error!(
276-
"Received invalid rsa exponent value {}, from the TPM",
277-
tpm_uint32_value,
278-
);
279-
Err(Error::WrapperError(WrapperErrorKind::WrongValueFromTpm))
280-
}
266+
Ok(RsaExponent {
267+
value: tpm_uint32_value,
268+
})
281269
}
282270
}
283271

tss-esapi/tests/integration_tests/structures_tests/tagged_tests/public_rsa_exponent_tests.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
// Copyright 2021 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
use tss_esapi::{structures::RsaExponent, Error, WrapperErrorKind};
4-
#[test]
5-
fn rsa_exponent_create_test() {
6-
let expected_error = Err(Error::WrapperError(WrapperErrorKind::InvalidParam));
7-
// Valid values for RsaExponent are only 0 or a prime number value larger then 2.
8-
assert_eq!(expected_error, RsaExponent::create(1));
9-
10-
// The specification says that 0 or any prime number larger then 2 should be accepted.
11-
let _ = RsaExponent::create(0).expect("Failed to create a RsaExponent from the value 0");
12-
let _ = RsaExponent::create(5).expect("Failed to create a RsaExponent from the value 5");
13-
}
14-
15-
#[test]
16-
fn rsa_exponent_is_valid_test() {
17-
assert!(!RsaExponent::is_valid(1));
18-
assert!(RsaExponent::is_valid(17));
19-
}
3+
use tss_esapi::structures::RsaExponent;
204

215
#[test]
226
fn rsa_exponent_value_test() {

0 commit comments

Comments
 (0)