cgss

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2017 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reconstruct

func Reconstruct(ctx context.Context, shares []Share, status io.Writer) (res []byte, err error)

Reconstruct computes the secret from a set of shares. The given shares must satisfy the group and data constraints set to distribute the secret. If the number of groups and/or the number of shares are not enough, the result is undefined (maybe some random value).

If status isn't nil, logging information will be written to the Writer.

Example

The following example reconstructs the secret from a subset of distributed shares. As same as the example of Distribute function, the secret is distributed into 6 shares over 3 groups so that each group has 2 shares.

Since the group threshold and data threshold are 2 and 3, respectively, we use two shares from group 1 and one share from group 2, i.e. three shares from two groups, to reconstruct the secret.

Reconstruct function returns a byte slice; you might need to cast it to string if the secret is a string.

ctx := context.Background()
// Distribute step is as same as the example of Dictribute function.
secret := []byte("This is secret information")
shares, err := Distribute(ctx, secret, &DistributeOpt{
	ChunkSize:      8,
	Allocation:     Allocation{2, 2, 2},
	GroupThreshold: 2,
	DataThreshold:  3,
}, nil)
if err != nil {
	log.Fatal(err.Error())
}

// Pick up two shares from group 1 and one share from group 2.
subset := []Share{shares[0], shares[1], shares[2]}
res, err := Reconstruct(ctx, subset, nil)
if err != nil {
	log.Fatal(err.Error())
}
fmt.Println(string(res))
Output:

This is secret information

Types

type Allocation

type Allocation []int

Allocation defines a share allocation.

func (Allocation) Size

func (a Allocation) Size() int

Size returns the size of allocated regions.

func (Allocation) Sum

func (a Allocation) Sum() (res int)

Sum returns the summation of this allocate values.

type DistributeOpt

type DistributeOpt struct {
	// Secrets will be divided into chunks based on the ChunkSize.
	ChunkSize int
	// Share assignment information.
	Allocation Allocation
	// Minimum number of groups from which shares must be collected to reconstruct secrets.
	GroupThreshold int
	// Minimum number of shares required to reconstruct secrets.
	DataThreshold int
}

DistributeOpt defines arguments of Distribute function.

type Share

type Share struct {
	Field       *sss.Field
	GroupKey    *big.Int
	GroupShares []*big.Int
	DataKey     *big.Int
	DataShares  []*big.Int
}

Share defines a share of the Cross-Group Secret Sharing scheme.

func Distribute

func Distribute(ctx context.Context, secret []byte, opt *DistributeOpt, status io.Writer) (shares []Share, err error)

Distribute computes cross-groupt secret sharing shares of the given secret according to the given configuration, opt. If status isn't nil, logging information will be written to the Writer.

Example

The following example assumes three groups and assigns two shares to each of them, and the group and data thredholds are set to 2 and 3, respectively. It means, to reconstruct the secret, at least three shares must be collected from at least 2 groups.

Since the chunk size is set to 8bytes, the secret will be divided every 8bytes and each chunk will be converted to a set of shares.

From the share assignment, the dictribute function makes totally 6 shares, and it thus returns a slice of shares of which the length is 6. Note that the returned shares do not have any information about groups but the order of them are associated with the given allocation. More precisely, shares[0] and shares[1] are for the group 1, shares[2] and shares[3] are for the groupt 2, and shares[4] and shares[5] are for the group 3 in this example.

secret := []byte(`abcdefgaerogih:weori:ih:opih:oeijhg@roeinv;dlkjh:
		roihg:3pw9bdlnbmxznd:lah:orsihg:operinbk:sldfj:aporinb`)
chunksize := 8

allocation := Allocation{2, 2, 2}
gthreshold := 2
dthreshold := 3
ctx := context.Background()

shares, err := Distribute(ctx, secret, &DistributeOpt{
	ChunkSize:      chunksize,
	Allocation:     allocation,
	GroupThreshold: gthreshold,
	DataThreshold:  dthreshold,
}, nil)
if err != nil {
	log.Fatal(err.Error())
}

fmt.Println(len(shares))
Output:

6

Jump to

Keyboard shortcuts

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