Skip to content

Commit

Permalink
SignedFW: add sha
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed May 2, 2023
1 parent 7dfc3b1 commit 6de490d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ExtLibs/Utilities/SignedFW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Ionic.Zlib;
using Newtonsoft.Json;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
Expand Down Expand Up @@ -93,6 +94,12 @@ public static byte[] CreateSignedAPJ(AsymmetricCipherKeyPair keyPair, string fil
signer.BlockUpdate(img, 0, offset);
signer.BlockUpdate(img, offset + desc_len, img.Length - (offset + desc_len));
var sig = signer.GenerateSignature();

var sha = new Sha512Digest();
byte[] h = new byte[sha.GetDigestSize()];
sha.BlockUpdate(img, 0, offset);
sha.BlockUpdate(img, offset + desc_len, img.Length - (offset + desc_len));
sha.DoFinal(h, 0);

//desc = struct.pack("<IQ64s", sig_len+8, sig_version, signature)
//img = img[:(offset + 16)] + desc + img[(offset + desc_len):]
Expand All @@ -112,7 +119,8 @@ public static byte[] CreateSignedAPJ(AsymmetricCipherKeyPair keyPair, string fil
}

d["signed_firmware"] = true;

d["sha"] = Convert.ToBase64String(h);
Console.WriteLine("FW SHA: " + Convert.ToBase64String(h));

return System.Text.ASCIIEncoding.ASCII.GetBytes(JsonConvert.SerializeObject(d, Formatting.Indented));
}
Expand Down

0 comments on commit 6de490d

Please sign in to comment.