mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 22:54:26 +01:00
watchtower/blob/breach_key: define breach key as sha(txid || txid)
This commit is contained in:
@@ -29,3 +29,42 @@ func NewBreachHintFromHash(hash *chainhash.Hash) BreachHint {
|
|||||||
func (h BreachHint) String() string {
|
func (h BreachHint) String() string {
|
||||||
return hex.EncodeToString(h[:])
|
return hex.EncodeToString(h[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BreachKey is computed as SHA256(txid || txid), which produces the key for
|
||||||
|
// decrypting a client's encrypted blobs.
|
||||||
|
type BreachKey [KeySize]byte
|
||||||
|
|
||||||
|
// NewBreachKeyFromHash creates a breach key from a transaction ID.
|
||||||
|
func NewBreachKeyFromHash(hash *chainhash.Hash) BreachKey {
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write(hash[:])
|
||||||
|
h.Write(hash[:])
|
||||||
|
|
||||||
|
var key BreachKey
|
||||||
|
copy(key[:], h.Sum(nil))
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a hex encoding of the breach key.
|
||||||
|
func (k BreachKey) String() string {
|
||||||
|
return hex.EncodeToString(k[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBreachHintAndKeyFromHash derives a BreachHint and BreachKey from a given
|
||||||
|
// txid in a single pass. The hint and key are computed as:
|
||||||
|
// hint = SHA256(txid)
|
||||||
|
// key = SHA256(txid || txid)
|
||||||
|
func NewBreachHintAndKeyFromHash(hash *chainhash.Hash) (BreachHint, BreachKey) {
|
||||||
|
var (
|
||||||
|
hint BreachHint
|
||||||
|
key BreachKey
|
||||||
|
)
|
||||||
|
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write(hash[:])
|
||||||
|
copy(hint[:], h.Sum(nil))
|
||||||
|
h.Write(hash[:])
|
||||||
|
copy(key[:], h.Sum(nil))
|
||||||
|
|
||||||
|
return hint, key
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user