Skip to content

Commit

Permalink
Merge pull request #215 from aead/master
Browse files Browse the repository at this point in the history
Replace ChaCha20 implementation with an optimized version
  • Loading branch information
DarienRaymond committed Jul 23, 2016
2 parents 85d6e1a + 0cd0033 commit 08526a3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 276 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/onsi/gomega
- go get github.com/onsi/ginkgo
- go get github.com/aead/chacha20

script:
- go test -tags json github.com/v2ray/v2ray-core/...
Expand Down
22 changes: 20 additions & 2 deletions common/crypto/chacha20.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ package crypto
import (
"crypto/cipher"

"github.com/v2ray/v2ray-core/common/crypto/internal"
"github.com/aead/chacha20"
)

func makeNonce(nonce *[chacha20.NonceSize]byte, iv []byte) {
switch len(iv) {
case 8:
copy(nonce[4:], iv)
case 12:
copy(nonce[:], iv)
default:
panic("bad nonce length")
}
}

func NewChaCha20Stream(key []byte, iv []byte) cipher.Stream {
return internal.NewChaCha20Stream(key, iv, 20)
var Key [32]byte
var Nonce [12]byte
if len(key) != 32 {
panic("bad key length")
}
copy(Key[:], key)
makeNonce(&Nonce, iv)
return chacha20.NewCipher(&Nonce, &Key)
}
80 changes: 0 additions & 80 deletions common/crypto/internal/chacha.go

This file was deleted.

124 changes: 0 additions & 124 deletions common/crypto/internal/chacha_core.go

This file was deleted.

70 changes: 0 additions & 70 deletions common/crypto/internal/chacha_core_gen.go

This file was deleted.

0 comments on commit 08526a3

Please sign in to comment.