示例#1
0
文件: operations.go 项目: apanda/smpc
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())

}
示例#2
0
文件: operations.go 项目: apanda/smpc
// 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())
}
示例#3
0
文件: operations.go 项目: apanda/smpc
// 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())
}
示例#4
0
文件: operations.go 项目: apanda/smpc
// 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())
}
示例#5
0
文件: operations.go 项目: apanda/smpc
func (state *ComputePeerState) ncmp(share0val int64, share1val int64, rcode int64) int64 {
	a := core.Sub(share0val, share1val)
	return state.neqz(a, rcode)
}