Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ChaCha20 implementation with an optimized version #215

Merged
merged 1 commit into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.