|
@@ -6,7 +6,10 @@ package packet
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
|
|
+ "crypto/ecdsa"
|
|
|
|
|
+ "crypto/elliptic"
|
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
|
|
|
+ "math/big"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
@@ -186,6 +189,29 @@ func TestEcc384Serialize(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestP256KeyID(t *testing.T) {
|
|
|
|
|
+ // Confirm that key IDs are correctly calculated for ECC keys.
|
|
|
|
|
+ ecdsaPub := &ecdsa.PublicKey{
|
|
|
|
|
+ Curve: elliptic.P256(),
|
|
|
|
|
+ X: fromHex("81fbbc20eea9e8d1c3ceabb0a8185925b113d1ac42cd5c78403bd83da19235c6"),
|
|
|
|
|
+ Y: fromHex("5ed6db13d91db34507d0129bf88981878d29adbf8fcd1720afdb767bb3fcaaff"),
|
|
|
|
|
+ }
|
|
|
|
|
+ pub := NewECDSAPublicKey(time.Unix(1297309478, 0), ecdsaPub)
|
|
|
|
|
+
|
|
|
|
|
+ const want = uint64(0xd01055fbcadd268e)
|
|
|
|
|
+ if pub.KeyId != want {
|
|
|
|
|
+ t.Errorf("want key ID: %x, got %x", want, pub.KeyId)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func fromHex(hex string) *big.Int {
|
|
|
|
|
+ n, ok := new(big.Int).SetString(hex, 16)
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ panic("bad hex number: " + hex)
|
|
|
|
|
+ }
|
|
|
|
|
+ return n
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const rsaFingerprintHex = "5fb74b1d03b1e3cb31bc2f8aa34d7e18c20c31bb"
|
|
const rsaFingerprintHex = "5fb74b1d03b1e3cb31bc2f8aa34d7e18c20c31bb"
|
|
|
|
|
|
|
|
const rsaPkDataHex = "988d044d3c5c10010400b1d13382944bd5aba23a4312968b5095d14f947f600eb478e14a6fcb16b0e0cac764884909c020bc495cfcc39a935387c661507bdb236a0612fb582cac3af9b29cc2c8c70090616c41b662f4da4c1201e195472eb7f4ae1ccbcbf9940fe21d985e379a5563dde5b9a23d35f1cfaa5790da3b79db26f23695107bfaca8e7b5bcd0011010001"
|
|
const rsaPkDataHex = "988d044d3c5c10010400b1d13382944bd5aba23a4312968b5095d14f947f600eb478e14a6fcb16b0e0cac764884909c020bc495cfcc39a935387c661507bdb236a0612fb582cac3af9b29cc2c8c70090616c41b662f4da4c1201e195472eb7f4ae1ccbcbf9940fe21d985e379a5563dde5b9a23d35f1cfaa5790da3b79db26f23695107bfaca8e7b5bcd0011010001"
|