You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that this library is now deprecated, but perhaps this information will be useful for those who intend to fork this library.
Background
We run an internal fork of this library and noticed around a small percentage of applepay token decryptions were failing with a cipher: message authentication failed error in production. We tried to replicate the issue locally and managed to narrow it down to the ECDHE and KDF functions.
Issue
The combined use of the ecdheSharedSecret and deriveEncryptionKey functions do not correctly implement P256 ECDHE correctly. Notably, they fail to pad the X coordinate of the point to 32 bytes as specified in SEC 1, Version 2.0, Section 2.3.5.
Replication
This snippet (playground link) illustrates the difference between the ScalarMult and Bytes implementation with the correct crypto/ecdh implementation:
For versions less than go1.20, replacing the (*big.Int).Bytes() call in deriveEncryptionKey with (*big.Int).SetBytes on a 32 length byte slice would be an alternative.
The text was updated successfully, but these errors were encountered:
I understand that this library is now deprecated, but perhaps this information will be useful for those who intend to fork this library.
Background
We run an internal fork of this library and noticed around a small percentage of applepay token decryptions were failing with a
cipher: message authentication failed
error in production. We tried to replicate the issue locally and managed to narrow it down to the ECDHE and KDF functions.Issue
The combined use of the
ecdheSharedSecret
andderiveEncryptionKey
functions do not correctly implement P256 ECDHE correctly. Notably, they fail to pad the X coordinate of the point to 32 bytes as specified in SEC 1, Version 2.0, Section 2.3.5.Replication
This snippet (playground link) illustrates the difference between the
ScalarMult
andBytes
implementation with the correctcrypto/ecdh
implementation:Fix
If you are using go1.20 or newer, I would recommend that you refactor the code to use
crypto/ecdh
instead. As at go1.20,(elliptic.Curve).ScalarMult
contained a note advising against its use while recommending the then newly addedcrypto/ecdh
package which correctly implements ECDHE. From go1.21 onwards,(elliptic.Curve).ScalarMult
is marked as deprecated.For versions less than go1.20, replacing the
(*big.Int).Bytes()
call inderiveEncryptionKey
with(*big.Int).SetBytes
on a 32 length byte slice would be an alternative.The text was updated successfully, but these errors were encountered: