kdf.go 414 B

1234567891011121314151617181920212223
  1. package aead
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha256"
  5. "hash"
  6. )
  7. func KDF(key []byte, path ...string) []byte {
  8. var hmacf hash.Hash
  9. for _, v := range path {
  10. hmacf = hmac.New(func() hash.Hash {
  11. return hmac.New(sha256.New, []byte(KDFSaltConstVMessAEADKDF))
  12. }, []byte(v))
  13. }
  14. hmacf.Write(key)
  15. return hmacf.Sum(nil)
  16. }
  17. func KDF16(key []byte, path ...string) []byte {
  18. r := KDF(key, path...)
  19. return r[:16]
  20. }