kdf

package
v0.0.0-...-6fdec92 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2019 Thales e-Security, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Example (Usage)

Usage example that expands one master secret into three other cryptographically secure keys using KDF2.

// Cryptographically secure master secret.
seed := []byte{0x00, 0x01, 0x02, 0x03} // i.e. NOT this.

// Non-secret context info, optional (can be nil).
other := []byte("kdf example")

// Generate three 128-bit/16-byte derived keys.
kdf, err := NewKDF2(seed, other, crypto.SHA256, 48)
if err != nil {
	panic(err)
}

var keys [][]byte
for i := 0; i < 3; i++ {
	key := make([]byte, 16)
	if _, err := io.ReadFull(kdf, key); err != nil {
		panic(err)
	}
	keys = append(keys, key)
}

for i := range keys {
	fmt.Printf("Key #%d: %v\n", i+1, !bytes.Equal(keys[i], make([]byte, 16)))
}
Output:

Key #1: true
Key #2: true
Key #3: true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KDF

type KDF struct {
	// contains filtered or unexported fields
}

KDF key derivation context struct

func NewKDF1

func NewKDF1(seed, other []byte, hash crypto.Hash, length int) (*KDF, error)

NewKDF1 create a new KDF1 context.

func NewKDF2

func NewKDF2(seed, other []byte, hash crypto.Hash, length int) (*KDF, error)

NewKDF2 create a new KDF2 context.

func (*KDF) Read

func (kdf *KDF) Read(p []byte) (int, error)

Read read the next len(p) bytes from the KDF context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL