JHUISI / charm

Charm: A Framework for Rapidly Prototyping Cryptosystems
http://charm-crypto.io
GNU Lesser General Public License v3.0
542 stars 166 forks source link

Not working with current version of RELIC #220

Closed vusirikala closed 3 years ago

vusirikala commented 5 years ago

I tried to run charm using current version of RELIC. There seems to be some code change in RELIC that is not reflected in charm. Here's the error I obtain when trying to compile charm.

lindys-MacBook-Pro:charm-dev satya$ make
Setup build/staging directories
set -x
set +x
Building the Charm Framework
/usr/local/bin/python3 setup.py build  
Platform: Darwin
Config file: /Users/satya/Downloads/charm-dev/config.mk
running build
running build_py
copying charm/config.py -> build/lib.macosx-10.14-x86_64-3.7/charm
package init file 'charm/schemes/prenc/__init__.py' not found (or not a regular file)
running build_ext
building 'charm.core.math.pairing' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DBENCHMARK_ENABLED=1 -Icharm/core/utilities/ -Icharm/core/benchmark/ -I/usr/local/include/relic -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c charm/core/math/pairing/relic/pairingmodule3.c -o build/temp.macosx-10.14-x86_64-3.7/charm/core/math/pairing/relic/pairingmodule3.o
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:161:10: error: conflicting types for 'ep_read_bin'
status_t g1_read_bin(g1_t g, uint8_t *data, int data_len);
         ^
/usr/local/include/relic/relic_pc.h:437:31: note: expanded from macro 'g1_read_bin'
#define g1_read_bin(P, B, L)    RLC_CAT(G1_LOWER, read_bin)(P, B, L)
                                ^
/usr/local/include/relic/relic_util.h:142:25: note: expanded from macro 'RLC_CAT'
#define RLC_CAT(A, B)                   _RLC_CAT(A, B)
                                        ^
/usr/local/include/relic/relic_util.h:143:26: note: expanded from macro '_RLC_CAT'
#define _RLC_CAT(A, B)                  A ## B
                                        ^
<scratch space>:144:1: note: expanded from here
ep_read_bin
^
/usr/local/include/relic/relic_ep.h:674:6: note: previous declaration is here
void ep_read_bin(ep_t a, const uint8_t *bin, int len);
     ^
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:162:58: error: too few arguments provided to function-like macro invocation
status_t g1_write_bin(g1_t g, uint8_t *data, int data_len);
                                                         ^
/usr/local/include/relic/relic_pc.h:469:9: note: macro 'g1_write_bin' defined here
#define g1_write_bin(B, L, P, C)        RLC_CAT(G1_LOWER, write_bin)(B, L, P, C)
        ^
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:165:10: error: conflicting types for 'ep2_read_bin'
status_t g2_read_bin(g2_t g, uint8_t *data, int data_len);
         ^
/usr/local/include/relic/relic_pc.h:447:31: note: expanded from macro 'g2_read_bin'
#define g2_read_bin(P, B, L)    RLC_CAT(G2_LOWER, read_bin)(P, B, L)
                                ^
/usr/local/include/relic/relic_util.h:142:25: note: expanded from macro 'RLC_CAT'
#define RLC_CAT(A, B)                   _RLC_CAT(A, B)
                                        ^
/usr/local/include/relic/relic_util.h:143:26: note: expanded from macro '_RLC_CAT'
#define _RLC_CAT(A, B)                  A ## B
                                        ^
<scratch space>:145:1: note: expanded from here
ep2_read_bin
^
/usr/local/include/relic/relic_epx.h:529:6: note: previous declaration is here
void ep2_read_bin(ep2_t a, const uint8_t *bin, int len);
     ^
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:166:58: error: too few arguments provided to function-like macro invocation
status_t g2_write_bin(g2_t g, uint8_t *data, int data_len);
                                                         ^
/usr/local/include/relic/relic_pc.h:481:9: note: macro 'g2_write_bin' defined here
#define g2_write_bin(B, L, P, C)        RLC_CAT(G2_LOWER, write_bin)(B, L, P, C)
        ^
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:169:10: error: conflicting types for 'fp12_read_bin'
status_t gt_read_bin(gt_t g, uint8_t *data, int data_len);
         ^
/usr/local/include/relic/relic_pc.h:457:31: note: expanded from macro 'gt_read_bin'
#define gt_read_bin(A, B, L)    RLC_CAT(GT_LOWER, read_bin)(A, B, L)
                                ^
/usr/local/include/relic/relic_util.h:142:25: note: expanded from macro 'RLC_CAT'
#define RLC_CAT(A, B)                   _RLC_CAT(A, B)
                                        ^
/usr/local/include/relic/relic_util.h:143:26: note: expanded from macro '_RLC_CAT'
#define _RLC_CAT(A, B)                  A ## B
                                        ^
<scratch space>:146:1: note: expanded from here
fp12_read_bin
^
/usr/local/include/relic/relic_fpx.h:1507:6: note: previous declaration is here
void fp12_read_bin(fp12_t a, const uint8_t *bin, int len);
     ^
In file included from charm/core/math/pairing/relic/pairingmodule3.c:30:
In file included from charm/core/math/pairing/relic/pairingmodule3.h:42:
charm/core/math/pairing/relic/relic_interface.h:170:58: error: too few arguments provided to function-like macro invocation
status_t gt_write_bin(gt_t g, uint8_t *data, int data_len);
                                                         ^
/usr/local/include/relic/relic_pc.h:493:9: note: macro 'gt_write_bin' defined here
#define gt_write_bin(B, L, A, C)        RLC_CAT(GT_LOWER, write_bin)(B, L, A, C)
        ^
charm/core/math/pairing/relic/pairingmodule3.c:114:35: error: use of undeclared identifier 'BN_NEG'
        int size, isNeg = (bn_sign(x) == BN_NEG) ? TRUE : FALSE;
                                         ^
charm/core/math/pairing/relic/pairingmodule3.c:115:24: error: too many arguments to function call, expected 2, have 3
        bn_size_str(&size, x, 2);
        ~~~~~~~~~~~           ^
/usr/local/include/relic/relic_bn.h:565:1: note: 'bn_size_str' declared here
int bn_size_str(const bn_t a, int radix);
^
charm/core/math/pairing/relic/pairingmodule3.c:311:37: warning: address of array 'self->e' will always evaluate to 'true'
      [-Wpointer-bool-conversion]
        if(self->elem_initialized && self->e) {
                                  ~~ ~~~~~~^
1 warning and 8 errors generated.
error: command 'clang' failed with exit status 1
make: *** [all] Error 1
friedrichsenm commented 3 years ago

I was also trying to get Charm to work with the current version of Relic and was running into similar errors. It looks like most of them are name changes to macros in Relic that weren't changed in Charm's interface and there were a few function names in Charms that conflicted with new function names in Relic.

I attempted to fix these myself and seem to have done something that works since I can now load the Relic curves using Charm. Here's what I did

  1. in /charm/core/math/pairing/relic/pairingmodule3.c I changed line 115 from

    bn_size_str(&size, x, 2);

    to

    size = bn_size_str(x, 2);
  2. In /charm/core/math/pairing/relic/relic_interface.h, I added some additional macros around the block in lines 59-62. I changed it from

    #define FP_STR FP_BYTES * 2 + 1
    #define G1_LEN (FP_BYTES * 2) + 2
    #define G2_LEN (FP_BYTES * 4) + 4
    #define GT_LEN (FP_BYTES * 12) + 12

to

#define FP_BYTES RLC_FP_BYTES
#define FP_STR FP_BYTES * 2 + 1
#define G1_LEN (FP_BYTES * 2) + 2
#define G2_LEN (FP_BYTES * 4) + 4
#define GT_LEN (FP_BYTES * 12) + 12
#define BN_NEG RLC_NEG
#define BN_POS RLC_POS
#define STS_OK RLC_OK
#define G1_TABLE RLC_G1_TABLE
#define G2_TABLE RLC_G2_TABLE
#define CMP_GT RLC_GT
#define CMP_EQ RLC_EQ
#define BN_BYTES (RLC_BN_DIGS * sizeof(dig_t))
#define fp_write fp_write_str
  1. In relic_interface.h and relic_interface.c, I added charm_ as a prefix to the functions g1_read_bin, g1_write_bin, g2_read_bin, g2_write_bin, gt_read_bin, gt_write_bin
jakinyele commented 3 years ago

Yeah, Relic update is overdue. Thanks for your changes @friedrichsenm! Would appreciate a PR so others can benefit.

friedrichsenm commented 3 years ago

There are at least a few things that are still not working appropriately. For example serialization/deserialization of points in the pairing groups. I'll take a look when I can, but likely won't have time in the near future to attempt a fix.