Skip to content
Snippets Groups Projects
Commit 38c8ed27 authored by Josh Brooks's avatar Josh Brooks
Browse files

Update readme, WIP adding package descriptions

parent 6d5f585d
No related branches found
No related tags found
No related merge requests found
...@@ -25,10 +25,11 @@ run `go test ./...` ...@@ -25,10 +25,11 @@ run `go test ./...`
`blockchain` contains the implementation of our simple blockchain. `blockchain` contains the implementation of our simple blockchain.
`cmix` derives new keys within the cyclic group from salts and a base key.
It also is used for managing keys and salts for communication between clients
`coin` contains the coin and compound data structures, and supporting `coin` contains the coin and compound data structures, and supporting
functionality including minting for tests. Minting functionality should be functionality including minting for tests.
removed or changed to a real-world model before open-sourcing or alphanet
release.
`csprng` wraps the golang crypto/rand package so that if we come up with a `csprng` wraps the golang crypto/rand package so that if we come up with a
better random number generator, we can easily switch to it. better random number generator, we can easily switch to it.
...@@ -39,24 +40,13 @@ information, it's possible to incrementally replace the golang big int ...@@ -39,24 +40,13 @@ information, it's possible to incrementally replace the golang big int
implementation with our own. It also implements modular operations within a implementation with our own. It also implements modular operations within a
cyclic group. //TODO split this with `large` cyclic group. //TODO split this with `large`
`diffieHellman` implements a Diffie-Hellman key exchange. At the time of `diffieHellman` implements a Diffie-Hellman key exchange.
writing, this is dead code.
`e2e` contains functions used in the end-to-end encryption algorithm, including `e2e` contains functions used in the end-to-end encryption algorithm, including
the end-to-end key rotation. the end-to-end key rotation.
`forward` derives new keys within the cyclic group from salts and a base key.
//TODO: Remove? now called cmix along with messaging?
`hash` includes a general-purpose hashing algorithm, blake2b, that should be `hash` includes a general-purpose hashing algorithm, blake2b, that should be
suitable for most of our needs. It also includes functions to calculate an HMAC. suitable for most of our needs. It also includes functions to calculate an HMAC.
`messaging` is currently for managing keys and salts for communication between
clients. //TODO: call `cmix`? merge w/ `forward`?
`shuffle` has a Fisher-Yates shuffle algorithm that we use for mixing `shuffle` has a Fisher-Yates shuffle algorithm that we use for mixing
the slots in our Permute phases. the slots in our Permute phases.
`verification` contains a MIC algorithm that we currently use to prevent
men in the middle from tampering with the message while it's in the middle of
being sent through the network. //TODO remove?
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package blockchain contains the implementation of our simple blockchain.
package blockchain package blockchain
import ( import (
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package blockchain contains the implementation of our simple blockchain.
package blockchain package blockchain
import "errors" import "errors"
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package cmix derives new keys within the cyclic group from salts and a base key.
// It also is used for managing keys and salts for communication between clients
package cmix package cmix
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package cmix derives new keys within the cyclic group from salts and a base key.
// It also is used for managing keys and salts for communication between clients
package cmix package cmix
import ( import (
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package cmix derives new keys within the cyclic group from salts and a base key.
// It also is used for managing keys and salts for communication between clients
package cmix package cmix
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package cmix derives new keys within the cyclic group from salts and a base key.
// It also is used for managing keys and salts for communication between clients
package cmix package cmix
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package coin contains the coin and compound data structures,
// and supporting functionality including minting for tests.
package coin package coin
import ( import (
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package diffieHellman implements a Diffie-Hellman key exchange
package diffieHellman package diffieHellman
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// / // /
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Packagee 2e contains functions used in the end-to-end encryption algorithm, including
// the end-to-end key rotation.
package e2e package e2e
import ( import (
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package hash includes a general-purpose hashing algorithm, blake2b,
// that should be suitable for most of our needs.
// It also includes functions to calculate an HMAC.
package hash package hash
import ( import (
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
// All rights reserved. / // All rights reserved. /
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Package hash includes a general-purpose hashing algorithm, blake2b,
// that should be suitable for most of our needs.
// It also includes functions to calculate an HMAC.
package hash package hash
import ( import (
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package verification
import (
"bytes"
"gitlab.com/elixxir/crypto/hash"
)
//TODO: Remove package? These 2 funcs aren't used anywhere in the project
func GenerateMIC(hashee [][]byte, length uint64) []byte {
h, _ := hash.NewCMixHash()
for i := 0; i < int(len(hashee)); i++ {
h.Write(hashee[i])
}
var mic []byte
for uint64(len(mic)) < length {
mic = h.Sum(mic)
}
return mic[0:length]
}
func CheckMic(hasheeList [][]byte, mic []byte) bool {
newmic := GenerateMIC(hasheeList, uint64(len(mic)))
return bytes.Equal(mic, newmic)
}
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package verification
import "testing"
func TestMIC(t *testing.T) {
miclengths := []uint64{26, 36, 25, 25}
hashdata := make([][][]byte, 4)
hashdata[0] = make([][]byte, 3)
hashdata[0][0] = []byte("blarg")
hashdata[0][1] = []byte("fred")
hashdata[0][2] = []byte("fredburger")
hashdata[1] = make([][]byte, 5)
hashdata[1][0] = []byte("artichoke")
hashdata[1][1] = []byte("asbestos")
hashdata[1][2] = []byte("cryptography")
hashdata[1][2] = []byte("haberdashery")
hashdata[1][2] = []byte("autometalogolex")
hashdata[2] = make([][]byte, 1)
hashdata[2][0] = []byte("arbitrary")
hashdata[3] = make([][]byte, 9)
hashdata[3][0] = hashdata[0][0]
hashdata[3][1] = hashdata[0][1]
hashdata[3][2] = hashdata[0][2]
hashdata[3][3] = hashdata[1][0]
hashdata[3][4] = hashdata[1][1]
hashdata[3][5] = hashdata[1][2]
hashdata[3][6] = hashdata[1][3]
hashdata[3][7] = hashdata[1][4]
hashdata[3][8] = hashdata[2][0]
miclist := make([][]byte, len(miclengths))
for i := 0; i < len(miclist); i++ {
miclist[i] = GenerateMIC(hashdata[i], miclengths[i])
if uint64(len(miclist[i])) != miclengths[i] {
t.Errorf("TestMIC: MIC came back at the wrong size on Index %v"+
"Expected: %v; Received: %v ", i, miclengths[i], len(miclist))
}
}
for i := 0; i < len(miclist)-1; i++ {
for j := i + 1; j < len(miclist); j++ {
same := true
for x := 0; x < minlen(miclist[i], miclist[j]); x++ {
if miclist[i][x] != miclist[j][x] {
same = false
}
}
if same {
t.Errorf("TestMIC: MICs on index %v and %v are the same",
i, j)
}
}
}
for i := 0; i < len(miclist); i++ {
if !CheckMic(hashdata[i], miclist[i]) {
t.Errorf("TestMIC: MICs did not match on inxed %v", i)
}
}
for i := 0; i < len(miclist); i++ {
for j := i + 1; j < len(miclist); j++ {
valid := CheckMic(hashdata[i], miclist[j])
if valid {
t.Errorf("TestMIC: Reported valid MIC when invalid with"+
" index %v and"+
" %v", i, j)
}
}
}
}
func minlen(a, b []byte) int {
if len(a) < len(b) {
return len(a)
} else {
return len(b)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment