Beispiel #1
0
func (state *ComputePeerState) OneSub(action *sproto.Action) *sproto.Response {
	//fmt.Println("Subtraction one from value")
	result := *action.Result
	share0 := *action.Share0
	share0val, hasShare0val := state.SharesGet(share0)
	if hasShare0val {
		val := core.Sub(1, share0val)
		state.SharesSet(result, val)
	}
	return state.failResponse(action.GetRequestCode())

}
Beispiel #2
0
// Add two shares
func (state *ComputePeerState) Add(action *sproto.Action) *sproto.Response {
	//fmt.Println("Adding two values")
	result := *action.Result
	share0 := *action.Share0
	share1 := *action.Share1
	share0val, hasShare0val := state.SharesGet(share0)
	share1val, hasShare1val := state.SharesGet(share1)
	if hasShare0val && hasShare1val {
		state.SharesSet(result, core.Add(share0val, share1val))
		//fmt.Println("Done Adding")
		return state.okResponse(action.GetRequestCode())
	}
	//fmt.Printf("Failed additions, response would have been %s (%s, %v, %s, %v)\n", result, share0, hasShare0val, share1, hasShare1val)
	return state.failResponse(action.GetRequestCode())
}
Beispiel #3
0
// Test inequality to zero
func (state *ComputePeerState) Neqz(action *sproto.Action) *sproto.Response {
	//fmt.Println("Comparing values")
	result := *action.Result
	share0 := *action.Share0
	share0val, hasShare0Val := state.SharesGet(share0)
	rcode := *action.RequestCode
	if !hasShare0Val {
		//fmt.Printf("Failing, variable %s not found\n", share0)
		return state.failResponse(action.GetRequestCode())
	}
	res := state.neqz(share0val, rcode)
	state.SharesSet(result, res)
	//fmt.Printf("Done testing value for not zero\n")
	return state.okResponse(action.GetRequestCode())
}
Beispiel #4
0
// Retrieve the value of a share
func (state *ComputePeerState) GetValue(action *sproto.Action) *sproto.Response {
	result := *action.Result
	val, hasVal := state.SharesGet(result)
	if hasVal {
		resp := &sproto.Response{}
		rcode := action.GetRequestCode()
		resp.RequestCode = &rcode
		resp.Share = &val
		status := sproto.Response_Val
		resp.Status = &status
		client := int32(state.Client)
		resp.Client = &client
		return resp
	}
	return state.failResponse(action.GetRequestCode())
}
Beispiel #5
0
// Multiply const
func (state *ComputePeerState) MulConst(action *sproto.Action) *sproto.Response {
	//fmt.Println("Multiplying with constants")
	result := *action.Result
	share0 := *action.Share0
	val := *action.Value
	share0val, hasShare0Val := state.SharesGet(share0)
	rcode := *action.RequestCode
	if !hasShare0Val {
		//fmt.Printf("Failing, variable %s not found\n", share0)
		return state.failResponse(action.GetRequestCode())
	}
	res := core.MultUnderMod(val, share0val)
	state.SharesSet(result, res)
	//fmt.Println("Done multiplying constants")
	return state.okResponse(rcode)
}
Beispiel #6
0
// Test equality to zero
func (state *ComputePeerState) Eqz(action *sproto.Action) *sproto.Response {
	//fmt.Println("Comparing values")
	result := *action.Result
	share0 := *action.Share0
	share0val, hasShare0Val := state.SharesGet(share0)
	rcode := *action.RequestCode
	if !hasShare0Val {
		return state.failResponse(action.GetRequestCode())
	}
	res := state.neqz(share0val, rcode)
	one := int64(1)
	res = core.Sub(one, res)
	state.SharesSet(result, res)
	//fmt.Printf("Done testing value for zero\n")
	return state.okResponse(action.GetRequestCode())
}
Beispiel #7
0
// Inequality
func (state *ComputePeerState) Neq(action *sproto.Action) *sproto.Response {
	//fmt.Println("Comparing values")
	result := *action.Result
	share0 := *action.Share0
	share1 := *action.Share1
	share0val, hasShare0Val := state.SharesGet(share0)
	share1val, hasShare1Val := state.SharesGet(share1)
	rcode := *action.RequestCode
	if !hasShare0Val || !hasShare1Val {
		return state.failResponse(action.GetRequestCode())
	}
	res := state.ncmp(share0val, share1val, rcode)
	state.SharesSet(result, res)
	//fmt.Printf("Done comparing values\n")
	return state.okResponse(action.GetRequestCode())
}
Beispiel #8
0
// Set the value of a share
func (state *ComputePeerState) SetValue(action *sproto.Action) *sproto.Response {
	//fmt.Println("Setting value ", *action.Result, *action.Value)
	result := *action.Result
	val := *action.Value
	state.SharesSet(result, int64(val))
	//fmt.Println("Returned from sharesset")
	resp := &sproto.Response{}
	rcode := action.GetRequestCode()
	resp.RequestCode = &rcode
	status := sproto.Response_OK
	resp.Status = &status
	client := int32(state.Client)
	resp.Client = &client
	//fmt.Println("Done setting value")
	return resp
}
Beispiel #9
0
// Compare to const
func (state *ComputePeerState) NeqConst(action *sproto.Action) *sproto.Response {
	//fmt.Println("Comparing to constant")
	result := *action.Result
	share0 := *action.Share0
	val := *action.Value
	share0val, hasShare0Val := state.SharesGet(share0)
	rcode := *action.RequestCode
	if !hasShare0Val {
		//fmt.Printf("Failing, variable %s not found\n", share0)
		return state.failResponse(action.GetRequestCode())
	}
	res := core.Sub(val, share0val)
	//fmt.Printf("Subtractiong const %d", val)
	res = state.neqz(res, rcode)
	state.SharesSet(result, res)
	//fmt.Printf("Done comparing to const\n")
	return state.okResponse(action.GetRequestCode())
}
Beispiel #10
0
// Remove the value for a share
func (state *ComputePeerState) RemoveValue(action *sproto.Action) *sproto.Response {
	result := *action.Result
	_, hasVal := state.SharesGet(result)
	if hasVal {
		//fmt.Println("Deleting value ", *action.Result)
		result := *action.Result
		state.SharesDelete(result)
		//fmt.Println("Returned from sharesdelete")
		resp := &sproto.Response{}
		rcode := action.GetRequestCode()
		resp.RequestCode = &rcode
		status := sproto.Response_OK
		resp.Status = &status
		client := int32(state.Client)
		resp.Client = &client
		//fmt.Println("Done setting value")
		return resp
	}
	return state.failResponse(action.GetRequestCode())
}
Beispiel #11
0
// Multiply two shares
func (state *ComputePeerState) Mul(action *sproto.Action) *sproto.Response {
	//fmt.Println("Multiplying two values")
	result := *action.Result
	share0 := *action.Share0
	share1 := *action.Share1
	share0val, hasShare0val := state.SharesGet(share0)
	share1val, hasShare1val := state.SharesGet(share1)
	//fmt.Printf("Multiplying, will set %s\n", result)
	rcode := *action.RequestCode
	if hasShare0val && hasShare1val {
		share := state.mul(share0val, share1val, rcode, 1)
		//fmt.Printf("Done multiplying, setting %s\n", result)
		state.SharesSet(result, share)
		//fmt.Printf("Done multiplying, done setting %s\n", result)
		//fmt.Printf("Done multiplying\n")
		state.UnregisterChannelForRequest(*MakeRequestStep(rcode, 1))
		return state.okResponse(action.GetRequestCode())
	} else {
		//fmt.Printf("Not setting %s, could not find operands %s %v %s %v\n", result, share0, hasShare0val, share1, hasShare1val)
	}
	return state.failResponse(action.GetRequestCode())
}
Beispiel #12
0
// Compare to const
func (state *ComputePeerState) CmpConst(action *sproto.Action) *sproto.Response {
	//fmt.Println("Comparing to constant")
	result := *action.Result
	share0 := *action.Share0
	val := *action.Value
	share0val, hasShare0Val := state.SharesGet(share0)
	rcode := *action.RequestCode
	if !hasShare0Val {
		return state.failResponse(action.GetRequestCode())
	}
	//fmt.Printf("For rcode %d (CMPCONST) subtracting\n", rcode)
	res := core.Sub(val, share0val)
	//fmt.Printf("For rcode %d (CMPCONST) neqz\n", rcode)
	res = state.neqz(res, rcode)
	//fmt.Printf("For rcode %d (CMPCONST) done with neqz\n", rcode)
	one := int64(1)
	//fmt.Printf("For rcode %d (CMPCONST) subtracting\n", rcode)
	res = core.Sub(one, res)
	//fmt.Printf("For rcode %d (CMPCONST) setting share\n", rcode)
	state.SharesSet(result, res)
	//fmt.Printf("Done comparing to const\n")
	return state.okResponse(action.GetRequestCode())
}
Beispiel #13
0
func (state *ComputePeerState) DefaultAction(action *sproto.Action) *sproto.Response {
	//fmt.Println("Illegal action")
	return state.failResponse(action.GetRequestCode())
}