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

fix: name jacobian representation more explicitly #31

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ec-gpu-gen/src/cl/ec.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Elliptic curve operations (Short Weierstrass Jacobian form)

#define POINT_ZERO ((POINT_projective){FIELD_ZERO, FIELD_ONE, FIELD_ZERO})
#define POINT_ZERO ((POINT_jacobian){FIELD_ZERO, FIELD_ONE, FIELD_ZERO})

typedef struct {
FIELD x;
Expand All @@ -11,10 +11,10 @@ typedef struct {
FIELD x;
FIELD y;
FIELD z;
} POINT_projective;
} POINT_jacobian;

// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l
DEVICE POINT_projective POINT_double(POINT_projective inp) {
DEVICE POINT_jacobian POINT_double(POINT_jacobian inp) {
const FIELD local_zero = FIELD_ZERO;
if(FIELD_eq(inp.z, local_zero)) {
return inp;
Expand Down Expand Up @@ -42,7 +42,7 @@ DEVICE POINT_projective POINT_double(POINT_projective inp) {
}

// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-madd-2007-bl
DEVICE POINT_projective POINT_add_mixed(POINT_projective a, POINT_affine b) {
DEVICE POINT_jacobian POINT_add_mixed(POINT_jacobian a, POINT_affine b) {
const FIELD local_zero = FIELD_ZERO;
if(FIELD_eq(a.z, local_zero)) {
const FIELD local_one = FIELD_ONE;
Expand All @@ -67,7 +67,7 @@ DEVICE POINT_projective POINT_add_mixed(POINT_projective a, POINT_affine b) {
FIELD r = FIELD_sub(s2, a.y); r = FIELD_double(r); // r = 2*(S2-Y1)
const FIELD v = FIELD_mul(a.x, i);

POINT_projective ret;
POINT_jacobian ret;

// X3 = r^2 - J - 2*V
ret.x = FIELD_sub(FIELD_sub(FIELD_sqr(r), j), FIELD_double(v));
Expand All @@ -82,7 +82,7 @@ DEVICE POINT_projective POINT_add_mixed(POINT_projective a, POINT_affine b) {
}

// http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#addition-add-2007-bl
DEVICE POINT_projective POINT_add(POINT_projective a, POINT_projective b) {
DEVICE POINT_jacobian POINT_add(POINT_jacobian a, POINT_jacobian b) {

const FIELD local_zero = FIELD_ZERO;
if(FIELD_eq(a.z, local_zero)) return b;
Expand Down
10 changes: 5 additions & 5 deletions ec-gpu-gen/src/cl/multiexp.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

KERNEL void POINT_multiexp(
GLOBAL POINT_affine *bases,
GLOBAL POINT_projective *buckets,
GLOBAL POINT_projective *results,
GLOBAL POINT_jacobian *buckets,
GLOBAL POINT_jacobian *results,
GLOBAL EXPONENT *exps,
uint n,
uint num_groups,
Expand All @@ -28,7 +28,7 @@ KERNEL void POINT_multiexp(
// Each thread has its own set of buckets in global memory.
buckets += bucket_len * gid;

const POINT_projective local_zero = POINT_ZERO;
const POINT_jacobian local_zero = POINT_ZERO;
for(uint i = 0; i < bucket_len; i++) buckets[i] = local_zero;

const uint len = (uint)ceil(n / (float)num_groups); // Num of elements in each group
Expand All @@ -40,7 +40,7 @@ KERNEL void POINT_multiexp(
const uint bits = (gid % num_windows) * window_size;
const ushort w = min((ushort)window_size, (ushort)(EXPONENT_BITS - bits));

POINT_projective res = POINT_ZERO;
POINT_jacobian res = POINT_ZERO;
for(uint i = nstart; i < nend; i++) {
uint ind = EXPONENT_get_bits(exps[i], bits, w);

Expand All @@ -60,7 +60,7 @@ KERNEL void POINT_multiexp(
// e.g. 3a + 2b + 1c = a +
// (a) + b +
// ((a) + b) + c
POINT_projective acc = POINT_ZERO;
POINT_jacobian acc = POINT_ZERO;
for(int j = bucket_len - 1; j >= 0; j--) {
acc = POINT_add(acc, buckets[j]);
res = POINT_add(res, acc);
Expand Down