Skip to content

Commit

Permalink
ndp: NewNonce generates a 6 byte nonce
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <[email protected]>
  • Loading branch information
mdlayher committed Mar 23, 2022
1 parent 7d558c9 commit 3ad9ce1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,9 @@ type Nonce struct {

// NewNonce creates a Nonce option with an opaque random value.
func NewNonce() *Nonce {
// Minimum is 6 bytes but the final length of the message must be a multiple
// of 8 bytes, so we'll go with 14 for now and re-evaluate later.
const n = 14
// Minimum is 6 bytes, and this is also the only value that the Linux kernel
// recognizes as of kernel 5.17.
const n = 6
b := make([]byte, n)
_, _ = rand.Read(b)

Expand Down
12 changes: 11 additions & 1 deletion option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,21 @@ func nonceTests() []optionSub {
},
ok: true,
},
{
name: "ok, larger length",
os: []Option{&Nonce{b: make([]byte, 14)}},
bs: [][]byte{
{14, 2},
// Nonce.
ndptest.Zero(14),
},
ok: true,
},
{
name: "ok, random",
os: []Option{nonce},
bs: [][]byte{
{14, 2},
{14, 1},
// Nonce.
nonce.b,
},
Expand Down

0 comments on commit 3ad9ce1

Please sign in to comment.