]> Cypherpunks.ru repositories - govpn.git/commitdiff
Replace HSalsa20 with already got BLAKE2b well-known hash
authorSergey Matveev <stargrave@stargrave.org>
Sun, 10 Jan 2016 13:57:47 +0000 (16:57 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 10 Jan 2016 13:59:51 +0000 (16:59 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
doc/handshake.texi
doc/news.texi
src/govpn/handshake.go

index c469021c5fe5a1c44cb503f0bc1fd6296dd14a6a..f19fde0c153d9f0b7afe9bd2411aee9916d233a4 100644 (file)
@@ -20,7 +20,7 @@ human readable form. Server knows his identity and
 @ref{Verifier structure, verifier}: @code{DSAPub}.
 @item
 Client computes verifier which produces @code{DSAPriv} and
-@code{DSAPub}. @code{H()} is @emph{HSalsa20} hash function.
+@code{DSAPub}. @code{H()} is @emph{BLAKE2b-256} hash function.
 @item
 Client generates DH keypair: @code{CDHPub} and @code{CDHPriv}.
 Also it generates random 64-bit @code{R} that is used as a nonce for
index b1781ce4b2dfe312650707219af7d5fa8b7b8545..d70471509ce0a18727ad6a0c8475a2979881bf40 100644 (file)
@@ -7,6 +7,8 @@
 @itemize
 @item Server is configured using @url{http://yaml.org/, YAML} file. It
 is very convenient to have comments and templates, comparing to JSON.
+@item Incompatible with previous versions replacement of @emph{HSalsa20}
+with @emph{BLAKE2b} in handshake code.
 @end itemize
 
 @item Release 5.0
index 8c7696728ab6e342a166713c5a7467f876ef445b..d9e86352dbde5e26b6a22d40e66859b8908d7e6d 100644 (file)
@@ -27,9 +27,9 @@ import (
 
        "github.com/agl/ed25519"
        "github.com/agl/ed25519/extra25519"
+       "github.com/dchest/blake2b"
        "golang.org/x/crypto/curve25519"
        "golang.org/x/crypto/salsa20"
-       "golang.org/x/crypto/salsa20/salsa"
        "golang.org/x/crypto/xtea"
 )
 
@@ -61,11 +61,6 @@ func keyFromSecrets(server, client []byte) *[SSize]byte {
        return k
 }
 
-// Apply HSalsa20 function for data. Used to hash public keys.
-func HApply(data *[32]byte) {
-       salsa.HSalsa20(data, new([16]byte), data, &salsa.Sigma)
-}
-
 // Zero handshake's memory state
 func (h *Handshake) Zero() {
        if h.rNonce != nil {
@@ -118,8 +113,8 @@ func dhKeypairGen() (*[32]byte, *[32]byte) {
 func dhKeyGen(priv, pub *[32]byte) *[32]byte {
        key := new([32]byte)
        curve25519.ScalarMult(key, priv, pub)
-       HApply(key)
-       return key
+       hashed := blake2b.Sum256(key[:])
+       return &hashed
 }
 
 // Create new handshake state.
@@ -132,7 +127,8 @@ func NewHandshake(addr string, conn io.Writer, conf *PeerConf) *Handshake {
        }
        state.dsaPubH = new([ed25519.PublicKeySize]byte)
        copy(state.dsaPubH[:], state.Conf.Verifier.Pub[:])
-       HApply(state.dsaPubH)
+       hashed := blake2b.Sum256(state.dsaPubH[:])
+       state.dsaPubH = &hashed
        return &state
 }