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

Custom initialization of ChaCha counter #47

Open
xpe opened this issue Jan 1, 2024 · 2 comments
Open

Custom initialization of ChaCha counter #47

xpe opened this issue Jan 1, 2024 · 2 comments

Comments

@xpe
Copy link

xpe commented Jan 1, 2024

Would you be open to a PR? The ChaCha reference allows for initializing the counter to arbitrary values, but the current API doesn't allow this. I expect this would be a fairly simple change to the following code...

/// Initialize the ChaCha internal state, with a 256-bit key and 64-bit nonce.
pub const fn chacha_init(key: [u8; 32], nonce: [u8; 8]) -> [u32; 16] {
	let mut state = [0u32; 16];
	state[0] = chacha_pack(CHACHA_TAU, 0);
	state[1] = chacha_pack(CHACHA_TAU, 4);
	state[2] = chacha_pack(CHACHA_TAU, 8);
	state[3] = chacha_pack(CHACHA_TAU, 12);

	state[4] = chacha_pack(&key, 0);
	state[5] = chacha_pack(&key, 4);
	state[6] = chacha_pack(&key, 8);
	state[7] = chacha_pack(&key, 12);
	state[8] = chacha_pack(&key, 16);
	state[9] = chacha_pack(&key, 20);
	state[10] = chacha_pack(&key, 24);
	state[11] = chacha_pack(&key, 28);

	// 64-bit counter
	state[12] = 0;
	state[13] = 0;
	// Nonce
	state[14] = chacha_pack(&nonce, 0);
	state[15] = chacha_pack(&nonce, 4);
	state
}
@xpe
Copy link
Author

xpe commented Jan 1, 2024

See for example:

main...xpe:nanorand-rs:0.7.0_chacha_counter

@xpe
Copy link
Author

xpe commented Aug 6, 2024

@Absolucy hello, would you be open to this change?

I've made an updated pull request for version 0.8 at #51.

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

No branches or pull requests

1 participant