milagro-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-milagro-crypto-c] GuillaumeCisco commented on issue #38: Python wrappers
Date Thu, 15 Aug 2019 09:14:10 GMT
GuillaumeCisco commented on issue #38: Python wrappers
URL: https://github.com/apache/incubator-milagro-crypto-c/issues/38#issuecomment-521572957
 
 
   Ok I succeeded runing this example, on a fresh environment, using these steps:
   
   `sudo apt-get install -y git cmake build-essential python python-dev python-pip libffi-dev
doxygen doxygen-latex parallel `
   `pip install cffi` (in a virtual env)
   Do not modify config.mk
   `make`
   `cd target/default`
   `sudo make install` (sudo is important for installing in /usr/... folders)
   `cp ./example_bls_BLS381.c /tmp`
   `cd /tmp`
   Edit `example_bls_BLS381.c` for replacing imports"
   ```
   #include "config_curve_BLS381.h"
   #include "randapi.h"
   
   #if CURVE_SECURITY_BLS381 == 128
   #include "bls_BLS381.h"
   #elif CURVE_SECURITY_BLS381 == 192
   #include "bls192_BLS381.h"
   #elif CURVE_SECURITY_BLS381 == 256
   #include "bls256_BLS381.h"
   #endif
   ```
   to
   ```
   #include <amcl/config_curve_BLS381.h>
   #include <amcl/randapi.h>
   
   #if CURVE_SECURITY_BLS381 == 128
   #include <amcl/bls_BLS381.h>
   #elif CURVE_SECURITY_BLS381 == 192
   #include <amcl/bls192_BLS381.h>
   #elif CURVE_SECURITY_BLS381 == 256
   #include <amcl/bls256_BLS381.h>
   #endif
   ```
   Then compile it"
   `gcc -O0 -g ./example_bls_BLS381.c $(pkg-config --libs --cflags amcl) -o example_bls_BLS381`
   Try it:
   ```
   $> ./example_bls_BLS381 
   ./example_bls_BLS381: error while loading shared libraries: libamcl_core.so.1: cannot open
shared object file: No such file or directory
   ```
   Find where is `libamcl_core.so`.
   ```
    $> sudo find / -name libamcl_core.so
   /usr/local/lib/libamcl_core.so
   ```
   exporting library
   `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/`
   Try again:
   ```
   ./example_bls_BLS381 
   SEED: 78d0fb6705ce77dee47d03eb5b9c5d30
   
   
   Testing BLS signature for curve BLS381
   Private key SK1: 000000000000000000000000000000001ab4d90898292c30524488630453308cd2fa1f9d76c15f98b1025138f81bf1da
   Public key PKTMP: 0f0bcdc9de4968355e30302ef97e8ec0dd344f87aeb35f6c556dc810a0a506a7aa5e8a4ae3063ad7de241511445e708006796e2ba3b366fda588937fa5cead3a9b6e0e6c29eb328339cd1afb3e0c838f39d2a5f438122c35529658cccd789c700f33fd318079ec077f7c17b89d5c94feffff1d3fab02cde565854a93458dce002241281a7e2d9f58d8a88952fc7fe0260991bc6c2971004a78c9724a18f5fa4c4995b2a2697b9cb0d0adddfae6f500b0732173f092971cbaaaba13c8ffb4ec09
   Public key PK1: 0f0bcdc9de4968355e30302ef97e8ec0dd344f87aeb35f6c556dc810a0a506a7aa5e8a4ae3063ad7de241511445e708006796e2ba3b366fda588937fa5cead3a9b6e0e6c29eb328339cd1afb3e0c838f39d2a5f438122c35529658cccd789c700f33fd318079ec077f7c17b89d5c94feffff1d3fab02cde565854a93458dce002241281a7e2d9f58d8a88952fc7fe0260991bc6c2971004a78c9724a18f5fa4c4995b2a2697b9cb0d0adddfae6f500b0732173f092971cbaaaba13c8ffb4ec09
   Private key SK2: 000000000000000000000000000000002c78985d1620cf5f585fb95fa12643f35874f8ac3e27b1a72793244734eadb2b
   Public key PK2: 00e083bfbf91ccb04e332758ae84aecd23948b349a36d271e9444c04d2cd9263e4cd2b7df79187a71f2d2a2059524938169b09f3ce0e8be623ede589bb5b8d999d023222a20827089897217667b11d8d659bb42b1b55127659b5d2dda50af5eb0e7b36d785d1db7ffcfbbee023c6330ad39440bf8ed287657ea7a3b4b30445de1eb512f8764d3ce7b2a1aa6505e267d81155e430e7248c20ee62d7dc7836d1835f9c0cbf0d551f469ff2e2a7ffcaab46be00162e30e09a382f02396828bbabf9
   Private key SK3: 000000000000000000000000000000002c78985d1620cf5f585fb95fa12643f35874f8ac3e27b1a72793244734eadb2b
   Public key PK3: 00e083bfbf91ccb04e332758ae84aecd23948b349a36d271e9444c04d2cd9263e4cd2b7df79187a71f2d2a2059524938169b09f3ce0e8be623ede589bb5b8d999d023222a20827089897217667b11d8d659bb42b1b55127659b5d2dda50af5eb0e7b36d785d1db7ffcfbbee023c6330ad39440bf8ed287657ea7a3b4b30445de1eb512f8764d3ce7b2a1aa6505e267d81155e430e7248c20ee62d7dc7836d1835f9c0cbf0d551f469ff2e2a7ffcaab46be00162e30e09a382f02396828bbabf9
   
   SIG1: 0308be9a543a978c9a5b143fc8aed6482bdbe5f9dd969693b65c9b2bfdea25e1a611bcbf96f8899bfea06ef71c30bf70ad
   SIG2: 0216d5cbfd2e29445a42bfa7075a28fdf139d4d9c48f31c7233c8b9822929148bdf0fadf315f082c2377ed08cf5dd57f5b
   SIG3: 02082ab439b2c6d366199ae44fcdf72f15529a3af88f413a471196a69aaf65ccddf9ace8a9975426c6080148ca2d30ac9b
   
   Success: Signature is valid
   Success: Signature is valid
   Success: Signature is valid
   Public key PK: 08c2ead7baac23a8b648d6572fd2b3cfe06a0a3d31dafdde14f901fdc582be72647fcc088d33b923ddcc63eba62723e81403ce9283381ab0b56d398da01b7886064eb5679d164cd1fb2efcac21f56d19247d40b7a52a4e6463c792bfb41909f40b1024ffdf0a7fdfc4f92c437f00dde3ac8bbff6c6bbe65a8393aa488d6b5af7f7919acee8262eb240915619b95a65f4017785c554211282bd3d2478fcb236d4fa7c459a6a7b2067785d1a50ae00c9ea5a4921d80a41b8b26b7ce6f34d3a8b2a
   
   Error: Aggregated signature is invalid (expected result) 
   SIG: 030b5620207d709e2991413830ba052fc15199731442f8b868217de7cceaa5406c27261c76eb942b426d0c031e8a349836
   
   Success: Aggregated signature is valid
   message Zest message
   Error: Invalid Signature (expected result) 
   message test message
   Signature SIG1: 0508be9a543a978c9a5b143fc8aed6482bdbe5f9dd969693b65c9b2bfdea25e1a611bcbf96f8899bfea06ef71c30bf70ad
   Error: Invalid Signature  (expected result) 
   ```
   It works as expected!
   
   Now we can finally work on the part I'm looking at, the linking between C and python.
   
   Creating a shared library instead of an executable"
   `gcc -O0 -g ./example_bls_BLS381.c $(pkg-config --libs --cflags amcl) --shared -o example_bls_BLS381.so`
   Creating the python file example_bls_BLS381.py:
   ```
   import cffi
   
   ffi = cffi.FFI()
   ffi.cdef("""
      int main();
   """)
   
   
   lib = ffi.dlopen("/tmp/example_bls_BLS381.so")
   lib.main()
   ```
   Testing:
   ```
   python example_bls_BLS381.py 
   SEED: 78d0fb6705ce77dee47d03eb5b9c5d30
   
   
   Testing BLS signature for curve BLS381
   Private key SK1: 000000000000000000000000000000001ab4d90898292c30524488630453308cd2fa1f9d76c15f98b1025138f81bf1da
   Public key PKTMP: 0f0bcdc9de4968355e30302ef97e8ec0dd344f87aeb35f6c556dc810a0a506a7aa5e8a4ae3063ad7de241511445e708006796e2ba3b366fda588937fa5cead3a9b6e0e6c29eb328339cd1afb3e0c838f39d2a5f438122c35529658cccd789c700f33fd318079ec077f7c17b89d5c94feffff1d3fab02cde565854a93458dce002241281a7e2d9f58d8a88952fc7fe0260991bc6c2971004a78c9724a18f5fa4c4995b2a2697b9cb0d0adddfae6f500b0732173f092971cbaaaba13c8ffb4ec09
   Public key PK1: 0f0bcdc9de4968355e30302ef97e8ec0dd344f87aeb35f6c556dc810a0a506a7aa5e8a4ae3063ad7de241511445e708006796e2ba3b366fda588937fa5cead3a9b6e0e6c29eb328339cd1afb3e0c838f39d2a5f438122c35529658cccd789c700f33fd318079ec077f7c17b89d5c94feffff1d3fab02cde565854a93458dce002241281a7e2d9f58d8a88952fc7fe0260991bc6c2971004a78c9724a18f5fa4c4995b2a2697b9cb0d0adddfae6f500b0732173f092971cbaaaba13c8ffb4ec09
   Private key SK2: 000000000000000000000000000000002c78985d1620cf5f585fb95fa12643f35874f8ac3e27b1a72793244734eadb2b
   Public key PK2: 00e083bfbf91ccb04e332758ae84aecd23948b349a36d271e9444c04d2cd9263e4cd2b7df79187a71f2d2a2059524938169b09f3ce0e8be623ede589bb5b8d999d023222a20827089897217667b11d8d659bb42b1b55127659b5d2dda50af5eb0e7b36d785d1db7ffcfbbee023c6330ad39440bf8ed287657ea7a3b4b30445de1eb512f8764d3ce7b2a1aa6505e267d81155e430e7248c20ee62d7dc7836d1835f9c0cbf0d551f469ff2e2a7ffcaab46be00162e30e09a382f02396828bbabf9
   Private key SK3: 000000000000000000000000000000002c78985d1620cf5f585fb95fa12643f35874f8ac3e27b1a72793244734eadb2b
   Public key PK3: 00e083bfbf91ccb04e332758ae84aecd23948b349a36d271e9444c04d2cd9263e4cd2b7df79187a71f2d2a2059524938169b09f3ce0e8be623ede589bb5b8d999d023222a20827089897217667b11d8d659bb42b1b55127659b5d2dda50af5eb0e7b36d785d1db7ffcfbbee023c6330ad39440bf8ed287657ea7a3b4b30445de1eb512f8764d3ce7b2a1aa6505e267d81155e430e7248c20ee62d7dc7836d1835f9c0cbf0d551f469ff2e2a7ffcaab46be00162e30e09a382f02396828bbabf9
   
   SIG1: 0308be9a543a978c9a5b143fc8aed6482bdbe5f9dd969693b65c9b2bfdea25e1a611bcbf96f8899bfea06ef71c30bf70ad
   SIG2: 0216d5cbfd2e29445a42bfa7075a28fdf139d4d9c48f31c7233c8b9822929148bdf0fadf315f082c2377ed08cf5dd57f5b
   SIG3: 02082ab439b2c6d366199ae44fcdf72f15529a3af88f413a471196a69aaf65ccddf9ace8a9975426c6080148ca2d30ac9b
   
   Success: Signature is valid
   Success: Signature is valid
   Success: Signature is valid
   Public key PK: 08c2ead7baac23a8b648d6572fd2b3cfe06a0a3d31dafdde14f901fdc582be72647fcc088d33b923ddcc63eba62723e81403ce9283381ab0b56d398da01b7886064eb5679d164cd1fb2efcac21f56d19247d40b7a52a4e6463c792bfb41909f40b1024ffdf0a7fdfc4f92c437f00dde3ac8bbff6c6bbe65a8393aa488d6b5af7f7919acee8262eb240915619b95a65f4017785c554211282bd3d2478fcb236d4fa7c459a6a7b2067785d1a50ae00c9ea5a4921d80a41b8b26b7ce6f34d3a8b2a
   
   Error: Aggregated signature is invalid (expected result) 
   SIG: 030b5620207d709e2991413830ba052fc15199731442f8b868217de7cceaa5406c27261c76eb942b426d0c031e8a349836
   
   Success: Aggregated signature is valid
   message Zest message
   Error: Invalid Signature (expected result) 
   message test message
   Signature SIG1: 0508be9a543a978c9a5b143fc8aed6482bdbe5f9dd969693b65c9b2bfdea25e1a611bcbf96f8899bfea06ef71c30bf70ad
   Error: Invalid Signature  (expected result)
   ```
   
   It works as expected.
   I now need to tweak this example for being able to play with `CURVE_Order_FP256BN`
   I'm close :)
   Thanks again for these pieces of informations.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@milagro.apache.org
For additional commands, e-mail: issues-help@milagro.apache.org


Mime
View raw message