-
Notifications
You must be signed in to change notification settings - Fork 2
/
cipher.go
51 lines (39 loc) · 869 Bytes
/
cipher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sealion
import (
"crypto/cipher"
"strconv"
)
type seaLionCipher struct {
subkeys [40]uint32
}
const BlockSize = 16
type KeySizeError int
func (k KeySizeError) Error() string {
return "sealion: invalid key size " + strconv.Itoa(int(k))
}
func NewCipher(key []byte) (cipher.Block, error) {
switch len(key) {
case 16, 24, 32:
break
default:
return nil, KeySizeError(len(key))
}
c := new(seaLionCipher)
c.subkeys = generateSubKeys(key)
return c, nil
}
func (s seaLionCipher) BlockSize() int {
return BlockSize
}
func (s seaLionCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("sealion: input not full block")
}
cryptBlock(s.subkeys, dst, src, false)
}
func (s seaLionCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("sealion: input not full block")
}
cryptBlock(s.subkeys, dst, src, true)
}