micropython / micropython-lib

Core Python libraries ported to MicroPython
Other
2.3k stars 981 forks source link

Add to hashlib password-based key derivation function 'scrypt' #755

Open Atiseug opened 8 months ago

Atiseug commented 8 months ago

After Python 3.6 there is password-based key derivation function scrypt in a default hashlib library. It is better suitable for creation of the key for encryption (e.g. AES which is a part of a standard cryptolib) than the other already existing functions in Micropython's hashlib. Micropython doesn't have any of key derivation function from standard hashlib library so it would be good if Micropython would have it. There are some of pure Python implementations of such a functions, but it is extremely slow.

projectgus commented 8 months ago

Hi @Atiseug,

I agree this would be potentially useful to have! I've moved this over to micropython-lib as this is probably where it would need to be implemented (there are other "extensions" to hashlib here, for example you can mip install hashlib-sha512 separately to get this individual algorithm.)

The reason for this is that otherwise all algorithms have to be included in all binary builds of MicroPython.

Unfortunately, that does mean any such implementation will need to be in Python. This is probably the case anyhow here though, as I believe our underlying TLS library (mbedTLS) has no support for scrypt (RFC 7693), or the component algorithm Salsa20/8 - so these would be need to be implemented in Python anyway.