// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package hmac

import ( //nolint:gci
	 //nolint:gosec
	
	
	
)

func ( *hmac) ( []byte) {
	.outer.Reset()
	.inner.Reset()
	 := .inner.BlockSize()

	// Reset size and zero of ipad and opad.
	.ipad = append(.ipad[:0], make([]byte, )...)
	.opad = append(.opad[:0], make([]byte, )...)

	if len() >  {
		// If key is too big, hash it.
		.outer.Write() //nolint:errcheck,gosec
		 = .outer.Sum(nil)
	}
	copy(.ipad, )
	copy(.opad, )
	for  := range .ipad {
		.ipad[] ^= 0x36
	}
	for  := range .opad {
		.opad[] ^= 0x5c
	}
	.inner.Write(.ipad) //nolint:errcheck,gosec

	.marshaled = false
}

var hmacSHA1Pool = &sync.Pool{ //nolint:gochecknoglobals
	New: func() interface{} {
		 := New(sha1.New, make([]byte, sha1.BlockSize))
		return 
	},
}

// AcquireSHA1 returns new HMAC from pool.
func ( []byte) hash.Hash {
	 := hmacSHA1Pool.Get().(*hmac) //nolint:forcetypeassert
	assertHMACSize(, sha1.Size, sha1.BlockSize)
	.resetTo()
	return 
}

// PutSHA1 puts h to pool.
func ( hash.Hash) {
	 := .(*hmac) //nolint:forcetypeassert
	assertHMACSize(, sha1.Size, sha1.BlockSize)
	hmacSHA1Pool.Put()
}

var hmacSHA256Pool = &sync.Pool{ //nolint:gochecknoglobals
	New: func() interface{} {
		 := New(sha256.New, make([]byte, sha256.BlockSize))
		return 
	},
}

// AcquireSHA256 returns new HMAC from SHA256 pool.
func ( []byte) hash.Hash {
	 := hmacSHA256Pool.Get().(*hmac) //nolint:forcetypeassert
	assertHMACSize(, sha256.Size, sha256.BlockSize)
	.resetTo()
	return 
}

// PutSHA256 puts h to SHA256 pool.
func ( hash.Hash) {
	 := .(*hmac) //nolint:forcetypeassert
	assertHMACSize(, sha256.Size, sha256.BlockSize)
	hmacSHA256Pool.Put()
}

// assertHMACSize panics if h.size != size or h.blocksize != blocksize.
//
// Put and Acquire functions are internal functions to project, so
// checking it via such assert is optimal.
func assertHMACSize( *hmac, ,  int) { //nolint:unparam
	if .Size() !=  || .BlockSize() !=  {
		panic("BUG: hmac size invalid") //nolint
	}
}