react-native-cryptopp icon indicating copy to clipboard operation
react-native-cryptopp copied to clipboard

Allow to set saltLength for RSA-PSS

Open tex0l opened this issue 2 years ago • 0 comments

Currently, the saltLength used for PSS signatures is the cryptopp default one of 32 bytes.

However, it is very common to specify it (the RFC has this parameters available https://www.rfc-editor.org/rfc/rfc3447#section-9.1.1). Here are examples in JS that allow to:

  • https://www.npmjs.com/package/node-forge#rsa
  • https://nodejs.org/api/crypto.html#cryptosignalgorithm-data-key-callback which default to the maximum salt length (key size in bytes, minus hash length, minus 2, which gives 478 bytes for a 4096bits (512 bytes) key with SHA256 (32 bytes).

Would it be possible to set such a parameter upon signing?

I made it work like this with a hard-coded salt value of 478 bytes (see above why 478):

struct PSS_CUSTOM : public SignatureStandard
{
    typedef PSSR_MEM<false, P1363_MGF1, 478> SignatureMessageEncodingMethod;
};

and then instead of setting PSSR I set PSS_CUSTOM. It is compatible with my reference implementation.

EDIT: I wasnt able to pass a saltLength as an argument, as the saltLength of 478 I set in my example is defined statically and not dynamically.. I don't see how it'd be possible with cryptopp to pass it dynamically, I'm not fluent enough in cpp... Do you think of anything? This is really blocking for me, as I need to make this implementation compatible with the node.js default implementation of PSS which used the max salt length.

EDIT2: apparently, the saltLength can only be set as a template parameter at compile time.. see https://groups.google.com/g/cryptopp-users/c/UFVcV9Ml_Cs/m/NFYEfxhF0CEJ would it be possible to define a max PSS length for relevant hashing algorithms and key sizes?

tex0l avatar May 18 '22 13:05 tex0l