mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
Fixed KDF tests
This commit is contained in:
parent
0294a5c0dd
commit
c24b883c01
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"golang.org/x/crypto/blake2s"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,10 +45,12 @@ func TestKDF(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var t0, t1, t2 [blake2s.Size]byte
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
key, _ := hex.DecodeString(test.key)
|
key, _ := hex.DecodeString(test.key)
|
||||||
input, _ := hex.DecodeString(test.input)
|
input, _ := hex.DecodeString(test.input)
|
||||||
t0, t1, t2 := KDF3(key, input)
|
KDF3(&t0, &t1, &t2, key, input)
|
||||||
t0s := hex.EncodeToString(t0[:])
|
t0s := hex.EncodeToString(t0[:])
|
||||||
t1s := hex.EncodeToString(t1[:])
|
t1s := hex.EncodeToString(t1[:])
|
||||||
t2s := hex.EncodeToString(t2[:])
|
t2s := hex.EncodeToString(t2[:])
|
||||||
@ -59,7 +62,7 @@ func TestKDF(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
key, _ := hex.DecodeString(test.key)
|
key, _ := hex.DecodeString(test.key)
|
||||||
input, _ := hex.DecodeString(test.input)
|
input, _ := hex.DecodeString(test.input)
|
||||||
t0, t1 := KDF2(key, input)
|
KDF2(&t0, &t1, key, input)
|
||||||
t0s := hex.EncodeToString(t0[:])
|
t0s := hex.EncodeToString(t0[:])
|
||||||
t1s := hex.EncodeToString(t1[:])
|
t1s := hex.EncodeToString(t1[:])
|
||||||
assertEquals(t, t0s, test.t0)
|
assertEquals(t, t0s, test.t0)
|
||||||
@ -69,7 +72,7 @@ func TestKDF(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
key, _ := hex.DecodeString(test.key)
|
key, _ := hex.DecodeString(test.key)
|
||||||
input, _ := hex.DecodeString(test.input)
|
input, _ := hex.DecodeString(test.input)
|
||||||
t0 := KDF1(key, input)
|
KDF1(&t0, key, input)
|
||||||
t0s := hex.EncodeToString(t0[:])
|
t0s := hex.EncodeToString(t0[:])
|
||||||
assertEquals(t, t0s, test.t0)
|
assertEquals(t, t0s, test.t0)
|
||||||
}
|
}
|
||||||
|
@ -117,8 +117,8 @@ func TestNoiseHandshake(t *testing.T) {
|
|||||||
var err error
|
var err error
|
||||||
var out []byte
|
var out []byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
out = key1.send.Seal(out, nonce[:], testMsg, nil)
|
out = key1.send.aead.Seal(out, nonce[:], testMsg, nil)
|
||||||
out, err = key2.receive.Open(out[:0], nonce[:], out, nil)
|
out, err = key2.receive.aead.Open(out[:0], nonce[:], out, nil)
|
||||||
assertNil(t, err)
|
assertNil(t, err)
|
||||||
assertEqual(t, out, testMsg)
|
assertEqual(t, out, testMsg)
|
||||||
}()
|
}()
|
||||||
@ -128,8 +128,8 @@ func TestNoiseHandshake(t *testing.T) {
|
|||||||
var err error
|
var err error
|
||||||
var out []byte
|
var out []byte
|
||||||
var nonce [12]byte
|
var nonce [12]byte
|
||||||
out = key2.send.Seal(out, nonce[:], testMsg, nil)
|
out = key2.send.aead.Seal(out, nonce[:], testMsg, nil)
|
||||||
out, err = key1.receive.Open(out[:0], nonce[:], out, nil)
|
out, err = key1.receive.aead.Open(out[:0], nonce[:], out, nil)
|
||||||
assertNil(t, err)
|
assertNil(t, err)
|
||||||
assertEqual(t, out, testMsg)
|
assertEqual(t, out, testMsg)
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user