github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/secboot/encrypt.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2020 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package secboot
    21  
    22  import (
    23  	"crypto/rand"
    24  )
    25  
    26  const (
    27  	// The encryption key size is set so it has the same entropy as the derived
    28  	// key.
    29  	encryptionKeySize = 64
    30  )
    31  
    32  // EncryptionKey is the key used to encrypt the data partition.
    33  type EncryptionKey [encryptionKeySize]byte
    34  
    35  func NewEncryptionKey() (EncryptionKey, error) {
    36  	var key EncryptionKey
    37  	// rand.Read() is protected against short reads
    38  	_, err := rand.Read(key[:])
    39  	// On return, n == len(b) if and only if err == nil
    40  	return key, err
    41  }