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

Fixed

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