Documentation
¶
Overview ¶
ECDH implementation with curve25519. https://tools.ietf.org/html/rfc7748
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Basepoint []byte = curve25519.Basepoint
)
Functions ¶
This section is empty.
Types ¶
type Pair ¶
type Pair struct {
Private PrivateKey
Public PublicKey
}
Pair holds private and public key.
func New ¶
New generates a pair of a random private and corresponding public key. Private key consists of randomly generated bytes. (rfc7748 pages 7/8) Both keys size is 32 bytes.
Example ¶
package main
import (
"fmt"
"log"
"catinello.eu/ecdh25519"
)
func main() {
p, err := ecdh25519.New()
if err != nil {
log.Fatal(err)
}
fmt.Println(len(p.Private), len(p.Public))
}
Output: 32 32
func Use ¶
Use takes a []byte value of a valid PrivateKey and calculates a Pair.
Example ¶
package main
import (
"fmt"
"log"
"catinello.eu/ecdh25519"
)
var P1, P2 *ecdh25519.Pair
func main() {
var err error
P1, err = ecdh25519.Use([]byte{99, 75, 54, 81, 49, 102, 50, 108, 74, 97, 55, 88, 99, 75, 104, 88, 73, 56, 52, 88, 82, 55, 48, 116, 85, 79, 110, 122, 86, 99, 80, 107})
if err != nil {
log.Fatal(err)
}
P2, err = ecdh25519.Use([]byte{65, 76, 68, 75, 109, 112, 86, 72, 97, 73, 97, 105, 80, 81, 117, 49, 98, 70, 86, 88, 79, 82, 73, 98, 51, 66, 68, 69, 122, 66, 86, 77})
if err != nil {
log.Fatal(err)
}
fmt.Println(P1.Public, P2.Public)
}
Output: [248 69 226 11 251 195 84 145 220 51 63 112 231 156 98 5 249 8 166 80 85 46 193 196 160 126 66 55 174 118 128 32] [16 141 48 51 183 25 22 123 3 152 245 146 201 38 250 197 76 66 151 193 249 54 234 131 21 125 51 140 131 131 183 111]
type PrivateKey ¶
type PrivateKey []byte
func (PrivateKey) Bytes ¶
func (pri PrivateKey) Bytes() []byte
func (PrivateKey) PlainSecret ¶
func (pri PrivateKey) PlainSecret(pub PublicKey) ([]byte, error)
PlainSecret provides a shared secret (32 bytes) of the given private and public keys.
func (PrivateKey) Public ¶
func (pri PrivateKey) Public() (PublicKey, error)
Public provides the PublicKey of the given PrivateKey.
func (PrivateKey) Secret ¶
func (pri PrivateKey) Secret(pub PublicKey) (SharedSecret, error)
Secret provides a SHA3 hashed shared secret of the given private and public keys. SharedSecret size is 64 bytes hashed by SHAKE256.
Example ¶
package main
import (
"bytes"
"fmt"
"log"
"catinello.eu/ecdh25519"
)
var P1, P2 *ecdh25519.Pair
func main() {
s1, err := P1.Private.Secret(P2.Public)
if err != nil {
log.Fatal(err)
}
s2, err := P2.Private.Secret(P1.Public)
if err != nil {
log.Fatal(err)
}
fmt.Println(bytes.Compare(s1.Bytes(), s2.Bytes()))
}
Output: 0
type SharedSecret ¶
type SharedSecret []byte
func (SharedSecret) Bytes ¶
func (s SharedSecret) Bytes() []byte
Click to show internal directories.
Click to hide internal directories.