is there a bug in nvs_partition_gen.py in latest (3.2-dev) esp-idf?

stoikos
Posts: 22
Joined: Mon Aug 06, 2018 4:38 am

is there a bug in nvs_partition_gen.py in latest (3.2-dev) esp-idf?

Postby stoikos » Fri Nov 16, 2018 5:38 am

when executing

Code: Select all


 python nvs_partition_gen.py --keygen True --encrypt True sample_multipage_blob.csv xxx.bin  0x10000
this is what I get

Code: Select all


Traceback (most recent call last):
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 775, in <module>
main()
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 770, in main
nvs_part_gen(input_filename, output_filename, input_size, key_gen, is_encrypt_data, key_file, version_no)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 692, in nvs_part_gen
write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"])
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 611, in write_entry
nvs_instance.write_namespace(key)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 508, in write_namespace
self.cur_page.write_primitive_data(key, self.namespace_idx, "u8", 0,self)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 449, in write_primitive_data
self.write_entry_to_buf(entry_struct, 1,nvs_obj)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 208, in write_entry_to_buf
encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 194, in encrypt_data
encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input)
File "C:/msys32/home/george/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py", line 123, in encrypt_entry
backend = default_backend()
File "C:/msys32/mingw32/lib/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 15, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "C:/msys32/mingw32/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:/msys32/mingw32/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 53, in <module>
from cryptography.hazmat.bindings.openssl import binding
File "C:/msys32/mingw32/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 13, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The specified module could not be found.
i have install all python requirements

Code: Select all

  python -m pip install --user -r $IDF_PATH/requirements.txt
Requirement already satisfied: setuptools in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 4)) (40.4.3)
Requirement already satisfied: pyserial>=3.0 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 8)) (3.4)
Requirement already satisfied: future>=0.15.2 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 9)) (0.16.0)
Requirement already satisfied: cryptography in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (2.3.1)
Requirement already satisfied: idna>=2.1 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (2.7)
Requirement already satisfied: asn1crypto>=0.21.0 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (0.24.0)
Requirement already satisfied: six>=1.4.1 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (1.11.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (1.10.0)
Requirement already satisfied: enum34 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (1.1.6)
Requirement already satisfied: ipaddress in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (1.0.22)
Requirement already satisfied: pycparser in c:/msys32/mingw32/lib/python2.7/site-packages (from cffi!=1.11.3,>=1.7->cryptography->-r C:/msys32/home/george/esp/esp-idf/requirements.txt (line 10)) (2.19)
any idea?

stoikos
Posts: 22
Joined: Mon Aug 06, 2018 4:38 am

Re: is there a bug in nvs_partition_gen.py in latest (3.2-dev) esp-idf?

Postby stoikos » Tue Nov 20, 2018 5:29 am

downloaded latest again, in a brand new VM running the example. now I get a different error
ValueError: Invalid key size (512) for AES.

Code: Select all


python nvs_partition_gen.py --encrypt True --keyfile testdata/encryption_keys.txt  sample_multipage_blob.csv xx.bin 0x4000
Traceback (most recent call last):
  File "nvs_partition_gen.py", line 775, in <module>
    main()
  File "nvs_partition_gen.py", line 770, in main
    nvs_part_gen(input_filename, output_filename, input_size, key_gen, is_encrypt_data, key_file, version_no)
  File "nvs_partition_gen.py", line 692, in nvs_part_gen
    write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"])
  File "nvs_partition_gen.py", line 611, in write_entry
    nvs_instance.write_namespace(key)
  File "nvs_partition_gen.py", line 508, in write_namespace
    self.cur_page.write_primitive_data(key, self.namespace_idx, "u8", 0,self)
  File "nvs_partition_gen.py", line 449, in write_primitive_data
    self.write_entry_to_buf(entry_struct, 1,nvs_obj)
  File "nvs_partition_gen.py", line 208, in write_entry_to_buf
    encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj)
  File "nvs_partition_gen.py", line 194, in encrypt_data
    encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input)
  File "nvs_partition_gen.py", line 127, in encrypt_entry
    cipher = Cipher(algorithms.AES(encr_key), modes.XTS(tweak), backend=backend)
  File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py", line 30, in __init__
    self.key = _verify_key_size(self, key)
  File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py", line 17, in _verify_key_size
    len(key) * 8, algorithm.name
ValueError: Invalid key size (512) for AES.

stoikos
Posts: 22
Joined: Mon Aug 06, 2018 4:38 am

Re: is there a bug in nvs_partition_gen.py in latest (3.2-dev) esp-idf?

Postby stoikos » Tue Nov 20, 2018 5:39 am

not even the examples in https://github.com/espressif/esp-idf/tr ... generator/ are executing successfully. Does that mean tha NVS encryption is broken? Is there a work around?


Return to “ESP32 IDF”

Who is online

Users browsing this forum: Bing [Bot] and 10 guests