Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
564B

  1. package storage
  2. import (
  3. "crypto/rand"
  4. "git.openprivacy.ca/openprivacy/libricochet-go/log"
  5. "golang.org/x/crypto/pbkdf2"
  6. "golang.org/x/crypto/sha3"
  7. "io"
  8. )
  9. // createKey derives a key from a password
  10. func createKey(password string) ([32]byte, [128]byte, error) {
  11. var salt [128]byte
  12. if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil {
  13. log.Errorf("Cannot read from random: %v\n", err)
  14. return [32]byte{}, salt, err
  15. }
  16. dk := pbkdf2.Key([]byte(password), salt[:], 4096, 32, sha3.New512)
  17. var dkr [32]byte
  18. copy(dkr[:], dk)
  19. return dkr, salt, nil
  20. }