mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-14 17:02:43 +00:00
Knut Ahlers
a1df72edc5
commitf0db1ff1f8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:19:56 2017 +0100 Mark option as deprecated Signed-off-by: Knut Ahlers <knut@ahlers.me> commit9891df2a16
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:11:56 2017 +0100 Fix: Typo Signed-off-by: Knut Ahlers <knut@ahlers.me> commit836006de64
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:04:20 2017 +0100 Add new dependencies Signed-off-by: Knut Ahlers <knut@ahlers.me> commitd64fee60c8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 11:55:52 2017 +0100 Replace insecure password hashing Prior this commit passwords were hashed with a static salt and using the SHA1 hashing function. This could lead to passwords being attackable in case someone gets access to the raw data stored inside the database. This commit introduces password hashing using bcrypt hashing function which addresses this issue. Old passwords are not automatically re-hashed as they are unknown. Replacing the old password scheme is not that easy and needs #10 to be solved. Therefore the old hashing scheme is kept for compatibility reason. Signed-off-by: Knut Ahlers <knut@ahlers.me> Signed-off-by: Knut Ahlers <knut@ahlers.me> closes #14 closes #15
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
// Copyright 2010 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cast5
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
// This test vector is taken from RFC 2144, App B.1.
|
|
// Since the other two test vectors are for reduced-round variants, we can't
|
|
// use them.
|
|
var basicTests = []struct {
|
|
key, plainText, cipherText string
|
|
}{
|
|
{
|
|
"0123456712345678234567893456789a",
|
|
"0123456789abcdef",
|
|
"238b4fe5847e44b2",
|
|
},
|
|
}
|
|
|
|
func TestBasic(t *testing.T) {
|
|
for i, test := range basicTests {
|
|
key, _ := hex.DecodeString(test.key)
|
|
plainText, _ := hex.DecodeString(test.plainText)
|
|
expected, _ := hex.DecodeString(test.cipherText)
|
|
|
|
c, err := NewCipher(key)
|
|
if err != nil {
|
|
t.Errorf("#%d: failed to create Cipher: %s", i, err)
|
|
continue
|
|
}
|
|
var cipherText [BlockSize]byte
|
|
c.Encrypt(cipherText[:], plainText)
|
|
if !bytes.Equal(cipherText[:], expected) {
|
|
t.Errorf("#%d: got:%x want:%x", i, cipherText, expected)
|
|
}
|
|
|
|
var plainTextAgain [BlockSize]byte
|
|
c.Decrypt(plainTextAgain[:], cipherText[:])
|
|
if !bytes.Equal(plainTextAgain[:], plainText) {
|
|
t.Errorf("#%d: got:%x want:%x", i, plainTextAgain, plainText)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestFull performs the test specified in RFC 2144, App B.2.
|
|
// However, due to the length of time taken, it's disabled here and a more
|
|
// limited version is included, below.
|
|
func TestFull(t *testing.T) {
|
|
if testing.Short() {
|
|
// This is too slow for normal testing
|
|
return
|
|
}
|
|
|
|
a, b := iterate(1000000)
|
|
|
|
const expectedA = "eea9d0a249fd3ba6b3436fb89d6dca92"
|
|
const expectedB = "b2c95eb00c31ad7180ac05b8e83d696e"
|
|
|
|
if hex.EncodeToString(a) != expectedA {
|
|
t.Errorf("a: got:%x want:%s", a, expectedA)
|
|
}
|
|
if hex.EncodeToString(b) != expectedB {
|
|
t.Errorf("b: got:%x want:%s", b, expectedB)
|
|
}
|
|
}
|
|
|
|
func iterate(iterations int) ([]byte, []byte) {
|
|
const initValueHex = "0123456712345678234567893456789a"
|
|
|
|
initValue, _ := hex.DecodeString(initValueHex)
|
|
|
|
var a, b [16]byte
|
|
copy(a[:], initValue)
|
|
copy(b[:], initValue)
|
|
|
|
for i := 0; i < iterations; i++ {
|
|
c, _ := NewCipher(b[:])
|
|
c.Encrypt(a[:8], a[:8])
|
|
c.Encrypt(a[8:], a[8:])
|
|
c, _ = NewCipher(a[:])
|
|
c.Encrypt(b[:8], b[:8])
|
|
c.Encrypt(b[8:], b[8:])
|
|
}
|
|
|
|
return a[:], b[:]
|
|
}
|
|
|
|
func TestLimited(t *testing.T) {
|
|
a, b := iterate(1000)
|
|
|
|
const expectedA = "23f73b14b02a2ad7dfb9f2c35644798d"
|
|
const expectedB = "e5bf37eff14c456a40b21ce369370a9f"
|
|
|
|
if hex.EncodeToString(a) != expectedA {
|
|
t.Errorf("a: got:%x want:%s", a, expectedA)
|
|
}
|
|
if hex.EncodeToString(b) != expectedB {
|
|
t.Errorf("b: got:%x want:%s", b, expectedB)
|
|
}
|
|
}
|