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

How do I add two group elements? #13

Open
benma opened this issue Dec 22, 2015 · 1 comment
Open

How do I add two group elements? #13

benma opened this issue Dec 22, 2015 · 1 comment

Comments

@benma
Copy link

benma commented Dec 22, 2015

If I have two edwards25519.ExtendedGroupElement, how do I add them on the curve? I don't see a function for it, but it would be very useful.

Here is an implementation of it in Python:
https://github.com/vbuterin/ed25519/blob/5b4f873bc88de51a3999994e30cb3a3759948308/ed25519.py#L170

I would port it, but I don't know what D is.

@benma
Copy link
Author

benma commented Dec 22, 2015

This seems to be working:

func Add(p, q *edwards25519.ExtendedGroupElement) *edwards25519.ExtendedGroupElement {
    var r edwards25519.CompletedGroupElement
    var qCached edwards25519.CachedGroupElement
    q.ToCached(&qCached)
    edwards25519.GeAdd(&r, p, &qCached)
    var result edwards25519.ExtendedGroupElement
    r.ToExtended(&result)
    edwards25519.FeNeg(&result.X, &result.X)
    return &result
}

I have no idea why the negation of the X is necessary in the end, but without it, the linearity does not hold:

sk1*B + sk2*B = (sk1+sk2)*B

(while taking care that sk1+sk2 has still the first three and the last two bits set correctly).

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

1 participant