github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/protocol/cipher.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package protocol 4 5 // Cipher represents an implementation for a cipher 6 type Cipher interface { 7 CipherSuite() CipherSuite 8 PublicKey() Codec // DER, PEM, ... 9 // SymmetricKey() []byte // length depend on CipherSuite Can't store it due to security impact 10 } 11 12 // A BlockCipher represents an implementation of block cipher 13 // using a given key. It provides the capability to encrypt 14 // or decrypt individual blocks. The mode implementations 15 // extend that capability to streams of blocks. 16 type BlockCipher interface { 17 // BlockSize returns the cipher's block size. 18 BlockSize() int 19 20 // Encrypt encrypts the first block in src into dst. 21 // Dst and src must overlap entirely or not at all. 22 Encrypt(dst, src []byte) 23 24 // Decrypt decrypts the first block in src into dst. 25 // Dst and src must overlap entirely or not at all. 26 Decrypt(dst, src []byte) 27 } 28 29 // A Stream represents a stream cipher. 30 type StreamCipher interface { 31 // XORKeyStream XORs each byte in the given slice with a byte from the 32 // cipher's key stream. Dst and src must overlap entirely or not at all. 33 // 34 // If len(dst) < len(src), XORKeyStream should panic. It is acceptable 35 // to pass a dst bigger than src, and in that case, XORKeyStream will 36 // only update dst[:len(src)] and will not touch the rest of dst. 37 // 38 // Multiple calls to XORKeyStream behave as if the concatenation of 39 // the src buffers was passed in a single run. That is, Stream 40 // maintains state and does not reset at each XORKeyStream call. 41 XORKeyStream(dst, src []byte) 42 } 43 44 // https://en.wikipedia.org/wiki/Cipher_suite 45 type CipherSuite interface { 46 Stringer // e.g. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 47 48 ID() uint64 // hash of Stringer like GitiURN 49 Protocol() string // Defines the protocol that this cipher suite is for e.g. TLS 50 KeyExchange() string // indicates the key exchange algorithm being used e.g. ECDHE 51 Authentication() string // authentication mechanism during the handshake e.g. RSA 52 SessionCipher() string // Encryption and Decryption mechanism e.g. AES 53 EncryptionKeySize() string // session encryption key size (bits) for cipher e.g. 128 54 EncryptionType() string // Type of encryption (cipher-block dependency and additional options) e.g. GCM 55 Hash() string // Signature mechanism. Indicates the message authentication algorithm which is used to authenticate a message. e.g. SHA(SHA2) 56 57 // Insecure is true if the cipher suite has known security issues 58 // due to its primitives, design, or implementation. 59 Insecure() bool 60 }