-
Notifications
You must be signed in to change notification settings - Fork 0
/
curve.go
executable file
·61 lines (51 loc) · 1.24 KB
/
curve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright © Sisu network contributors
//
// This file is a derived work from Binance's tss-lib. Please refer to the
// LICENSE copyright file at the root directory for usage of the source code.
//
// Original license:
//
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package tss
import (
"crypto/elliptic"
"fmt"
"strings"
s256k1 "github.com/btcsuite/btcd/btcec/v2"
"github.com/decred/dcrd/dcrec/edwards/v2"
)
const (
EcdsaScheme = "ecdsa"
EddsaScheme = "eddsa"
)
var (
ed, ec elliptic.Curve
)
// Init default curve (secp256k1)
func init() {
ec = s256k1.S256()
ed = edwards.Edwards()
}
// EC returns the current elliptic curve in use. The default is secp256k1
func EC(scheme string) elliptic.Curve {
switch strings.ToLower(scheme) {
case "", EcdsaScheme:
return ec
case EddsaScheme:
return ed
default:
panic(fmt.Errorf("Unknown curve: %s", scheme))
}
}
func GetCurveScheme(curve elliptic.Curve) string {
if curve == ec {
return "ecdsa"
} else if curve == ed {
return "eddsa"
}
panic(fmt.Errorf("Unknown curve %v", curve))
}