-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# dela-purb | ||
# purb-db | ||
A {key,value} storage that is PURBified before saving it to disk. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
module dela-purb | ||
module purb-db | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.8.4 | ||
go.dedis.ch/dela v0.0.0-20231011144949-4677467c030c | ||
go.dedis.ch/kyber/v3 v3.1.1-0.20231024084410-31ea167adbbb | ||
go.dedis.ch/libpurb v0.0.0-20231107160354-ffba29c17caf | ||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/prometheus/client_golang v1.5.1 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.10.0 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
github.com/rs/zerolog v1.31.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.0.1 // indirect | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | ||
github.com/urfave/cli/v2 v2.2.0 // indirect | ||
go.dedis.ch/fixbuf v1.0.3 // indirect | ||
go.etcd.io/bbolt v1.3.5 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package kv | ||
|
||
import ( | ||
"go.dedis.ch/kyber/v3/group/curve25519" | ||
"go.dedis.ch/kyber/v3/util/key" | ||
"go.dedis.ch/libpurb/libpurb" | ||
"golang.org/x/xerrors" | ||
|
||
"go.dedis.ch/kyber/v3/util/random" | ||
) | ||
|
||
type Blob struct { | ||
purb *libpurb.Purb | ||
} | ||
|
||
// NewBlob creates a new blob | ||
func NewBlob() *Blob { | ||
suitesInfo := getSuiteInfo() | ||
simplified := true | ||
|
||
p := libpurb.NewPurb( | ||
suitesInfo, | ||
simplified, | ||
random.New(), | ||
) | ||
|
||
p.Recipients = createRecipients(1) | ||
|
||
return &Blob{ | ||
purb: p, | ||
} | ||
} | ||
|
||
// Encode encodes a slice of bytes into a blob | ||
func (b *Blob) Encode(data []byte) ([]byte, error) { | ||
err := b.purb.Encode(data) | ||
blob := b.purb.ToBytes() | ||
|
||
return blob, err | ||
} | ||
|
||
// Decode decodes a blob into a slice of bytes | ||
func (b *Blob) Decode(blob []byte) ([]byte, error) { | ||
success, decrypted, err := b.purb.Decode(blob) | ||
|
||
if !success { | ||
xerrors.Errorf("Failed to decrypt blob", err) | ||
} | ||
|
||
return decrypted, err | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// helper functions | ||
|
||
// see example in libpurb | ||
func getSuiteInfo() libpurb.SuiteInfoMap { | ||
info := make(libpurb.SuiteInfoMap) | ||
cornerstoneLength := 32 // defined by Curve 25519 | ||
entryPointLength := 16 + 4 + 4 + 16 // 16-byte symmetric key + 2 * 4-byte offset positions + 16-byte authentication tag | ||
info[curve25519.NewBlakeSHA256Curve25519(true).String()] = &libpurb.SuiteInfo{ | ||
AllowedPositions: []int{ | ||
12 + 0*cornerstoneLength, | ||
12 + 1*cornerstoneLength, | ||
12 + 3*cornerstoneLength, | ||
12 + 4*cornerstoneLength, | ||
}, | ||
CornerstoneLength: cornerstoneLength, EntryPointLength: entryPointLength, | ||
} | ||
return info | ||
} | ||
|
||
// see example in libpurb | ||
func createRecipients(n int) []libpurb.Recipient { | ||
decs := make([]libpurb.Recipient, 0) | ||
suites := []libpurb.Suite{curve25519.NewBlakeSHA256Curve25519(true)} | ||
for _, suite := range suites { | ||
for i := 0; i < n; i++ { | ||
pair := key.NewKeyPair(suite) | ||
decs = append(decs, libpurb.Recipient{ | ||
SuiteName: suite.String(), | ||
Suite: suite, | ||
PublicKey: pair.Public, | ||
PrivateKey: pair.Private, | ||
}) | ||
} | ||
} | ||
return decs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.