Skip to content

Commit 65cb3f2

Browse files
committed
BCCSP additional KeyGen and Hash Opts
This change-set introduces new options to generate keys and hash at given security level. It applies to: -ECDSA: P256, P384 curve support -RSA: 10247, 2048, 3072, 4096 key length -AES: 128, 192, 256 key length -SHA2: 256, 384 -SHA3: 256, 384 This change-set comes in the context of: https://jira.hyperledger.org/browse/FAB-354 Change-Id: I16518081281d38185c67946f84d6ae6dea2ed7ac Signed-off-by: Angelo De Caro <[email protected]>
1 parent 61affa0 commit 65cb3f2

File tree

10 files changed

+726
-97
lines changed

10 files changed

+726
-97
lines changed

core/crypto/bccsp/aesopts.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package bccsp
18+
19+
// AES128KeyGenOpts contains options for AES key generation at 128 security level
20+
type AES128KeyGenOpts struct {
21+
Temporary bool
22+
}
23+
24+
// Algorithm returns the key generation algorithm identifier (to be used).
25+
func (opts *AES128KeyGenOpts) Algorithm() string {
26+
return AES128
27+
}
28+
29+
// Ephemeral returns true if the key to generate has to be ephemeral,
30+
// false otherwise.
31+
func (opts *AES128KeyGenOpts) Ephemeral() bool {
32+
return opts.Temporary
33+
}
34+
35+
// AES192KeyGenOpts contains options for AES key generation at 192 security level
36+
type AES192KeyGenOpts struct {
37+
Temporary bool
38+
}
39+
40+
// Algorithm returns the key generation algorithm identifier (to be used).
41+
func (opts *AES192KeyGenOpts) Algorithm() string {
42+
return AES192
43+
}
44+
45+
// Ephemeral returns true if the key to generate has to be ephemeral,
46+
// false otherwise.
47+
func (opts *AES192KeyGenOpts) Ephemeral() bool {
48+
return opts.Temporary
49+
}
50+
51+
// AES256KeyGenOpts contains options for AES key generation at 256 security level
52+
type AES256KeyGenOpts struct {
53+
Temporary bool
54+
}
55+
56+
// Algorithm returns the key generation algorithm identifier (to be used).
57+
func (opts *AES256KeyGenOpts) Algorithm() string {
58+
return AES256
59+
}
60+
61+
// Ephemeral returns true if the key to generate has to be ephemeral,
62+
// false otherwise.
63+
func (opts *AES256KeyGenOpts) Ephemeral() bool {
64+
return opts.Temporary
65+
}

core/crypto/bccsp/bccsp.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ type Key interface {
4747
// KeyGenOpts contains options for key-generation with a CSP.
4848
type KeyGenOpts interface {
4949

50-
// Algorithm returns an identifier for the algorithm to be used
51-
// to generate a key.
50+
// Algorithm returns the key generation algorithm identifier (to be used).
5251
Algorithm() string
5352

5453
// Ephemeral returns true if the key to generate has to be ephemeral,
@@ -59,8 +58,7 @@ type KeyGenOpts interface {
5958
// KeyDerivOpts contains options for key-derivation with a CSP.
6059
type KeyDerivOpts interface {
6160

62-
// Algorithm returns an identifier for the algorithm to be used
63-
// to derive a key.
61+
// Algorithm returns the key derivation algorithm identifier (to be used).
6462
Algorithm() string
6563

6664
// Ephemeral returns true if the key to derived has to be ephemeral,
@@ -70,8 +68,8 @@ type KeyDerivOpts interface {
7068

7169
// KeyImportOpts contains options for importing the raw material of a key with a CSP.
7270
type KeyImportOpts interface {
73-
// Algorithm returns an identifier for the algorithm to be used
74-
// to import the raw material of a key.
71+
72+
// Algorithm returns the key importation algorithm identifier (to be used).
7573
Algorithm() string
7674

7775
// Ephemeral returns true if the key generated has to be ephemeral,
@@ -81,8 +79,8 @@ type KeyImportOpts interface {
8179

8280
// HashOpts contains options for hashing with a CSP.
8381
type HashOpts interface {
84-
// Algorithm returns an identifier for the algorithm to be used
85-
// to hash.
82+
83+
// Algorithm returns the hash algorithm identifier (to be used).
8684
Algorithm() string
8785
}
8886

core/crypto/bccsp/ecdsaopts.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package bccsp
18+
19+
// ECDSAP256KeyGenOpts contains options for ECDSA key generation with curve P-256.
20+
type ECDSAP256KeyGenOpts struct {
21+
Temporary bool
22+
}
23+
24+
// Algorithm returns the key generation algorithm identifier (to be used).
25+
func (opts *ECDSAP256KeyGenOpts) Algorithm() string {
26+
return ECDSAP256
27+
}
28+
29+
// Ephemeral returns true if the key to generate has to be ephemeral,
30+
// false otherwise.
31+
func (opts *ECDSAP256KeyGenOpts) Ephemeral() bool {
32+
return opts.Temporary
33+
}
34+
35+
// ECDSAP384KeyGenOpts contains options for ECDSA key generation with curve P-384.
36+
type ECDSAP384KeyGenOpts struct {
37+
Temporary bool
38+
}
39+
40+
// Algorithm returns the key generation algorithm identifier (to be used).
41+
func (opts *ECDSAP384KeyGenOpts) Algorithm() string {
42+
return ECDSAP384
43+
}
44+
45+
// Ephemeral returns true if the key to generate has to be ephemeral,
46+
// false otherwise.
47+
func (opts *ECDSAP384KeyGenOpts) Ephemeral() bool {
48+
return opts.Temporary
49+
}
File renamed without changes.

core/crypto/bccsp/hashopts.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package bccsp
18+
19+
// SHA256Opts contains options relating to SHA-256.
20+
type SHA256Opts struct {
21+
}
22+
23+
// Algorithm returns the hash algorithm identifier (to be used).
24+
func (opts *SHA256Opts) Algorithm() string {
25+
return SHA256
26+
}
27+
28+
// SHA384Opts contains options relating to SHA-384.
29+
type SHA384Opts struct {
30+
}
31+
32+
// Algorithm returns the hash algorithm identifier (to be used).
33+
func (opts *SHA384Opts) Algorithm() string {
34+
return SHA384
35+
}
36+
37+
// SHA3_256Opts contains options relating to SHA3-256.
38+
type SHA3_256Opts struct {
39+
}
40+
41+
// Algorithm returns the hash algorithm identifier (to be used).
42+
func (opts *SHA3_256Opts) Algorithm() string {
43+
return SHA3_256
44+
}
45+
46+
// SHA3_384Opts contains options relating to SHA3-384.
47+
type SHA3_384Opts struct {
48+
}
49+
50+
// Algorithm returns the hash algorithm identifier (to be used).
51+
func (opts *SHA3_384Opts) Algorithm() string {
52+
return SHA3_384
53+
}

0 commit comments

Comments
 (0)