Documentation ¶
Overview ¶
dhkam implements the Diffie Hellman Key Agreement Method using the RFC 3526 Group 14 modulus, and uses blinded key generation.
The package supports using the shared key as a static key, and using the shared key to compute a KEK, implementing the system described in RFC 2631.
The shared key may be retrieved using the SharedKey method. A KEK must first be initialised using the InitializeKEK function, which returns a set of KEK paramaters stored in a KEK type. This can be combined with the `CEK` method on private keys to derive an appropriate CEK.
For example, to generate a KEK for use with AES128CBC with an HMAC-SHA256 MAC:
prv, err := dhkam.GenerateKey(rand.Reader) if err != nil { // ... } // pub is a *dhkam.PublicKey containing the public key // of the party for whom we share this KEK. kek := prv.InitializeKEK(rand.Reader, pub, dhkam.KEKAES128CBCHMACSHA256, nil, sha256.New()) if kek == nil { // an error occurred while initialising the KEK. }
We can generate a CEK from this with:
key, err := prv.CEK(kek) if err != nil { // ... } aesKey := key[:16] // 16 bytes is AES-128 key length. hmacKey := key[16:] // the rest of the key is the HMAC key.
Index ¶
- Variables
- type KEK
- type KEKParams
- type KeySpecificInfo
- type PrivateKey
- func (prv *PrivateKey) CEK(kek *KEK) (key []byte, err error)
- func (prv *PrivateKey) Export() []byte
- func (prv *PrivateKey) ExportPrivate() []byte
- func (prv *PrivateKey) InitializeKEK(rand io.Reader, pub *PublicKey, params KEKParams, ainfo []byte, h hash.Hash) *KEK
- func (prv *PrivateKey) SharedKey(prng io.Reader, pub *PublicKey, size int) (sk []byte, err error)
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
var ( ErrBlindingFailed = fmt.Errorf("dhkam: blinding failed") ErrInvalidKEKParams = fmt.Errorf("dhkam: invalid KEK parameters") ErrInvalidPrivateKey = fmt.Errorf("dhkam: invalid private key") ErrInvalidPublicKey = fmt.Errorf("dhkam: invalid public key") )
var ( AES128CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 2} AES128GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 6} AES192CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 22} AES192GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 26} AES256CBC = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 42} AES256GCM = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 1, 46} )
ASN.1 definitions for a few algorithms
var ( KEKAES128CBCHMACSHA256 = KEKParams{ KeySpecificInfo: KeySpecificInfo{ Algorithm: AES128CBC, }, SuppPubInfo: []byte{0, 0, 0, 48}, } KEKAES192CBCHMACSHA384 = KEKParams{ KeySpecificInfo: KeySpecificInfo{ Algorithm: AES192CBC, }, SuppPubInfo: []byte{0, 0, 0, 72}, } KEKAES256CBCHMACSHA512 = KEKParams{ KeySpecificInfo: KeySpecificInfo{ Algorithm: AES256CBC, }, SuppPubInfo: []byte{0, 0, 0, 32}, } KEKAES256CBCHMACSHA256 = KEKParams{ KeySpecificInfo: KeySpecificInfo{ Algorithm: AES256CBC, }, SuppPubInfo: []byte{0, 0, 0, 64}, } )
Pre-defined KEK parameters to make life easier when generating KEKs.
var (
P = new(big.Int).SetBytes(p)
)
Functions ¶
This section is empty.
Types ¶
type KEK ¶
KEK represents the information needed to make use of a KEK. A KEK should correspond to a specific private - public keypair as used in the key exchange.
type KEKParams ¶
type KEKParams struct { KeySpecificInfo KeySpecificInfo PartyAInfo []byte `asn1:"optional"` SuppPubInfo []byte }
type KeySpecificInfo ¶
type KeySpecificInfo struct { Algorithm asn1.ObjectIdentifier // contains filtered or unexported fields }
type PrivateKey ¶
func GenerateKey ¶
func GenerateKey(prng io.Reader) (prv *PrivateKey, err error)
GenerateKey generates a new key pair.
func ImportPrivate ¶
func ImportPrivate(prng io.Reader, in []byte) (prv *PrivateKey, err error)
ImportPrivate loads a byte slice into a private key and regenerates the public key for it.
func (*PrivateKey) CEK ¶
func (prv *PrivateKey) CEK(kek *KEK) (key []byte, err error)
Generate a new CEK from the provided KEK.
func (*PrivateKey) Export ¶
func (prv *PrivateKey) Export() []byte
Export returns a byte slice representation of the public key. This is not DER-encoded.
func (*PrivateKey) ExportPrivate ¶
func (prv *PrivateKey) ExportPrivate() []byte
ExportPrivate returns a byte slice representation of the private key.
type PublicKey ¶
func ImportPublic ¶
ImportPublic takes a byte slice and attempts to convert it to a public key, checking to make sure it's a valid key.