Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DES-CTR workaround for an upstream bug #647

Closed
wants to merge 5 commits into from
Closed

Conversation

cbeuw
Copy link
Contributor

@cbeuw cbeuw commented Sep 26, 2019

The upstream project forge has a pretty bad issue (digitalbazaar/forge#721) which causes block ciphers with block size smaller than 16 bytes to produce wrong outputs with CTR mode. DES has a block size of 8 bytes so DES-CTR is affected (but other modes are still correct). The upstream maintainer has made a fix (digitalbazaar/forge#722) but we don't know when the fixed version will be released to npm.

This means that CyberChef's DES-CTR outputs are wrong (and vulnerable. See Consequences section in digitalbazaar/forge#721). This PR provides a workaround by implementing DES-CTR mode manually.

Forge didn't have unit tests for DES-CTR so this problem went unnoticed. While there are unit tests for DES-CTR in this repo, the ground truths were presumably produced by forge, and therefore incorrect. This PR corrects these test using outputs from GoLang's standard library. These are also reproducible by pyCryptoDome:

{
name: "DES Encrypt: DES-CTR, Binary",
input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018",
expectedOutput: "09015087e15b0937ab0ae5a84d66e520893690a6ea066382bf1330e8876cb3aa82ccc634f8f0d458bbe0257df6f4637cdac89f311168ba91208a21ba4bdd13c4b1a92cb93b33364b5b94a5d3d7fba68f6eed5807d9f5afeb7fbffcd94792131d264004ae",
recipeConfig: [
{
"op": "DES Encrypt",
"args": [
{"option": "Hex", "string": "58345efb0a64e87e"},
{"option": "Hex", "string": "533ed1378bfd929e"},
"CTR", "Hex", "Hex"
]
}
],
},

https://play.golang.org/p/4Qm2hfLGsqc produces 09015087e15b0937c462fd5974af0c4b5880de136a5680453c99f4500628cbeca769623515d836985110b93eacfea7fa4a7b2b3cb4f67acbb5f7e8ddb5a5d445da74bf6572b0a874befa3888c81110776388e400afd8dc908dcc0c018c7753355f8a1c9f. Diff in CyberChef

{
name: "DES Decrypt: DES-CTR, Binary",
input: "09015087e15b0937ab0ae5a84d66e520893690a6ea066382bf1330e8876cb3aa82ccc634f8f0d458bbe0257df6f4637cdac89f311168ba91208a21ba4bdd13c4b1a92cb93b33364b5b94a5d3d7fba68f6eed5807d9f5afeb7fbffcd94792131d264004ae",
expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018",
recipeConfig: [
{
"op": "DES Decrypt",
"args": [
{"option": "Hex", "string": "58345efb0a64e87e"},
{"option": "Hex", "string": "533ed1378bfd929e"},
"CTR", "Hex", "Hex"
]
}
],
},

https://play.golang.org/p/FpvqncmPk7R produces 7a0e643132750e96b76dc9efa7810bea2b8feaa5b97887e44f96c0e6d506cc4dd4665683c6f63139221f8d887fd0a05b39741f8a67d87d6ac6f8dc6b668bd3e4a97b8bd3a19eafd5cdf50c3e1b3f17d61087d0b67cf6db31fec338b75f5954942c852829. Diff in CyberChef

@CLAassistant
Copy link

CLAassistant commented Sep 26, 2019

CLA assistant check
All committers have signed the CLA.

@cbeuw
Copy link
Contributor Author

cbeuw commented Sep 26, 2019

I've removed the workarounds as forge has released version 0.9.1 and DES-CTR works correctly now; however the tests still need to be corrected. Forge's version needs to be updated as well.

In addition, forge now enforces IV to be the same size as block size (as it should): digitalbazaar/forge@9979169. This broke a lot of tests. I may do another PR to fix them

@cbeuw
Copy link
Contributor Author

cbeuw commented Sep 26, 2019

I'll close this and consolidate the all tests' changes resulting from forge 0.9.1 into another PR.

@cbeuw cbeuw closed this Sep 26, 2019
@cbeuw cbeuw deleted the des-ctr branch September 26, 2019 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants