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 GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error)
- func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error)
- func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error)
- func GenerateSecp256k1Key(src io.Reader) (PrivKey, PubKey, error)
- func KeyEqual(k1, k2 Key) bool
- 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 Ed25519PrivateKey
- func (k *Ed25519PrivateKey) Bytes() ([]byte, error)
- func (k *Ed25519PrivateKey) Equals(o Key) bool
- func (k *Ed25519PrivateKey) GetPublic() PubKey
- func (k *Ed25519PrivateKey) Raw() ([]byte, error)
- func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)
- func (k *Ed25519PrivateKey) ToCurve25519() *[32]byte
- func (k *Ed25519PrivateKey) Type() pb.KeyType
- type Ed25519PublicKey
- func (k *Ed25519PublicKey) Bytes() ([]byte, error)
- func (k *Ed25519PublicKey) Equals(o Key) bool
- func (k *Ed25519PublicKey) Raw() ([]byte, error)
- func (k *Ed25519PublicKey) ToCurve25519() (*[32]byte, error)
- func (k *Ed25519PublicKey) Type() pb.KeyType
- func (k *Ed25519PublicKey) Verify(data []byte, sig []byte) (bool, error)
- type GenSharedKey
- type Key
- type PrivKey
- type PrivKeyUnmarshaller
- type PubKey
- type PubKeyUnmarshaller
- 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) GetPublic() PubKey
- func (sk *RsaPrivateKey) Raw() ([]byte, error)
- func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error)
- func (sk *RsaPrivateKey) Type() pb.KeyType
- type RsaPublicKey
- type Secp256k1PrivateKey
- func (sk *Secp256k1PrivateKey) Bytes() ([]byte, error)
- func (k *Secp256k1PrivateKey) Equals(o Key) bool
- func (k *Secp256k1PrivateKey) GetPublic() PubKey
- func (k *Secp256k1PrivateKey) Raw() ([]byte, error)
- func (k *Secp256k1PrivateKey) Sign(data []byte) ([]byte, error)
- func (sk *Secp256k1PrivateKey) Type() pb.KeyType
- type Secp256k1PublicKey
- type StretchedKeys
Constants ¶
const ( RSA = iota Ed25519 Secp256k1 )
Variables ¶
var ErrBadKeyType = errors.New("invalid or unsupported key type")
var KeyTypes = []int{ RSA, Ed25519, Secp256k1, }
var PrivKeyUnmarshallers = map[pb.KeyType]PrivKeyUnmarshaller{ pb.KeyType_RSA: UnmarshalRsaPrivateKey, pb.KeyType_Ed25519: UnmarshalEd25519PrivateKey, pb.KeyType_Secp256k1: UnmarshalSecp256k1PrivateKey, }
var PubKeyUnmarshallers = map[pb.KeyType]PubKeyUnmarshaller{ pb.KeyType_RSA: UnmarshalRsaPublicKey, pb.KeyType_Ed25519: UnmarshalEd25519PublicKey, pb.KeyType_Secp256k1: UnmarshalSecp256k1PublicKey, }
Functions ¶
func ConfigDecodeKey ¶
ConfigDecodeKey decodes from b64 (for config file), and unmarshals.
func ConfigEncodeKey ¶
ConfigEncodeKey encodes to b64 (for config file), and marshals.
func GenerateEd25519Key ¶ added in v1.1.0
func GenerateKeyPairWithReader ¶
Generates a keypair of the given type and bitsize
func GenerateSecp256k1Key ¶ added in v1.4.0
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 Ed25519PrivateKey ¶ added in v1.1.0
type Ed25519PrivateKey struct {
// contains filtered or unexported fields
}
func (*Ed25519PrivateKey) Bytes ¶ added in v1.1.0
func (k *Ed25519PrivateKey) Bytes() ([]byte, error)
func (*Ed25519PrivateKey) Equals ¶ added in v1.1.0
func (k *Ed25519PrivateKey) Equals(o Key) bool
func (*Ed25519PrivateKey) GetPublic ¶ added in v1.1.0
func (k *Ed25519PrivateKey) GetPublic() PubKey
func (*Ed25519PrivateKey) Raw ¶
func (k *Ed25519PrivateKey) Raw() ([]byte, error)
func (*Ed25519PrivateKey) Sign ¶ added in v1.1.0
func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)
func (*Ed25519PrivateKey) ToCurve25519 ¶ added in v1.4.0
func (k *Ed25519PrivateKey) ToCurve25519() *[32]byte
func (*Ed25519PrivateKey) Type ¶
func (k *Ed25519PrivateKey) Type() pb.KeyType
type Ed25519PublicKey ¶ added in v1.1.0
type Ed25519PublicKey struct {
// contains filtered or unexported fields
}
func (*Ed25519PublicKey) Bytes ¶ added in v1.1.0
func (k *Ed25519PublicKey) Bytes() ([]byte, error)
func (*Ed25519PublicKey) Equals ¶ added in v1.1.0
func (k *Ed25519PublicKey) Equals(o Key) bool
func (*Ed25519PublicKey) Raw ¶
func (k *Ed25519PublicKey) Raw() ([]byte, error)
func (*Ed25519PublicKey) ToCurve25519 ¶ added in v1.4.0
func (k *Ed25519PublicKey) ToCurve25519() (*[32]byte, error)
func (*Ed25519PublicKey) Type ¶
func (k *Ed25519PublicKey) Type() pb.KeyType
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 // DEPRECATED in favor of Marshal / Unmarshal Bytes() ([]byte, error) // Equals checks whether two PubKeys are the same Equals(Key) bool // Raw returns the raw bytes of the key (not wrapped in the // libp2p-crypto protobuf). // // This function is the inverse of {Priv,Pub}KeyUnmarshaler. Raw() ([]byte, error) // Type returns the protobof key type. Type() pb.KeyType }
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 }
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 UnmarshalEd25519PrivateKey ¶ added in v1.1.0
func UnmarshalPrivateKey ¶
UnmarshalPrivateKey converts a protobuf serialized private key into its representative object
func UnmarshalRsaPrivateKey ¶
func UnmarshalSecp256k1PrivateKey ¶ added in v1.4.0
type PrivKeyUnmarshaller ¶ added in v1.6.0
PrivKeyUnmarshaller is a func that creates a PrivKey from a given slice of bytes
type PubKey ¶
type PubKey interface { Key // Verify that 'sig' is the signed hash of 'data' Verify(data []byte, sig []byte) (bool, error) }
func UnmarshalEd25519PublicKey ¶ added in v1.5.0
func UnmarshalPublicKey ¶
UnmarshalPublicKey converts a protobuf serialized public key into its representative object
func UnmarshalRsaPublicKey ¶
func UnmarshalSecp256k1PublicKey ¶ added in v1.4.0
type PubKeyUnmarshaller ¶ added in v1.6.0
PubKeyUnmarshaller is a func that creates a PubKey from a given slice of bytes
type RsaPrivateKey ¶
type RsaPrivateKey struct {
// contains filtered or unexported fields
}
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) GetPublic ¶
func (sk *RsaPrivateKey) GetPublic() PubKey
func (*RsaPrivateKey) Raw ¶
func (sk *RsaPrivateKey) Raw() ([]byte, error)
func (*RsaPrivateKey) Type ¶
func (sk *RsaPrivateKey) Type() pb.KeyType
type RsaPublicKey ¶
type RsaPublicKey struct {
// contains filtered or unexported fields
}
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) Raw ¶
func (pk *RsaPublicKey) Raw() ([]byte, error)
func (*RsaPublicKey) Type ¶
func (pk *RsaPublicKey) Type() pb.KeyType
type Secp256k1PrivateKey ¶ added in v1.4.0
type Secp256k1PrivateKey btcec.PrivateKey
func (*Secp256k1PrivateKey) Bytes ¶ added in v1.4.0
func (sk *Secp256k1PrivateKey) Bytes() ([]byte, error)
func (*Secp256k1PrivateKey) Equals ¶ added in v1.4.0
func (k *Secp256k1PrivateKey) Equals(o Key) bool
func (*Secp256k1PrivateKey) GetPublic ¶ added in v1.4.0
func (k *Secp256k1PrivateKey) GetPublic() PubKey
func (*Secp256k1PrivateKey) Raw ¶
func (k *Secp256k1PrivateKey) Raw() ([]byte, error)
func (*Secp256k1PrivateKey) Sign ¶ added in v1.4.0
func (k *Secp256k1PrivateKey) Sign(data []byte) ([]byte, error)
func (*Secp256k1PrivateKey) Type ¶
func (sk *Secp256k1PrivateKey) Type() pb.KeyType
type Secp256k1PublicKey ¶ added in v1.4.0
func (*Secp256k1PublicKey) Bytes ¶ added in v1.4.0
func (sk *Secp256k1PublicKey) Bytes() ([]byte, error)
func (*Secp256k1PublicKey) Equals ¶ added in v1.4.0
func (k *Secp256k1PublicKey) Equals(o Key) bool
func (*Secp256k1PublicKey) Raw ¶
func (k *Secp256k1PublicKey) Raw() ([]byte, error)
func (*Secp256k1PublicKey) Type ¶
func (sk *Secp256k1PublicKey) Type() pb.KeyType