Domain

public class Domain : CustomStringConvertible, Equatable

A Domain instance contains an elliptic curve domain - either with characteristic 2 or characteristic an odd prime. Please refer [SEC 1] section 3.1.

Constants

  • Prime characteristic domain OID

    Declaration

    Swift

    public static let OID_P: ASN1ObjectIdentifier
  • Characteristic 2 domain OID

    Declaration

    Swift

    public static let OID_2: ASN1ObjectIdentifier

Static Methods

  • Returns a predefined domain from its curve

    Declaration

    Swift

    public static func instance(curve: ECCurve) -> Domain

    Parameters

    curve

    The domain curve

    Return Value

    The corresponding domain

  • Returns a predefined domain from its OID

    Throws

    An unknownOid exception if oid does not match any domain

    Declaration

    Swift

    public static func instance(oid: ASN1ObjectIdentifier) throws -> Domain

    Parameters

    oid

    The domain OID

    Return Value

    The corresponding domain

  • Constructs a domain from its PEM encoding

    Throws

    An exception if the PEM contents is wrong

    Declaration

    Swift

    public static func instance(pem: String) throws -> Domain

    Parameters

    pem

    The PEM encoding of the domain

    Return Value

    The corresponding domain

  • Constructs an odd prime characteristic domain based on the curve y^2 = x^3 + a * x + b

    Throws

    A domainParameter exception if 4 * a^3 + 27 * b^2 = 0 or the generator point is not on the curve

    Declaration

    Swift

    public static func instance(name: String, p: BInt, a: BInt, b: BInt, gx: BInt, gy: BInt, order: BInt, cofactor: Int, oid: ASN1ObjectIdentifier? = nil) throws -> Domain

    Parameters

    name

    The domain name

    p

    The field order - a prime greater then 3

    a

    The a coefficient

    b

    The b coefficient

    gx

    The generator point x-coordinate

    gy

    The generator point y-coordinate

    order

    The curve order

    cofactor

    The cofactor

    oid

    An optional domain OID

    Return Value

    The domain

  • Constructs a characteristic 2 domain based on the curve y^2 + x * y = x^3 + a * x^2 + b

    Throws

    A domainParameter exception if b = 0 or the generator point is not on the curve

    Declaration

    Swift

    public static func instance(name: String, rp: RP, a: BInt, b: BInt, gx: BInt, gy: BInt, order: BInt, cofactor: Int, oid: ASN1ObjectIdentifier? = nil) throws -> Domain

    Parameters

    name

    The domain name

    rp

    The reduction polynomial

    a

    The a coefficient

    b

    The b coefficient

    gx

    The generator point x-coordinate

    gy

    The generator point y-coordinate

    order

    The curve order

    cofactor

    The cofactor

    oid

    An optional domain OID

    Return Value

    The domain

Stored Properties

  • The domain name

    Declaration

    Swift

    public let name: String
  • p

    The modulus

    Declaration

    Swift

    public let p: BInt
  • a

    The curve a coefficient

    Declaration

    Swift

    public let a: BInt
  • b

    The curve b coefficient

    Declaration

    Swift

    public let b: BInt
  • g

    The generator point

    Declaration

    Swift

    public let g: Point
  • The curve order

    Declaration

    Swift

    public let order: BInt
  • The cofactor

    Declaration

    Swift

    public let cofactor: Int
  • oid

    An optional domain OID

    Declaration

    Swift

    public let oid: ASN1ObjectIdentifier?
  • Is true if self has characteristic 2, false if it has an odd prime characteristic

    Declaration

    Swift

    public let characteristic2: Bool

Computed Properties

  • The ASN1 encoding of self

    Declaration

    Swift

    public var asn1: ASN1 { get }
  • pem

    The PEM encoding of self

    Declaration

    Swift

    public var pem: String { get }
  • A textual representation of the ASN1 encoding of self

    Declaration

    Swift

    public var description: String { get }

