Latest 2.0.7
Homepage https://github.com/shamatar/EllipticSwift
License Apache License 2.0
Platforms ios 9.0, osx 10.11
Dependencies BigInt
Authors

Library for arbitrary elliptic curve arithmetics written in the native Swift and can in principle run on any platform (not just iOS or OSX). Implements long arithmetics, modular arithmetics, allows to define finite fields (over prime modulus only for now), field polynomials and later will bring extension fields and pairing support.

Installation

Add the following line to your Podfile

  pod 'EllipticSwift', '~> 2.0'

Example

let curve = secp256k1Curve
        let generatorX = BigUInt("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", radix: 16)!
        let generatorY = BigUInt("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", radix: 16)!
        let success = curve.testGenerator(AffineCoordinates(generatorX, generatorY))
        XCTAssert(success, "Failed to init secp256k1 curve!")

        // this is basically a private key - large random scalar
        let randomScalar = BigUInt.randomInteger(lessThan: 256)
        guard let privateKey = U256(randomScalar.serialize()) else { return XCTFail()}

        // make point. Point is made from affine coordinates in normal (not Montgomery) representation
        guard let G = curve.toPoint(generatorX, generatorY) else {return XCTFail()}

        // calculate a public key
        let publicKey = privateKey * G
        XCTAssert(!publicKey.isInfinity)

        // also try to multiply by group order
        let groupOrder = curve.order
        let expectInfinity = groupOrder * G
        XCTAssert(expectInfinity.isInfinity)

Limitations

  • Point multiplication is not yet constant time
  • Protocols are quite suboptimal, global cleanups will happen
  • No support of pairings yet
  • U512 type is not polyfilled
  • No Montgomery support on iOS (should work, but untested)
  • Only Weierstrass curves for now

Authors

Latest podspec

{
    "name": "EllipticSwift",
    "version": "2.0.7",
    "summary": "Elliptic curve arithmetics in vanilla Swift for iOS ans macOS",
    "description": "Elliptic curve arithmetics and modular multiprecision arithmetics in vanilla Swift. Uses Apple's Accelerate framework on MacOS and manually implemented U256 type for iOS.",
    "homepage": "https://github.com/shamatar/EllipticSwift",
    "license": "Apache License 2.0",
    "authors": {
        "Alex Vlasov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/shamatar/EllipticSwift.git",
        "tag": "2.0.7"
    },
    "social_media_url": "https://twitter.com/shamatar",
    "swift_version": "4.1",
    "module_name": "EllipticSwift",
    "source_files": [
        "EllipticSwift/Common/**/*.swift",
        "EllipticSwift/Common/PrecompiledCurves/**/*.swift",
        "EllipticSwift/EllipticSwift.h"
    ],
    "platforms": {
        "ios": "9.0",
        "osx": "10.11"
    },
    "ios": {
        "source_files": "EllipticSwift/iOS/**/*.swift"
    },
    "osx": {
        "source_files": "EllipticSwift/MacOS/**/*.swift",
        "frameworks": "Accelerate"
    },
    "public_header_files": "EllipticSwift/EllipticSwift.h",
    "pod_target_xcconfig": {
        "DEFINES_MODULE": "YES"
    },
    "dependencies": {
        "BigInt": [
            "~> 3.1"
        ]
    }
}

Pin It on Pinterest

Share This