kdf.go 410 B

123456789101112131415161718192021222324
  1. package aead
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha256"
  5. "hash"
  6. )
  7. func KDF(key []byte, path ...string) []byte {
  8. hmacf := hmac.New(sha256.New, []byte(KDFSaltConstVMessAEADKDF))
  9. for _, v := range path {
  10. hmacf = hmac.New(func() hash.Hash {
  11. return hmacf
  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. }