microsoft / go-crypto-winnative

Go crypto backend for Windows using CNG
MIT License
28 stars 3 forks source link

Update DES and 3DES to use ECB instead of CBC chaining mode #58

Closed qmuntal closed 3 weeks ago

qmuntal commented 3 weeks ago

Go's DES and 3DES implementations use the ECB chaining mode. Unfortunately, CNG defaults to CBC chaining mode, and we were not overriding that property when instantiating DES and 3DES keys.

This PR fixes this mismatch by honoring Go's chaining mode together with a new extensive test suite that ensures we don't regress.

This a breaking change: data longer than the DES or 3DES block size (8 bytes and 24 bytes respectively) encrypted with the CNG backend won't be decryptable after this fix. Note that the Microsoft Go toolchain has implemented DES and 3DES using the CNG backend since Go 1.22.

To work around this issue, please follow these steps:

  1. Decrypt the existing encrypted data using a Microsoft Go toolchain that doesn't contain the fix.
  2. Encrypt the just-decrypted data using a Microsoft Go toolchain that contains the fix.