This repository has been archived on 2020-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
libricochet-go/utils/crypto_test.go

38 lines
877 B
Go
Raw Permalink Normal View History

2017-11-04 20:31:37 +00:00
package utils
import (
2018-09-22 20:12:08 +00:00
"crypto/rand"
"cwtch.im/tapir/utils"
2018-09-22 20:12:08 +00:00
"golang.org/x/crypto/ed25519"
"math"
2018-01-12 18:04:20 +00:00
"testing"
2017-11-04 20:31:37 +00:00
)
const (
privateKeyFile = "./../testing/private_key"
)
2017-11-04 20:31:37 +00:00
func TestLoadPrivateKey(t *testing.T) {
_, err := LoadPrivateKeyFromFile(privateKeyFile)
if err != nil {
t.Errorf("Error while loading private key from file: %v", err)
}
2017-11-04 20:31:37 +00:00
}
2018-09-22 20:12:08 +00:00
func TestEDH(t *testing.T) {
cpub, cpriv, _ := ed25519.GenerateKey(rand.Reader)
spub, spriv, _ := ed25519.GenerateKey(rand.Reader)
cedh, _ := utils.EDH(cpriv, spub)
sedh, _ := utils.EDH(spriv, cpub)
2018-09-22 20:12:08 +00:00
if string(cedh[:]) != string(sedh[:]) {
t.Errorf("Client and Server should see the same secret %v %v", cedh, sedh)
}
}
func TestGetRandNumber(t *testing.T) {
2018-01-12 18:04:20 +00:00
num := GetRandNumber()
if !num.IsUint64() || num.Uint64() > uint64(math.MaxUint32) {
t.Errorf("Error random number outside of expected bounds %v", num)
}
}