ASN1 integer encoding#289
Conversation
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
The design is on the right track, but to do a better review I'd need to see the new function's documentation. In particular I don't understand the role of buffer_length: it seems redundant with integer_length?
b09ea1a to
62cfb00
Compare
76064e8 to
41047aa
Compare
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
I just reviewed the documentation of mbedtls_asn1_write_integer.
I expected mbedtls_asn1_write_integer to be used in library code, at least to implement mbedtls_asn1_write_integer. It's ok to not do that yet, we can do it later. But having used the function in more than unit tests would help us validate that the design is good.
| * | ||
| * \param p The reference to the current position pointer. | ||
| * \param start The start of the buffer, for bounds-checking. | ||
| * \param integer The start of the integer buffer. |
There was a problem hiding this comment.
Is it ok if integer overlaps with the output buffer? That can be useful in typical cases that we'll encounter when printing out a bignum. For that we first convert the bignum to a big-endian byte array, then convert that to ASN.1. If we can do the second step in place, then we don't need to allocate an intermediate step.
We may not want to promise that it works if it's too difficult to implement. We do have to be careful that the ASN.1 representation is usually a few bytes larger than the byte array (because there's 2 or more bytes of overhead for the ASN.1 type, ASN.1 length and the possible additional byte for the ASN.1 sign bit), but it can also be smaller if the byte array has leading zeros.
There was a problem hiding this comment.
Currently overlap is not handled, but it should be possible using memmove(). I'll have a careful think about it tomorrow and see if it is easy to do.
There was a problem hiding this comment.
Given that we're pressed for time, I suggest making that a follow-up in 1.1.
|
#184 is merged, so please rebase on top of |
Instead, make integer_start const Signed-off-by: David Horstmann <david.horstmann@arm.com>
These will cause a NULL dereference if they are NULL. Signed-off-by: David Horstmann <david.horstmann@arm.com>
We still want to test a non-NULL output buffer that is zero-length. Signed-off-by: David Horstmann <david.horstmann@arm.com>
Don't set p to its previous position on failure, since this is untested. Signed-off-by: David Horstmann <david.horstmann@arm.com>
Signed-off-by: David Horstmann <david.horstmann@arm.com>
a39d1ea to
4e726ae
Compare
|
Second rebase completed (sorry for the delay). I have squashed some commits together and done some merging so that there are only 45 commits total (rather than 67). The commits from 1a3e2cb onwards I have left unchanged. before that point there were previously 39 commits and there are now 18. If this is still too much to review commit-by-commit I can do some more rebasing work, let me know. |
|
LGTM |
davidhorstmann-arm
left a comment
There was a problem hiding this comment.
Approving on behalf of:
- Myself, for @bjwtaylor's commits
- @bjwtaylor, for my commits
|
I think this needs a ChangeLog entry. #337 took care of the migration guide part, but we still need a ChangeLog entry. (We have one of for the parsing side.) |
Ah you're right, I'll add that momentarily. |
Signed-off-by: David Horstmann <david.horstmann@arm.com>
6a525ed
|
Changelog also looks good. |
davidhorstmann-arm
left a comment
There was a problem hiding this comment.
Approving again on behalf of myself and @bjwtaylor
Description
Introduce a new function for asn1 encoding of mpi integers. resolves Mbed-TLS/mbedtls#9372 depends #184.
There is currently a bug in #184, which is causing the tests to fail, I will rebase it once this is fixed.
PR checklist