-
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.
Merge pull request #1 from dedis/purbified-db
link purb-db to libpurb
- Loading branch information
Showing
15 changed files
with
904 additions
and
143 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
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
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,38 @@ | ||
module dela-purb | ||
module go.dedis.ch/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-20231108133532-c70e1b84b632 | ||
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa | ||
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.14.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,90 @@ | ||
// Blob is a wrapper around libpurb.Purb | ||
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" | ||
) | ||
|
||
const numberOfRecipients = 1 | ||
|
||
// NewBlob creates a new blob | ||
func NewBlob(keypair []key.Pair) *libpurb.Purb { | ||
p := libpurb.NewPurb( | ||
getSuiteInfo(), | ||
false, | ||
random.New(), | ||
) | ||
p.Recipients = createRecipients(keypair) | ||
|
||
return p | ||
} | ||
|
||
// Encode encodes a slice of bytes into a blob | ||
func Encode(purb *libpurb.Purb, data []byte) ([]byte, error) { | ||
err := purb.Encode(data) | ||
blob := purb.ToBytes() | ||
|
||
return blob, err | ||
} | ||
|
||
// Decode decodes a blob into a slice of bytes | ||
func Decode(purb *libpurb.Purb, blob []byte) ([]byte, error) { | ||
success, decrypted, err := purb.Decode(blob) | ||
|
||
if !success { | ||
err = xerrors.Errorf("Failed to decrypt blob: %v", 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(keypair []key.Pair) []libpurb.Recipient { | ||
r := make([]libpurb.Recipient, 0) | ||
suites := []libpurb.Suite{curve25519.NewBlakeSHA256Curve25519(true)} | ||
|
||
if len(keypair) < numberOfRecipients { | ||
keypair = make([]key.Pair, 0) | ||
} | ||
|
||
for _, suite := range suites { | ||
for i := 0; i < numberOfRecipients; i++ { | ||
if len(keypair) < numberOfRecipients { | ||
keypair = append(keypair, *key.NewKeyPair(suite)) | ||
} | ||
|
||
r = append(r, libpurb.Recipient{ | ||
SuiteName: suite.String(), | ||
Suite: suite, | ||
PublicKey: keypair[i].Public, | ||
PrivateKey: keypair[i].Private, | ||
}) | ||
} | ||
} | ||
return r | ||
} |
Oops, something went wrong.