You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/05 02:01:29 UTC

incubator-mynewt-newt git commit: Add hash TLV to image even when there is another TLV with signature; it's handy to have access to hash for identification purpose when running the image without having to compute it.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 546cec1f1 -> 9a47b7e0f


Add hash TLV to image even when there is another TLV with signature;
it's handy to have access to hash for identification purpose when
running the image without having to compute it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/9a47b7e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/9a47b7e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/9a47b7e0

Branch: refs/heads/develop
Commit: 9a47b7e0f396b3a4cf60be34b8076a0302bf3143
Parents: 546cec1
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 4 16:57:28 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 4 16:57:28 2016 -0700

----------------------------------------------------------------------
 newt/image/image.go | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9a47b7e0/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
index 75f3216..2d61339 100644
--- a/newt/image/image.go
+++ b/newt/image/image.go
@@ -265,8 +265,8 @@ func (image *Image) Generate() error {
 		Pad3:  0,
 	}
 	if image.signingKey != nil {
-		hdr.TlvSz = 4 + 256
-		hdr.Flags = IMAGE_F_PKCS15_RSA2048_SHA256
+		hdr.TlvSz = 4 + 256 + 4 + 32
+		hdr.Flags = IMAGE_F_PKCS15_RSA2048_SHA256 | IMAGE_F_SHA256
 		hdr.KeyId = image.keyId
 	} else {
 		hdr.TlvSz = 4 + 32
@@ -311,26 +311,26 @@ func (image *Image) Generate() error {
 
 	image.hash = hash.Sum(nil)
 
-	if image.signingKey == nil {
-		/*
-		 * Trailer with hash of the data
-		 */
-		tlv := &ImageTrailerTlv{
-			Type: IMAGE_TLV_SHA256,
-			Pad:  0,
-			Len:  uint16(len(image.hash)),
-		}
-		err = binary.Write(imgFile, binary.LittleEndian, tlv)
-		if err != nil {
-			return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
-				"trailer: %s", err.Error()))
-		}
-		_, err = imgFile.Write(image.hash)
-		if err != nil {
-			return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
-				err.Error()))
-		}
-	} else {
+	/*
+	 * Trailer with hash of the data
+	 */
+	tlv := &ImageTrailerTlv{
+		Type: IMAGE_TLV_SHA256,
+		Pad:  0,
+		Len:  uint16(len(image.hash)),
+	}
+	err = binary.Write(imgFile, binary.LittleEndian, tlv)
+	if err != nil {
+		return util.NewNewtError(fmt.Sprintf("Failed to serialize image "+
+			"trailer: %s", err.Error()))
+	}
+	_, err = imgFile.Write(image.hash)
+	if err != nil {
+		return util.NewNewtError(fmt.Sprintf("Failed to append hash: %s",
+			err.Error()))
+	}
+
+	if image.signingKey != nil {
 		/*
 		 * If signing key was set, generate TLV for that.
 		 */