Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to PR #262 made during review. #344

Closed
wants to merge 0 commits into from
Closed

Conversation

briansmith
Copy link
Owner

@samscott89 Could you please take a look at these changes I am proposing for your PR?

try!(em.read_byte()) != 1 {
return Err(error::Unspecified);
}
let em = m;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:sigh: All of these changes are just supposed to be un-indenting and re-wrapping the code.

let em_bits = mod_bits - 1;
let em_len = (em_bits + 7) / 8;
let top_byte_mask = 0xffu8 >> ((8 * em_len) - em_bits);
// RSASSA-PSS-VERIFY Step 2(c). The `m` this function is given is the
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. I'll verify that I didn't actually change the code in any significant way other than reformatting it.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1fa60373cab9636811ee4fffffc52228712ef211 on padding into * on master*.

Copy link
Contributor

@samscott89 samscott89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great. Left a few minor formatting comments. Other than that I think the only thing to be addressed is the lack of PSS padding tests.

return Err(error::Unspecified);
}
if try!(em.read_byte()) != 0 ||
try!(em.read_byte()) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition fits fine on one line.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now split it into two conditions so that the code coverage can see whether we're testing both checks.

// the out buffer, and then XOR the value of db.

// Step 9. First output the mask into the out buffer.
let (mut masked_db, mut digest_terminator) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing from start of the line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Next line would need an additional space as well)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


let digest_alg = self.digest_alg;
let decoded_digest =
try!(em.skip_and_get_input(digest_alg.output_len));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also fits in one 80-char line now.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

let em_bits = mod_bits - 1;
let em_len = (em_bits + 7) / 8;
let leading_zero_bits = (8 * em_len) - em_bits;
assert!(leading_zero_bits < 8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: why assert over debug_assert or returning an error?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to a debug_assert!.

// Step 8.
for i in 1..db.len() {
db[i] ^= try!(masked_bytes.read_byte());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've added iter in untrusted 0.3.2, is it worth updating this code to use that instead, similarly to how you've written the equivalent code in encode?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's exactly what I want to happen.

return Err(error::Unspecified);
}

try!(padding_alg.encode(msg, signature));
try!(padding_alg.encode(msg, signature, mod_len*8, rng));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces around the operator: mod_len * 8?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.



// Maximum RSA modulus size supported for signature verification (in bits).
const PUBLIC_MODULUS_MAX_LEN: usize = 8192;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you commented in the other thread, PUBLIC_MODULUS_MAX_BITS is a better name for this.

@@ -0,0 +1,60 @@
# Test vectors for RSA-PSS padding for variable public modulus lengths
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding tasks for this file:

  • Rename to rsa_pss_verify_padding_tests.txt.
  • Add failing cases.
  • Cover more digest types.

Would it be simpler to add these cases to the existing rsa_pss_verify_tests.txt file instead? The only reason I could see that these should have independent tests is if the padding functions were made public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make a start on adding failing cases.

params.padding_alg.verify(msg, untrusted::Input::from(decoded))
untrusted::Input::from(decoded).read_all(
error::Unspecified,
|m| params.padding_alg.verify(msg, m, n.length_in_bits()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the closing bracket be on the line below, at the same indentation level as line 127?

@@ -1,5 +1,8 @@
# NIST Test Vectors

[CAVP](CAVP) contains a number of test cases from the [NIST Individual Component
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines can be deleted since we not longer store the NIST tests here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@briansmith
Copy link
Owner Author

@samscott89 Please check out the new commits I appended to this series to address your concerns. Let me know if you want me to squash them into the prior commits before or after you review them.

Pay special attention to the change I made to the PSS encoding, passing in the actual bit length of the public modulus instead of 8 * mod_len. I think this was another bug, triggered by me saying that we only needed to support moduli that are even multiples of 8 for signing.

Also, do you want to take over the remaining tasks? I definitely don't want to steal this from you.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5f139ea on padding into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5f139ea on padding into * on master*.

use error;

#[derive(Clone, Copy, Eq, PartialEq)]
pub struct BitLength {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called just Length since it will presumably always be used as bits::Length vs bits::BitLength?

Also, is this not practically the canonical example for using newtypes?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's weird to have bits::BitLength but I also think bits::Length or bit::Length is too clever. I found out that these names that only make sense with module prefixes don't work well in rustdoc (see error::Unspecified which rustdoc presents as just Unspecified, which is confusing).

I think we probably should create a "prelude" of common types that are used internally in ring and use those types (only) unprefixed. I think BitLength is a prime candidate for that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding newtypes, see #350. The problem is that we have to constructors: from bits, and from bytes. A newtype would make the from-bits constructor implicit, but I'd rather have the constructors be used explicitly. However, we may want to switch to newtype style if it helps work around the lack of const fn.

@samscott89
Copy link
Contributor

Yup, all looks good to me. The BitLength additional particularly seems like a good idea project-wide. Would it make sense to (in a separate PR) try and type all lengths? So that there is ByteLength(usize) and BitLength(usize) or something? Or is it okay to assume that all non-BitLength lengths are in bytes?

Also, do you want to take over the remaining tasks? I definitely don't want to steal this from you.

I'm more than happy to, and allow you to move onto something else. I think you've given me enough help at this point for me to get it across the finish line. I'm not worried about it being 'stolen' from me though, I'm just looking to learn/help as much as I can.

If you could squash it down to a reasonable number of commits (perhaps original commit + review or something?), that would be great. I'll then pull the padding branch and continue in the original PR.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5f139ea on padding into * on master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5f139ea on padding into * on master*.

@briansmith
Copy link
Owner Author

Yup, all looks good to me. The BitLength additional particularly seems like a good idea project-wide.

I filed #350 for this.

Would it make sense to (in a separate PR) try and type all lengths? So that there is ByteLength(usize) and BitLength(usize) or something? Or is it okay to assume that all non-BitLength lengths are in bytes?

I think we should just assume all non-BitLength lengths are in bytes. Otherwise we'd have to move ByteLength (at least) to untrusted.

Also, do you want to take over the remaining tasks? I definitely don't want to steal this from you.
I'm more than happy to, and allow you to move onto something else. I think you've given me enough help at this point for me to get it across the finish line. I'm not worried about it being 'stolen' from me though, I'm just looking to learn/help as much as I can.

If you could squash it down to a reasonable number of commits (perhaps original commit + review or something?), that would be great. I'll then pull the padding branch and continue in the original PR.

Will do.

@briansmith
Copy link
Owner Author

I squashed and landed all these changes onto master. See discussion in #262.

@briansmith briansmith deleted the padding branch November 15, 2016 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants