crypto

package
v0.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2019 The Swarm Authors This file is part of the Swarm library.

The Swarm library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Swarm library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the Swarm library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	SizeMask = byte(3) // mask used to extract the size of payload size field from the flags

)

Variables

This section is empty.

Functions

func New

func New() *defaultCryptoBackend

Return the default implementation of Crypto

Types

type Crypto

type Crypto interface {
	Message
	KeyStore
}

Crypto contains methods from Message and KeyStore

type KeyStore

type KeyStore interface {

	// Symmetric key management
	GetSymmetricKey(id string) ([]byte, error)
	GenerateSymmetricKey() (string, error)
	AddSymmetricKey(bytes []byte) (string, error)

	// Key serialization
	SerializePublicKey(pub *ecdsa.PublicKey) []byte
	UnmarshalPublicKey(pub []byte) (*ecdsa.PublicKey, error)
	CompressPublicKey(pub *ecdsa.PublicKey) []byte
}

KeyStore contains key manipulation methods

type Message

type Message interface {
	Wrap(plaintext []byte, params *WrapParams) (data []byte, err error)
	UnWrap(ciphertext []byte, unwrapParams *UnwrapParams) (ReceivedMessage, error)
}

Message contains methods for wrapping(encrypting) and unwrapping(decrypting) messages

type ReceivedMessage

type ReceivedMessage interface {
	GetPayload() ([]byte, error)
	GetSender() *ecdsa.PublicKey
}

Contains a successfully decrypted message prior to parsing and validating

type UnwrapParams

type UnwrapParams struct {
	Sender       *ecdsa.PublicKey  // Public key of sender used for signature validation
	Receiver     *ecdsa.PrivateKey // Private key of receiver for decryption
	SymmetricKey []byte            // Symmetric key for decryption
}

Config params to unwrap and decrypt a message. For asymmetric encryption Receiver is needed. For symmetric, SymmetricKey is needed. Sender is not mandatory but used to sign the message in both schemes.

type WrapParams

type WrapParams struct {
	Sender       *ecdsa.PrivateKey // Private key of sender used for signature
	Receiver     *ecdsa.PublicKey  // Public key of receiver for encryption
	SymmetricKey []byte            // Symmetric key for encryption
}

Config params to wrap and encrypt a message. For asymmetric encryption Receiver is needed. For symmetric, SymmetricKey is needed. Sender is not mandatory but used to sign the message in both schemes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL