Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop f4a9711f5 -> 94497bf2a


bootutil: ecdsa P-256: Fix handling of sizes

>From David Brown:
The ECDSA signature is written as two DER-encoded INTEGERS.  Although
the values are always 256 bits, the encoding ends up being variable
length, because the encoding is signed, and therefore needs an extra
zero byte to keep the number positive.  This means that the length can
vary by up to two bytes.

The 'newt' tool handles this for signature by allowing space for the
largest encoding, and padding with one or two zeros.  However, the
bootutil image check code insists that the length is exact, resulting in
a decoding error on about 3/4 signatures.

Fix this by only verifying that we have at least enough payload to hold
the signature.  There are later checks that will fail if the integers
themselves are too large.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/94497bf2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/94497bf2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/94497bf2

Branch: refs/heads/develop
Commit: 94497bf2af4d51046b211ffb4e676f0a7718e22c
Parents: f4a9711
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Feb 6 09:47:14 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Feb 6 09:47:14 2017 -0800

----------------------------------------------------------------------
 boot/bootutil/src/image_ec256.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/94497bf2/boot/bootutil/src/image_ec256.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/image_ec256.c b/boot/bootutil/src/image_ec256.c
index f59a8f0..1e7354e 100644
--- a/boot/bootutil/src/image_ec256.c
+++ b/boot/bootutil/src/image_ec256.c
@@ -122,7 +122,7 @@ tinycrypt_decode_sig(uint32_t r[NUM_ECC_DIGITS], uint32_t 
s[NUM_ECC_DIGITS],
     if (rc) {
         return -1;
     }
-    if (cp + len != end) {
+    if (cp + len > end) {
         return -2;
     }
     rc = tinycrypt_read_bigint(r, &cp, end);

Reply via email to