Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello friend! We both wrote Pure Swift ECC SDKs this summer #1

Open
Sajjon opened this issue Sep 23, 2018 · 6 comments
Open

Hello friend! We both wrote Pure Swift ECC SDKs this summer #1

Sajjon opened this issue Sep 23, 2018 · 6 comments

Comments

@Sajjon
Copy link

Sajjon commented Sep 23, 2018

We seem to have been working on the same thing :D

Have a look at EllipticCurveKit. My goal is to finish my rewrite using EquationKit, I have got it working already in the equations branch which allows for pretty cool syntax:

///
/// Elliptic Curve on Short Weierstrass form (`𝑆`)
/// - Covers all elliptic curves char≠𝟚,𝟛
/// - Mixed Jacobian coordinates have been the speed leader for a long time.
///
///
/// # Equation
///      𝑆: 𝑦² = 𝑥³ + 𝑎𝑥 + 𝑏
/// - Requires: `𝟜𝑎³ + 𝟚𝟟𝑏² ≠ 𝟘`
///
public struct ShortWeierstraßCurve: CurveForm {


    private let a: Number
    private let b: Number
    public let galoisField: Field
    public let equation: Polynomial

    private let 𝑥: Polynomial
    private let 𝑦: Polynomial

    public init?(
        a: Number,
        b: Number,
        galoisField: Field
        ) {

        let 𝑝 = galoisField.modulus

        guard 𝟜𝑎³ + 𝟚𝟟𝑏²  𝟘 % 𝑝  [ 𝑎  a, 𝑏  b ] else { return nil }

        self.a = a
        self.b = b
        self.galoisField = galoisField
        self.equation = EllipticCurveForm.Weierstraß.short.substitute() {[ 𝑎  a, 𝑏  b ] }
        self.𝑥' = equation.differentiateWithRespectTo(𝑥)!
        self.𝑦' = equation.differentiateWithRespectTo(𝑦)!
    }
}

I have also begun implemented other curve forms than ShortWeierstraß, such as TwistedEdwards and Montgomery.

I saw you PR in CryptoSwift adding support for Scrypt which I am also working on currently.

I'm in need of it in the Zilliqa Swift SDK I am developing, for the export wallet function.

@shamatar
Copy link
Owner

Hello @Sajjon

I'll start wit the last question: Scrypt for CryptoSwift is unfortunately delayed, I couldn't make it fast enough and fight copy of write.

The purpose of the library was to

  • Use for signatures as a replacement to secp256k1 and other C libs
  • Use for fancy stuff like confidential transaction, lib
  • Implement pairings and BLS signatures (for future Ethereum releases)
  • Implement zkSNARK verification and proving for small circuits

There was no intention to make it abstract and based on some general underlying math package like "Sage", but more like pure EC arithmetics packages in other languages.

Regarding the curve forms - I'd focus on a twisted edwards first. Montgommery form is more interesting only for ECDH.

Sincerely, Alex

@Sajjon
Copy link
Author

Sajjon commented Sep 24, 2018

What is your goal time for a release build (using optmization) of Scrypt?

I forked your repo and fixed support for iOS yesterday. I also added a public iOS scheme to support Carthage and it works fine. I might do a PR if you want?

Regardign EC, I too think BLS would be pretty cool to have native support for. I might support it in EllipticCurveKit in the future. I have implemented Schnorr signatures appart form ECDSA.

Yes I wanted to support ECDH that is why I did Montgomery, with Montgomery ladder multiplication(using "mladd-1987-m-3")

@hyugit have also been developing some EllipticCurve Swift SDK. It would be nice for the community with one standard EllipticCurve SDK in Swift. As CryptoSwift is a standard for hashing algorithms. It would also be cool to move all Swift crypto repos into an organisation.

@shamatar
Copy link
Owner

shamatar commented Sep 24, 2018 via email

@Sajjon
Copy link
Author

Sajjon commented Sep 24, 2018

@shamatar I just tried it using N: 262144 (cost parameter) and that did not even complete in 20 minutes on iOS Simulator on my Macbook Pro 2016 (maxed hardware config) using optimization flags.

So yeah it is unfortunately too slow, even when using the C version of calculate. I tried to Profile the unit tests but got some errors, so no luck. Have you CPU time profiled calculate to see what takes time?

@hyugit
Copy link

hyugit commented Sep 29, 2018

pooling everything into one organization sounds good

@shamatar
Copy link
Owner

shamatar commented Sep 29, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants