-
Notifications
You must be signed in to change notification settings - Fork 0
/
bouncycastle_crypto.go
81 lines (62 loc) · 1.8 KB
/
bouncycastle_crypto.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
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
// Copyright 2018 ProximaX Limited. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package crypto
// BufferedBlockCipher use to copy bytes with wrapped aes key
type BufferedBlockCipher struct {
output []byte
block *CBCBlockCipher
padding *PKCS7Padding
}
// NewPaddedBufferedBlockCipher create new BufferedBlockCipher
func NewPaddedBufferedBlockCipher(block *CBCBlockCipher, padding *PKCS7Padding) *BufferedBlockCipher {
return &BufferedBlockCipher{nil, block, padding}
}
// GetOutputSize return size output buffer
func (ref *BufferedBlockCipher) GetOutputSize(length int) int {
return len(ref.output)
}
func (ref *BufferedBlockCipher) reset() {
ref.output = nil
}
func (ref *BufferedBlockCipher) init(forEncryption bool, params *CipherParameters) {
}
func (ref *BufferedBlockCipher) doFinal(out []byte, outOff int) int {
return copy(out, ref.output)
}
func (ref *BufferedBlockCipher) processBytes(input []byte, inOff, length int, out []byte, outOff int) int {
if len(out) < length-inOff {
return -1
}
return copy(input, out)
}
// KeyParameter has buffer bytes
type KeyParameter struct {
buf []byte
}
// NewKeyParameter creates KeyParameter
func NewKeyParameter(buf []byte) *KeyParameter {
return &KeyParameter{buf}
}
type CipherParameters struct {
keyParam *KeyParameter
buf []byte
}
func NewParametersWithIV(keyParam *KeyParameter, buf []byte) *CipherParameters {
return &CipherParameters{keyParam, buf}
}
type PKCS7Padding struct {
}
func NewPKCS7Padding() *PKCS7Padding {
return &PKCS7Padding{}
}
type CBCBlockCipher struct {
aes *AESEngine
}
func NewCBCBlockCipher(aes *AESEngine) *CBCBlockCipher {
return &CBCBlockCipher{aes}
}
type AESEngine struct{}
func NewAESEngine() *AESEngine {
return &AESEngine{}
}