Coder Social home page Coder Social logo

完全自定义的加密方式 about kcp-go HOT 7 CLOSED

xtaci avatar xtaci commented on May 18, 2024
完全自定义的加密方式

from kcp-go.

Comments (7)

xtaci avatar xtaci commented on May 18, 2024

@v2ray 有点难度,在kcp里面,对数据的分段,是内部进行的,比如送入一个Payload []byte,可能被分割为很多个MTU大小的 UDP数据包发送,每个数据包都是独立加密封装的,并会填充CRC32。

其次,kcp为了做整个数据包加密,包括数据+KCP协议头(特别是协议头),只能在内部最终sendto之前完成加密,如果在外部做,kcp协议头只能是明文了,有安全风险。

所以这样的接口定义不合适,另外,目前的kcp-go使用的cipher.Block已经不依赖于某种特定的加密算法了, 常用算法都可以方便使用这个接口,比如加密算法在kcptun里面自定义。

所以,我的建议是,实现cipher.Block接口即可,和你给的接口定义没有本质差异

type Block interface {
        // BlockSize returns the cipher's block size.
        BlockSize() int

        // Encrypt encrypts the first block in src into dst.
        // Dst and src may point at the same memory.
        Encrypt(dst, src []byte)

        // Decrypt decrypts the first block in src into dst.
        // Dst and src may point at the same memory.
        Decrypt(dst, src []byte)
}

from kcp-go.

xtaci avatar xtaci commented on May 18, 2024

@v2ray 你说的意思,是不是把encrypt()/decrypt()函数描述的CFB模式,改为外部自定义?如果是这样,存在加密用法错误的风险,比如用 CTR/ECB,会导致特征泄漏,加密是需要精心设计的,最好不交给调用者控制,如果缺算法,可以补上即可。

from kcp-go.

 avatar commented on May 18, 2024

是你说的第二种方式。

我想说的只是耦合的问题,加密解密和 session 没有直接关系,你可以把现有的 encrypt()/decrypt() 做成一个比如 DefaultCryptor,普通用户依然可以通过简单的调用实现默认的加密方式,而高级用户可以更自由地定义加密和解密的方式。

from kcp-go.

xtaci avatar xtaci commented on May 18, 2024

@v2ray 我试一下

from kcp-go.

xtaci avatar xtaci commented on May 18, 2024

@v2ray 实现了一个 BlockCrypt接口,看下是不是你需要的

from kcp-go.

 avatar commented on May 18, 2024

谢谢,正是我想要的。

from kcp-go.

testcaoy7 avatar testcaoy7 commented on May 18, 2024

但愿自定义加密早日能成为现实,建议加入基于公钥的加密方式

from kcp-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.