Skip to content

Commit 6759f22

Browse files
committed
Minor.
1 parent 52b7a5a commit 6759f22

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

keystore/encryptor.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,15 @@ func (k *keystore) encryptECDHP256Anonymous(data []byte, remotePubKey []byte) ([
303303
return nil, fmt.Errorf("ecdh-p256: new gcm: %w", err)
304304
}
305305

306+
// Caution:
306307
// Include both nonce and ephemeral public key in AAD for complete authentication
307-
// AAD is [12 byte nonce] [65 byte ephemeral public key]
308+
// AAD is [12 byte nonce] [65 byte ephemeral public key]. This is in line with https://www.ietf.org/rfc//rfc5116:
309+
// <<<The nonce is authenticated internally to the algorithm, and it is not
310+
// necessary to include it in the AD input. The nonce MAY be included
311+
// in P or A if it is convenient to the application.>>>
312+
// However, the second nonce reuse in gcm.Seal(nil, nonce...) is not conventional - this means that we reuse the
313+
// same nonce both for the symmetric key and the block cipher counter.
314+
// It would be simpler to use new nonce here (by just extending nonceSizeECDHP256 size).
308315
ciphertext := gcm.Seal(nil, nonce, data, append(nonce[:], ephPriv.PublicKey().Bytes()...))
309316

310317
// Embed ephemeral public key and nonce in the result

0 commit comments

Comments
 (0)