Skip to content

Does not support memoryviews or bytearrays #81

@twisteroidambassador

Description

@twisteroidambassador

The various interfaces that accept bytes don't accept memoryviews or bytearrays.

For example, calling MlKemPublic.decode_key() with a memoryview or bytearray argument results in:

wolfcrypt.exceptions.WolfCryptError: wc_KyberKey_DecodePublicKey() error (-132)

As far as I can see, adding support for memoryviews and bytearrays should not be too difficult. Only 2 changes are required:

First, change utils.t2b to pass through memoryview and bytearray types in addition to bytes. (It may also be time to drop Python 2 support.) This already fixes the majority of the interfaces.

Some interfaces still report errors after this, such as ciphers.ChaCha20Poly1305.decrypt(), which reports the following error:

  File ".../venv/lib/python3.11/site-packages/wolfcrypt/ciphers.py", line 615, in decrypt
    ret = _lib.wc_ChaCha20Poly1305_Decrypt(self._key, self._IV, aad, len(self._aad),
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: initializer for ctype 'unsigned char *' must be a cdata pointer, not memoryview

For these interfaces, it should be sufficient to wrap the input arguments in _ffi.from_buffer.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions