# The|dkLen| parameter is given implicitly as the length of |DK|.

# PBKDF2 HMAC-SHA256 Test Vectors from
# https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors

Hash = SHA256
P = "password"
S = "salt"
c = 1
DK = 120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b
Verify = OK

Hash = SHA256
P = "password"
S = "salt"
c = 2
DK = ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43
Verify = OK

Hash = SHA256
P = "password"
S = "salt"
c = 4096
DK = c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a
Verify = OK

# Skipped because of the large number of iterations and the amount of time
# it would add to the test suite.
# Hash = SHA256
# P = "password"
# S = "salt"
# c = 16777216
# DK = cf81c66fe8cfc04d1f31ecb65dab4089f7f179e89b3b0bcb17ad10e3ac6eba46
# Verify = OK

Hash = SHA256
P = "passwordPASSWORDpassword"
S = "saltSALTsaltSALTsaltSALTsaltSALTsalt"
c = 4096
DK = 348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9
Verify = OK

# P is "pass\0word" S is "sa\0lt"
Hash = SHA256
P = 7061737300776f7264
S = 7361006c74
c = 4096
DK = 89b69d0516f829893c696226650a8687
Verify = OK

# PBKDF2 HMAC-SHA512 Test Vectors from
# https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors

Hash = SHA512
P = "password"
S = "salt"
c = 1
DK = 867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce
Verify = OK

Hash = SHA512
P = "password"
S = "salt"
c = 2
DK = e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e
Verify = OK

Hash = SHA512
P = "password"
S = "salt"
c = 4096
DK = d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5
Verify = OK

Hash = SHA512
P = "passwordPASSWORDpassword"
S = "saltSALTsaltSALTsaltSALTsaltSALTsalt"
c = 4096
DK = 8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8
Verify = OK

# PBKDF2 test vectors from Ruby OpenSSL
#
# Ruby code used to generate each test vector given in comments (be sure to
# `require "openssl"`)

# Example with 1 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("1byteboundarytest", "salt", 8, 1, digest).unpack("H*")
Hash = SHA256
P = "1byteboundarytest"
S = "salt"
c = 8
DK = 68
Verify = OK

# Same as the previous test case, but with a bit flipped.
Hash = SHA256
P = "1byteboundarytest"
S = "salt"
c = 8
DK = 69
Verify = Err

# Example with 31 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("31byteboundarytest", "salt", 8, 31, digest).unpack("H*")
Hash = SHA256
P = "31byteboundarytest"
S = "salt"
c = 8
DK = cb84e165acfa5bfab1b5aa8c78d62e86deb608b983a102cb843c7ecad886e9
Verify = OK

# Same as the previous test case, bit with a bit flipped in the first byte.
Hash = SHA256
P = "31byteboundarytest"
S = "salt"
c = 8
DK = cc84e165acfa5bfab1b5aa8c78d62e86deb608b983a102cb843c7ecad886e9
Verify = Err

# Example with 32 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("32byteboundarytest", "salt", 8, 32, digest).unpack("H*")
Hash = SHA256
P = "32byteboundarytest"
S = "salt"
c = 8
DK = 2e0a6832b70598815e6d1350a1705291bc58fc9a66e08a9fb2d89e0b2db26285
Verify = OK

# Same as the previous test case, but with a bit flipped in the middle.
Hash = SHA256
P = "32byteboundarytest"
S = "salt"
c = 8
DK = 2e0a6832b70598815e6d1350a1715291bc58fc9a66e08a9fb2d89e0b2db26285
Verify = Err

# Example with 33 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("33byteboundarytest", "salt", 8, 33, digest).unpack("H*")
Hash = SHA256
P = "33byteboundarytest"
S = "salt"
c = 8
DK = b7c1a3d23a03b1d29ebcb46b3e422251bae8d649e45ab00f8815553c76efe5cdeb
Verify = OK

# Same as the previous test case, but with the first bit flipped.
Hash = SHA256
P = "33byteboundarytest"
S = "salt"
c = 8
DK = 37c1a3d23a03b1d29ebcb46b3e422251bae8d649e45ab00f8815553c76efe5cdeb
Verify = Err

# Same as previous test case, but last bit is flipped.
Hash = SHA256
P = "33byteboundarytest"
S = "salt"
c = 8
DK = b7c1a3d23a03b1d29ebcb46b3e422251bae8d649e45ab00f8815553c76efe5cdea
Verify = Err


# Example with 63 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("63byteboundarytest", "salt", 8, 63, digest).unpack("H*")
Hash = SHA256
P = "63byteboundarytest"
S = "salt"
c = 8
DK = d10fa19eefabe3b543e90394934173547747a1d38e9d5d8f62bf1f49c9e5d306bc8a4e483b855fb6d7c6a2f2f2dcb5d25340ce87b82661f1185c24313723be
Verify = OK

# Example with 64 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("64byteboundarytest", "salt", 8, 64, digest).unpack("H*")
Hash = SHA256
P = "64byteboundarytest"
S = "salt"
c = 8
DK = 76d44b557a1e3062fff1c9035e30e0d3352a21fa9bb0bef446e792a75a6211fe7943e156ea32b2bbba68298792e710971e754e1e9e443f167194c957cdcaa95e
Verify = OK

# Example with 65 byte output
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("65byteboundarytest", "salt", 8, 65, digest).unpack("H*")
Hash = SHA256
P = "65byteboundarytest"
S = "salt"
c = 8
DK = 28f8f2177c828fb447b439548603d9b3b3a455bbd339d6186772b9e7b1dfec5be27bfb5713c51181720bed046bb2d162003edb2c4f5c54722d0f68c8d597b7fa52
Verify = OK

# Same as the previous test case, but the last bit in the middle block was
# flipped.
Hash = SHA256
P = "65byteboundarytest"
S = "salt"
c = 8
DK = 28f8f2177c828fb447b439548603d9b3b3a455bbd339d6186772b9e7b1dfec5be27bfb5713c51181720bed046bb2d162003edb2c4f5c54722d0f68c8d597b7fb52
Verify = Err


# Example with 255 SHA-256 blocks
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("255blockboundarytest", "salt", 8, 32 * 255, digest).unpack("H*")
Hash = SHA256
P = "255blockboundarytest"
S = "salt"
c = 8
DK = [encoded data, 16320 characters]
Verify = OK

# Example with 256 SHA-256 blocks
#
# digest = OpenSSL::Digest::SHA256.new
# OpenSSL::PKCS5.pbkdf2_hmac("256blockboundarytest", "salt", 8, 32 * 256, digest).unpack("H*")
Hash = SHA256
P = "256blockboundarytest"
S = "salt"
c = 8
DK = [encoded data, 16384 characters]
Verify = OK

# Same as the previous test case, but the last bit is flipped.
Hash = SHA256
P = "256blockboundarytest"
S = "salt"
c = 8
DK = [encoded data, 16384 characters]
Verify = Err

Hash = SHA256
P = "EmptyDKTest"
S = "salt"
c = 8
DK = ""
Verify = Err

# PBKDF2 test vectors from RFC 7914

Hash = SHA256
P = "passwd"
S = "salt"
c = 1
DK = 55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc49ca9cccf179b645991664b39d77ef317c71b845b1e30bd509112041d3a19783
Verify = OK

Hash = SHA256
P = "Password"
S = "NaCl"
c = 80000
DK = 4ddcd8f60b98be21830cee5ef22701f9641a4418d04c0414aeff08876b34ab56a1d425a1225833549adb841b51c9b3176a272bdebba1d078478f62b397f33c8d
Verify = OK
