shares

package
v0.0.0-...-cf48056 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: BSD-3-Clause Imports: 17 Imported by: 2

Documentation

Overview

Package shares implements signed&encrypted share groups

Index

Constants

View Source
const (
	// ShareMessageType signals a message containing shares after splitting
	ShareMessageType = iota + 1
	// ShareRequestType signals a message reqesting shares
	ShareRequestType
	// ShareResponseType signals a message containing shares for combination
	ShareResponseType
)
View Source
const (
	// PublicKeyXField field marker for public key X part
	PublicKeyXField = iota + 1
	// PublicKeyYField field marker for public key Y part
	PublicKeyYField
	// SecretField is the secret when padded
	SecretField
	// ShareField stores a share in a signature
	ShareField
	// RField is the R of a signature
	RField
	// SField is the S of a signature
	SField
	// NonceField is the Nonce for the signature
	NonceField
	// ShareRawField is the raw share in a signature
	ShareRawField
	// PublicKeyField is the public key in a signature
	PublicKeyField
	// CommentField contains the comment
	CommentField
	// SigKeyPublicHashField contains the hash of the ecdsa pubkey
	SigKeyPublicHashField
	// CommentHashField contains the hash of the comment
	CommentHashField
	// SigkeyPublicByteField contains the ecdsa pubkey
	SigkeyPublicByteField
	// SecretHashField contains the hash of the secret
	SecretHashField
	// ThreshholdField contains the threshold
	ThreshholdField
	// MemberSecretField contains the secret that identifies share group members
	MemberSecretField

	// MessageHeaderField contains either the encrypted or public header
	MessageHeaderField
	// NaclMessageField contains a NaCL encrypted message
	NaclMessageField
	// NumSharesField identifies how many shares are contained in the message
	NumSharesField
	// ShareMessageField contains one or more shares
	ShareMessageField
	// EncodedShare is a single encoded share
	EncodedShare
	// FakeMessageField contains a fake share, if any
	FakeMessageField
	// PaddingField is the padding
	PaddingField
	// SpecificContentField contains per-recipient data
	SpecificContentField
	// CommonContentField contains global data
	CommonContentField
	// HMACField contains an HMAC
	HMACField
	// MessageTypeField contains the message type of the message
	MessageTypeField
)

Variables

View Source
var (
	// ErrConfig is returned when the configuration is wrong
	ErrConfig = errors.New("Shares: Bad config")
	// ErrSecretShort is returned when the secret is too short (<10 bytes)
	ErrSecretShort = errors.New("Shares: Secret is smaller than 10 bytes")
	// ErrSecretLong is returned when the secret is too long (>255-3-3 == 249 bytes)
	ErrSecretLong = errors.New("Shares: Secret is bigger than 248 bytes")
	// ErrCommentShort is returned when the comment is too short (<4 bytes)
	ErrCommentShort = errors.New("Shares: Comment is smaller than 4 bytes")
	// ErrCommentLong is returned when the comment is too long (max 1024 byte)
	ErrCommentLong = errors.New("Shares: Comment is longer than 1024 bytes")
	// ErrThresholdSmall is returned when the threshold is too small (<3)
	ErrThresholdSmall = errors.New("Shares: Threshold is smaller than 3")
	// ErrThresholdBig is returned when the threshold is too big >253
	ErrThresholdBig = errors.New("Shares: Threshold is bigger than 253")
	// ErrThresholdExceed is returned when the Threshold cannot be fullfilled by the shares
	ErrThresholdExceed = errors.New("Shares: Threshold bigger than number of shares")
	// ErrSharesOverThreshold is returned when a member gets >= Threshold shares
	ErrSharesOverThreshold = errors.New("Shares: Member can reveal secret alone, increase Threshold or assign less Shares")
	// ErrTooManyShares is returned when the total number of shares > 254
	ErrTooManyShares = errors.New("Shares: Cannot produce more than 254 shares")
	// ErrTooFewShares is returned if <3 shares are to be generated
	ErrTooFewShares = errors.New("Shares: Need to generate at least 4 shares")
	// ErrDuplicateMember is returned if trying to add the same member twice to the share group
	ErrDuplicateMember = errors.New("Shares: Duplicate member")
	// ErrNegativeShares is returned if trying to add negative shares
	ErrNegativeShares = errors.New("Shares: Negative shares")
	// ErrTooFewMembers is returned if <2 members are in the group
	ErrTooFewMembers = errors.New("Shares: Need at least two members")
	// ErrSignatureDecode is returned if an encoded signature cannot be decoded
	ErrSignatureDecode = errors.New("Shares: Cannot decode signed share")
	// ErrTooFewSharesToRecover is returned if not enough shares are available to recover the secret
	ErrTooFewSharesToRecover = errors.New("Shares: Cannot recover secret, too few shares known")
	// ErrSecretNotRecovered is returned when the secret could not been recovered
	ErrSecretNotRecovered = errors.New("Shares: Secret not recovered")
	// ErrCannotConvert is returned if type conversion fails
	ErrCannotConvert = errors.New("Shares: Cannot convert type")
	// ErrCannotDecode is returned if type decoding fails
	ErrCannotDecode = errors.New("Shares: Cannot decode type")
	// ErrSignatureVerify is returned if signature verification failed
	ErrSignatureVerify = errors.New("Shares: Signature could not be verified")
	// ErrPubkeyNotMatching is returned when a wrong public key is present
	ErrPubkeyNotMatching = errors.New("Shares: Public Key mismatch")
	// ErrNotFound is returned if no matching entry in the list could be found
	ErrNotFound = errors.New("Shares: No entry found")
	// ErrHMAC is returned if the hmac does not verify
	ErrHMAC = errors.New("Shares: HMAC failure")
	// ErrNoFakes is returned if a fake was requested but not available
	ErrNoFakes = errors.New("Shares: No fake available")
	// ErrBadMessageType is returned if trying to parse a message of a different type
	ErrBadMessageType = errors.New("Shares: Unexpected message type")
	// ErrMixedPubKeys is returned if a single share response contains mixed senders
	ErrMixedPubKeys = errors.New("Shares: Mixed public keys")
)

