PeculiarVentures / webcrypto-core

A input validation layer for WebCrypto polyfills.
MIT License
28 stars 13 forks source link

Error "Parameter 'saltLength' should be a multiple of 8" is incorrect #7

Closed YuryStrozhevsky closed 7 years ago

YuryStrozhevsky commented 7 years ago

During some operations with RSA-PSS algorithm I had this error:

Error: Parameter 'saltLength' should be a multiple of 8

So, the "saltLength" parameter is using only as a part of RSASSA-PSS-params which in turn came from RFC4055. In the RFC we have this definition of RSASSA-PSS-params:

RSASSA-PSS-params  ::=  Sequence  {
    hashAlgorithm      [0] HashAlgorithm DEFAULT sha1Identifier,
    maskGenAlgorithm   [1] MaskGenAlgorithm DEFAULT mgf1SHA1Identifier,
    saltLength         [2] Integer DEFAULT 20,
    trailerField       [3] Integer DEFAULT 1  }

As you can see the "saltLength" parameter has a default value equal to 20 and let me explain why. As you can see the "RSASSA-PSS-params" also has default value for "hashAlgorithm" parameter and the default value is SHA-1. And as a result of SHA-1 algorithm we have value with length equal to 20. That is why we have "saltLength" default value as 20.

Also let me quote some part of WebCrypto API specification for "exportKey" operation for RSA-PSS algorithm:

Set the saltLength field to the length in octets of the digest algorithm identified by the name attribute of the hash attribute of the [[algorithm]] internal slot of key

So, in fact the "saltLength" value must be equal in length to output of hashAlgorithm used inside "RSASSA-PSS-params".

Please remove the check "if (alg.saltLength % 8) ..." because it is completely incorrect.