forked from hyperledger/fabric-sdk-go
/
cryptosuitebridge.go
119 lines (100 loc) · 3.96 KB
/
cryptosuitebridge.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Please review third_party pinning scripts and patches for more details.
*/
package cryptosuitebridge
import (
"crypto"
"crypto/ecdsa"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp"
cspsigner "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/signer"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/utils"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
)
const (
ECDSA = bccsp.ECDSA
ECDSAP256 = bccsp.ECDSAP256
ECDSAP384 = bccsp.ECDSAP384
ECDSAReRand = bccsp.ECDSAReRand
RSA = bccsp.RSA
RSA1024 = bccsp.RSA1024
RSA2048 = bccsp.RSA2048
RSA3072 = bccsp.RSA3072
RSA4096 = bccsp.RSA4096
AES = bccsp.AES
AES128 = bccsp.AES128
AES192 = bccsp.AES192
AES256 = bccsp.AES256
HMAC = bccsp.HMAC
HMACTruncated256 = bccsp.HMACTruncated256
SHA = bccsp.SHA
SHA2 = bccsp.SHA2
SHA3 = bccsp.SHA3
SHA256 = bccsp.SHA256
SHA384 = bccsp.SHA384
SHA3_256 = bccsp.SHA3_256
SHA3_384 = bccsp.SHA3_384
X509Certificate = bccsp.X509Certificate
)
// NewCspSigner is a bridge for bccsp signer.New call
func NewCspSigner(csp core.CryptoSuite, key core.Key) (crypto.Signer, error) {
return cspsigner.New(csp, key)
}
// PEMtoPrivateKey is a bridge for bccsp utils.PEMtoPrivateKey()
func PEMtoPrivateKey(raw []byte, pwd []byte) (interface{}, error) {
return utils.PEMtoPrivateKey(raw, pwd)
}
// PrivateKeyToDER marshals is bridge for utils.PrivateKeyToDER
func PrivateKeyToDER(privateKey *ecdsa.PrivateKey) ([]byte, error) {
return utils.PrivateKeyToDER(privateKey)
}
//GetDefault returns default cryptosuite from bccsp factory default
func GetDefault() core.CryptoSuite {
return cryptosuite.GetDefault()
}
//GetSHAOpts returns options for computing SHA.
func GetSHAOpts() core.HashOpts {
return &bccsp.SHAOpts{}
}
//GetSHA256Opts returns options relating to SHA-256.
func GetSHA256Opts() core.HashOpts {
return &bccsp.SHA256Opts{}
}
//GetRSA2048KeyGenOpts returns options for RSA key generation at 2048 security.
func GetRSA2048KeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.RSA2048KeyGenOpts{Temporary: ephemeral}
}
//GetRSA3072KeyGenOpts returns options for RSA key generation at 3072 security.
func GetRSA3072KeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.RSA3072KeyGenOpts{Temporary: ephemeral}
}
//GetRSA4096KeyGenOpts returns options for RSA key generation at 4096 security.
func GetRSA4096KeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.RSA4096KeyGenOpts{Temporary: ephemeral}
}
// GetECDSAKeyGenOpts returns options for ECDSA key generation.
func GetECDSAKeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.ECDSAKeyGenOpts{Temporary: ephemeral}
}
//GetECDSAP256KeyGenOpts returns options for ECDSA key generation with curve P-256.
func GetECDSAP256KeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.ECDSAP256KeyGenOpts{Temporary: ephemeral}
}
//GetECDSAP384KeyGenOpts options for ECDSA key generation with curve P-384.
func GetECDSAP384KeyGenOpts(ephemeral bool) core.KeyGenOpts {
return &bccsp.ECDSAP384KeyGenOpts{Temporary: ephemeral}
}
//GetX509PublicKeyImportOpts options for importing public keys from an x509 certificate
func GetX509PublicKeyImportOpts(ephemeral bool) core.KeyImportOpts {
return &bccsp.X509PublicKeyImportOpts{Temporary: ephemeral}
}
//GetECDSAPrivateKeyImportOpts options for ECDSA secret key importation in DER format
// or PKCS#8 format.
func GetECDSAPrivateKeyImportOpts(ephemeral bool) core.KeyImportOpts {
return &bccsp.ECDSAPrivateKeyImportOpts{Temporary: ephemeral}
}