aboutsummaryrefslogtreecommitdiff
path: root/verifysetup/core
diff options
context:
space:
mode:
Diffstat (limited to 'verifysetup/core')
-rw-r--r--verifysetup/core/crypt.go3
-rw-r--r--verifysetup/core/storage.go10
2 files changed, 10 insertions, 3 deletions
diff --git a/verifysetup/core/crypt.go b/verifysetup/core/crypt.go
index 4658641..1307bd3 100644
--- a/verifysetup/core/crypt.go
+++ b/verifysetup/core/crypt.go
@@ -11,6 +11,7 @@ import (
"strings"
)
+// CalculateBlockHash calculates the sha1 checksum of a byte slice.
func CalculateBlockHash(block []byte) (string, error) {
hash := sha1.New()
if _, err := io.Copy(hash, bytes.NewReader(block)); err != nil {
@@ -20,6 +21,8 @@ func CalculateBlockHash(block []byte) (string, error) {
return strings.TrimSpace(fmt.Sprintf("%x", hashInBytes)), nil
}
+// SignDatabase generates a minisign signature of the database using given keys.
+// The minisign signature uses "fsverify" as the comments to ensure predictability when fsverify verifies the signature.
func SignDatabase(database string, minisignKeys string) ([]byte, error) {
fmt.Print("Enter your password (will not echo): ")
p, err := term.ReadPassword(int(os.Stdin.Fd()))
diff --git a/verifysetup/core/storage.go b/verifysetup/core/storage.go
index 64b06a1..a4fc66d 100644
--- a/verifysetup/core/storage.go
+++ b/verifysetup/core/storage.go
@@ -10,8 +10,8 @@ import (
bolt "go.etcd.io/bbolt"
)
-var TotalReadBlocks = 0
-
+// ReadBlock reads the bytes in a specified ranges from a bytes.Reader.
+// It additionally verifies that the amount of bytes read match with the size of the area and fails if the they do not match.
func ReadBlock(start int, end int, device *bytes.Reader) ([]byte, error) {
if end-start < 0 {
return []byte{}, fmt.Errorf("tried creating byte slice with negative length. %d to %d total %d\n", start, end, end-start)
@@ -24,10 +24,11 @@ func ReadBlock(start int, end int, device *bytes.Reader) ([]byte, error) {
return []byte{}, err
}
_, err = device.Read(block)
- TotalReadBlocks = TotalReadBlocks + (end - start)
return block, err
}
+// CreateNode creates a Node based on given parameters.
+// If prevNode is set to nil, meaning this node is the first node in a verification chain, prevNodeHash is set to "EntrypointN" with N being the number of entrypoint.
func CreateNode(blockStart int, blockEnd int, block []byte, prevNode *verify.Node, n string) (verify.Node, error) {
node := verify.Node{}
node.BlockStart = blockStart
@@ -50,6 +51,8 @@ func CreateNode(blockStart int, blockEnd int, block []byte, prevNode *verify.Nod
return node, nil
}
+// AddNode adds a node to the bucket "Nodes" in the database.
+// It assumes that a database transaction has already been started and takes bolt.Tx as an argument.
func AddNode(node verify.Node, tx *bolt.Tx) error {
if node.BlockStart == node.BlockEnd {
return nil
@@ -66,6 +69,7 @@ func AddNode(node verify.Node, tx *bolt.Tx) error {
return nil
}
+// CreateHeader creates a header to be used in an fsverify partition containing all necessary information.
func CreateHeader(unsignedHash string, signedHash string, diskSize int, tableSize int) ([]byte, error) {
header := make([]byte, 200)
header[0] = 0xAC