mqv

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

mqv

GoDoc

Package mqv implements MQV ECC as described in "NIST Special Publication 800-56A Revision 3".

MQV is a key agreement protocol similar to Diffie-Hellman, but instead of using 2 ephemeral keys C(2e, 0s), MQV uses 2 ephemeral and 2 static keys C(2e, 2s) in the full variant. The static keys are previously distributed and will be used to authenticate the parties.

Another advantage of MQV is the "one-pass" mode C(1e, 2s) which allows senders and receivers to transmit data without a full roundtrip for the key agreement. In this case, the sender uses the static key of the other party twice (its safe to pass a key twice, once as static key and once as ephemeral key), and the receiver uses his own static key twice to decode the message.

In addition to the basic MQV primitive, this package also implements a blinded version BlindMQV, which blinds the keys before doing the computations in order to prevent side channel attacks.

Please see SP 800-56A Rev. 3 for more details.

Installation

go get github.com/mgit-at/mqv

License

Copyright (c) 2017 mgIT GmbH. All rights reserved. Distributed under the Apache License. See LICENSE for details.

Documentation

Overview

Package mqv implements MQV ECC as described in "NIST Special Publication 800-56A Revision 3".

MQV is a key agreement protocol similar to Diffie-Hellman, but instead of using 2 ephemeral keys C(2e, 0s), MQV uses 2 ephemeral and 2 static keys C(2e, 2s) in the full variant. The static keys are previously distributed and will be used to authenticate the parties.

Another advantage of MQV is the "one-pass" mode C(1e, 2s) which allows senders and receivers to transmit data without a full roundtrip for the key agreement. In this case, the sender uses the static key of the other party twice (its safe to pass a key twice, once as static key and once as ephemeral key), and the receiver uses his own static key twice to decode the message.

In addition to the basic MQV primitive, this package also implements a blinded version BlindMQV, which blinds the keys before doing the computations in order to prevent side channel attacks.

Please see https://csrc.nist.gov/publications/detail/sp/800-56a/rev-3/final for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlindKey

func BlindKey(priv []byte, params *elliptic.CurveParams, rand io.Reader) ([]byte, []byte, error)

BlindKey blinds the original private key (p) with a random blind key (b) and returns (p+b, -b) mod n.

func BlindMQV

func BlindMQV(ownStaticPriv, ownEphemeralPriv []byte, ownEphemeralX, otherStaticX, otherStaticY, otherEphemeralX, otherEphemeralY *big.Int, curve elliptic.Curve, rand io.Reader) (*big.Int, *big.Int, error)

BlindMQV implements the ECC MQV primitive with additional blinding to prevent side channel attacks.

Usually Z is calculated with mqvSig(ownStaticPriv, ownEphemeralPriv) * mqvBase() (see mqvSimple), but this might leak information about the private keys on various side channels (e.g. timing or power consumption) since neither the elliptic curve implementation nor the big number implementation is constant time. Therefore we blind each key by a random number 0 <= r < n. Assuming r is completely random, then (originalPrivKey + r) mod n has also full entropy, as well as -r mod n. We do this for both private keys. The blinding process (simple addition / substraction modulo n) is done in constant time and the random numbers are kept secret. Z is now calculated by mqvSig(ownStaticPriv + r1, ownEphemeralPriv + r2) * mqvBase() + mqvSig(-r1, -r2) * mqvBase(), which are basically two MQV primitives with random keys instead of one using the original key.

func GenerateKey

func GenerateKey(params *elliptic.CurveParams, rand io.Reader) ([]byte, error)

GenerateKey returns a public / private key pair. The private key is generated using the given reader, which must return random data.

func MQV

func MQV(ownStaticPriv, ownEphemeralPriv []byte, ownEphemeralX, otherStaticX, otherStaticY, otherEphemeralX, otherEphemeralY *big.Int, curve elliptic.Curve) (*big.Int, *big.Int, error)

MQV implements the ECC MQV primitive that calculates a shared secret based on the domain parameters, the own public and private keys and the other party's public keys. In the full form, each party has a static and a ephemeral key. In the one-pass form the other party only has a static key which is used twice with this primitive. h is the cofactor of the elliptic curve. See section 5.7.2.3 of SP 800-56A Rev. 3 for more details.

func ScalarMultBlind

func ScalarMultBlind(x *big.Int, y *big.Int, priv []byte, curve elliptic.Curve, rand io.Reader) (*big.Int, *big.Int, error)

ScalarMultBlind is similar to to the elliptic.ScalarMult function, but it does two scalar multiplications with the blinded keys instead and adds the afterwards.

func SubtleIntSize

func SubtleIntSize(numBits int) int

SubtleIntSize returns the size of a SubtleInt that can store at least numBits of information.

func WipeBytes

func WipeBytes(b []byte)

WipeBytes overrides the internal byte array with zeros.

func WipeInt

func WipeInt(x *big.Int)

WipeInt overrides the internal array of a big.Int with zeros.

Types

type SubtleInt

type SubtleInt []uint

SubtleInt represents a non-negative big integer with a fixed size. All operations on this integer are performed in constant time.

func (SubtleInt) Add

func (z SubtleInt) Add(x, y SubtleInt) uint

Add sets z to the sum x+y and returns the carry.

func (SubtleInt) AddMod

func (z SubtleInt) AddMod(x, y, n SubtleInt)

AddMod sets z to x+y mod n. Both parameters x and y must be less than n.

func (SubtleInt) Big

func (z SubtleInt) Big() *big.Int

Big converts the integer z to a big.Int.

func (SubtleInt) Bytes

func (z SubtleInt) Bytes() []byte

Bytes returns the value of z as a big-endian byte slice.

func (SubtleInt) Less

func (z SubtleInt) Less(y SubtleInt) uint

Less returns 1 if z < y and 0 otherwise.

func (SubtleInt) Select

func (z SubtleInt) Select(p uint, x, y SubtleInt)

Select sets z to x if p = 1 and y if p = 0.

func (SubtleInt) SetBytes

func (z SubtleInt) SetBytes(buf []byte)

SetBytes interprets buf as a big-endian byte slice and sets z to this value.

func (SubtleInt) SetZero

func (z SubtleInt) SetZero()

SetZero sets z to zero.

func (SubtleInt) String

func (z SubtleInt) String() string

String returns the value of z.

func (SubtleInt) Sub

func (z SubtleInt) Sub(x, y SubtleInt) uint

Sub sets z to the difference x-y and returns the borrow.

Jump to

Keyboard shortcuts

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