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

feat(ext/crypto) - support encrypt/decrypt with AES-CTR #13177

Merged
merged 4 commits into from
Jan 3, 2022
Merged

feat(ext/crypto) - support encrypt/decrypt with AES-CTR #13177

merged 4 commits into from
Jan 3, 2022

Conversation

cryptographix
Copy link
Contributor

@cryptographix cryptographix commented Dec 22, 2021

Towards #11690. Adds support for AES-CTR algorithm in encrypt()and decrypt().

Values of counter-length restricted to 32/64/128 as per common usage described in issue #13201.

cli/tests/unit/webcrypto_test.ts Show resolved Hide resolved
cli/tests/unit/webcrypto_test.ts Outdated Show resolved Hide resolved
ext/crypto/encrypt.rs Outdated Show resolved Hide resolved
let mut cipher = Ctr::<B, F>::new(key.into(), counter.into());

let mut ciphertext = data.to_vec();
cipher.apply_keystream(&mut ciphertext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking to see if my understanding is correct: it's okay to use apply_keystream() instead of try_apply_keystream() because the ciphertext is always a multiple of the block size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a stream cipher, any length of text is allowed, not being restricted to multiples of the block-size. There is a case where apply_keystream will throw, however, which is when the user tries to encrypt more than 2 ^ length x 16 bytes of data, which in our current worse case, is 128GB in a single call.

Altered to use try_apply_keystream as excess of caution.

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@bnoordhuis bnoordhuis merged commit 9a42d65 into denoland:main Jan 3, 2022
@littledivy littledivy mentioned this pull request Jan 4, 2022
@cryptographix cryptographix deleted the crypto-aes-enc-dec branch January 5, 2022 00:07
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