Documentation ¶
Overview ¶
package crypto implements various cryptographic utilities used by ipfs. This includes a Public and Private key interface and an RSA key implementation that satisfies it.
Index ¶
- Constants
- Variables
- func ConfigDecodeKey(b string) ([]byte, error)
- func ConfigEncodeKey(b []byte) string
- func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error)
- func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error)
- func KeyEqual(k1, k2 Key) bool
- func KeyHash(k Key) ([]byte, error)
- func KeyStretcher(cipherType string, hashType string, secret []byte) (StretchedKeys, StretchedKeys)
- func MarshalPrivateKey(k PrivKey) ([]byte, error)
- func MarshalPublicKey(k PubKey) ([]byte, error)
- func MarshalRsaPrivateKey(k *RsaPrivateKey) []byte
- func MarshalRsaPublicKey(k *RsaPublicKey) ([]byte, error)
- type GenSharedKey
- type Key
- type PrivKey
- type PubKey
- type RsaPrivateKey
- func (sk *RsaPrivateKey) Bytes() ([]byte, error)
- func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error)
- func (sk *RsaPrivateKey) Equals(k Key) bool
- func (sk *RsaPrivateKey) GenSecret() []byte
- func (sk *RsaPrivateKey) GetPublic() PubKey
- func (sk *RsaPrivateKey) Hash() ([]byte, error)
- func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error)
- type RsaPublicKey
- type StretchedKeys
Constants ¶
const (
RSA = iota
)
Variables ¶
var ErrBadKeyType = errors.New("invalid or unsupported key type")
Functions ¶
func ConfigDecodeKey ¶
ConfigDecodeKey decodes from b64 (for config file), and unmarshals.
func ConfigEncodeKey ¶
ConfigEncodeKey encodes to b64 (for config file), and marshals.
func GenerateKeyPairWithReader ¶
Generates a keypair of the given type and bitsize
func KeyStretcher ¶
func KeyStretcher(cipherType string, hashType string, secret []byte) (StretchedKeys, StretchedKeys)
Generates a set of keys for each party by stretching the shared key. (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey)
func MarshalPrivateKey ¶
MarshalPrivateKey converts a key object into its protobuf serialized form.
func MarshalPublicKey ¶
MarshalPublicKey converts a public key object into a protobuf serialized public key
func MarshalRsaPrivateKey ¶
func MarshalRsaPrivateKey(k *RsaPrivateKey) []byte
func MarshalRsaPublicKey ¶
func MarshalRsaPublicKey(k *RsaPublicKey) ([]byte, error)
Types ¶
type GenSharedKey ¶
Given a public key, generates the shared key.
func GenerateEKeyPair ¶
func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error)
Generates an ephemeral public key and returns a function that will compute the shared secret key. Used in the identify module.
Focuses only on ECDH now, but can be made more general in the future.
type Key ¶
type Key interface { // Bytes returns a serialized, storeable representation of this key Bytes() ([]byte, error) // Hash returns the hash of this key Hash() ([]byte, error) // Equals checks whether two PubKeys are the same Equals(Key) bool }
Key represents a crypto key that can be compared to another key
type PrivKey ¶
type PrivKey interface { Key // Cryptographically sign the given bytes Sign([]byte) ([]byte, error) // Return a public key paired with this private key GetPublic() PubKey // Generate a secret string of bytes GenSecret() []byte Decrypt(b []byte) ([]byte, error) }
PrivKey represents a private key that can be used to generate a public key, sign data, and decrypt data that was encrypted with a public key
func UnmarshalPrivateKey ¶
UnmarshalPrivateKey converts a protobuf serialized private key into its representative object
type PubKey ¶
type PubKey interface { Key // Verify that 'sig' is the signed hash of 'data' Verify(data []byte, sig []byte) (bool, error) // Encrypt data in a way that can be decrypted by a paired private key Encrypt(data []byte) ([]byte, error) }
func UnmarshalPublicKey ¶
UnmarshalPublicKey converts a protobuf serialized public key into its representative object
type RsaPrivateKey ¶
type RsaPrivateKey struct {
// contains filtered or unexported fields
}
func UnmarshalRsaPrivateKey ¶
func UnmarshalRsaPrivateKey(b []byte) (*RsaPrivateKey, error)
func (*RsaPrivateKey) Bytes ¶
func (sk *RsaPrivateKey) Bytes() ([]byte, error)
func (*RsaPrivateKey) Equals ¶
func (sk *RsaPrivateKey) Equals(k Key) bool
Equals checks whether this key is equal to another
func (*RsaPrivateKey) GenSecret ¶
func (sk *RsaPrivateKey) GenSecret() []byte
func (*RsaPrivateKey) GetPublic ¶
func (sk *RsaPrivateKey) GetPublic() PubKey
func (*RsaPrivateKey) Hash ¶
func (sk *RsaPrivateKey) Hash() ([]byte, error)
type RsaPublicKey ¶
type RsaPublicKey struct {
// contains filtered or unexported fields
}
func UnmarshalRsaPublicKey ¶
func UnmarshalRsaPublicKey(b []byte) (*RsaPublicKey, error)
func (*RsaPublicKey) Bytes ¶
func (pk *RsaPublicKey) Bytes() ([]byte, error)
func (*RsaPublicKey) Equals ¶
func (pk *RsaPublicKey) Equals(k Key) bool
Equals checks whether this key is equal to another
func (*RsaPublicKey) Hash ¶
func (pk *RsaPublicKey) Hash() ([]byte, error)
type StretchedKeys ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
pb
Package crypto_pb is a generated protocol buffer package.
|
Package crypto_pb is a generated protocol buffer package. |
package secio handles establishing secure communication between two peers.
|
package secio handles establishing secure communication between two peers. |
internal/pb
Package spipe_pb is a generated protocol buffer package.
|
Package spipe_pb is a generated protocol buffer package. |
pb
Package spipe_pb is a generated protocol buffer package.
|
Package spipe_pb is a generated protocol buffer package. |