示例#1
0
func ProtobufEncodePointList(plist []abstract.Point) []byte {
	byteNym, err := protobuf.Encode(&PointList{plist})
	if err != nil {
		panic(err.Error())
	}
	return byteNym
}
示例#2
0
func (sm *SigningMessage) MarshalBinary() ([]byte, error) {
	b, e := protobuf.Encode(sm)
	if len(b) != 0 {
		//dbg.Print("Length of bytes is", len(b), "for", sm)
		//debug.PrintStack()
	}
	return b, e
}
示例#3
0
文件: main.go 项目: jackowitzd2/neff
func (s *shuffler) getSignOffs(state *stateVector) error {
	replies := make(chan *signature)
	for i := 1; i < s.N; i++ {
		go func(id int) {
			port := 8080 + (id % s.N)
			addr := fmt.Sprintf("localhost:%d", port)
			rwc, err := net.Dial("tcp", addr)
			if err != nil {
				replies <- nil
				return
			}
			defer rwc.Close()

			bc := &ByteConn{rwc, make([]byte, 1)}
			if err = protobuf.Write(bc, state); err != nil {
				replies <- nil
				return
			}
			rwc.(*net.TCPConn).CloseWrite()

			var sig signature
			if err = protobuf.Read(bc, &sig); err != nil {
				replies <- nil
				return
			}
			replies <- &sig
		}(i)
	}

	sigs := make([][]byte, s.N)
	sig, err := s.signStateVector(state)
	if err != nil {
		return err
	}
	sigs[0] = sig

	for i := 0; i < s.N-1; i++ {
		reply := <-replies
		if reply != nil {
			X := s.HH[reply.Id]
			bytes, _ := protobuf.Encode(state)
			_, err := anon.Verify(s.suite, bytes, anon.Set{X}, nil, reply.S)
			if err != nil {
				return err
			}
			sigs[reply.Id] = reply.S
		}
	}

	fmt.Println("Got all signatures.")
	return s.checkKeys(state.States[len(state.States)-1])
}
示例#4
0
文件: main.go 项目: jackowitzd2/neff
func (s *shuffler) signStateVector(state *stateVector) ([]byte, error) {
	rand := s.suite.Cipher(abstract.RandomKey)

	st := state.States
	for i := 1; i < len(st); i++ {
		S, Sbar := st[i-1], st[i]

		X, Y := S.X, S.Dec
		Xbar, Ybar := Sbar.X, Sbar.Y
		H, prf := Sbar.G, Sbar.Prf

		// Verify the shuffle.
		verifier := shuffle.Verifier(s.suite, nil, H, X, Y, Xbar, Ybar)
		err := proof.HashVerify(s.suite, "PairShuffle", verifier, prf)
		if err != nil {
			panic("verify failed")
			return nil, err
		}

		// Verify the decryption.
		seed := abstract.Sum(s.suite, prf)
		verRand := s.suite.Cipher(seed)

		dec, decPrf := Sbar.Dec, Sbar.DecPrf

		// Scratch space for calculations.
		pair, c := s.suite.Point(), s.suite.Secret()
		zp := s.suite.Point()

		for j := range dec {
			pair.Sub(Ybar[j], dec[j])
			c.Pick(verRand)

			T := decPrf[j].T
			ss := decPrf[j].S
			if !zp.Mul(Xbar[j], ss).Equal(T.Add(T, pair.Mul(pair, c))) {
				return nil, errors.New("invalid decryption proof")
			}
		}
	}

	bytes, _ := protobuf.Encode(state)
	return anon.Sign(s.suite, rand, bytes, anon.Set{s.H}, nil, 0, s.h), nil
}
示例#5
0
// MarshalRegisteredType will marshal a struct with its respective type into a
// slice of bytes. That slice of bytes can be then decoded in
// UnmarshalRegisteredType.
func MarshalRegisteredType(data Body) ([]byte, error) {
	marshalLock.Lock()
	defer marshalLock.Unlock()
	var msgType MessageTypeID
	if msgType = TypeFromData(data); msgType == ErrorType {
		return nil, fmt.Errorf("Type of message %s not registered to the network library.", reflect.TypeOf(data))
	}
	b := new(bytes.Buffer)
	if err := binary.Write(b, globalOrder, msgType); err != nil {
		return nil, err
	}
	var buf []byte
	var err error
	if buf, err = protobuf.Encode(data); err != nil {
		log.Error("Error for protobuf encoding:", err)
		if log.DebugVisible() >= 3 {
			log.Error(log.Stack())
		}
		return nil, err
	}
	_, err = b.Write(buf)
	return b.Bytes(), err
}
示例#6
0
func (v *Vote) MarshalBinary() ([]byte, error) {
	return protobuf.Encode(v)
}
示例#7
0
func (nm *NetworkMessg) MarshalBinary() ([]byte, error) {
	return protobuf.Encode(nm)
}
func (m ProtobufSerializer) Marshal(o interface{}) []byte {
	d, _ := protobuf.Encode(o)
	return d
}
示例#9
0
func (sm *SigningMessage) MarshalBinary() ([]byte, error) {
	return protobuf.Encode(sm)
}
示例#10
0
func main() {
	uj := &Pmd.UserJsMessageForwardUserPmd_CS{}
	uj.Msgbytes = []byte(`{"whj":111}`)
	fmt.Println("XXXXX", uj.String(), proto.MarshalTextString(uj))
	rc := &Pmd.ReconnectErrorLoginUserPmd_S{}
	rc.Desc = proto.String(`{"whj":111}`)
	fmt.Println("xxxxx", rc.String(), proto.MarshalTextString(rc), *rc.Desc)
	m := make(map[int]string)
	m[1] = "wabghaijun"
	a := 1
	fmt.Println(protobuf.Encode(&a))
	mset := make(map[int32]proto.Extension)
	//mset[1] = proto.Extension{enc: []byte("sss")}
	//umset, err := proto.MarshalMessageSet(mset)
	var b []byte
	fmt.Println(len(b))
	nmd := &Pmd.ForwardNullUserPmd_CS{}
	nmd1 := &Pmd.ForwardNullUserPmd_CS{}
	nmd2 := &Pmd.ForwardNullUserPmd_CS{}
	cmd3 := &Pmd.RequestCloseNullUserPmd_CS{}
	cmd4 := &Pmd.RequestCloseNullUserPmd_CS{}
	cmd3.Reason = proto.String("2222")
	fmt.Println(proto.GetProperties(reflect.TypeOf(cmd3).Elem()))
	cmd3byte, err1 := proto.Marshal(cmd3)
	if err1 != nil {
		fmt.Println("xxxxxxxxxxx", err1)
	}
	fmt.Println(proto.Unmarshal(cmd3byte, cmd3))
	fmt.Println(mset)
	cmd3test := proto.MarshalTextString(cmd3)
	fmt.Println(cmd3test)
	fmt.Println(proto.UnmarshalText(cmd3test, nmd))
	//nmd.Prototype = proto.Uint64(2)
	nmd.ByCmd = proto.Uint32(0)
	//nmd.ByParam = proto.Uint32(0)
	//nmd.ByCmd = append(nmd.ByCmd, 0)
	//nmd.ByParam = append(nmd.ByParam, 0)
	sendbuf := proto.NewBuffer(nil)
	err := sendbuf.Marshal(nmd)
	if err != nil {
		fmt.Println("1", err)
	}
	nmd.Data = sendbuf.Bytes()
	fmt.Println(nmd, proto.Size(nmd), len(sendbuf.Bytes()))
	fmt.Println(len(sendbuf.Bytes()), sendbuf.Bytes())
	//data := sendbuf.Bytes()
	err = sendbuf.Marshal(cmd3)
	if err != nil {
		fmt.Println("2", err)
	}
	fmt.Println(len(sendbuf.Bytes()), sendbuf.Bytes())
	data := sendbuf.Bytes()
	fmt.Println(len(data), data)
	//data = append(data, byte(1))
	databuf := proto.NewBuffer(data)
	err = databuf.Unmarshal(nmd1)
	if err != nil {
		fmt.Println("3", err)
	}
	//err = databuf.Unmarshal(nmd2)
	err = proto.Unmarshal(data[:2], nmd2)
	if err != nil {
		fmt.Println("4", err)
	}
	err = proto.Unmarshal(data[2:], cmd4)
	//err = databuf.Unmarshal(cmd4)
	if err != nil {
		fmt.Println("5", err)
	}
	fmt.Println(nmd, proto.Size(nmd))
	fmt.Println(nmd1)
	fmt.Println(nmd2)
	fmt.Println(cmd4)
}
示例#11
0
// Encodes a policy message for sending over the Internet
func (msg *PolicyApprovedMessage) MarshalBinary() ([]byte, error) {
	return protobuf.Encode(msg)
}