ceremonyclient/bedlam/pkg/crypto/hmac/sha1.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
770 B
Go

// -*- go -*-
//
// Copyright (c) 2020-2024 Markku Rossi
//
// All rights reserved.
//
package hmac
import (
"crypto/sha1"
)
// SumSHA1 computes the HMAC-SHA1 signature for the data using the
// key.
func SumSHA1(data, key []byte) [sha1.Size]byte {
if len(key) > sha1.BlockSize {
key = sha1.Sum(key[:])
}
var ipad [sha1.BlockSize]byte
var opad [sha1.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 := sha1.Sum(idata[:])
var odata [len(opad) + len(idigest)]byte
copy(odata, opad)
copy(odata[len(opad):], idigest)
return sha1.Sum(odata[:])
}