shamatar / EllipticSwift

Elliptic curve and modular long arithmetics in pure Swift
Other
8 stars 3 forks source link

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

Open Sajjon opened 6 years ago

Sajjon commented 6 years ago

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 commented 6 years ago

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

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 commented 6 years ago

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 commented 6 years ago

How much did you get for one Scrypt operation? It should ideally be below 0.1 second for β€œweak” parameters (N=4096). I think C implementation has something like 0.016, while debug scheme I had was about 2.5. Please make a PR, I’ll check what’s going on and may be finally update it for CryptoSwift.

One library sounds cool! Also there is huge room for improvement, for example, hashing to Edwards is completely different, and there is an alternative signature scheme on x25519 curve by Bernstein.

Sincerely, Alex


From: Alexander Cyon notifications@github.com Sent: Monday, September 24, 2018 1:19:16 PM To: shamatar/EllipticSwift Cc: Alexander; Comment Subject: Re: [shamatar/EllipticSwift] Hello friend! We both wrote Pure Swift ECC SDKs this summer (#1)

What is your goal time for a release build (using optmization) of Scrypthttps://github.com/shamatar/scrypt-cryptoswift/?

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 multiplicationhttps://github.com/Sajjon/EllipticCurveKit/blob/equations/Source/EllipticCurve/Curve/CurveForms/MontgomeryCurve.swift#L164-L205(using "mladd-1987-m-3"http://www.hyperelliptic.org/EFD/g1p/auto-code/montgom/xz/ladder/mladd-1987-m.op3)

@hyugithttps://github.com/hyugit have also been developing some EllipticCurve Swift SDKhttps://github.com/hyugit/EllipticCurve. 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.

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/shamatar/EllipticSwift/issues/1#issuecomment-423930527, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGKv9xVsJG0NUq9K1MpwIu9tJc5YdU8Tks5ueLGkgaJpZM4W1yxt.

Sajjon commented 6 years ago

@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 commented 6 years ago

pooling everything into one organization sounds good

shamatar commented 6 years ago

I’ll start working on a consolidation structure after finishing a work on extension fields and pairing operation


From: Huang Yu notifications@github.com Sent: Saturday, September 29, 2018 12:43:16 PM To: shamatar/EllipticSwift Cc: Alexander; Mention Subject: Re: [shamatar/EllipticSwift] Hello friend! We both wrote Pure Swift ECC SDKs this summer (#1)

pooling everything into one organization sounds good

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/shamatar/EllipticSwift/issues/1#issuecomment-425631975, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGKv9yXbE1S2m_HN_jgvqvy6TEuWq3Oaks5uf0C0gaJpZM4W1yxt.