Functions

func GenShareRequestMessage

func GenShareRequestMessage(content, sigkeybytes, receivePub, sendPub, sendPriv []byte) ([]byte, error)

GenShareRequestMessage encodes and encrypts a ShareRequestTemplate for a single public key

func GenShareRequestMessages

func GenShareRequestMessages(msgList, pubkey, privkey []byte) (messages []byte, err error)

GenShareRequestMessages encodes and encrypts all ShareRequestTemplates

Types

type CommonMessageHeader

type CommonMessageHeader struct {
	Comment       []byte // The comment
	SigPubKeyHash []byte // The hash of the signature public key
	Encoded       []byte // Header encoded
}

CommonMessageHeader is the public header of a message

type EncryptedCommonHeader

type EncryptedCommonHeader struct {
	MemberSecret     []byte // secret to verify membership in sharing group
	CommentHash      []byte // hash of comment
	SigkeyPublicByte []byte // encoded public key
	SecretHash       []byte // Hash of the secret
	Threshhold       byte   // Minimum number of shares required to reconstruct secret
	Encoded          []byte // The EncryptedCommonHeader bytepack encoded
}

EncryptedCommonHeader is the encrypted header that is common to all messages

type MessageBlock

type MessageBlock struct {
	// Message generation
	SigPublicKey          *ecdsa.PublicKey         // Public key for signature verification
	EncryptKey            *naclwrapper.NaCLKeyPair // Keypair for NaCL-Encryption
	MemberMessages        []ShareMemberMessage     // The generated member messages
	KnownMembers          map[[32]byte]bool        // known members
	CommonMessageHeader   *CommonMessageHeader
	EncryptedCommonHeader *EncryptedCommonHeader
}

MessageBlock defines all fields needed in message generation

func DecodeShareMessage

func DecodeShareMessage(pubkey, privkey, msg []byte) (*MessageBlock, error)

DecodeShareMessage decode a share message, taking into account that some fields might be missing

func DecodeShareMessageFromList

func DecodeShareMessageFromList(pubkey, privkey, messageList []byte) (*MessageBlock, error)

DecodeShareMessageFromList decode a share message from a list, taking into account that some fields might be missing

func NewMessageBlock

func NewMessageBlock(Threshhold byte, SecretHash, SigPubKey []byte) (*MessageBlock, error)

NewMessageBlock initializes the data for a new combine run

func VerifyShareRequest

func VerifyShareRequest(pubkey, privkey, message, myshares []byte) (*MessageBlock, []byte, error)

VerifyShareRequest decrypts, decodes and validates a ShareRequestMessage. Returns the corresponding messageblock (includes shares), public key of sender

func VerifyShareRequestFromList

func VerifyShareRequestFromList(pubkey, privkey, messageList, myshares []byte) (*MessageBlock, []byte, error)

VerifyShareRequestFromList decrypts, decodes and validates a ShareRequestMessage from a List. Returns the corresponding messageblock (includes shares), public key of sender

func (*MessageBlock) Combine

func (messages *MessageBlock) Combine() ([]byte, error)

Combine combines the shares and returns the secret

func (*MessageBlock) GenShareReply

