Hi Norbert
I can't make your code working

I loaded the OpenSSL-Pharo lib, but when I run your code it gives me a DNU Exception: Instance of LcLibCrypto did not understand #moduleName.
See screenshot

Cheers
Davide






On Thursday, November 30, 2023 at 11:06:09 PM GMT+1, Norbert Hartl <norbert@hartl.name> wrote:


You can load the code and I think PBKDF2 does not rely on the troubling code. But when you do this you will see that it is way too slow. The number of iterations for modern crypto environment makes a single password action many seconds to complete.

I use the https://github.com/PierceNg/OpenSSL-Pharo library where I���ve added two methods 

pbkdf2: password passwordLength: passlen salt: salt saltLength: saltlen iterations: iterations keySize: keySize result: result hashFunction: algo
^ self ffiCall: #(void PKCS5_PBKDF2_HMAC (const char* password, int passlen, const char* salt, int saltlen, int32 iterations, EVP_MD *algo, uint32 keySize, uint8* result))

and 

pbkdf2Password: password salt: salt iterations: iterations keySize: keySize
| result |
result := ByteArray new: keySize.
self 
pbkdf2: password 
passwordLength: password size
salt: salt 
saltLength: salt size
iterations: iterations 
keySize: keySize 
result: result
hashFunction: LcEvpSHA256 new.
^ result


maybe this helps even if it is not a load and use option. The two methods can just be added as extension methods in your own code.

Norbert