|
|
@@ -6,40 +6,48 @@ import (
|
|
6
|
6
|
)
|
|
7
|
7
|
|
|
8
|
8
|
// 키관리 부분, 노드 입력받고 키 반환하는 부분 구현
|
|
9
|
|
-type Security struct{
|
|
10
|
|
- KeyMap map[string] string
|
|
|
9
|
+type Security struct {
|
|
|
10
|
+ KeyMap map[string]string
|
|
11
|
11
|
}
|
|
12
|
12
|
|
|
13
|
|
-type SecurityManage interface {
|
|
14
|
|
- reEncrypt()
|
|
15
|
|
- keyGenPrivate()
|
|
16
|
|
- compare()
|
|
|
13
|
+func NewSecurity() *Security {
|
|
|
14
|
+ security := &Security{map[string]string{}}
|
|
|
15
|
+ return security
|
|
|
16
|
+}
|
|
|
17
|
+
|
|
|
18
|
+type SecurityManager interface {
|
|
|
19
|
+ RegKey(ksm KeyShareMsg)
|
|
|
20
|
+ GetNodeKey(message Message) int64
|
|
|
21
|
+ ReEncrypt(fromKey int64, toKey int64, target []int64) []int64
|
|
|
22
|
+ CompareTopic(topic1 []int64, topic2 []int64) int
|
|
|
23
|
+ CompareDigit(topic1 int64, topic2 int64) int
|
|
|
24
|
+ CompareAlpha(topic1 []int64, topic2 []int64) int
|
|
17
|
25
|
}
|
|
18
|
26
|
|
|
19
|
27
|
/**
|
|
20
|
28
|
keyShareMsg 에서 각 노드의 private 키를 받아 keyMap 에 저장
|
|
21
|
|
- */
|
|
|
29
|
+*/
|
|
22
|
30
|
func (sc Security) RegKey(ksm KeyShareMsg) {
|
|
23
|
31
|
sc.KeyMap[ksm.Message.From()] = ksm.key
|
|
24
|
32
|
}
|
|
25
|
33
|
|
|
26
|
34
|
/**
|
|
27
|
35
|
각 노드의 키를 주소를 이용하여 맵에서 가져옴
|
|
28
|
|
- */
|
|
29
|
|
-func (sc Security) GetNodeKey(message Message) int{
|
|
|
36
|
+*/
|
|
|
37
|
+func (sc Security) GetNodeKey(message Message) int64 {
|
|
30
|
38
|
|
|
31
|
39
|
messageStringKey := sc.KeyMap[message.From()]
|
|
32
|
|
- mKey, err := strconv.Atoi(messageStringKey)
|
|
|
40
|
+ mKey, err := strconv.ParseInt(messageStringKey, 10, 64)
|
|
33
|
41
|
if err != nil {
|
|
34
|
|
- fmt.Println("reEncrypt Error: key string to int error.")
|
|
|
42
|
+ fmt.Println("reEncrypt Error: key string to int64 parsing error.")
|
|
35
|
43
|
}
|
|
36
|
44
|
return mKey
|
|
37
|
45
|
}
|
|
38
|
46
|
|
|
39
|
47
|
/**
|
|
40
|
48
|
reEncrypt 해서 슬라이스 반환
|
|
41
|
|
- */
|
|
42
|
|
-func (sc Security) ReEncrypt(fromKey int, toKey int, target []int) []int{
|
|
|
49
|
+*/
|
|
|
50
|
+func (sc Security) ReEncrypt(fromKey int64, toKey int64, target []int64) []int64 {
|
|
43
|
51
|
for index := range target {
|
|
44
|
52
|
target[index] = target[index] - fromKey + toKey
|
|
45
|
53
|
}
|
|
|
@@ -47,6 +55,35 @@ func (sc Security) ReEncrypt(fromKey int, toKey int, target []int) []int{
|
|
47
|
55
|
return target
|
|
48
|
56
|
}
|
|
49
|
57
|
|
|
|
58
|
+/**
|
|
|
59
|
+Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
|
|
|
60
|
+*/
|
|
|
61
|
+func (sc Security) CompareTopic(topic1 []int64, topic2 []int64) int {
|
|
|
62
|
+ for i := 0; i < len(topic2); i++ {
|
|
|
63
|
+ if topic1[i] != topic2[i] {
|
|
|
64
|
+ return -1
|
|
|
65
|
+ }
|
|
|
66
|
+ }
|
|
|
67
|
+ return 0
|
|
|
68
|
+}
|
|
|
69
|
+
|
|
|
70
|
+func (sc Security) CompareDigit(topic1 int64, topic2 int64) int {
|
|
|
71
|
+ if topic1 < topic2 {
|
|
|
72
|
+ return 1
|
|
|
73
|
+ } else if topic1 > topic2 {
|
|
|
74
|
+ return -1
|
|
|
75
|
+ }
|
|
|
76
|
+ return 0
|
|
|
77
|
+}
|
|
|
78
|
+
|
|
|
79
|
+func (sc Security) CompareAlpha(topic1 []int64, topic2 []int64) int {
|
|
|
80
|
+ for i := 0; i < len(topic2); i++ {
|
|
|
81
|
+ if topic1[i] != topic2[i] {
|
|
|
82
|
+ return -1
|
|
|
83
|
+ }
|
|
|
84
|
+ }
|
|
|
85
|
+ return 0
|
|
|
86
|
+}
|
|
50
|
87
|
|
|
51
|
88
|
// private key 생성 메세지
|
|
52
|
89
|
//func (sc Security) keyGenPrivate() KeyGenMsg{
|