Skip to content

crypto: Endianess of nonce in secret connection #2263

@liamsi

Description

@liamsi

Currently, the nonces used in secret connection are 12 bytes / 96 bits and basically a big endian encoded counter:

// increment nonce big-endian by 1 with wraparound.
func incrNonce(nonce *[aeadNonceSize]byte) {
for i := aeadNonceSize - 1; 0 <= i; i-- {
nonce[i]++
// if this byte wrapped around to zero, we need to increment the next byte
if nonce[i] != 0 {
return
}
}
}

For the sake of consistency (ChaCha20 is all little endian) it would be great to change the nonce encoding to little endian, too.

Additionally to that, a counter using a simple 64-bit (unsigned) integer should be sufficiently large. It will not overflow in practice and we should have rekeyed long before it happens.

We should then also encode the chunk size here using little endian, too.

Related discussion: tendermint/tmkms#38 (comment)

cc @tarcieri @ValarDragon

Metadata

Metadata

Assignees

No one assigned

    Labels

    C:cryptoComponent: CryptoC:p2pComponent: P2P pkg

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions