|
|
@@ -10,10 +10,18 @@ type Security struct{
|
|
10
|
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
|
/**
|
|
|
@@ -26,12 +34,12 @@ func (sc Security) RegKey(ksm KeyShareMsg) {
|
|
26
|
34
|
/**
|
|
27
|
35
|
각 노드의 키를 주소를 이용하여 맵에서 가져옴
|
|
28
|
36
|
*/
|
|
29
|
|
-func (sc Security) GetNodeKey(message Message) int{
|
|
|
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
|
}
|
|
|
@@ -39,7 +47,7 @@ func (sc Security) GetNodeKey(message Message) int{
|
|
39
|
47
|
/**
|
|
40
|
48
|
reEncrypt 해서 슬라이스 반환
|
|
41
|
49
|
*/
|
|
42
|
|
-func (sc Security) ReEncrypt(fromKey int, toKey int, target []int) []int{
|
|
|
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
|
}
|
|
|
@@ -48,6 +56,39 @@ func (sc Security) ReEncrypt(fromKey int, toKey int, target []int) []int{
|
|
48
|
56
|
}
|
|
49
|
57
|
|
|
50
|
58
|
|
|
|
59
|
+/**
|
|
|
60
|
+Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
|
|
|
61
|
+ */
|
|
|
62
|
+func (sc Security) CompareTopic(topic1 []int64, topic2 []int64) int {
|
|
|
63
|
+ for i := 0; i< len(topic2); i++ {
|
|
|
64
|
+ if topic1[i] != topic2[i] {
|
|
|
65
|
+ return -1
|
|
|
66
|
+ }
|
|
|
67
|
+ }
|
|
|
68
|
+ return 0
|
|
|
69
|
+}
|
|
|
70
|
+
|
|
|
71
|
+func (sc Security) CompareDigit(topic1 int64, topic2 int64) int {
|
|
|
72
|
+ if topic1 < topic2 {
|
|
|
73
|
+ return 1
|
|
|
74
|
+ } else if topic1 > topic2 {
|
|
|
75
|
+ return -1
|
|
|
76
|
+ }
|
|
|
77
|
+ return 0
|
|
|
78
|
+}
|
|
|
79
|
+
|
|
|
80
|
+func (sc Security) CompareAlpha(topic1 []int64, topic2 []int64) int {
|
|
|
81
|
+ for i := 0; i< len(topic2); i++ {
|
|
|
82
|
+ if topic1[i] != topic2[i] {
|
|
|
83
|
+ return -1
|
|
|
84
|
+ }
|
|
|
85
|
+ }
|
|
|
86
|
+ return 0
|
|
|
87
|
+}
|
|
|
88
|
+
|
|
|
89
|
+
|
|
|
90
|
+
|
|
|
91
|
+
|
|
51
|
92
|
// private key 생성 메세지
|
|
52
|
93
|
//func (sc Security) keyGenPrivate() KeyGenMsg{
|
|
53
|
94
|
//
|