func (messages *MessageBlock) GenShareReply(recipientPubKey []byte, numShares int, fake bool) ([]byte, error)

GenShareReply constructs,encodes and encrypts a share reply based on public key,

func (*MessageBlock) GenShareRequestTemplate

func (messages *MessageBlock) GenShareRequestTemplate(pubkey, privkey []byte) []byte

GenShareRequestTemplate constructs a share request out of a single share message and the corresponding private key

func (*MessageBlock) GenerateShareMessageList

func (messages *MessageBlock) GenerateShareMessageList() ([]byte, error)

GenerateShareMessageList generates all share messages for the group

func (*MessageBlock) InsertShareReplies

func (messages *MessageBlock) InsertShareReplies(shareReplies, pub, priv []byte) ([]byte, error)

InsertShareReplies loads ShareReply messages, decrypts them, and adds the shares to the message block

func (*MessageBlock) LoadShare

func (messages *MessageBlock) LoadShare(share []byte, duplicateCheck bool) error

LoadShare loads a share into the MessageBlock, verifying the signature

func (*MessageBlock) LoadShares

func (messages *MessageBlock) LoadShares(shares [][]byte, duplicateCheck bool) ([]byte, error)

LoadShares loads a share into the MessageBlock, verifying the signature

type ShareConfig

type ShareConfig struct {
	// Defined during New:
	Threshhold       int               // Minimum number of shares required to reconstruct secret
	Secret           []byte            // The secret to be shared
	PaddedSecret     []byte            // The padded secret (to be shared)
	SecretHash       []byte            // Hash of the secret
	SigkeyPrivate    *ecdsa.PrivateKey // Private key for signature
	SigkeyPublic     ecdsa.PublicKey   //  public key
	SigkeyPublicByte []byte            // encoded public key
	SigKeyPublicHash []byte            // Hash of signature public key
	Comment          []byte            // Sharing comment
	CommentHash      []byte            // hash of comment
	MemberSecret     []byte            // secret to verify membership in sharing group
	// Defined by added members:
	ShareCount       int                      // Total number of shares
	FakeCount        int                      // Total number of fakes to create
	MaxShare         int                      // Maximum number of shares one member will get
	MaxShareWithFake int                      // Maximum number of shares including fakes
	MaxMember        [32]byte                 // Public key with the maximum size
	Members          map[[32]byte]ShareMember // Members of the sharing group, index is the pubkey of the member
	Shares           [][]byte                 // The shares of the secret
	Fakes            [][]byte                 // Fake shares
	TotalLen         int                      // Total length of a message, calculated from maximum message on generation
	// Message generation
	MemberMessages        []ShareMemberMessage // The generated member messages
	CommonMessageHeader   *CommonMessageHeader
	EncryptedCommonHeader *EncryptedCommonHeader
}

ShareConfig is the configuration for a single sharing operations

func New

func New(Secret, Comment []byte, Threshhold int) (*ShareConfig, error)

New returns a new ShareConfig

func (*ShareConfig) AddMember

func (sc *ShareConfig) AddMember(PublicKey []byte, NumShares int, HasFake bool) error

AddMember adds a new member to the group. Updates ShareConfig

func (*ShareConfig) GenerateMessages

func (sc *ShareConfig) GenerateMessages() (*MessageBlock, error)

GenerateMessages generates the messages to the members

func (*ShareConfig) Verify

func (sc *ShareConfig) Verify() error

Verify verifies the ShareConfig struct and members for validity

func (*ShareConfig) VerifyInit

func (sc *ShareConfig) VerifyInit() error

VerifyInit verifies the ShareConfig struct for validity

type ShareMember

type ShareMember struct {
	PublicKey []byte // Public key of the member
	NumShares int    // Number of shares to give to this member
	HasFake   bool   // Generate a fake share for this member
}

ShareMember is a single member of the sharing group

type ShareMemberMessage

type ShareMemberMessage struct {
	PublicKey []byte        // Public key of the member
	Shares    []SignedShare // Shares. Share|nonce|signature
	Fake      *SignedShare  // Fake, if any. Fake|nonce|signature
	Padding   []byte
}

ShareMemberMessage is a single message to be sent (specific parts only)

type ShareRequest

type ShareRequest struct {
	// contains filtered or unexported fields
}

ShareRequest is a received share request message

type SignedShare

type SignedShare struct {
	Content   []byte // Share|Pubkey, bytepack encoded
	PublicKey []byte // Member public key
	Share     []byte // Share
	R         []byte // R of Signature
	S         []byte // S of Signature
	Encoded   []byte // The encoded SignShare
}

SignedShare is a signed share

Jump to

Keyboard shortcuts

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