This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
forked from keys-pub/zkgroup
-
Notifications
You must be signed in to change notification settings - Fork 3
/
group.go
70 lines (59 loc) · 2.31 KB
/
group.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
62
63
64
65
66
67
68
69
70
package zkgroup
/*
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_x86_64
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_aarch64
#cgo linux,arm LDFLAGS: -L${SRCDIR}/lib '-Wl,-rpath,$$ORIGIN/' -lzkgroup_linux_armv7
#include "lib/zkgroup.h"
*/
import "C"
// GroupSecretParams ...
type GroupSecretParams []byte
// GenerateGroupSecretParams ...
func GenerateGroupSecretParams() (GroupSecretParams, error) {
return GenerateGroupSecretParamsDeterministic(randBytes(32))
}
// GenerateGroupSecretParamsDeterministic ...
func GenerateGroupSecretParamsDeterministic(random []byte) (GroupSecretParams, error) {
out := make([]byte, C.GROUP_SECRET_PARAMS_LEN)
if res := C.FFI_GroupSecretParams_generateDeterministic(cBytes(random), cLen(random), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return GroupSecretParams(out), nil
}
// NewGroupSecretParams ...
// DeriveFromMasterKey
func NewGroupSecretParams(masterKey []byte) (GroupSecretParams, error) {
out := make([]byte, C.GROUP_SECRET_PARAMS_LEN)
if res := C.FFI_GroupSecretParams_deriveFromMasterKey(cBytes(masterKey), cLen(masterKey), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return GroupSecretParams(out), nil
}
// MasterKey ...
func (g GroupSecretParams) MasterKey() ([]byte, error) {
out := make([]byte, 32)
if res := C.FFI_GroupSecretParams_getMasterKey(cBytes(g), cLen(g), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return out, nil
}
// PublicParams ...
func (g GroupSecretParams) PublicParams() (GroupPublicParams, error) {
out := make([]byte, C.GROUP_PUBLIC_PARAMS_LEN)
if res := C.FFI_GroupSecretParams_getPublicParams(cBytes(g), cLen(g), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return GroupPublicParams(out), nil
}
// GroupPublicParams ...
type GroupPublicParams []byte
// GroupIdentifier ...
type GroupIdentifier []byte
// GroupIdentifier ...
func (g GroupPublicParams) GroupIdentifier() (GroupIdentifier, error) {
out := make([]byte, C.GROUP_IDENTIFIER_LEN)
if res := C.FFI_GroupPublicParams_getGroupIdentifier(cBytes(g), cLen(g), cBytes(out), cLen(out)); res != C.FFI_RETURN_OK {
return nil, errFromCode(res)
}
return GroupIdentifier(out), nil
}