Skip to content

Commit a126555

Browse files
authored
Merge pull request #43 from tankyleo/25-10-use-12-byte-nonce
Use a 12-byte nonce as an input to Chacha20-Poly1305
2 parents 862252c + 4128ce8 commit a126555

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/util/key_obfuscator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ impl KeyObfuscator {
136136
fn generate_synthetic_nonce(&self, initial_nonce_material: &[u8]) -> [u8; NONCE_LENGTH] {
137137
let hmac = Self::hkdf(&self.hashing_key, initial_nonce_material);
138138
let mut nonce = [0u8; NONCE_LENGTH];
139+
// TODO: While the RFC specifies a 12-byte nonce, we use an 8-byte nonce for
140+
// backwards compatibility with the rust-lightning implementation of
141+
// Chacha20Poly1305. We now use the rust-bitcoin implementation, which allows
142+
// for 12-byte nonces, so we should figure out an upgrade path for this.
139143
nonce[4..].copy_from_slice(&hmac[..8]);
140144
nonce
141145
}

src/util/storable_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T: EntropySource> StorableBuilder<T> {
4747
&self, input: Vec<u8>, version: i64, data_encryption_key: &[u8; 32], aad: &[u8],
4848
) -> Storable {
4949
let mut nonce = [0u8; NONCE_LENGTH];
50-
self.entropy_source.fill_bytes(&mut nonce[4..]);
50+
self.entropy_source.fill_bytes(&mut nonce);
5151

5252
let mut data_blob = PlaintextBlob { value: input, version }.encode_to_vec();
5353

0 commit comments

Comments
 (0)