X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=balloon_test.go;fp=balloon_test.go;h=87caf2094a55cbcf7404608d374ef07c81f0ce70;hb=362faad185dcdc9ad6039e873d0a06de48540997;hp=bd3ffec152f22ff6e271b0f62ce3078b32dd0f53;hpb=7a93eab905ad8534e0dbc853f67f84fea98976cc;p=balloon.git diff --git a/balloon_test.go b/balloon_test.go index bd3ffec..87caf20 100644 --- a/balloon_test.go +++ b/balloon_test.go @@ -19,8 +19,11 @@ License along with this program. If not, see package balloon import ( + "bytes" "crypto/rand" + "crypto/sha256" "crypto/sha512" + "encoding/hex" "testing" "testing/quick" ) @@ -75,3 +78,49 @@ func BenchmarkH(b *testing.B) { H(sha512.New, passwd, salt, sCost, 4, 4) } } + +func mustHexDecode(s string) []byte { + b, err := hex.DecodeString(s) + if err != nil { + panic(err) + } + return b +} + +func TestVectors(t *testing.T) { + // taken from Nettle 3.9 + if !bytes.Equal( + B(sha256.New(), []byte("password"), []byte("salt"), 1, 1), + mustHexDecode("eefda4a8a75b461fa389c1dcfaf3e9dfacbc26f81f22e6f280d15cc18c417545"), + ) { + t.FailNow() + } + + if !bytes.Equal( + B(sha256.New(), []byte{0}, []byte{0}, 3, 3), + mustHexDecode("4fc7e302ffa29ae0eac31166cee7a552d1d71135f4e0da66486fb68a749b73a4"), + ) { + t.FailNow() + } + + if !bytes.Equal( + B(sha256.New(), nil, []byte("salt"), 3, 3), + mustHexDecode("5f02f8206f9cd212485c6bdf85527b698956701ad0852106f94b94ee94577378"), + ) { + t.FailNow() + } + + if !bytes.Equal( + B(sha256.New(), []byte("password"), nil, 3, 3), + mustHexDecode("20aa99d7fe3f4df4bd98c655c5480ec98b143107a331fd491deda885c4d6a6cc"), + ) { + t.FailNow() + } + + if !bytes.Equal( + B(sha256.New(), []byte("hunter42"), []byte("examplesalt"), 1024, 3), + mustHexDecode("716043dff777b44aa7b88dcbab12c078abecfac9d289c5b5195967aa63440dfb"), + ) { + t.FailNow() + } +}