forked from usbarmory/armory-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.go
49 lines (36 loc) · 886 Bytes
/
crypto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// https://github.com/f-secure-foundry/armory-boot
//
// Copyright (c) F-Secure Corporation
// https://foundry.f-secure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
package main
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
)
const signatureSuffix = ".sig"
var PublicKeyStr string
func verifySignature(bin []byte, s []byte) (valid bool, err error) {
sig, err := DecodeSignature(string(s))
if err != nil {
return false, fmt.Errorf("invalid signature, %v", err)
}
pub, err := NewPublicKey(PublicKeyStr)
if err != nil {
return false, fmt.Errorf("invalid public key, %v", err)
}
return pub.Verify(bin, sig)
}
func verifyHash(bin []byte, s string) bool {
h := sha256.New()
h.Write(bin)
hash, err := hex.DecodeString(s)
if err != nil {
return false
}
return bytes.Equal(h.Sum(nil), hash)
}