diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index b84d2f3fb5..36739328b7 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -18,11 +18,13 @@ import os import random import struct import sys +import textwrap import zlib from io import open try: from cryptography.hazmat.backends import default_backend + from cryptography.hazmat.primitives import hashes, hmac from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes except ImportError: print('The cryptography package is not installed.' @@ -44,6 +46,13 @@ def reverse_hexbytes(addr_tmp): return reversed_bytes +def desc_format(*args): + desc = '' + for arg in args: + desc += textwrap.fill(replace_whitespace=False, text=arg) + '\n' + return desc + + """ Class for standard NVS page structure """ @@ -842,16 +851,63 @@ def generate_key(args): distutils.dir_util.mkpath(keys_outdir) keys_outdir, output_keyfile = set_target_filepath(keys_outdir, args.keyfile) - key = ''.join(random.choice('0123456789abcdef') for _ in range(128)).strip() - encr_key_bytes = codecs.decode(key, 'hex') - key_len = len(encr_key_bytes) - keys_buf = bytearray(b'\xff') * page_max_size - keys_buf[0:key_len] = encr_key_bytes - crc_data = keys_buf[0:key_len] - crc_data = bytes(crc_data) - crc = zlib.crc32(crc_data, 0xFFFFFFFF) - struct.pack_into('