2021-04-15 08:26:56 +00:00
|
|
|
package blowfish_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/cipher"
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-04-17 15:28:33 +00:00
|
|
|
|
2024-06-05 17:36:34 +00:00
|
|
|
"gitlab.com/slon/shad-go/blowfish"
|
2021-04-15 08:26:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ cipher.Block = (*blowfish.Blowfish)(nil)
|
|
|
|
|
|
|
|
func TestBlowfish(t *testing.T) {
|
|
|
|
b := blowfish.New([]byte("kek"))
|
|
|
|
|
|
|
|
for i, testCase := range []struct {
|
|
|
|
in uint64
|
|
|
|
enc uint64
|
|
|
|
dec uint64
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
in: 0x0,
|
|
|
|
enc: 0x03e009b8123919ea,
|
|
|
|
dec: 0xc5b3bba65042b0bf,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: 0x0123456789abcdef,
|
|
|
|
enc: 0x1c7879d650892fe0,
|
|
|
|
dec: 0xf714799fdf68637c,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
|
|
|
|
var in, out, expected [8]byte
|
|
|
|
|
|
|
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
|
|
|
binary.BigEndian.PutUint64(in[:], testCase.in)
|
|
|
|
|
|
|
|
b.Encrypt(out[:], in[:])
|
|
|
|
binary.BigEndian.PutUint64(expected[:], testCase.enc)
|
2021-04-18 11:05:57 +00:00
|
|
|
require.Equal(t, expected, out)
|
2021-04-15 08:26:56 +00:00
|
|
|
|
|
|
|
b.Decrypt(out[:], in[:])
|
|
|
|
binary.BigEndian.PutUint64(expected[:], testCase.dec)
|
2021-04-18 11:05:57 +00:00
|
|
|
require.Equal(t, expected, out)
|
2021-04-15 08:26:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|