]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/tx.go
Replace Twofish/HKDF with ChaCha20/BLAKE2X for speed and simplicity
[nncp.git] / src / cypherpunks.ru / nncp / tx.go
index 7faef491cf0f279de5e239a7c77e9c32ee4e11d6..5dff27c3be2aa5dcd030eabb0ea8d1bc20191da6 100644 (file)
@@ -22,7 +22,6 @@ import (
        "bufio"
        "bytes"
        "compress/zlib"
-       "crypto/cipher"
        "crypto/rand"
        "errors"
        "hash"
@@ -35,7 +34,6 @@ import (
 
        "github.com/davecgh/go-xdr/xdr2"
        "golang.org/x/crypto/blake2b"
-       "golang.org/x/crypto/twofish"
 )
 
 func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size, minSize int64, src io.Reader) (*Node, error) {
@@ -119,25 +117,20 @@ func prepareTxFile(srcPath string) (io.Reader, *os.File, int64, error) {
                }
                os.Remove(src.Name())
                tmpW := bufio.NewWriter(src)
-
-               tmpKey := make([]byte, 32)
-               if _, err = rand.Read(tmpKey); err != nil {
-                       return nil, nil, 0, err
-               }
-               ciph, err := twofish.NewCipher(tmpKey)
-               if err != nil {
+               tmpKey := new([32]byte)
+               if _, err = rand.Read(tmpKey[:]); err != nil {
                        return nil, nil, 0, err
                }
-               ctr := cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
-               encrypter := &cipher.StreamWriter{S: ctr, W: tmpW}
-               fileSize, err = io.Copy(encrypter, bufio.NewReader(os.Stdin))
+               written, err := ae(tmpKey, bufio.NewReader(os.Stdin), tmpW)
                if err != nil {
                        return nil, nil, 0, err
                }
+               fileSize = int64(written)
                tmpW.Flush()
                src.Seek(0, 0)
-               ctr = cipher.NewCTR(ciph, make([]byte, twofish.BlockSize))
-               reader = &cipher.StreamReader{S: ctr, R: bufio.NewReader(src)}
+               r, w := io.Pipe()
+               go ae(tmpKey, bufio.NewReader(src), w)
+               reader = r
        } else {
                src, err = os.Open(srcPath)
                if err != nil {