-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgroup.go
66 lines (56 loc) · 2.07 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
package zkgroup
/*
#cgo LDFLAGS: ${SRCDIR}/lib/libzkgroup.a
#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 ...
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
}