Loading scripts/imgtool.py +7 Changes for scripts/imgtool.py: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -26,7 +26,13 @@ def do_keygen(args): def do_getpub(args): key = keys.load(args.key) if args.lang == 'c': key.emit_c() elif args.lang == 'rust': key.emit_rust() else: msg = "Unsupported language, valid are: c, or rust" raise argparse.ArgumentTypeError(msg) def do_sign(args): if args.rsa_pkcs1_15: Loading Loading @@ -73,6 +79,7 @@ def args(): getpub = subs.add_parser('getpub', help='Get public key from keypair') getpub.add_argument('-k', '--key', metavar='filename', required=True) getpub.add_argument('-l', '--lang', metavar='lang', default='c') sign = subs.add_parser('sign', help='Sign an image with a private key') sign.add_argument('-k', '--key', metavar='filename') Loading scripts/imgtool/keys.py +17 −2 Changes for scripts/imgtool/keys.py: 17 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -34,13 +34,16 @@ class RSA2048(): with open(path, 'wb') as f: f.write(self.key.exportKey('PEM')) def emit_c(self): def get_public_bytes(self): node = RSAPublicKey() node['modulus'] = self.key.n node['publicExponent'] = self.key.e return bytearray(encode(node)) def emit_c(self): print(AUTOGEN_MESSAGE) print("const unsigned char rsa_pub_key[] = {", end='') encoded = bytearray(encode(node)) encoded = self.get_public_bytes() for count, b in enumerate(encoded): if count % 8 == 0: print("\n\t", end='') Loading @@ -50,6 +53,18 @@ class RSA2048(): print("\n};") print("const unsigned int rsa_pub_key_len = {};".format(len(encoded))) def emit_rust(self): print(AUTOGEN_MESSAGE) print("static RSA_PUB_KEY: &'static [u8] = &[", end='') encoded = self.get_public_bytes() for count, b in enumerate(encoded): if count % 8 == 0: print("\n ", end='') else: print(" ", end='') print("0x{:02x},".format(b), end='') print("\n];") def sig_type(self): """Return the type of this signature (as a string)""" if sign_rsa_pss: Loading Loading
scripts/imgtool.py +7 Changes for scripts/imgtool.py: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -26,7 +26,13 @@ def do_keygen(args): def do_getpub(args): key = keys.load(args.key) if args.lang == 'c': key.emit_c() elif args.lang == 'rust': key.emit_rust() else: msg = "Unsupported language, valid are: c, or rust" raise argparse.ArgumentTypeError(msg) def do_sign(args): if args.rsa_pkcs1_15: Loading Loading @@ -73,6 +79,7 @@ def args(): getpub = subs.add_parser('getpub', help='Get public key from keypair') getpub.add_argument('-k', '--key', metavar='filename', required=True) getpub.add_argument('-l', '--lang', metavar='lang', default='c') sign = subs.add_parser('sign', help='Sign an image with a private key') sign.add_argument('-k', '--key', metavar='filename') Loading
scripts/imgtool/keys.py +17 −2 Changes for scripts/imgtool/keys.py: 17 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -34,13 +34,16 @@ class RSA2048(): with open(path, 'wb') as f: f.write(self.key.exportKey('PEM')) def emit_c(self): def get_public_bytes(self): node = RSAPublicKey() node['modulus'] = self.key.n node['publicExponent'] = self.key.e return bytearray(encode(node)) def emit_c(self): print(AUTOGEN_MESSAGE) print("const unsigned char rsa_pub_key[] = {", end='') encoded = bytearray(encode(node)) encoded = self.get_public_bytes() for count, b in enumerate(encoded): if count % 8 == 0: print("\n\t", end='') Loading @@ -50,6 +53,18 @@ class RSA2048(): print("\n};") print("const unsigned int rsa_pub_key_len = {};".format(len(encoded))) def emit_rust(self): print(AUTOGEN_MESSAGE) print("static RSA_PUB_KEY: &'static [u8] = &[", end='') encoded = self.get_public_bytes() for count, b in enumerate(encoded): if count % 8 == 0: print("\n ", end='') else: print(" ", end='') print("0x{:02x},".format(b), end='') print("\n];") def sig_type(self): """Return the type of this signature (as a string)""" if sign_rsa_pss: Loading