Instance Methods

  • Equality of two Domain instances

    Declaration

    Swift

    public static func == (d1: Domain, d2: Domain) -> Bool

    Parameters

    d1

    a Domain instance

    d2

    a Domain instance

    Return Value

    true if d1 and d2 are equal, false otherwise

  • Doubles a curve Point

    Throws

    A notOnCurve exception if p is not on the curve

    Declaration

    Swift

    public func doublePoint(_ p: Point) throws -> Point

    Parameters

    p

    A curve point

    Return Value

    p + p

  • Adds two curve Points

    Throws

    A notOnCurve exception if p1 or p2 is not on the curve

    Declaration

    Swift

    public func addPoints(_ p1: Point, _ p2: Point) throws -> Point

    Parameters

    p1

    The first curve point

    p2

    The second curve point

    Return Value

    p1 + p2

  • Subtracts two curve Points

    Throws

    A notOnCurve exception if p1 or p2 is not on the curve

    Declaration

    Swift

    public func subtractPoints(_ p1: Point, _ p2: Point) throws -> Point

    Parameters

    p1

    The first curve point

    p2

    The second curve point

    Return Value

    p1 - p2

  • Negates a curve Point

    Throws

    A notOnCurve exception if p is not on the curve

    Declaration

    Swift

    public func negatePoint(_ p: Point) throws -> Point

    Parameters

    p

    A curve point

    Return Value

    -p

  • Multiplies a curve Point by an integer

    Throws

    A notOnCurve exception if p is not on the curve

    Declaration

    Swift

    public func multiplyPoint(_ p: Point, _ n: BInt) throws -> Point

    Parameters

    p

    The curve point to multiply

    n

    The integer to multiply with

    Return Value

    n * p

  • Tests if point is on curve

    Declaration

    Swift

    public func contains(_ p: Point) -> Bool

    Parameters

    p

    The point

    Return Value

    true iff p is on the domain curve

  • Encodes a Point to a byte array - please refer [SEC 1] section 2.3.3

    Throws

    An encodePoint exception if p is not on the curve

    Declaration

    Swift

    public func encodePoint(_ p: Point, _ compress: Bool = false) throws -> Bytes

    Parameters

    p

    The point to encode

    compress

    If true use compresssed encoding, if false use uncompressed encoding - false is default

    Return Value

    Encoding of p

  • Decodes a Point from a byte array - please refer [SEC 1] section 2.3.4

    Throws

    An decodePoint exception if bytes contains invalid data

    Declaration

    Swift

    public func decodePoint(_ bytes: Bytes) throws -> Point

    Parameters

    bytes

    The byte array to decode

    Return Value

    The point

  • Encodes a Point to an ASN1 structure

    Throws

    An encodePoint exception if p does not lie on the curve

    Declaration

    Swift

    public func asn1EncodePoint(_ p: Point, _ compress: Bool = false) throws -> ASN1

    Parameters

    p

    The point to encode

    compress

    If true use compresssed encoding, if false use uncompressed encoding - false is default

    Return Value

    ASN1 encoding of p

  • Decodes a Point from an ASN1 octet string

    Throws

    An decodePoint exception if the octet string contains invalid data

    Declaration

    Swift

    public func asn1DecodePoint(_ asn1: ASN1OctetString) throws -> Point

    Parameters

    asn1

    The ASN1 octet string to decode

    Return Value

    The point

  • Decodes a Point from an ASN1 bit string

    Throws

    An decodePoint exception if the bit string contains invalid data

    Declaration

    Swift

    public func asn1DecodePoint(_ asn1: ASN1BitString) throws -> Point

    Parameters

    asn1

    The ASN1 bit string to decode

    Return Value

    The point

  • Explicit ASN1 encoding of self - please refer [SEC 1] appendix C.2
    All domain components are included in the encoding - not just the domain OID

    Declaration

    Swift

    public func asn1Explicit() -> ASN1

    Return Value

    Explicit ASN1 encoding of self

  • Generates a private- and public key pair for self

    Declaration

    Swift

    public func makeKeyPair() -> (ECPublicKey, ECPrivateKey)

    Return Value

    (ECPublicKey, ECPrivateKey)