PBKDF2-HMAC-SHA256

medium · cryptography, kdf, pbkdf2, password

PBKDF2-HMAC-SHA256

PBKDF2 applies repeated HMAC to make password guessing expensive. For block i:

U1 = HMAC(password, salt || INT_32_BE(i))
U2 = HMAC(password, U1)
...
Uc = HMAC(password, Uc-1)
Ti = U1 XOR U2 XOR ... XOR Uc

Output is T1 || T2 || ... truncated to dkLen.

Function signature

func PBKDF2SHA256(password, salt []byte, iterations, dkLen int) []byte

Requirements

  • iterations >= 1
  • dkLen can be any non-negative length
  • Use the provided HMACSHA256 (do not import crypto libraries)
Run tests to see results
No issues detected