Commit 9c10de80 authored by Thomas Hoffmann's avatar Thomas Hoffmann
Browse files

Fixed

parent 93af3bc5
......@@ -78,7 +78,8 @@ type Protocol struct {
func NewProtocol() (p *Protocol, err error) {
conn := make(chan big.Int)
sKey, HEp, err := homomorphic.NewProtocol(3,27)
params := homomorphic.NewParams(200,100000, 1000000,200)
sKey, HEp, err := homomorphic.NewProtocol(params)
if err != nil {
return
}
......
package homomorphic
import (
"math/big"
"crycomp/internal/crypto/util"
"crypto/rand"
"math/big"
mRand "math/rand"
)
type Params struct {
len_sKey int
len_q int
len_r int
m int
}
func NewParams(len_sKey, len_q, len_r, m int) *Params {
return &Params{
len_sKey : len_sKey,
len_q : len_q,
len_r : len_r,
m : m,
}
}
type Protocol struct {
d, n int
pubKey []*big.Int
params *Params
}
func NewProtocol(d, n int) (sKey *big.Int, pr Protocol, err error) {
s_int, b_int := big.NewInt(27), big.NewInt(27)
sBytes := make([]byte, 250)
_, err = rand.Read(sBytes)
func NewProtocol(params *Params) (sKey *big.Int, pr Protocol, err error) {
//set private key to a random odd 2000-bit integer
res, err := util.RandInt(rand.Reader, big.NewInt(int64(params.len_sKey)))
if err != nil {return}
sBytes[len(sBytes)]
sKey = sKey.SetBit(sKey, 0, 1)
res.SetBit(res, 0, 1)
sKey = res
q := make([]*big.Int, n)
r := make([]*big.Int, n)
y := make([]*big.Int, n)
q := make([]*big.Int, params.m)
r := make([]*big.Int, params.m)
y := make([]*big.Int, params.m)
for i := range q {
q[i], err = rand.Int(rand.Reader, b_int)
q[i], err = rand.Int(rand.Reader, big.NewInt(int64(params.len_q)))
if err != nil {return}
r[i], err = rand.Int(rand.Reader, s_int)
r[i], err = rand.Int(rand.Reader, big.NewInt(int64(params.len_r)))
if err != nil {return}
right := big.NewInt(2)
right.Mul(right,r[i])
......@@ -35,21 +49,20 @@ func NewProtocol(d, n int) (sKey *big.Int, pr Protocol, err error) {
y[i] = right.Add(left, right)
}
pr = Protocol{
n : n,
d : d,
pubKey : y,
params : params,
}
return sKey, pr, err
}
func (p *Protocol) Encode(m int) (c *big.Int) {
SLen := 4 //TODO: Define actual value
S := make([]int, p.n)
for i := 0; i < p.n; i++ {
S := make([]int, p.params.m)
for i := 0; i < p.params.m; i++ {
S[i] = i
}
mRand.Shuffle(p.n, func(i,j int) {S[i],S[j] = S[j], S[i]})
S = S[:SLen]
mRand.Shuffle(p.params.m, func(i,j int) {S[i],S[j] = S[j], S[i]})
S = S[:SLen-1]
c = big.NewInt(int64(m))
for i := range S {
c = c.Add(c, p.pubKey[S[i]])
......
......@@ -72,4 +72,4 @@ func (s *cryptoSource) Int63() int64 {
func (s *cryptoSource) Seed(seed int64) {
panic("seed")
}
}
\ No newline at end of file
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