Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #24 from mikelodder7/master
Browse files Browse the repository at this point in the history
  • Loading branch information
CassOnMars authored Dec 20, 2021
2 parents a0c1a76 + 5814a92 commit ada6d94
Show file tree
Hide file tree
Showing 42 changed files with 418 additions and 115 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this repo will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.5.4
- Export Value in ElGamal Public Keys

## v1.5.3
- Address Alpha-Rays attack on GG20 DKG https://eprint.iacr.org/2021/1621.pdf

Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.17 AS builder
# Install gomarkdoc
RUN GO111MODULE=on go get -u github.com/princjef/gomarkdoc/cmd/gomarkdoc

# Install rust and build spdx
COPY . /kryptology
WORKDIR /kryptology

RUN apt update && apt install -y curl
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -- | sh -s -- -y
RUN /root/.cargo/bin/cargo build --release --manifest-path=./cmd/spdx/Cargo.toml && \
cp ./cmd/spdx/target/release/spdx /usr/bin/ && \
chmod 755 /usr/bin/spdx
2 changes: 1 addition & 1 deletion pkg/core/curves/native/bls12-381/arithmetic_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: Apache-2.0
//

//go:build amd64 && !generic
// +build amd64,!generic

package bls12381
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/curves/native/bls12-381/arithmetic_fallback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions pkg/dkg/frost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import "github.com/coinbase/kryptology/pkg/dkg/frost"
- [func (dp *DkgParticipant) Round2(bcast map[uint32]*Round1Bcast, p2psend map[uint32]*sharing.ShamirShare) (*Round2Bcast, error)](<#func-dkgparticipant-round2>)
- [type Round1Bcast](<#type-round1bcast>)
- [type Round1P2PSend](<#type-round1p2psend>)
- [type Round1Result](<#type-round1result>)
- [func (result *Round1Result) Decode(input []byte) error](<#func-round1result-decode>)
- [func (result *Round1Result) Encode() ([]byte, error)](<#func-round1result-encode>)
- [type Round2Bcast](<#type-round2bcast>)


Expand Down Expand Up @@ -72,6 +75,27 @@ Round1P2PSend are values that are P2PSend to all other participants after round1
type Round1P2PSend = map[uint32]*sharing.ShamirShare
```

## type [Round1Result](<https://github.com/coinbase/kryptology/blob/master/pkg/dkg/frost/dkg_round1.go#L28-L31>)

```go
type Round1Result struct {
Broadcast *Round1Bcast
P2P *sharing.ShamirShare
}
```

### func \(\*Round1Result\) [Decode](<https://github.com/coinbase/kryptology/blob/master/pkg/dkg/frost/dkg_round1.go#L44>)

```go
func (result *Round1Result) Decode(input []byte) error
```

### func \(\*Round1Result\) [Encode](<https://github.com/coinbase/kryptology/blob/master/pkg/dkg/frost/dkg_round1.go#L33>)

```go
func (result *Round1Result) Encode() ([]byte, error)
```

## type [Round2Bcast](<https://github.com/coinbase/kryptology/blob/master/pkg/dkg/frost/dkg_round2.go#L18-L21>)

Round2Bcast are values that are broadcast to all other participants after round2 completes
Expand Down
28 changes: 28 additions & 0 deletions pkg/dkg/frost/dkg_round1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
package frost

import (
"bytes"
crand "crypto/rand"
"encoding/gob"
"fmt"
"github.com/coinbase/kryptology/internal"
"github.com/coinbase/kryptology/pkg/core/curves"
"github.com/coinbase/kryptology/pkg/sharing"
"github.com/pkg/errors"
"reflect"
)

Expand All @@ -22,6 +25,31 @@ type Round1Bcast struct {
Wi, Ci curves.Scalar
}

type Round1Result struct {
Broadcast *Round1Bcast
P2P *sharing.ShamirShare
}

func (result *Round1Result) Encode() ([]byte, error) {
gob.Register(result.Broadcast.Verifiers.Commitments[0]) // just the point for now
gob.Register(result.Broadcast.Ci)
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
if err := enc.Encode(result); err != nil {
return nil, errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return buf.Bytes(), nil
}

func (result *Round1Result) Decode(input []byte) error {
buf := bytes.NewBuffer(input)
dec := gob.NewDecoder(buf)
if err := dec.Decode(result); err != nil {
return errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return nil
}

// Round1P2PSend are values that are P2PSend to all other participants
// after round1 completes
type Round1P2PSend = map[uint32]*sharing.ShamirShare
Expand Down
2 changes: 1 addition & 1 deletion pkg/sharing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import "github.com/coinbase/kryptology/pkg/sharing"
- [func NewShamir(threshold, limit uint32, curve *curves.Curve) (*Shamir, error)](<#func-newshamir>)
- [func (s Shamir) Combine(shares ...*ShamirShare) (curves.Scalar, error)](<#func-shamir-combine>)
- [func (s Shamir) CombinePoints(shares ...*ShamirShare) (curves.Point, error)](<#func-shamir-combinepoints>)
- [func (s Shamir) LagrangeCoeffs(shares map[uint32]*ShamirShare) (map[uint32]curves.Scalar, error)](<#func-shamir-lagrangecoeffs>)
- [func (s Shamir) LagrangeCoeffs(identities []uint32) (map[uint32]curves.Scalar, error)](<#func-shamir-lagrangecoeffs>)
- [func (s Shamir) Split(secret curves.Scalar, reader io.Reader) ([]*ShamirShare, error)](<#func-shamir-split>)
- [type ShamirShare](<#type-shamirshare>)
- [func (ss ShamirShare) Bytes() []byte](<#func-shamirshare-bytes>)
Expand Down
6 changes: 5 additions & 1 deletion pkg/sharing/feldman.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func (f Feldman) LagrangeCoeffs(shares map[uint32]*ShamirShare) (map[uint32]curv
limit: f.Limit,
curve: f.Curve,
}
return shamir.LagrangeCoeffs(shares)
identities := make([]uint32, 0)
for _, xi := range shares {
identities = append(identities, xi.Id)
}
return shamir.LagrangeCoeffs(identities)
}

func (f Feldman) Combine(shares ...*ShamirShare) (curves.Scalar, error) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/sharing/pedersen.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ func (pd Pedersen) LagrangeCoeffs(shares map[uint32]*ShamirShare) (map[uint32]cu
limit: pd.limit,
curve: pd.curve,
}
return shamir.LagrangeCoeffs(shares)
identities := make([]uint32, 0)
for _, xi := range shares {
identities = append(identities, xi.Id)
}
return shamir.LagrangeCoeffs(identities)
}

func (pd Pedersen) Combine(shares ...*ShamirShare) (curves.Scalar, error) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/sharing/shamir.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func (s Shamir) getPolyAndShares(secret curves.Scalar, reader io.Reader) ([]*Sha
return shares, poly
}

func (s Shamir) LagrangeCoeffs(shares map[uint32]*ShamirShare) (map[uint32]curves.Scalar, error) {
xs := make(map[uint32]curves.Scalar, len(shares))
for i, xi := range shares {
xs[i] = s.curve.Scalar.New(int(xi.Id))
func (s Shamir) LagrangeCoeffs(identities []uint32) (map[uint32]curves.Scalar, error) {
xs := make(map[uint32]curves.Scalar, len(identities))
for _, xi := range identities {
xs[xi] = s.curve.Scalar.New(int(xi))
}

result := make(map[uint32]curves.Scalar, len(shares))
result := make(map[uint32]curves.Scalar, len(identities))
for i, xi := range xs {
num := s.curve.Scalar.One()
den := s.curve.Scalar.One()
Expand Down
6 changes: 5 additions & 1 deletion pkg/sharing/shamir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func TestShamirComputeL(t *testing.T) {
shares, err := scheme.Split(secret, crand.Reader)
assert.Nil(t, err)
assert.NotNil(t, shares)
lCoeffs, err := scheme.LagrangeCoeffs(map[uint32]*ShamirShare{1: shares[0], 2: shares[1]})
identities := make([]uint32, 0)
for _, xi := range shares {
identities = append(identities, xi.Id)
}
lCoeffs, err := scheme.LagrangeCoeffs(identities)
assert.Nil(t, err)
assert.NotNil(t, lCoeffs)

Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/lib.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/lib_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/tiny_bls.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/tiny_bls_sig.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/tiny_bls_sig_aug_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/tiny_bls_sig_basic_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/tiny_bls_sig_pop_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/usual_bls.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/usual_bls_sig.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/usual_bls_sig_aug_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/usual_bls_sig_basic_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/bls_sig/usual_bls_sig_pop_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package bls_sig

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/finitefield/finitefield.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

/*
Package finitefield provides a finite field type (Field) that wraps big.Int operations and verifies that all
mutations to the value are done within the field.
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/finitefield/finitefield_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package finitefield

import (
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

use bls_sigs_ref::BLSSignaturePop;
use miracl_core::{
bls12381::{
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/shamir/shamir.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

/*
Package shamir is a port of the hashicorp/vault implementation of Shamir's Secret Sharing
which has been modified to work with a finite field rather than arbitrary length content.
Expand Down
6 changes: 6 additions & 0 deletions pkg/signatures/bls/shamir/shamir_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package shamir

import (
Expand Down
Loading

0 comments on commit ada6d94

Please sign in to comment.