|
@@ -188,7 +188,7 @@ func main() {
|
|
}
|
|
}
|
|
leaderConnection.SetDeadline(time.Time{})
|
|
leaderConnection.SetDeadline(time.Time{})
|
|
startTime = time.Now()
|
|
startTime = time.Now()
|
|
- go phase1(i, leaderConnection, m, wg)
|
|
|
|
|
|
+ go phase1(i, leaderConnection, m, wg, virtualAddresses)
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
|
@@ -236,7 +236,7 @@ func main() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func phase1(id int, leaderWorkerConnection net.Conn, m sync.Mutex, wg *sync.WaitGroup) {
|
|
|
|
|
|
+func phase1(id int, leaderWorkerConnection net.Conn, m sync.Mutex, wg *sync.WaitGroup, virtualAddresses []int) {
|
|
|
|
|
|
gotClient := make([]byte, 1)
|
|
gotClient := make([]byte, 1)
|
|
|
|
|
|
@@ -268,8 +268,13 @@ func phase1(id int, leaderWorkerConnection net.Conn, m sync.Mutex, wg *sync.Wait
|
|
}
|
|
}
|
|
clientPublicKey = &tmpClientPublicKey
|
|
clientPublicKey = &tmpClientPublicKey
|
|
|
|
|
|
- //auditing starts here
|
|
|
|
- //todo!
|
|
|
|
|
|
+ clientKeys := clientData[tmpClientPublicKey]
|
|
|
|
+ clientKeys, pirQuery := handlePirQuery(clientKeys, leaderWorkerConnection, 0, tmpClientPublicKey, true)
|
|
|
|
+ getSendVirtualAddress(pirQuery[0], virtualAddresses, clientKeys.SharedSecret, leaderWorkerConnection)
|
|
|
|
+
|
|
|
|
+ clientData[*clientPublicKey] = clientKeys
|
|
|
|
+
|
|
|
|
+ fmt.Println(pirQuery[0])
|
|
|
|
|
|
//gets dpfQuery from leader
|
|
//gets dpfQuery from leader
|
|
dpfLengthBytes := make([]byte, 4)
|
|
dpfLengthBytes := make([]byte, 4)
|
|
@@ -294,22 +299,54 @@ func phase1(id int, leaderWorkerConnection net.Conn, m sync.Mutex, wg *sync.Wait
|
|
panic("dpfQueryB decryption not ok")
|
|
panic("dpfQueryB decryption not ok")
|
|
}
|
|
}
|
|
|
|
|
|
- //run dpf, xor into local db
|
|
|
|
- for i := 0; i < dbSize; i++ {
|
|
|
|
- ds := int(C.db[i].dataSize)
|
|
|
|
- dataShare := make([]byte, ds)
|
|
|
|
- pos := C.getUint128_t(C.int(virtualAddresses[i]))
|
|
|
|
- C.evalDPF(C.ctx[id], (*C.uchar)(&dpfQueryB[0]), pos, C.int(ds), (*C.uchar)(&dataShare[0]))
|
|
|
|
- for j := 0; j < ds; j++ {
|
|
|
|
- db[i][j] = db[i][j] ^ dataShare[j]
|
|
|
|
|
|
+ ds := int(C.db[0].dataSize)
|
|
|
|
+ dataShareFollower := make([]byte, ds)
|
|
|
|
+ pos := C.getUint128_t(C.int(virtualAddresses[dbWriteSize]))
|
|
|
|
+ C.evalDPF(C.ctx[id], (*C.uchar)(&dpfQueryB[0]), pos, C.int(ds), (*C.uchar)(&dataShareFollower[0]))
|
|
|
|
+
|
|
|
|
+ dataShareLeader := make([]byte, ds)
|
|
|
|
+
|
|
|
|
+ _, err = leaderWorkerConnection.Write(dataShareFollower)
|
|
|
|
+ if err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, err = leaderWorkerConnection.Read(dataShareLeader)
|
|
|
|
+ if err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ auditXOR := make([]byte, ds)
|
|
|
|
+ passedAudit := true
|
|
|
|
+ for i := 0; i < ds; i++ {
|
|
|
|
+ auditXOR[i] = dataShareLeader[i] ^ dataShareFollower[i]
|
|
|
|
+
|
|
|
|
+ //client tried to write to a position that is not a virtuallAddress
|
|
|
|
+ if auditXOR[i] != 0 {
|
|
|
|
+ passedAudit = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //xor the worker's DB into the main DB
|
|
|
|
- for i := 0; i < dbSize; i++ {
|
|
|
|
- m.Lock()
|
|
|
|
- C.xorIn(C.int(i), (*C.uchar)(&db[i][0]))
|
|
|
|
- m.Unlock()
|
|
|
|
|
|
+ fmt.Println("auditXOR", auditXOR, passedAudit)
|
|
|
|
+
|
|
|
|
+ if passedAudit {
|
|
|
|
+ //run dpf, xor into local db
|
|
|
|
+ for i := 0; i < dbSize; i++ {
|
|
|
|
+ ds := int(C.db[i].dataSize)
|
|
|
|
+ dataShare := make([]byte, ds)
|
|
|
|
+ pos := C.getUint128_t(C.int(virtualAddresses[i]))
|
|
|
|
+ C.evalDPF(C.ctx[id], (*C.uchar)(&dpfQueryB[0]), pos, C.int(ds), (*C.uchar)(&dataShare[0]))
|
|
|
|
+ for j := 0; j < ds; j++ {
|
|
|
|
+ db[i][j] = db[i][j] ^ dataShare[j]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //xor the worker's DB into the main DB
|
|
|
|
+ for i := 0; i < dbSize; i++ {
|
|
|
|
+ m.Lock()
|
|
|
|
+ C.xorIn(C.int(i), (*C.uchar)(&db[i][0]))
|
|
|
|
+ m.Unlock()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -508,7 +545,7 @@ func phase3(leaderWorkerConnection net.Conn, wg *sync.WaitGroup) {
|
|
clientKeys := clientData[clientPublicKey]
|
|
clientKeys := clientData[clientPublicKey]
|
|
|
|
|
|
if subPhase[0] == 0 || subPhase[0] == 1 {
|
|
if subPhase[0] == 0 || subPhase[0] == 1 {
|
|
- clientKeys, _ = handlePirQuery(clientKeys, leaderWorkerConnection, int(subPhase[0]), clientPublicKey)
|
|
|
|
|
|
+ clientKeys, _ = handlePirQuery(clientKeys, leaderWorkerConnection, int(subPhase[0]), clientPublicKey, false)
|
|
}
|
|
}
|
|
|
|
|
|
getSendTweets(clientKeys, nil, leaderWorkerConnection)
|
|
getSendTweets(clientKeys, nil, leaderWorkerConnection)
|
|
@@ -520,7 +557,7 @@ func phase3(leaderWorkerConnection net.Conn, wg *sync.WaitGroup) {
|
|
}
|
|
}
|
|
|
|
|
|
if wantsArchive[0] == 1 {
|
|
if wantsArchive[0] == 1 {
|
|
- _, archiveQuerys := handlePirQuery(clientKeys, leaderWorkerConnection, -1, clientPublicKey)
|
|
|
|
|
|
+ _, archiveQuerys := handlePirQuery(clientKeys, leaderWorkerConnection, -1, clientPublicKey, false)
|
|
getSendTweets(clientKeys, archiveQuerys, leaderWorkerConnection)
|
|
getSendTweets(clientKeys, archiveQuerys, leaderWorkerConnection)
|
|
|
|
|
|
}
|
|
}
|
|
@@ -572,7 +609,8 @@ func getSendTweets(clientKeys clientKeys, archiveQuerys [][]byte, leaderWorkerCo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subPhase int, clientPublicKey [32]byte) (clientKeys, [][]byte) {
|
|
|
|
|
|
+func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subPhase int, clientPublicKey [32]byte, doAuditing bool) (clientKeys, [][]byte) {
|
|
|
|
+
|
|
archiveNeededSubscriptions := make([]byte, 4)
|
|
archiveNeededSubscriptions := make([]byte, 4)
|
|
if subPhase == -1 {
|
|
if subPhase == -1 {
|
|
_, err := leaderWorkerConnection.Read(archiveNeededSubscriptions)
|
|
_, err := leaderWorkerConnection.Read(archiveNeededSubscriptions)
|
|
@@ -603,6 +641,7 @@ func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subP
|
|
if !ok {
|
|
if !ok {
|
|
panic("pirQuery decryption not ok")
|
|
panic("pirQuery decryption not ok")
|
|
}
|
|
}
|
|
|
|
+
|
|
//gets sharedSecret
|
|
//gets sharedSecret
|
|
if subPhase == 0 {
|
|
if subPhase == 0 {
|
|
//bs!
|
|
//bs!
|
|
@@ -613,6 +652,12 @@ func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subP
|
|
clientKeys.SharedSecret = newSharedSecret
|
|
clientKeys.SharedSecret = newSharedSecret
|
|
decrypted = decrypted[32:]
|
|
decrypted = decrypted[32:]
|
|
|
|
|
|
|
|
+ if doAuditing {
|
|
|
|
+ result := make([][]byte, 1)
|
|
|
|
+ result[0] = decrypted
|
|
|
|
+ return clientKeys, result
|
|
|
|
+ }
|
|
|
|
+
|
|
//follower updates sharedSecret
|
|
//follower updates sharedSecret
|
|
} else if subPhase == 1 {
|
|
} else if subPhase == 1 {
|
|
sharedSecret := clientKeys.SharedSecret
|
|
sharedSecret := clientKeys.SharedSecret
|
|
@@ -623,13 +668,14 @@ func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subP
|
|
//follower expects pirQuery
|
|
//follower expects pirQuery
|
|
|
|
|
|
//transforms byteArray to ints of wanted topics
|
|
//transforms byteArray to ints of wanted topics
|
|
- pirQueryFlattened := decrypted
|
|
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
tmpNeededSubscriptions := neededSubscriptions
|
|
tmpTopicAmount := topicAmount
|
|
tmpTopicAmount := topicAmount
|
|
if subPhase == -1 {
|
|
if subPhase == -1 {
|
|
tmpNeededSubscriptions = byteToInt(archiveNeededSubscriptions)
|
|
tmpNeededSubscriptions = byteToInt(archiveNeededSubscriptions)
|
|
_, tmpTopicAmount = lib.GetTopicList(1)
|
|
_, tmpTopicAmount = lib.GetTopicList(1)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ pirQueryFlattened := decrypted
|
|
pirQuerys := make([][]byte, tmpNeededSubscriptions)
|
|
pirQuerys := make([][]byte, tmpNeededSubscriptions)
|
|
for i := range pirQuerys {
|
|
for i := range pirQuerys {
|
|
pirQuerys[i] = make([]byte, tmpTopicAmount)
|
|
pirQuerys[i] = make([]byte, tmpTopicAmount)
|
|
@@ -646,6 +692,30 @@ func handlePirQuery(clientKeys clientKeys, leaderWorkerConnection net.Conn, subP
|
|
return clientKeys, pirQuerys
|
|
return clientKeys, pirQuerys
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func getSendVirtualAddress(pirQuery []byte, virtualAddresses []int, sharedSecret [32]byte, leaderWorkerConnection net.Conn) {
|
|
|
|
+ //xores all requested addresses into virtuallAddress
|
|
|
|
+ virtualAddress := make([]byte, 4)
|
|
|
|
+ fmt.Println(pirQuery[15])
|
|
|
|
+ for _, num := range pirQuery {
|
|
|
|
+ if num == 1 {
|
|
|
|
+ currentAddress := intToByte(virtualAddresses[num])
|
|
|
|
+ for i := 0; i < 4; i++ {
|
|
|
|
+ virtualAddress[i] = virtualAddress[i] ^ currentAddress[i]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //xores the sharedSecret
|
|
|
|
+ for i := 0; i < 4; i++ {
|
|
|
|
+ virtualAddress[i] = virtualAddress[i] ^ sharedSecret[i]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, err := leaderWorkerConnection.Write(virtualAddress)
|
|
|
|
+ if err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func transformBytesToStringArray(topicsAsBytes []byte) []string {
|
|
func transformBytesToStringArray(topicsAsBytes []byte) []string {
|
|
var topics []string
|
|
var topics []string
|
|
var topic string
|
|
var topic string
|