ceremonyclient/bedlam/pkg/crypto/hmac/sha256.qcl
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -05:00

46 lines
801 B
Go

// -*- go -*-
//
// Copyright (c) 2020-2024 Markku Rossi
//
// All rights reserved.
//
package hmac
import (
"crypto/sha256"
)
// SumSHA256 computes the HMAC-SHA256 signature for the data using the
// key.
func SumSHA256(data, key []byte) [sha256.Size]byte {
if len(key) > sha256.BlockSize {
key = sha256.Sum256(key[:])
}
var ipad [sha256.BlockSize]byte
var opad [sha256.BlockSize]byte
copy(ipad, key)
copy(opad, key)
for i := 0; i < len(ipad); i++ {
ipad[i] ^= 0x36
}
for i := 0; i < len(opad); i++ {
opad[i] ^= 0x5c
}
var idata [len(ipad) + len(data)]byte
copy(idata, ipad)
copy(idata[len(ipad):], data)
idigest := sha256.Sum256(idata[:])
var odata [len(opad) + len(idigest)]byte
copy(odata, opad)
copy(odata[len(opad):], idigest)
return sha256.Sum256(odata[:])
}