Documentation
¶
Overview ¶
Copyright (C) 2018 NuCypher
This file is part of goUmbral.
goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.
Copyright (C) 2018 NuCypher ¶
This file is part of goUmbral.
goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.
Copyright (C) 2018 NuCypher ¶
This file is part of goUmbral.
goUmbral is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
goUmbral is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with goUmbral. If not, see <https://www.gnu.org/licenses/>.
Index ¶
- Constants
- func DefaultCurve() *openssl.Curve
- func DeriveKeyFromPassword(password []byte, salt []byte) []byte
- func ExpectedBytesLength(curve *openssl.Curve)
- func NewDerivedKey(password []byte, salt []byte) ([]byte, error)
- func PointLength(curve *openssl.Curve, isCompressed bool) uint
- func SetDefaultCurve(curve *openssl.Curve) error
- func UnwrapKey(wrappedKey []byte, wrappingKey []byte, password []byte, nonce *[24]byte) []byte
- func WrapKey(keyToWrap []byte, wrappingKey []byte, password []byte, nonce *[24]byte) []byte
- type Config
- type ModBigNum
- func BytesToModBN(data []byte, curve *openssl.Curve) (*ModBigNum, error)
- func GenRandModBN(curve *openssl.Curve) (*ModBigNum, error)
- func HashToModBN(bytes []byte, params *UmbralParameters) (*ModBigNum, error)
- func IntToModBN(num int, curve *openssl.Curve) (*ModBigNum, error)
- func NewModBigNum(cNum openssl.BigNum, curve *openssl.Curve) (*ModBigNum, error)
- func (z *ModBigNum) Add(x, y *ModBigNum) error
- func (m *ModBigNum) Bytes() ([]byte, error)
- func (m ModBigNum) Compare(other *ModBigNum) int
- func (m *ModBigNum) Copy() (*ModBigNum, error)
- func (z *ModBigNum) Div(x, y *ModBigNum) error
- func (m *ModBigNum) Equals(other *ModBigNum) bool
- func (m *ModBigNum) Free()
- func (z *ModBigNum) Invert(x *ModBigNum) error
- func (z *ModBigNum) Mod(x, y *ModBigNum) error
- func (z *ModBigNum) Mul(x, y *ModBigNum) error
- func (z *ModBigNum) Neg(x *ModBigNum) error
- func (z *ModBigNum) Pow(x, y *ModBigNum) error
- func (z *ModBigNum) Sub(x, y *ModBigNum) error
- type Point
- func AffineToPoint(affineX, affineY *big.Int, curve *openssl.Curve) (*Point, error)
- func BytesToPoint(data []byte, curve *openssl.Curve) (*Point, error)
- func GenRandPoint(curve *openssl.Curve) (*Point, error)
- func GetGeneratorFromCurve(curve *openssl.Curve) *Point
- func NewPoint(point openssl.ECPoint, curve *openssl.Curve) (*Point, error)
- func UnsafeHashToPoint(data []byte, params *UmbralParameters, label []byte) (*Point, error)
- func (z *Point) Add(x, y *Point) error
- func (m *Point) Copy() (*Point, error)
- func (m *Point) Equals(other *Point) (bool, error)
- func (m *Point) Free()
- func (z *Point) Invert(x *Point) error
- func (z *Point) Mul(x *Point, y *ModBigNum) error
- func (z *Point) Sub(x, y *Point) error
- func (m Point) ToAffine() (*big.Int, *big.Int, error)
- func (m Point) ToBytes(isCompressed bool) ([]byte, error)
- type UmbralKeyingMaterial
- type UmbralParameters
- type UmbralPrivateKey
- type UmbralPublicKey
- func (uPubKey UmbralPublicKey) ByteString() ([]byte, error)
- func (uPubKey UmbralPublicKey) Equals(umbralPubKey UmbralPublicKey) bool
- func (uPubKey UmbralPublicKey) ExpectedBytesLength(curve *openssl.Curve, isCompressed bool) uint
- func (uPubKey UmbralPublicKey) Hash() int
- func (uPubKey UmbralPublicKey) ToBytes(isCompressed bool) []byte
- func (uPubKey UmbralPublicKey) ToHex(isCompressed bool) string
Constants ¶
const ( SALT_SIZE = 32 DEFAULT_SCRYPT_COST = 20 SYMMETRIC_KEY_SIZE = 128 NONCE_SIZE = 64 )
Variables ¶
This section is empty.
Functions ¶
func DefaultCurve ¶
func DeriveKeyFromPassword ¶
* Derives a symmetric encryption key from a pair of password and salt. It uses Scrypt by default.
func ExpectedBytesLength ¶
func NewDerivedKey ¶
* Derives a symmetric encryption key from a pair of password and salt. WARNING: RFC7914 recommends that you use a 2^20 cost value for sensitive files. It is NOT recommended to change the `_scrypt_cost` value unless you know what you are doing.
func PointLength ¶
Returns the size (in bytes) of a compressed Point given a curve. If no curve is provided, it returns 0.
func SetDefaultCurve ¶
func UnwrapKey ¶
* Unwraps a key using a provided wrapping key. Alternatively, it can derive the wrapping key from a password.
TODO can nonce be null? if so, delete that from params
Types ¶
type Config ¶
type Config struct { Curve *openssl.Curve Params *UmbralParameters }
TODO pointer params so they can be nil
type ModBigNum ¶
func BytesToModBN ¶
Returns the ModBigNum associated with the bytes-converted bignum provided by the data argument.
func GenRandModBN ¶
Returns a ModBigNum with a cryptographically secure OpenSSL BIGNUM based on the given curve.
func HashToModBN ¶
func HashToModBN(bytes []byte, params *UmbralParameters) (*ModBigNum, error)
Returns a ModBigNum based on provided data hashed by blake2b.
func NewModBigNum ¶
func (*ModBigNum) Add ¶
ModBigNum.Add() will perform (x + y) modulo the order of the curve of x and y. It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Add will return the error if one occurred, and nil otherwise.
func (*ModBigNum) Div ¶
ModBigNum.Div() will perform (x / y) modulo the order of the curve of x and y. It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Div will return the error if one occurred, and nil otherwise.
func (*ModBigNum) Invert ¶
ModBigNum.Invert() computes (x*z)%m==1 where m is the order of the curve of x and z. It will then set z to the result of that operation.
x and z must use the same curve and must be initialized.
Invert will return the error if one occurred, and nil otherwise.
func (*ModBigNum) Mod ¶
ModBigNum.Mod() will perform (x % y). It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Mod will return the error, and nil otherwise.
func (*ModBigNum) Mul ¶
ModBigNum.Mul() will perform (x * y) modulo the order of the curve of x and y. It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Mul will return the error if one occurred, and nil otherwise.
func (*ModBigNum) Neg ¶
ModBigNum.Neg() computes the modular opposite (i. e., additive inverse) of x. It will then set z to the result of that operation.
x and z must use the same curve and must be initialized.
Neg will return the error if one occurred, and nil otherwise.
func (*ModBigNum) Pow ¶
ModBigNum.Pow() will perform (x^y) modulo the order of the curve of x and y. It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Pow will return the error if one occurred, and nil otherwise.
type Point ¶
func AffineToPoint ¶
Returns a Point object from the given affine coordinates.
func GenRandPoint ¶
Returns a Point struct with a cryptographically secure EC_POINT based on the provided curve.
This operation isn't safe unless you know the discrete log of the generated Point.
func GetGeneratorFromCurve ¶
func NewPoint ¶
Generate a new Point struct based on the arguments provided.
If point is nil then GetNewPoint will generate a new opensslraphically secure ECPoint and check for errors before returning the new Point.
if point is nil AND the curve group is also nil then GetNewPoint will fail and return the error.
func UnsafeHashToPoint ¶
func UnsafeHashToPoint(data []byte, params *UmbralParameters, label []byte) (*Point, error)
WARNING: Do not use when the input data is secret, as this implementation is not in constant time, and hence, it is not safe with respect to timing attacks. TODO: Check how to uniformly generate ycoords. Currently, it only outputs points where ycoord is even (i.e., starting with 0x02 in compressed notation)
func (*Point) Add ¶
Point.Add() will perform (x + y). It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Add will return the error if one occurred, and nil otherwise.
func (*Point) Invert ¶
Point.Invert() will find the inverse of x. It will then set z to the result of that operation.
x must be initialized.
Invert will return the error if one occurred, and nil otherwise.
func (*Point) Mul ¶
Point.Mul() will perform (x * y). It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Mul will return the error if one occurred, and nil otherwise.
func (*Point) Sub ¶
Point.Sub() will perform (x - y). It will then set z to the result of that operation.
x, y, and z must use the same curve and must be initialized.
Sub will return the error if one occurred, and nil otherwise.
type UmbralKeyingMaterial ¶
type UmbralKeyingMaterial struct {
KeyingMaterial []byte
}
* This type with its methods handles keying material for Umbral, by allowing deterministic derivation of UmbralPrivateKeys based on labels. Don't use this key material directly as a key.
func KeyingMaterialFromBytes ¶
func KeyingMaterialFromBytes(keyBytes []byte, wrappingKey []byte, password []byte, nonce *[24]byte) UmbralKeyingMaterial
func NewUmbralKeyingMaterial ¶
func NewUmbralKeyingMaterial(keyingMaterial *[]byte) UmbralKeyingMaterial
func (UmbralKeyingMaterial) DerivePrivKeyByLabel ¶
func (uKeyMat UmbralKeyingMaterial) DerivePrivKeyByLabel(label []byte, salt []byte, params *UmbralParameters) UmbralPrivateKey
type UmbralParameters ¶
func DefaultParams ¶
func DefaultParams() *UmbralParameters
func NewUmbralParameters ¶
func NewUmbralParameters(curve *openssl.Curve) (*UmbralParameters, error)
func (*UmbralParameters) Equals ¶
func (m *UmbralParameters) Equals(other *UmbralParameters) bool
type UmbralPrivateKey ¶
type UmbralPrivateKey struct { Params UmbralParameters BnKey ModBigNum PublicKey UmbralPublicKey }
func GenerateUmbralPrivateKey ¶
func GenerateUmbralPrivateKey(params *UmbralParameters) UmbralPrivateKey
Generates a private key and returns it.
func PrivateKeyFromBytes ¶
func PrivateKeyFromBytes(keyBytes []byte, wrappingKey *[]byte, password *[]byte, params *UmbralParameters, nonce *[24]byte) UmbralPrivateKey
Loads an Umbral private key from bytes. Optionally, uses a wrapping key to unwrap an encrypted Umbral private key. Alternatively, if a password is provided it will derive the wrapping key from it.
func (UmbralPrivateKey) GetPublicKey ¶
func (uPrivKey UmbralPrivateKey) GetPublicKey() UmbralPublicKey
func (UmbralPrivateKey) ToBytes ¶
func (uPrivKey UmbralPrivateKey) ToBytes(wrappingKey *[]byte, password *[]byte, nonce *[24]byte) []byte
Returns an UmbralPrivateKey as bytes with optional symmetric encryption via nacl's Salsa20-Poly1305. If a password is provided instead of a wrapping key, it will use Scrypt for key derivation.
func (UmbralPrivateKey) ToCryptographyPrivKey ¶
func (uPrivKey UmbralPrivateKey) ToCryptographyPrivKey() ecdsa.PrivateKey
type UmbralPublicKey ¶
type UmbralPublicKey struct { PointKey Point Params UmbralParameters }
func FromHex ¶
func FromHex(hexUmbralPubKey string, isCompressed bool) UmbralPublicKey
func PublicKeyFromBytes ¶
func PublicKeyFromBytes(keyBytes []byte, params *UmbralParameters) UmbralPublicKey
* Loads an Umbral public key from bytes.
func (UmbralPublicKey) ByteString ¶
func (uPubKey UmbralPublicKey) ByteString() ([]byte, error)
func (UmbralPublicKey) Equals ¶
func (uPubKey UmbralPublicKey) Equals(umbralPubKey UmbralPublicKey) bool
func (UmbralPublicKey) ExpectedBytesLength ¶
func (uPubKey UmbralPublicKey) ExpectedBytesLength(curve *openssl.Curve, isCompressed bool) uint
* Returns the size (in bytes) of an UmbralPublicKey given a curve. If no curve is provided, it uses the default curve. By default, it assumes compressed representation (is_compressed = True).
func (UmbralPublicKey) Hash ¶
func (uPubKey UmbralPublicKey) Hash() int
func (UmbralPublicKey) ToBytes ¶
func (uPubKey UmbralPublicKey) ToBytes(isCompressed bool) []byte
* Returns an Umbral public key as bytes.
func (UmbralPublicKey) ToHex ¶
func (uPubKey UmbralPublicKey) ToHex(isCompressed bool) string