mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-14 08:52:44 +00:00
Knut Ahlers
a1df72edc5
commitf0db1ff1f8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:19:56 2017 +0100 Mark option as deprecated Signed-off-by: Knut Ahlers <knut@ahlers.me> commit9891df2a16
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:11:56 2017 +0100 Fix: Typo Signed-off-by: Knut Ahlers <knut@ahlers.me> commit836006de64
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 12:04:20 2017 +0100 Add new dependencies Signed-off-by: Knut Ahlers <knut@ahlers.me> commitd64fee60c8
Author: Knut Ahlers <knut@ahlers.me> Date: Sun Dec 24 11:55:52 2017 +0100 Replace insecure password hashing Prior this commit passwords were hashed with a static salt and using the SHA1 hashing function. This could lead to passwords being attackable in case someone gets access to the raw data stored inside the database. This commit introduces password hashing using bcrypt hashing function which addresses this issue. Old passwords are not automatically re-hashed as they are unknown. Replacing the old password scheme is not that easy and needs #10 to be solved. Therefore the old hashing scheme is kept for compatibility reason. Signed-off-by: Knut Ahlers <knut@ahlers.me> Signed-off-by: Knut Ahlers <knut@ahlers.me> closes #14 closes #15
54 lines
1.9 KiB
Go
54 lines
1.9 KiB
Go
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
/*
|
|
Package salsa20 implements the Salsa20 stream cipher as specified in https://cr.yp.to/snuffle/spec.pdf.
|
|
|
|
Salsa20 differs from many other stream ciphers in that it is message orientated
|
|
rather than byte orientated. Keystream blocks are not preserved between calls,
|
|
therefore each side must encrypt/decrypt data with the same segmentation.
|
|
|
|
Another aspect of this difference is that part of the counter is exposed as
|
|
a nonce in each call. Encrypting two different messages with the same (key,
|
|
nonce) pair leads to trivial plaintext recovery. This is analogous to
|
|
encrypting two different messages with the same key with a traditional stream
|
|
cipher.
|
|
|
|
This package also implements XSalsa20: a version of Salsa20 with a 24-byte
|
|
nonce as specified in https://cr.yp.to/snuffle/xsalsa-20081128.pdf. Simply
|
|
passing a 24-byte slice as the nonce triggers XSalsa20.
|
|
*/
|
|
package salsa20 // import "golang.org/x/crypto/salsa20"
|
|
|
|
// TODO(agl): implement XORKeyStream12 and XORKeyStream8 - the reduced round variants of Salsa20.
|
|
|
|
import (
|
|
"golang.org/x/crypto/salsa20/salsa"
|
|
)
|
|
|
|
// XORKeyStream crypts bytes from in to out using the given key and nonce.
|
|
// In and out must overlap entirely or not at all. Nonce must
|
|
// be either 8 or 24 bytes long.
|
|
func XORKeyStream(out, in []byte, nonce []byte, key *[32]byte) {
|
|
if len(out) < len(in) {
|
|
in = in[:len(out)]
|
|
}
|
|
|
|
var subNonce [16]byte
|
|
|
|
if len(nonce) == 24 {
|
|
var subKey [32]byte
|
|
var hNonce [16]byte
|
|
copy(hNonce[:], nonce[:16])
|
|
salsa.HSalsa20(&subKey, &hNonce, key, &salsa.Sigma)
|
|
copy(subNonce[:], nonce[16:])
|
|
key = &subKey
|
|
} else if len(nonce) == 8 {
|
|
copy(subNonce[:], nonce[:])
|
|
} else {
|
|
panic("salsa20: nonce must be 8 or 24 bytes")
|
|
}
|
|
|
|
salsa.XORKeyStream(out, in, &subNonce, key)
|
|
}
|