Commit 2c872b29 authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Merge branch 'main' of gitlab.au.dk:au583826/crycomp into main

parents 2b381cc0 937bede3
......@@ -2,8 +2,10 @@ package main
import (
"crycomp/internal/blood"
"crypto/rand"
"fmt"
"math/big"
"strconv"
"golang.org/x/crypto/openpgp/elgamal"
)
......@@ -34,15 +36,30 @@ func (p *Party) Listen() {
if !ok {
panic("key channel closed unexpectedly")
}
// TODO enc column y
var encs []*Encryption
for i, key := range(<-p.keyChan) {
var res []byte
res = strconv.AppendBool(res, blood.Table[i][p.x])
c1, c2, _ := elgamal.Encrypt(rand.Reader, key, res)
encs = append(encs, &Encryption{c1, c2})
}
p.encChan <- encs
}
func (p *Party) ObliviousTransfer() bool {
return false // TODO
keys := make([]*elgamal.PublicKey, 8)
//TODO: insert actual publickey on index x
var pKey elgamal.PrivateKey
//TODO: Generate 7 fake public keys
p.keyChan <- keys
encs := <-p.encChan
data, _ := elgamal.Decrypt(&pKey,encs[p.x].C1, encs[p.x].C2) //Result as byte slice
result, _ := strconv.ParseBool(string(data))
return result
}
type Protocol struct {
......@@ -50,7 +67,14 @@ type Protocol struct {
}
func NewProtocol(x, y int) *Protocol {
return nil // TODO
keyChan := make(chan []*elgamal.PublicKey)
encChan := make(chan []*Encryption)
rec := NewParty(x, keyChan,encChan)
sen := NewParty(y,keyChan,encChan)
return &Protocol{
Receiver: rec,
Sender: sen,
}
}
// RunProtocol runs the protocol between receiving blood type x and donor blood
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment