github.com/defanghe/fabric@v2.1.1+incompatible/bccsp/sw/internals.go (about) 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 sw 18 19 import ( 20 "hash" 21 22 "github.com/hyperledger/fabric/bccsp" 23 ) 24 25 // KeyGenerator is a BCCSP-like interface that provides key generation algorithms 26 type KeyGenerator interface { 27 28 // KeyGen generates a key using opts. 29 KeyGen(opts bccsp.KeyGenOpts) (k bccsp.Key, err error) 30 } 31 32 // KeyDeriver is a BCCSP-like interface that provides key derivation algorithms 33 type KeyDeriver interface { 34 35 // KeyDeriv derives a key from k using opts. 36 // The opts argument should be appropriate for the primitive used. 37 KeyDeriv(k bccsp.Key, opts bccsp.KeyDerivOpts) (dk bccsp.Key, err error) 38 } 39 40 // KeyImporter is a BCCSP-like interface that provides key import algorithms 41 type KeyImporter interface { 42 43 // KeyImport imports a key from its raw representation using opts. 44 // The opts argument should be appropriate for the primitive used. 45 KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (k bccsp.Key, err error) 46 } 47 48 // Encryptor is a BCCSP-like interface that provides encryption algorithms 49 type Encryptor interface { 50 51 // Encrypt encrypts plaintext using key k. 52 // The opts argument should be appropriate for the algorithm used. 53 Encrypt(k bccsp.Key, plaintext []byte, opts bccsp.EncrypterOpts) (ciphertext []byte, err error) 54 } 55 56 // Decryptor is a BCCSP-like interface that provides decryption algorithms 57 type Decryptor interface { 58 59 // Decrypt decrypts ciphertext using key k. 60 // The opts argument should be appropriate for the algorithm used. 61 Decrypt(k bccsp.Key, ciphertext []byte, opts bccsp.DecrypterOpts) (plaintext []byte, err error) 62 } 63 64 // Signer is a BCCSP-like interface that provides signing algorithms 65 type Signer interface { 66 67 // Sign signs digest using key k. 68 // The opts argument should be appropriate for the algorithm used. 69 // 70 // Note that when a signature of a hash of a larger message is needed, 71 // the caller is responsible for hashing the larger message and passing 72 // the hash (as digest). 73 Sign(k bccsp.Key, digest []byte, opts bccsp.SignerOpts) (signature []byte, err error) 74 } 75 76 // Verifier is a BCCSP-like interface that provides verifying algorithms 77 type Verifier interface { 78 79 // Verify verifies signature against key k and digest 80 // The opts argument should be appropriate for the algorithm used. 81 Verify(k bccsp.Key, signature, digest []byte, opts bccsp.SignerOpts) (valid bool, err error) 82 } 83 84 // Hasher is a BCCSP-like interface that provides hash algorithms 85 type Hasher interface { 86 87 // Hash hashes messages msg using options opts. 88 // If opts is nil, the default hash function will be used. 89 Hash(msg []byte, opts bccsp.HashOpts) (hash []byte, err error) 90 91 // GetHash returns and instance of hash.Hash using options opts. 92 // If opts is nil, the default hash function will be returned. 93 GetHash(opts bccsp.HashOpts) (h hash.Hash, err error) 94 }