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 <[email protected]>
- Loading branch information
konstantin.goncharov
committed
Aug 10, 2022
1 parent
6c0753b
commit a27d8e9
Showing
45 changed files
with
1,610 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") | ||
} |
Oops, something went wrong.