]> Cypherpunks.ru repositories - balloon.git/blobdiff - balloon_test.go
Compatible results with other implementations
[balloon.git] / balloon_test.go
index bd3ffec152f22ff6e271b0f62ce3078b32dd0f53..87caf2094a55cbcf7404608d374ef07c81f0ce70 100644 (file)
@@ -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()
+       }
+}