prf

package
v2.0.0-...-6b5deca Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package prf implements TLS 1.2 Pseudorandom functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtendedMasterSecret

func ExtendedMasterSecret(preMasterSecret, sessionHash []byte, h HashFunc) ([]byte, error)

ExtendedMasterSecret generates a Extended MasterSecret as defined in https://tools.ietf.org/html/rfc7627

func MasterSecret

func MasterSecret(preMasterSecret, clientRandom, serverRandom []byte, h HashFunc) ([]byte, error)

MasterSecret generates a TLS 1.2 MasterSecret

func PHash

func PHash(secret, seed []byte, requestedLength int, h HashFunc) ([]byte, error)

PHash is PRF is the SHA-256 hash function is used for all cipher suites defined in this TLS 1.2 document and in TLS documents published prior to this document when TLS 1.2 is negotiated. New cipher suites MUST explicitly specify a PRF and, in general, SHOULD use the TLS PRF with SHA-256 or a stronger standard hash function.

P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
                       HMAC_hash(secret, A(2) + seed) +
                       HMAC_hash(secret, A(3) + seed) + ...

A() is defined as:

A(0) = seed
A(i) = HMAC_hash(secret, A(i-1))

P_hash can be iterated as many times as necessary to produce the required quantity of data. For example, if P_SHA256 is being used to create 80 bytes of data, it will have to be iterated three times (through A(3)), creating 96 bytes of output data; the last 16 bytes of the final iteration will then be discarded, leaving 80 bytes of output data.

https://tools.ietf.org/html/rfc4346w

func PSKPreMasterSecret

func PSKPreMasterSecret(psk []byte) []byte

PSKPreMasterSecret generates the PSK Premaster Secret The premaster secret is formed as follows: if the PSK is N octets long, concatenate a uint16 with the value N, N zero octets, a second uint16 with the value N, and the PSK itself.

https://tools.ietf.org/html/rfc4279#section-2

func PreMasterSecret

func PreMasterSecret(publicKey, privateKey []byte, curve elliptic.Curve) ([]byte, error)

PreMasterSecret implements TLS 1.2 Premaster Secret generation given a keypair and a curve

func VerifyDataClient

func VerifyDataClient(masterSecret, handshakeBodies []byte, h HashFunc) ([]byte, error)

VerifyDataClient is caled on the Client Side to either verify or generate the VerifyData message

func VerifyDataServer

func VerifyDataServer(masterSecret, handshakeBodies []byte, h HashFunc) ([]byte, error)

VerifyDataServer is caled on the Server Side to either verify or generate the VerifyData message

Types

type EncryptionKeys

type EncryptionKeys struct {
	MasterSecret   []byte
	ClientMACKey   []byte
	ServerMACKey   []byte
	ClientWriteKey []byte
	ServerWriteKey []byte
	ClientWriteIV  []byte
	ServerWriteIV  []byte
}

EncryptionKeys is all the state needed for a TLS CipherSuite

func GenerateEncryptionKeys

func GenerateEncryptionKeys(masterSecret, clientRandom, serverRandom []byte, macLen, keyLen, ivLen int, h HashFunc) (*EncryptionKeys, error)

GenerateEncryptionKeys is the final step TLS 1.2 PRF. Given all state generated so far generates the final keys need for encryption

func (*EncryptionKeys) String

func (e *EncryptionKeys) String() string

type HashFunc

type HashFunc func() hash.Hash

HashFunc allows callers to decide what hash is used in PRF

Jump to

Keyboard shortcuts

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