-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-9672] Idemix User Key Generator
This change-set does the following: - implement the idemix user key generator - tests Change-Id: Iaa2b1b1fda5eee2278cd45e235bf17489f8351a2 Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
- Loading branch information
Showing
6 changed files
with
389 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package idemix | ||
|
||
import ( | ||
"crypto/sha256" | ||
|
||
"github.com/hyperledger/fabric/bccsp" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// userSecretKey contains the User secret key | ||
type userSecretKey struct { | ||
// sk is the idemix reference to the User key | ||
sk Big | ||
// Exportable if true, sk can be exported via the Bytes function | ||
exportable bool | ||
} | ||
|
||
func NewUserSecretKey(sk Big, exportable bool) *userSecretKey { | ||
return &userSecretKey{sk: sk, exportable: exportable} | ||
} | ||
|
||
func (k *userSecretKey) Bytes() ([]byte, error) { | ||
if k.exportable { | ||
return k.sk.Bytes() | ||
} | ||
|
||
return nil, errors.New("not exportable") | ||
} | ||
|
||
func (k *userSecretKey) SKI() []byte { | ||
raw, err := k.sk.Bytes() | ||
if err != nil { | ||
return nil | ||
} | ||
hash := sha256.New() | ||
hash.Write(raw) | ||
return hash.Sum(nil) | ||
} | ||
|
||
func (*userSecretKey) Symmetric() bool { | ||
return true | ||
} | ||
|
||
func (*userSecretKey) Private() bool { | ||
return true | ||
} | ||
|
||
func (k *userSecretKey) PublicKey() (bccsp.Key, error) { | ||
return nil, errors.New("cannot call this method on a symmetric key") | ||
} | ||
|
||
type UserKeyGen struct { | ||
// Exportable is a flag to allow an issuer secret key to be marked as Exportable. | ||
// If a secret key is marked as Exportable, its Bytes method will return the key's byte representation. | ||
Exportable bool | ||
// User implements the underlying cryptographic algorithms | ||
User User | ||
} | ||
|
||
func (g *UserKeyGen) KeyGen(opts bccsp.KeyGenOpts) (bccsp.Key, error) { | ||
sk, err := g.User.NewKey() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &userSecretKey{exportable: g.Exportable, sk: sk}, nil | ||
} |
Oops, something went wrong.