File: curve4Q.go

package info (click to toggle)
golang-github-cloudflare-circl 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,064 kB
  • sloc: asm: 20,492; ansic: 1,292; makefile: 68
file content (29 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
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
package curve4q

import "github.com/cloudflare/circl/ecc/fourq"

// Size is the size in bytes of keys.
const Size = 32

// Key represents a public or private key of FourQ.
type Key [Size]byte

// KeyGen calculates a public key k from a secret key.
func KeyGen(public, secret *Key) {
	var P fourq.Point
	P.ScalarBaseMult((*[Size]byte)(secret))
	P.Marshal((*[Size]byte)(public))
}

// Shared calculates a shared key k from Alice's secret and Bob's public key.
// Returns true on success.
func Shared(shared, secret, public *Key) bool {
	var P, Q fourq.Point
	ok := P.Unmarshal((*[Size]byte)(public))
	if !ok {
		return false
	}
	Q.ScalarMult((*[Size]byte)(secret), &P)
	Q.Marshal((*[Size]byte)(shared))
	return !Q.IsIdentity() && Q.IsOnCurve()
}