mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-10 07:00:08 +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
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
// Copyright 2016 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 chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
|
|
package chacha20poly1305 // import "golang.org/x/crypto/chacha20poly1305"
|
|
|
|
import (
|
|
"crypto/cipher"
|
|
"errors"
|
|
)
|
|
|
|
const (
|
|
// KeySize is the size of the key used by this AEAD, in bytes.
|
|
KeySize = 32
|
|
// NonceSize is the size of the nonce used with this AEAD, in bytes.
|
|
NonceSize = 12
|
|
)
|
|
|
|
type chacha20poly1305 struct {
|
|
key [32]byte
|
|
}
|
|
|
|
// New returns a ChaCha20-Poly1305 AEAD that uses the given, 256-bit key.
|
|
func New(key []byte) (cipher.AEAD, error) {
|
|
if len(key) != KeySize {
|
|
return nil, errors.New("chacha20poly1305: bad key length")
|
|
}
|
|
ret := new(chacha20poly1305)
|
|
copy(ret.key[:], key)
|
|
return ret, nil
|
|
}
|
|
|
|
func (c *chacha20poly1305) NonceSize() int {
|
|
return NonceSize
|
|
}
|
|
|
|
func (c *chacha20poly1305) Overhead() int {
|
|
return 16
|
|
}
|
|
|
|
func (c *chacha20poly1305) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
|
|
if len(nonce) != NonceSize {
|
|
panic("chacha20poly1305: bad nonce length passed to Seal")
|
|
}
|
|
|
|
if uint64(len(plaintext)) > (1<<38)-64 {
|
|
panic("chacha20poly1305: plaintext too large")
|
|
}
|
|
|
|
return c.seal(dst, nonce, plaintext, additionalData)
|
|
}
|
|
|
|
var errOpen = errors.New("chacha20poly1305: message authentication failed")
|
|
|
|
func (c *chacha20poly1305) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
|
|
if len(nonce) != NonceSize {
|
|
panic("chacha20poly1305: bad nonce length passed to Open")
|
|
}
|
|
if len(ciphertext) < 16 {
|
|
return nil, errOpen
|
|
}
|
|
if uint64(len(ciphertext)) > (1<<38)-48 {
|
|
panic("chacha20poly1305: ciphertext too large")
|
|
}
|
|
|
|
return c.open(dst, nonce, ciphertext, additionalData)
|
|
}
|
|
|
|
// sliceForAppend takes a slice and a requested number of bytes. It returns a
|
|
// slice with the contents of the given slice followed by that many bytes and a
|
|
// second slice that aliases into it and contains only the extra bytes. If the
|
|
// original slice has sufficient capacity then no allocation is performed.
|
|
func sliceForAppend(in []byte, n int) (head, tail []byte) {
|
|
if total := len(in) + n; cap(in) >= total {
|
|
head = in[:total]
|
|
} else {
|
|
head = make([]byte, total)
|
|
copy(head, in)
|
|
}
|
|
tail = head[len(in):]
|
|
return
|
|
}
|