Skip to content

Commit 10b73f6

Browse files
Merge pull request marshallpierce#204 from marshallpierce/mp/malleability-test-cases
Add malleability test cases
2 parents 9fcde48 + c57209e commit 10b73f6

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/engine/tests.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,75 @@ fn decode_too_little_data_before_padding_error_invalid_byte<E: EngineWrapper>(en
687687
}
688688
}
689689

690+
// https://eprint.iacr.org/2022/361.pdf table 2, test 1
691+
#[apply(all_engines)]
692+
fn decode_malleability_test_case_3_byte_suffix_valid<E: EngineWrapper>(engine_wrapper: E) {
693+
assert_eq!(
694+
b"Hello".as_slice(),
695+
&E::standard().decode_ez_str_vec("SGVsbG8=").unwrap()
696+
);
697+
}
698+
699+
// https://eprint.iacr.org/2022/361.pdf table 2, test 2
700+
#[apply(all_engines)]
701+
fn decode_malleability_test_case_3_byte_suffix_invalid_trailing_symbol<E: EngineWrapper>(
702+
engine_wrapper: E,
703+
) {
704+
assert_eq!(
705+
DecodeError::InvalidLastSymbol(6, 0x39),
706+
E::standard().decode_ez_str_vec("SGVsbG9=").unwrap_err()
707+
);
708+
}
709+
710+
// https://eprint.iacr.org/2022/361.pdf table 2, test 3
711+
#[apply(all_engines)]
712+
fn decode_malleability_test_case_3_byte_suffix_no_padding<E: EngineWrapper>(engine_wrapper: E) {
713+
assert_eq!(
714+
DecodeError::InvalidPadding,
715+
E::standard().decode_ez_str_vec("SGVsbG9").unwrap_err()
716+
);
717+
}
718+
719+
// https://eprint.iacr.org/2022/361.pdf table 2, test 4
720+
#[apply(all_engines)]
721+
fn decode_malleability_test_case_2_byte_suffix_valid_two_padding_symbols<E: EngineWrapper>(
722+
engine_wrapper: E,
723+
) {
724+
assert_eq!(
725+
b"Hell".as_slice(),
726+
&E::standard().decode_ez_str_vec("SGVsbA==").unwrap()
727+
);
728+
}
729+
730+
// https://eprint.iacr.org/2022/361.pdf table 2, test 5
731+
#[apply(all_engines)]
732+
fn decode_malleability_test_case_2_byte_suffix_short_padding<E: EngineWrapper>(engine_wrapper: E) {
733+
assert_eq!(
734+
DecodeError::InvalidPadding,
735+
E::standard().decode_ez_str_vec("SGVsbA=").unwrap_err()
736+
);
737+
}
738+
739+
// https://eprint.iacr.org/2022/361.pdf table 2, test 6
740+
#[apply(all_engines)]
741+
fn decode_malleability_test_case_2_byte_suffix_no_padding<E: EngineWrapper>(engine_wrapper: E) {
742+
assert_eq!(
743+
DecodeError::InvalidPadding,
744+
E::standard().decode_ez_str_vec("SGVsbA").unwrap_err()
745+
);
746+
}
747+
748+
// https://eprint.iacr.org/2022/361.pdf table 2, test 7
749+
#[apply(all_engines)]
750+
fn decode_malleability_test_case_2_byte_suffix_too_much_padding<E: EngineWrapper>(
751+
engine_wrapper: E,
752+
) {
753+
assert_eq!(
754+
DecodeError::InvalidByte(6, PAD_BYTE),
755+
E::standard().decode_ez_str_vec("SGVsbA====").unwrap_err()
756+
);
757+
}
758+
690759
/// Requires canonical padding -> accepts 2 + 2, 3 + 1, 4 + 0 final quad configurations
691760
#[apply(all_engines)]
692761
fn decode_pad_mode_requires_canonical_accepts_canonical<E: EngineWrapper>(engine_wrapper: E) {

0 commit comments

Comments
 (0)