Exemplo n.º 1
0
// 密钥交换
func P_get_pike_seed_req(sess *Session, reader *packet.Packet) []byte {
	tbl, _ := PKT_pike_seed_info(reader)
	// KEY1
	X1, E1 := dh.DHExchange()
	KEY1 := dh.DHKey(X1, big.NewInt(int64(tbl.F_client_send_seed)))

	// KEY2
	X2, E2 := dh.DHExchange()
	KEY2 := dh.DHKey(X2, big.NewInt(int64(tbl.F_client_receive_seed)))

	ret := pike_seed_info{int32(E1.Int64()), int32(E2.Int64())}
	// 服务器加密种子是客户端解密种子
	sess.Encoder = pike.NewCtx(uint32(KEY2.Int64()))
	sess.Decoder = pike.NewCtx(uint32(KEY1.Int64()))
	sess.Flag |= SESS_KEYEXCG
	return packet.Pack(Code["get_pike_seed_ack"], ret, nil)
}
Exemplo n.º 2
0
func P_key_exchange_req(sess *Session, reader *packet.Packet) []byte {
	tbl, _ := PKT_KEY(reader)
	A := big.NewInt(int64(tbl.F_E))
	secret, B := diffie.DHGenKey(diffie.DH1BASE, diffie.DH1PRIME)

	key := big.NewInt(0).Exp(A, secret, diffie.DH1PRIME)
	sess.Crypto = pike.NewCtx(uint32(key.Uint64()))

	ret := KEY{int32(B.Uint64())}
	return packet.Pack(Code["key_exchange_ack"], &ret, nil)
}