|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+package modules
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "strconv"
|
|
|
6
|
+)
|
|
|
7
|
+
|
|
|
8
|
+// 키관리 부분, 노드 입력받고 키 반환하는 부분 구현
|
|
|
9
|
+type Security struct{
|
|
|
10
|
+ KeyMap map[string] string
|
|
|
11
|
+}
|
|
|
12
|
+
|
|
|
13
|
+type SecurityManage interface {
|
|
|
14
|
+ reEncrypt()
|
|
|
15
|
+ keyGenPrivate()
|
|
|
16
|
+ compare()
|
|
|
17
|
+}
|
|
|
18
|
+
|
|
|
19
|
+/**
|
|
|
20
|
+keyShareMsg 에서 각 노드의 private 키를 받아 keyMap 에 저장
|
|
|
21
|
+ */
|
|
|
22
|
+func (sc Security) RegKey(ksm KeyShareMsg) {
|
|
|
23
|
+ sc.KeyMap[ksm.Message.From()] = ksm.key
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+/**
|
|
|
27
|
+각 노드의 키를 주소를 이용하여 맵에서 가져옴
|
|
|
28
|
+ */
|
|
|
29
|
+func (sc Security) GetNodeKey(message Message) int{
|
|
|
30
|
+
|
|
|
31
|
+ messageStringKey := sc.KeyMap[message.From()]
|
|
|
32
|
+ mKey, err := strconv.Atoi(messageStringKey)
|
|
|
33
|
+ if err != nil {
|
|
|
34
|
+ fmt.Println("reEncrypt Error: key string to int error.")
|
|
|
35
|
+ }
|
|
|
36
|
+ return mKey
|
|
|
37
|
+}
|
|
|
38
|
+
|
|
|
39
|
+/**
|
|
|
40
|
+reEncrypt 해서 슬라이스 반환
|
|
|
41
|
+ */
|
|
|
42
|
+func (sc Security) ReEncrypt(fromKey int, toKey int, target []int) []int{
|
|
|
43
|
+ for index := range target {
|
|
|
44
|
+ target[index] = target[index] - fromKey + toKey
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ return target
|
|
|
48
|
+}
|
|
|
49
|
+
|
|
|
50
|
+
|
|
|
51
|
+// private key 생성 메세지
|
|
|
52
|
+//func (sc Security) keyGenPrivate() KeyGenMsg{
|
|
|
53
|
+//
|
|
|
54
|
+//}
|