forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:KMS support for BBS+ keys: create Tink key templates
closes hyperledger-archives#2548 Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
- Loading branch information
Baha Shaaban
committed
Feb 24, 2021
1 parent
c90ef9f
commit bf9b04c
Showing
4 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package bbs | ||
|
||
import ( | ||
"github.com/golang/protobuf/proto" | ||
commonpb "github.com/google/tink/go/proto/common_go_proto" | ||
tinkpb "github.com/google/tink/go/proto/tink_go_proto" | ||
|
||
bbspb "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/proto/bbs_go_proto" | ||
) | ||
|
||
// BLS12381G2KeyTemplate creates a Tink key template for BBS+ on BLS12-381 curve with G2 group. | ||
func BLS12381G2KeyTemplate() *tinkpb.KeyTemplate { | ||
return createKeyTemplate(bbspb.BBSCurveType_BLS12_381, bbspb.GroupField_G2, commonpb.HashType_SHA256) | ||
} | ||
|
||
// createKeyTemplate for BBS+ keys. | ||
func createKeyTemplate(curve bbspb.BBSCurveType, group bbspb.GroupField, hash commonpb.HashType) *tinkpb.KeyTemplate { | ||
format := &bbspb.BBSKeyFormat{ | ||
Params: &bbspb.BBSParams{ | ||
HashType: hash, | ||
Curve: curve, | ||
Group: group, | ||
}, | ||
} | ||
|
||
serializedFormat, err := proto.Marshal(format) | ||
if err != nil { | ||
panic("failed to marshal BBSKeyFormat proto") | ||
} | ||
|
||
return &tinkpb.KeyTemplate{ | ||
TypeUrl: bbsSignerKeyTypeURL, | ||
Value: serializedFormat, | ||
OutputPrefixType: tinkpb.OutputPrefixType_RAW, | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
pkg/crypto/tinkcrypto/primitive/bbs/bbs_key_template_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package bbs | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/google/tink/go/keyset" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBBSKeyTemplateSuccess(t *testing.T) { | ||
kt := BLS12381G2KeyTemplate() | ||
|
||
kh, err := keyset.NewHandle(kt) | ||
require.NoError(t, err) | ||
|
||
pubKH, err := kh.Public() | ||
require.NoError(t, err) | ||
|
||
// now test the BBS primitives with these keyset handles | ||
signer, err := NewSigner(kh) | ||
require.NoError(t, err) | ||
|
||
messages := [][]byte{[]byte("msg abc"), []byte("msg def"), []byte("msg ghi")} | ||
|
||
sig, err := signer.Sign(messages) | ||
require.NoError(t, err) | ||
|
||
verifier, err := NewVerifier(pubKH) | ||
require.NoError(t, err) | ||
|
||
err = verifier.Verify(messages, sig) | ||
require.NoError(t, err) | ||
|
||
revealedIndexes := []int{1, 2} | ||
nonce := make([]byte, 10) | ||
|
||
_, err = rand.Read(nonce) | ||
require.NoError(t, err) | ||
|
||
proof, err := verifier.DeriveProof(messages, sig, nonce, revealedIndexes) | ||
require.NoError(t, err) | ||
|
||
revealedMsgs := [][]byte{messages[1], messages[2]} | ||
|
||
err = verifier.VerifyProof(revealedMsgs, proof, nonce) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters