This repository was archived by the owner on Sep 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptoops.go
More file actions
99 lines (93 loc) · 2.65 KB
/
cryptoops.go
File metadata and controls
99 lines (93 loc) · 2.65 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package macaronsign
import (
"crypto/aes"
"crypto/cipher"
"crypto/hmac"
"crypto/sha512"
"hash"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/sha3"
"lukechampine.com/blake3"
"github.com/lemon-mint/LEA/golea"
)
func (s Signer) encrypt(data []byte, nonce []byte) (encrypted []byte) {
if s.encV == 0 {
return data
} else if s.encV == 1 {
b, _ := aes.NewCipher(s.encKey[:])
c, _ := cipher.NewGCM(b)
return c.Seal(nil, nonce[:12], data, nil)
} else if s.encV == 2 {
b, _ := golea.NewCipher(s.encKey[:])
c, _ := cipher.NewGCM(b)
return c.Seal(nil, nonce[:12], data, nil)
} else if s.encV == 3 {
cipher, _ := chacha20poly1305.NewX(s.encKey[:])
return cipher.Seal(nil, nonce[:cipher.NonceSize()], data, nil)
} else if s.encV == 4 {
cipher, _ := chacha20poly1305.New(s.encKey[:])
return cipher.Seal(nil, nonce[:cipher.NonceSize()], data, nil)
}
return
}
func (s Signer) decrypt(data []byte, nonce []byte) (decrypted []byte, err error) {
if s.encV == 0 {
return data, nil
} else if s.encV == 1 {
b, _ := aes.NewCipher(s.encKey[:])
c, _ := cipher.NewGCM(b)
return c.Open(nil, nonce[:12], data, nil)
} else if s.encV == 2 {
b, _ := golea.NewCipher(s.encKey[:])
c, _ := cipher.NewGCM(b)
return c.Open(nil, nonce[:c.NonceSize()], data, nil)
} else if s.encV == 3 {
cipher, _ := chacha20poly1305.NewX(s.encKey[:])
return cipher.Open(nil, nonce[:cipher.NonceSize()], data, nil)
} else if s.encV == 4 {
cipher, _ := chacha20poly1305.New(s.encKey[:])
return cipher.Open(nil, nonce[:cipher.NonceSize()], data, nil)
}
return
}
func (s Signer) gensig(data []byte) (sig []byte) {
if s.signV == 1 {
hash := sha512.Sum512(data)
mac := hmac.New(sha512.New384, s.signKey[:])
mac.Write(hash[:])
sig = mac.Sum(nil)
} else if s.signV == 2 {
hash := sha512.Sum512(data)
mac := hmac.New(sha512.New, s.signKey[:])
mac.Write(hash[:])
sig = mac.Sum(nil)
} else if s.signV == 3 {
hash := sha3.Sum512(data)
mac := hmac.New(sha3.New384, s.signKey[:])
mac.Write(hash[:])
sig = mac.Sum(nil)
} else if s.signV == 4 {
hash := sha3.Sum512(data)
mac := hmac.New(sha3.New512, s.signKey[:])
mac.Write(hash[:])
sig = mac.Sum(nil)
} else if s.signV == 5 {
hash := blake3.Sum256(data)
hf := blake3.New(256, s.signKey[:])
hf.Write(hash[:])
sig = hf.Sum(nil)
} else if s.signV == 6 {
sum := blake3.Sum256(data)
hf := blake3.New(256, nil)
mac := hmac.New(func() hash.Hash { return hf }, s.signKey[:])
mac.Write(sum[:])
sig = mac.Sum(nil)
} else if s.signV == 7 {
hash := blake2b.Sum256(data)
hf, _ := blake2b.New(256, s.signKey[:])
hf.Write(hash[:])
sig = hf.Sum(nil)
}
return
}