crypto: Remove polynomial from key

This commit is contained in:
Alexander Neumann 2015-05-03 17:51:04 +02:00
parent 991a325cc5
commit 08fac28e73
2 changed files with 3 additions and 27 deletions

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/restic/restic/chunker"
"golang.org/x/crypto/poly1305" "golang.org/x/crypto/poly1305"
"golang.org/x/crypto/scrypt" "golang.org/x/crypto/scrypt"
) )
@ -35,12 +34,10 @@ var (
// Key holds encryption and message authentication keys for a repository. It is stored // Key holds encryption and message authentication keys for a repository. It is stored
// encrypted and authenticated as a JSON data structure in the Data field of the Key // encrypted and authenticated as a JSON data structure in the Data field of the Key
// structure. For the master key, the secret random polynomial used for content // structure.
// defined chunking is included.
type Key struct { type Key struct {
MAC MACKey `json:"mac"` MAC MACKey `json:"mac"`
Encrypt EncryptionKey `json:"encrypt"` Encrypt EncryptionKey `json:"encrypt"`
ChunkerPolynomial chunker.Pol `json:"chunker_polynomial,omitempty"`
} }
type EncryptionKey [32]byte type EncryptionKey [32]byte
@ -340,9 +337,5 @@ func KDF(N, R, P int, salt []byte, password string) (*Key, error) {
// Valid tests if the key is valid. // Valid tests if the key is valid.
func (k *Key) Valid() bool { func (k *Key) Valid() bool {
if k.ChunkerPolynomial != 0 && !k.ChunkerPolynomial.Irreducible() {
return false
}
return k.Encrypt.Valid() && k.MAC.Valid() return k.Encrypt.Valid() && k.MAC.Valid()
} }

View File

@ -12,9 +12,7 @@ import (
"time" "time"
"github.com/restic/restic/backend" "github.com/restic/restic/backend"
"github.com/restic/restic/chunker"
"github.com/restic/restic/crypto" "github.com/restic/restic/crypto"
"github.com/restic/restic/debug"
) )
var ( var (
@ -92,13 +90,6 @@ func OpenKey(s *Server, name string, password string) (*Key, error) {
return nil, errors.New("Invalid key for repository") return nil, errors.New("Invalid key for repository")
} }
// test if the chunker polynomial is present in the master key
if k.master.ChunkerPolynomial == 0 {
return nil, errors.New("Polynomial for content defined chunking is zero")
}
debug.Log("OpenKey", "Master keys loaded, polynomial %v", k.master.ChunkerPolynomial)
return k, nil return k, nil
} }
@ -177,14 +168,6 @@ func AddKey(s *Server, password string, template *Key) (*Key, error) {
if template == nil { if template == nil {
// generate new random master keys // generate new random master keys
newkey.master = crypto.NewRandomKey() newkey.master = crypto.NewRandomKey()
// generate random polynomial for cdc
p, err := chunker.RandomPolynomial()
if err != nil {
debug.Log("AddKey", "error generating new polynomial for cdc: %v", err)
return nil, err
}
debug.Log("AddKey", "generated new polynomial for cdc: %v", p)
newkey.master.ChunkerPolynomial = p
} else { } else {
// copy master keys from old key // copy master keys from old key
newkey.master = template.master newkey.master = template.master