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

AES GCM stream encrypt wrong ciphertext after first block #25260

Closed
littledivy opened this issue Aug 28, 2024 · 0 comments · Fixed by #25261
Closed

AES GCM stream encrypt wrong ciphertext after first block #25260

littledivy opened this issue Aug 28, 2024 · 0 comments · Fixed by #25261
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto node compat

Comments

@littledivy
Copy link
Member

littledivy commented Aug 28, 2024

import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';

const none = new Buffer(12);
const key = new Buffer(16);

const gcm = crypto.createCipheriv('aes-128-gcm', key, none);

const ciphertext = [];
ciphertext.push(gcm.update('hello', 'utf8'));
ciphertext.push(gcm.update('world', 'utf8'));
gcm.final();

const tag = gcm.getAuthTag();
ciphertext.push(tag);

ciphertext.forEach((buf) => {
	console.log(buf.toString('hex'));
});

Expected:

6bedb6a20f
c1cce09f4c
bf6d20a38e0c828bea3de63b7ff1dfbd

Actual:

6bedb6a20f
80fad8c72d
eb073fa01597da4e7d1458984d1405d3
@littledivy littledivy added bug Something isn't working correctly node compat crypto Related to node:crypto or WebCrypto labels Aug 28, 2024
littledivy added a commit to littledivy/deno that referenced this issue Aug 28, 2024
Fixes denoland#25260
Fixes denoland#25254
Fixes denoland#23693

Verified that `web-push` GCM decryption works in the browser.
littledivy added a commit that referenced this issue Aug 28, 2024
Fixes #25260
Fixes #25254
Fixes #23693

Verified that `web-push` GCM decryption works in the browser. See
`aead-gcm-stream` changes
[here](littledivy/aead-gcm-stream@a9ffd0c)
lucacasonato pushed a commit that referenced this issue Aug 29, 2024
Fixes #25260
Fixes #25254
Fixes #23693

Verified that `web-push` GCM decryption works in the browser. See
`aead-gcm-stream` changes
[here](littledivy/aead-gcm-stream@a9ffd0c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant