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

C++ operator overloading with types from relic #233

Open
ghoshbishakh opened this issue May 4, 2022 · 3 comments
Open

C++ operator overloading with types from relic #233

ghoshbishakh opened this issue May 4, 2022 · 3 comments

Comments

@ghoshbishakh
Copy link

ghoshbishakh commented May 4, 2022

I am trying to use relic in a C++ project (MPSPDZ). In a class with members of type gt_t, I am trying to overload some operators. For example, to assign gt_t gtpoint, we need to use gt_copy. However gt_copy expects a non constant pointer but for operator overloading we will always get a const.

Two questions:

  1. Will changing the argument type to const in gt_copy affect relic in any unwanted way?
  2. From the macro gt_copy how to determine which function is going to be used, is there any documentation on that?
  3. Is there any possible trick to do this without changes in relic?
GtElement& GtElement::operator =(const GtElement& other)
{
    gt_copy(gtpoint, other.gtpoint); // other.gtpoint is a non constant pointer 
    return *this;
}
@ghoshbishakh
Copy link
Author

This is my current hack:

GtElement& GtElement::operator =(const GtElement& other)
{
    gt_t tmp;
    gt_null(tmp);
    gt_new(tmp);
    memcpy(tmp, other.gtpoint, sizeof(other.gtpoint));
    gt_copy(gtpoint, tmp);
    gt_free(tmp);
    return *this;
}

@dfaranha
Copy link
Contributor

dfaranha commented May 4, 2022

Thanks for the notification+details!

If you are using the BLS12-381 preset or the default configuration, then gt_copy is defined to be fp12_copy. I had tried enforcing const correctness for the extension field types a few years ago, but failed somehow.

Would that simple change fix the situation?

@ghoshbishakh
Copy link
Author

ghoshbishakh commented May 4, 2022

It should definitely fix the problem. Currently, the way around I mentioned above is working fine it seems.
There is another issue #234 which caused a major headache.

Thank you so much for your support and this awsm project!

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

2 participants