File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,27 @@ impl<'a> Manifest {
151151 let ke = [ k, & e. to_le_bytes ( ) ] . concat ( ) ;
152152 md5:: compute ( ke) . to_vec ( )
153153 }
154+
155+ /// Verify the manifest. Pass extra bytes from after the manifest.
156+ pub fn verify ( & self , ebytes : & [ u8 ] ) -> bool {
157+ use num_bigint:: BigUint ;
158+ use sha2:: { Digest , Sha256 } ;
159+
160+ let modulus = BigUint :: from_bytes_le ( & self . rsa_pub_key ) ;
161+ let exponent = BigUint :: from ( self . rsa_pub_exp ) ;
162+ let signature = BigUint :: from_bytes_le ( & self . rsa_sig ) ;
163+ let sb = signature. modpow ( & exponent, & modulus) . to_bytes_be ( ) ;
164+
165+ let header = self . header . as_bytes ( ) ;
166+ let mut hasher = Sha256 :: new ( ) ;
167+ hasher. update ( & header) ;
168+ hasher. update ( & ebytes) ;
169+ let hash = hasher. finalize ( ) ;
170+ let hb = hash. as_bytes ( ) ;
171+
172+ let sl = sb. len ( ) ;
173+ sb[ sl - hb. len ( ) ..sl] . eq ( hb)
174+ }
154175}
155176
156177impl Display for Manifest {
You can’t perform that action at this time.
0 commit comments