mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-04 21:57:44 +03:00
Update xsecretbox again
This commit is contained in:
parent
8213a96cd5
commit
81692a3a80
28 changed files with 33 additions and 4244 deletions
4
vendor/github.com/jedisct1/xsecretbox/.travis.yml
generated
vendored
4
vendor/github.com/jedisct1/xsecretbox/.travis.yml
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
sudo: false
|
||||
language: go
|
||||
go:
|
||||
- 1.x
|
9
vendor/github.com/jedisct1/xsecretbox/go.mod
generated
vendored
9
vendor/github.com/jedisct1/xsecretbox/go.mod
generated
vendored
|
@ -1,10 +1,5 @@
|
|||
module github.com/jedisct1/xsecretbox
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da
|
||||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
|
||||
)
|
||||
require golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
|
||||
|
|
23
vendor/github.com/jedisct1/xsecretbox/go.sum
generated
vendored
23
vendor/github.com/jedisct1/xsecretbox/go.sum
generated
vendored
|
@ -1,15 +1,8 @@
|
|||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
|
||||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
|
||||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw=
|
||||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg=
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
|
27
vendor/github.com/jedisct1/xsecretbox/sharedkey.go
generated
vendored
27
vendor/github.com/jedisct1/xsecretbox/sharedkey.go
generated
vendored
|
@ -2,27 +2,26 @@ package xsecretbox
|
|||
|
||||
import (
|
||||
crypto_rand "crypto/rand"
|
||||
"errors"
|
||||
|
||||
"github.com/aead/chacha20/chacha"
|
||||
"golang.org/x/crypto/chacha20"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
)
|
||||
|
||||
// SharedKey computes a shared secret compatible with the one used by `crypto_box_xchacha20poly1305``
|
||||
func SharedKey(secretKey [32]byte, publicKey [32]byte) ([32]byte, error) {
|
||||
var sharedKey [32]byte
|
||||
curve25519.ScalarMult(&sharedKey, &secretKey, &publicKey)
|
||||
c := byte(0)
|
||||
for i := 0; i < 32; i++ {
|
||||
c |= sharedKey[i]
|
||||
dhKey, err := curve25519.X25519(secretKey[:], publicKey[:])
|
||||
var subKey []byte
|
||||
if err == nil {
|
||||
var nonce [16]byte
|
||||
subKey, err = chacha20.HChaCha20(dhKey[:], nonce[:])
|
||||
}
|
||||
if c == 0 {
|
||||
if _, err := crypto_rand.Read(sharedKey[:]); err != nil {
|
||||
return sharedKey, err
|
||||
var key [32]byte
|
||||
if err != nil {
|
||||
if _, err2 := crypto_rand.Read(key[:]); err != nil {
|
||||
return key, err2
|
||||
}
|
||||
return sharedKey, errors.New("weak public key")
|
||||
return key, err
|
||||
}
|
||||
var nonce [16]byte
|
||||
chacha.HChaCha20(&sharedKey, &nonce, &sharedKey)
|
||||
return sharedKey, nil
|
||||
copy(key[:], subKey)
|
||||
return key, nil
|
||||
}
|
||||
|
|
12
vendor/github.com/jedisct1/xsecretbox/xsecretbox.go
generated
vendored
12
vendor/github.com/jedisct1/xsecretbox/xsecretbox.go
generated
vendored
|
@ -4,8 +4,8 @@ import (
|
|||
"crypto/subtle"
|
||||
"errors"
|
||||
|
||||
"github.com/aead/chacha20/chacha"
|
||||
"github.com/aead/poly1305"
|
||||
"golang.org/x/crypto/chacha20"
|
||||
"golang.org/x/crypto/poly1305"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -27,7 +27,7 @@ func Seal(out, nonce, message, key []byte) []byte {
|
|||
}
|
||||
|
||||
var firstBlock [64]byte
|
||||
cipher, _ := chacha.NewCipher(nonce, key, 20)
|
||||
cipher, _ := chacha20.NewUnauthenticatedCipher(key, nonce)
|
||||
cipher.XORKeyStream(firstBlock[:], firstBlock[:])
|
||||
var polyKey [32]byte
|
||||
copy(polyKey[:], firstBlock[:32])
|
||||
|
@ -51,7 +51,7 @@ func Seal(out, nonce, message, key []byte) []byte {
|
|||
cipher.XORKeyStream(out, message)
|
||||
|
||||
var tag [TagSize]byte
|
||||
hash := poly1305.New(polyKey)
|
||||
hash := poly1305.New(&polyKey)
|
||||
hash.Write(ciphertext)
|
||||
hash.Sum(tag[:0])
|
||||
copy(tagOut, tag[:])
|
||||
|
@ -72,14 +72,14 @@ func Open(out, nonce, box, key []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
var firstBlock [64]byte
|
||||
cipher, _ := chacha.NewCipher(nonce, key, 20)
|
||||
cipher, _ := chacha20.NewUnauthenticatedCipher(key, nonce)
|
||||
cipher.XORKeyStream(firstBlock[:], firstBlock[:])
|
||||
var polyKey [32]byte
|
||||
copy(polyKey[:], firstBlock[:32])
|
||||
|
||||
var tag [TagSize]byte
|
||||
ciphertext := box[TagSize:]
|
||||
hash := poly1305.New(polyKey)
|
||||
hash := poly1305.New(&polyKey)
|
||||
hash.Write(ciphertext)
|
||||
hash.Sum(tag[:0])
|
||||
if subtle.ConstantTimeCompare(tag[:], box[:TagSize]) != 1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue