This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extended Crypto API with SignWithSecrets and Blind methods * refactored CL primitives * implemented new methods for tinkcrypto * formatted all ursa code * added ursautil for common ursa methods * added stubs for CL for remotecrypto and non-ursa tinkcrypto build * added unit tests Signed-off-by: konstantin.goncharov <konstantin.goncharov@avast.com> Signed-off-by: konstantin.goncharov <konstantin.goncharov@avast.com>
- Loading branch information
1 parent
9957132
commit 45c3566
Showing
47 changed files
with
1,675 additions
and
1,423 deletions.
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
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
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
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,112 @@ | ||
//go:build ursa | ||
// +build ursa | ||
|
||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/tink/go/keyset" | ||
|
||
bld "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/cl/blinder" | ||
sgn "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto/primitive/cl/signer" | ||
) | ||
|
||
// Blind will blind provided values with MasterSecret provided in a kh | ||
// returns: | ||
// blinded values in []byte | ||
// error in case of errors | ||
func (t *Crypto) Blind(kh interface{}, values ...map[string]interface{}) ([][]byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, errBadKeyHandleFormat | ||
} | ||
|
||
blinder, err := bld.NewBlinder(keyHandle) | ||
if err != nil { | ||
return nil, fmt.Errorf("create new CL blinder: %w", err) | ||
} | ||
|
||
defer blinder.Free() // nolint: errcheck | ||
|
||
if len(values) == 0 { | ||
blinded, err := blinder.Blind(map[string]interface{}{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return [][]byte{blinded}, nil | ||
} | ||
|
||
blindedList := make([][]byte, len(values)) | ||
|
||
for i, val := range values { | ||
blinded, err := blinder.Blind(val) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blindedList[i] = blinded | ||
} | ||
|
||
return blindedList, nil | ||
} | ||
|
||
// GetCorrectnessProof will return correctness proof for a public key handle | ||
// returns: | ||
// correctness proof in []byte | ||
// error in case of errors | ||
func (t *Crypto) GetCorrectnessProof(kh interface{}) ([]byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, errBadKeyHandleFormat | ||
} | ||
|
||
signer, err := sgn.NewSigner(keyHandle) | ||
if err != nil { | ||
return nil, fmt.Errorf("create new CL signer: %w", err) | ||
} | ||
|
||
defer signer.Free() // nolint: errcheck | ||
|
||
correctnessProof, err := signer.GetCorrectnessProof() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return correctnessProof, nil | ||
} | ||
|
||
// SignWithSecrets will generate a signature and related correctness proof | ||
// for the provided values using secrets and related DID | ||
// returns: | ||
// signature in []byte | ||
// correctness proof in []byte | ||
// error in case of errors | ||
func (t *Crypto) SignWithSecrets(kh interface{}, values map[string]interface{}, | ||
secrets []byte, correctnessProof []byte, nonces [][]byte, did string) ([]byte, []byte, error) { | ||
keyHandle, ok := kh.(*keyset.Handle) | ||
if !ok { | ||
return nil, nil, errBadKeyHandleFormat | ||
} | ||
|
||
signer, err := sgn.NewSigner(keyHandle) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("create new CL signer: %w", err) | ||
} | ||
|
||
defer signer.Free() // nolint: errcheck | ||
|
||
signature, signatureCorrectnessProof, err := signer.Sign(values, secrets, correctnessProof, nonces, did) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return signature, signatureCorrectnessProof, nil | ||
} |
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,44 @@ | ||
//go:build !ursa | ||
// +build !ursa | ||
|
||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// Blind will blind provided values with MasterSecret provided in a kh | ||
// returns: | ||
// blinded values in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) Blind(kh interface{}, values ...map[string]interface{}) ([][]byte, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
// GetCorrectnessProof will return correctness proof for a public key handle | ||
// returns: | ||
// correctness proof in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) GetCorrectnessProof(kh interface{}) ([]byte, error) { | ||
return nil, errors.New("not implemented") | ||
} | ||
|
||
// SignWithSecrets will generate a signature and related correctness proof | ||
// for the provided values using secrets and related DID | ||
// returns: | ||
// signature in []byte | ||
// correctness proof in []byte | ||
// error in case of errors | ||
// STUB. | ||
func (t *Crypto) SignWithSecrets(kh interface{}, values map[string]interface{}, | ||
secrets []byte, correctnessProof []byte, nonces [][]byte, did string) ([]byte, []byte, error) { | ||
return nil, nil, errors.New("not implemented") | ||
} |
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,35 @@ | ||
//go:build !ursa | ||
// +build !ursa | ||
|
||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package tinkcrypto | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCLStubs(t *testing.T) { | ||
c := Crypto{} | ||
|
||
t.Run("test CL methods return not implemented", func(t *testing.T) { | ||
errNotImplemented := errors.New("not implemented") | ||
var err error | ||
|
||
_, err = c.GetCorrectnessProof(nil) | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
|
||
_, _, err = c.SignWithSecrets(nil, map[string]interface{}{}, nil, nil, nil, "") | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
|
||
_, err = c.Blind(nil, map[string]interface{}{}) | ||
require.EqualError(t, err, errNotImplemented.Error()) | ||
}) | ||
} |
Oops, something went wrong.