Beispiel #1
0
func TestSecureSecretoxKey(t *testing.T) {
	key1, ok := secretbox.GenerateKey()
	if !ok {
		fmt.Println("pwkey: failed to generate test key")
		t.FailNow()
	}

	skey, ok := SecureSecretboxKey(testPass, key1)
	if !ok {
		fmt.Println("pwkey: failed to secure secretbox key")
		t.FailNow()
	}

	key, ok := RecoverSecretboxKey(testPass, skey)
	if !ok {
		fmt.Println("pwkey: failed to recover box private key")
		t.FailNow()
	}

	if !bytes.Equal(key[:], key1[:]) {
		fmt.Println("pwkey: recovered  key doesn't match original")
		t.FailNow()
	}

	if _, ok = RecoverBoxKey([]byte("Password"), skey); ok {
		fmt.Println("pwkey: recover should fail with bad password")
		t.FailNow()
	}
}
Beispiel #2
0
// Benchmark encryption of an 80-byte strongbox key.
func BenchmarkEncrypt(b *testing.B) {
	b.StopTimer()
	sbKey, ok := secretbox.GenerateKey()
	if !ok {
		fmt.Println("tkdf: failed to generate secretbox secret key.")
		b.FailNow()
	}
	bmData = make([]byte, secretbox.KeySize)
	copy(bmData, sbKey[:])
	secretbox.Zero(sbKey[:])
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		bmBox = Encrypt(testKey, bmData)
		if bmBox == nil {
			fmt.Println("tkdf: failed to encrypt benchmark")
			b.FailNow()
		}
	}
}