[Mac] Installation process of cryptography library Miracl

【Mac】Cryptography library Miracl installation process

  • Hardware and software environment
  • installation steps
  • BLS algorithm based on bilinear pairing
  • Conclusion

Hardware and software environment

System environment

coalbrother@Macbook-Air ~ % uname -a
Darwin MacBook-Air.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64

gcc environment

coalbrother@MacBook-Air ~ % gcc -v
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Since mac comes with clang, the gcc typed on the command line is actually the clang compiler.
After using brew to install the GNU version of gcc, the running command is based on the actual version number. My gcc version is 13, so I use gcc-13. As for whether to use clang or GNU depends on your actual situation

Miracl library
Sourced from github, click to see details

Installation steps

Download the MIRACL-master.zip file of the github project locally. Don’t unzip it yet. Create a new folder named miracl and put MIRACL-master.zip in it, and open a terminal in the miracl directory and run the following command

unzip -j -aa -L MIRACL-master.zip

If a prompt similar to the following appears, enter n and press Enter.

replace readme.md? [y]es, [n]o, [A]ll, [N]one, [r]ename: n

The project comes with batch files such as linux, linux64, and linux_cpp. I chose linux64

coalbrother@MacBook-Air miracl % bash linux64
rm: *.exe: No such file or directory
rm: miracl.a: No such file or directory
mrmuldv.c:21:7: error: unknown register name 'eax' in asm
    : "eax","ebx","memory"
      ^
mrmuldv.c:38:7: error: unknown register name 'eax' in asm
    : "eax","ebx","memory"
      ^
mrmuldv.c:56:7: error: unknown register name 'eax' in asm
    : "eax","ebx","memory"
      ^
mrmuldv.c:76:7: error: unknown register name 'eax' in asm
    : "eax","ebx","esi","memory"
      ^
4 errors generated.
ar: mrmuldv.o: No such file or directory
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Based on the error message provided, it looks like we are trying to link using the ld linker for the -arch armv4t architecture. Obviously, the error message indicates that the schema name is unknown or unsupported. Because the gcc used in this batch file uses the -m32 option, which tells the Clang compiler to generate 32-bit object code, we need to remove this -m32.
In addition, we want to use GNU, so we replace all gcc in it with gcc-13, Be careful not to replace line 54 The gcc was replaced with , and similarly, g++ was replaced with g++ -13. If you want to use the clang compiler, you need to replace clang with gcc, g++ Replace clang++

coalbrother@MacBook-Air miracl % bash linux64
rm: *.exe: No such file or directory
mrmuldv.c: In function 'muldiv':
mrmuldv.c:10:5: error: unknown register name 'ebx' in 'asm'
   10 | __asm__ __volatile__ (
      | ^~~~~~~
mrmuldv.c:10:5: error: unknown register name 'eax' in 'asm'
mrmuldv.c: In function 'muldvm':
mrmuldv.c:29:5: error: unknown register name 'ebx' in 'asm'
   29 | __asm__ __volatile__ (
      | ^~~~~~~
mrmuldv.c:29:5: error: unknown register name 'eax' in 'asm'
mrmuldv.c: In function 'muldvd':
mrmuldv.c:46:5: error: unknown register name 'ebx' in 'asm'
   46 | __asm__ __volatile__ (
      | ^~~~~~~
mrmuldv.c:46:5: error: unknown register name 'eax' in 'asm'
mrmuldv.c: In function 'muldvd2':
mrmuldv.c:63:5: error: unknown register name 'esi' in 'asm'
   63 | __asm__ __volatile__ (
      | ^~~~~~~
mrmuldv.c:63:5: error: unknown register name 'ebx' in 'asm'
mrmuldv.c:63:5: error: unknown register name 'eax' in 'asm'
ar: mrmuldv.o: No such file or directory
Undefined symbols for architecture arm64:
  "_brick_end", referenced from:
      _powers_precomp in cccDVd7k.o
  "_brick_init", referenced from:
      _powers_precomp in cccDVd7k.o
  "_ebrick2_end", referenced from:
      _mult2_precomp in cccDVd7k.o
  "_ebrick2_init", referenced from:
      _mult2_precomp in cccDVd7k.o
  "_ebrick_end", referenced from:
      _mult_precomp in cccDVd7k.o
  "_ebrick_init", referenced from:
      _mult_precomp in cccDVd7k.o
  "_ecurve2_init", referenced from:
      _main in cccDVd7k.o
  "_ecurve2_mult", referenced from:
      _mults2 in cccDVd7k.o
      _mult2_double in cccDVd7k.o
  "_ecurve2_mult2", referenced from:
      _mult2_double in cccDVd7k.o
  "_epoint2_set", referenced from:
      _main in cccDVd7k.o
  "_mul2_brick", referenced from:
      _mult2_precomp in cccDVd7k.o
  "_mul_brick", referenced from:
      _mult_precomp in cccDVd7k.o
  "_muldiv", referenced from:
      _redc in miracl.a(mrmonty.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
  "_muldvd", referenced from:
      _divide in miracl.a(mrarth2.o)
      _mr_pmul in miracl.a(mrarth1.o)
  "_muldvd2", referenced from:
      _redc in miracl.a(mrmonty.o)
      _multiply in miracl.a(mrarth2.o)
  "_muldvm", referenced from:
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _mr_sdiv in miracl.a(mrarth1.o)
  "_pow_brick", referenced from:
      _powers_precomp in cccDVd7k.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _invers in miracl.a(mrsmall.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _build in miracl.a(mrbuild.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_muldiv", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _euclid in miracl.a(mrround.o)
  "_muldvd", referenced from:
      _divide in miracl.a(mrarth2.o)
      _mr_pmul in miracl.a(mrarth1.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
  "_muldvm", referenced from:
      _build in miracl.a(mrbuild.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _euclid in miracl.a(mrround.o)
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _build in miracl.a(mrbuild.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _build in miracl.a(mrbuild.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _build in miracl.a(mrbuild.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      _build in miracl.a(mrbuild.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Undefined symbols for architecture arm64:
  "_ecurve2_init", referenced from:
      __Z7ecurve2iiiiRK3BigS1_ii in big.o
  "_muldiv", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _mr_sdiv in miracl.a(mrarth1.o)
      _multiply in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
      _egcd in miracl.a(mrgcd.o)
      _mr_dif_fft in miracl.a(mrfast.o)
      ...
  "_muldvd", referenced from:
      _mr_pmul in miracl.a(mrarth1.o)
      _divide in miracl.a(mrarth2.o)
      _fft_mult in miracl.a(mrfast.o)
      _smul in miracl.a(mrsmall.o)
  "_muldvd2", referenced from:
      _multiply in miracl.a(mrarth2.o)
      _redc in miracl.a(mrmonty.o)
  "_muldvm", referenced from:
      _mr_sdiv in miracl.a(mrarth1.o)
      _normalise in miracl.a(mrarth2.o)
      _divide in miracl.a(mrarth2.o)
      _egcd in miracl.a(mrgcd.o)
      _invers in miracl.a(mrsmall.o)
      _euclid in miracl.a(mrround.o)
      _xgcd.part.0 in miracl.a(mrxgcd.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
coalbrother@MacBook-Air miracl %

We encountered many problems again, and we analyzed them in turn.

  • Don’t worry if the rm deletion fails. You can delete this sentence.
  • unknown register name ebx’ in asm’. Since ebx is not a register in the arm architecture, this operation will report an error. Therefore, we need to replace this operation with standard C language code.
    Change mrmuldv.gcc to mrmuldv.ccc
  • ar: mrmuldv.o: No such file or directory, including the following problems, are all caused by mrmuldv.o not being successfully compiled.
coalbrother@MacBook-Air miracl % bash linux64
rm: *.exe: No such file or directory

There is no problem now. According to the program in linux, we have successfully compiled the following files. The explanations come from readme.txt

bmark # Benchmark program for Public Key methods
fact #Factorials
big.o # C++ header for 'big' numbers
zzn.o # C++ header for 'big' numbers mod n
ecn.o # C++ header for GF(p) Elliptic Curves
ec2.o # EC2 function implementations
crt.o # Crt function implementations
mersenne # Mersenne primes
brent # Brent-pollard factoring
flash.o # Flash function implementations
sample # Example C++ source (uses FLASH.H)
ecsgen # DSS (Elliptic Curve GF(p) variation) key generator program
ecsign # DSS (Elliptic Curve GF(p) variation) signature program (static stack-only version)
ecsver # DSS (Elliptic Curve GF(p) variation) verification program (static stack-only version)
pk-demo # Demo of RSA/El Gamal/Diffie-Hellman/Elliptic Curve...
polymod.o # ZZn Polynomial arithmetic wrt a Polynomial Modulus
poly.o # Polynomial Arithmetic with ZZn coefficients

In fact, after having the static library miracl.a, our installation is completed (that is, after all ar operations are completed), all mr* The .o templates are stuffed into miracl.a and used for compiling C language programs.

BLS algorithm based on bilinear pairing

In the miracle manual manual and pairings.txt, it is mentioned that miracl supports pairing-based cryptography, including eta pairing and tate pairing. Unfortunately, GF(2^m) The pairing on is actually broken and is no longer used. Here we use bls.cpp
manual manual support for pairing

/*
   Boneh-Lynn-Shacham short signature

   Compile with modules as specified in the selected header file

   For MR_PAIRING_CP curve
   cl /O2 /GX bls.cpp cp_pair.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib
   (Note this really doesn't make much sense as the signature will not be "short")

   For MR_PAIRING_MNT curve
   cl /O2 /GX bls.cpp mnt_pair.cpp zzn6a.cpp ecn3.cpp zzn3.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib
\t
   For MR_PAIRING_BN curve
   cl /O2 /GX bls.cpp bn_pair.cpp zzn12a.cpp ecn2.cpp zzn4.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib

   For MR_PAIRING_KSS curve
   cl /O2 /GX bls.cpp kss_pair.cpp zzn18.cpp zzn6.cpp ecn3.cpp zzn3.cpp big.cpp zzn.cpp ecn.cpp miracl.lib

   For MR_PAIRING_BLS curve
   cl /O2 /GX bls.cpp bls_pair.cpp zzn24.cpp zzn8.cpp zzn4.cpp zzn2.cpp ecn4.cpp big.cpp zzn.cpp ecn.cpp miracl.lib

   Test program
*/

#include <iostream>
#include <ctime>

//********** choose just one of these pairs **********
//#define MR_PAIRING_CP // AES-80 security
//#define AES_SECURITY 80

//#define MR_PAIRING_MNT // AES-80 security
//#define AES_SECURITY 80

#define MR_PAIRING_BN // AES-128 or AES-192 security
#define AES_SECURITY 128
//#define AES_SECURITY 192

//#define MR_PAIRING_KSS // AES-192 security
//#define AES_SECURITY 192

//#define MR_PAIRING_BLS // AES-256 security
//#define AES_SECURITY 256
//************************************************

#include "pairing_3.h"

int main()
{<!-- -->
PFC pfc(AES_SECURITY); // initialise pairing-friendly curve

G2 Q,V;
G1 S,R;
int lsb;
Big s,X;
time_t seed;

time(& amp;seed);
    irand((long)seed);

// Create system-wide G2 constant
pfc.random(Q);

pfc.random(s); // private key
V=pfc.mult(Q,s); // public key

//signature
pfc.hash_and_map(R,(char *)"Test Message to sign");
S=pfc.mult(R,s);

lsb=S.g.get(X); // signature is lsb bit and X

cout << "Signature= " << lsb << " " << X << endl;

// verification - first recover full point S
if (!S.g.set(X,1-lsb))
{<!-- -->
cout << "Signature is invalid" << endl;
exit(0);
}
pfc.hash_and_map(R,(char *)"Test Message to sign");


// Observe that Q is a constant
// Interesting that this optimization doesn't work for the Tate pairing, only the Ate

pfc.precomp_for_pairing(Q);

G1 *g1[2];
G2 *g2[2];
g1[0]= & amp;S; g1[1]= & amp;R;
g2[0]= & amp;Q; g2[1]= & amp;V;

if (pfc.multi_pairing(2,g2,g1)==1)
cout << "Signature verifies" << endl;
else
cout << "Signature is bad" << endl;

    return 0;
}

You can see in the code that the header file pairing_3.h is referenced, and pairing_3.h also references ecn.h,zzn2.h,ecn2.h ,zzn12a.h
Create a new Makefile file and fill in the following content

# Compiler and compilation options
CXX := clang++
CXX_COMPILE_FLAGS := -std=c + + 14 -Wall -O2 -c -I. -L.
CXX_LINK_FLAGS := -std=c + + 14 -Wall -O2 -L. miracl.a
# Source File
CPPS := bls.cpp ecn.cpp zzn2.cpp ecn2.cpp zzn12a.cpp
OS := bls.o ecn.o zzn2.o ecn2.o zzn12a.o
# Target file
OBJ := bls
#Library file path and link options
LIBRARY_PATH := -L.
all:
# compile
$(CXX) $(CXX_COMPILE_FLAGS) $(CPPS) $(LIBRARIES)
# Link
$(CXX) $(CXX_LINK_FLAGS) $(OS) $(LIBRARIES) -o $(OBJ)

I encountered the following error when running, which is also a problem that has troubled me for a long time.

coalbrother@MacBook-Air miracl % make
clang + + -std=c + + 14 -Wall -O2 -c -I. -L. bls.cpp ecn.cpp zzn2.cpp ecn2.cpp zzn12a.cpp
clang: warning: argument unused during compilation: '-L.' [-Wunused-command-line-argument]
zzn2.cpp:146:9: warning: unused variable 'qnr' [-Wunused-variable]
    int qnr=get_mip()->qnr;
        ^
1 warning generated.
clang + + -std=c + + 14 -Wall -O2 -L. miracl.a bls.o ecn.o zzn2.o ecn2.o zzn12a.o -o bls
Undefined symbols for architecture arm64:
  "read_only_error()", referenced from:
      _main in bls.o
  "tx(ZZn4 const & amp;)", referenced from:
      ZZn12::operator*=(ZZn12 const & amp;) in zzn12a.o
      inverse(ZZn12 const & amp;) in zzn12a.o
      tx(ZZn12 const & amp;) in zzn12a.o
  "one()", referenced from:
      ZZn2::operator/=(ZZn const & amp;) in zzn2.o
      ZZn2::operator/=(int) in zzn2.o
      powu(ZZn2 const & amp;, Big const & amp;) in zzn2.o
      pow(ZZn12 const & amp;, Big const & amp;) in zzn12a.o
  "getA()", referenced from:
      is_on_curve(ZZn2 const & amp;) in zzn2.o
  "getB()", referenced from:
      is_on_curve(ZZn2 const & amp;) in zzn2.o
  "randn()", referenced from:
      randn2() in zzn2.o
  "randn4()", referenced from:
      randn12() in zzn12a.o
  "inverse(ZZn4 const & amp;)", referenced from:
      ZZn12::operator/=(ZZn4 const & amp;) in zzn12a.o
      inverse(ZZn12 const & amp;) in zzn12a.o
  "PFC::hash_and_map(G1 & amp;, char*)", referenced from:
      _main in bls.o
  "PFC::multi_pairing(int, G2**, G1**)", referenced from:
      _main in bls.o
  "PFC::precomp_for_pairing(G2 & amp;)", referenced from:
      _main in bls.o
  "PFC::mult(G1 const & amp;, Big const & amp;)", referenced from:
      _main in bls.o
  "PFC::mult(G2 const & amp;, Big const & amp;)", referenced from:
      _main in bls.o
  "PFC::random(G2 & amp;)", referenced from:
      _main in bls.o
  "PFC::random(Big & amp;)", referenced from:
      _main in bls.o
  "PFC::PFC(int, csprng*)", referenced from:
      _main in bls.o
  "PFC::~PFC()", referenced from:
      _main in bls.o
  "ZZn4::powq(ZZn2 const & amp;)", referenced from:
      ZZn12::powq(ZZn2 const & amp;) in zzn12a.o
  "Big::isone() const", referenced from:
      powu(ZZn2 const & amp;, Big const & amp;) in zzn2.o
  "Big::getbig() const", referenced from:
      _main in bls.o
      ECn::get(Big & amp;, Big & amp;) const in ecn.o
      ECn::get(Big &) const in ecn.o
      ECn::getx(Big & amp;) const in ecn.o
      ECn::getxy(Big & amp;, Big & amp;) const in ecn.o
      ECn::getxyz(Big & amp;, Big & amp;, Big & amp;) const in ecn.o
      operator*(Big const & amp;, ECn const & amp;) in ecn.o
      ...
  "Big::iszero() const", referenced from:
      powu(ZZn2 const & amp;, Big const & amp;) in zzn2.o
  "ZZn::getzzn() const", referenced from:
      ZZn2::get(ZZn & amp;, ZZn & amp;) const in zzn2.o
      ZZn2::get(ZZn & amp;) const in zzn2.o
      ZZn2::operator/=(ZZn const & amp;) in zzn2.o
      ZZn2::operator/=(int) in zzn2.o
      operator + (ZZn2 const & amp;, ZZn const & amp;) in zzn2.o
      operator-(ZZn2 const & amp;, ZZn const & amp;) in zzn2.o
      operator*(ZZn2 const & amp;, ZZn const & amp;) in zzn2.o
      ...
  "operator/(ZZn const & amp;, ZZn const & amp;)", referenced from:
      ZZn2::operator/=(ZZn const & amp;) in zzn2.o
  "operator/(ZZn const & amp;, int)", referenced from:
      ZZn2::operator/=(int) in zzn2.o
  "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char>> & amp;, Big const & amp;)", referenced from:
      _main in bls.o
      operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char>> & amp;, ECn const & amp;) in ecn.o
      operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char>> & amp;, ZZn2 const & amp;) in zzn2.o
  "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char>> & amp;, ZZn4 const & amp;)", referenced from:
      operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char>> & amp;, ZZn12 const & amp;) in zzn12a.o
  "operator-(ZZn4 const & amp;, ZZn4 const & amp;)", referenced from:
      ZZn12::operator*=(ZZn12 const & amp;) in zzn12a.o
      inverse(ZZn12 const & amp;) in zzn12a.o
  "operator*(ZZn4 const & amp;, ZZn4 const & amp;)", referenced from:
      ZZn12::operator*=(ZZn12 const & amp;) in zzn12a.o
      inverse(ZZn12 const & amp;) in zzn12a.o
  "operator*(int, Big const & amp;)", referenced from:
      powu(ZZn2 const & amp;, Big const & amp;) in zzn2.o
  "operator-(Big const & amp;)", referenced from:
      powu(ZZn2 const & amp;, Big const & amp;) in zzn2.o
      pow(ZZn12 const & amp;, Big const & amp;) in zzn12a.o
  "operator-(ZZn4 const & amp;)", referenced from:
      ZZn12::operator*=(ZZn12 const & amp;) in zzn12a.o
      ZZn12::conj() in zzn12a.o
      operator-(ZZn12 const & amp;) in zzn12a.o
  "operator + (ZZn4 const & amp;, ZZn4 const & amp;)", referenced from:
      ZZn12::operator*=(ZZn12 const & amp;) in zzn12a.o
      inverse(ZZn12 const & amp;) in zzn12a.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

ld: symbol(s) not found for architecture arm64
This error message indicates that the linker cannot find a symbol that meets the requirements of the arm64 architecture. In order to solve this problem, I searched all over the Internet and couldn’t find the answer
Finally I saw this sentence in the manual

Combined with the previous article, that is to say, we need to add the modules used to miracl.a! ! !

As for the code after line 69, you can actually delete it. We only need to regenerate miracl.a again.

coalbrother@MacBook-Air miracl % bash linux64
bn_pair.cpp:1439:8: warning: assigning field to itself [-Wself-assign-field]
        mtbits=mtbits;
              ^
1 warning generated.
coalbrother@MacBook-Air miracl % make
clang + + -std=c + + 14 -Wall -O2 -c -I. -L. bls.cpp ecn.cpp zzn2.cpp ecn2.cpp zzn12a.cpp
clang: warning: argument unused during compilation: '-L.' [-Wunused-command-line-argument]
zzn2.cpp:146:9: warning: unused variable 'qnr' [-Wunused-variable]
    int qnr=get_mip()->qnr;
        ^
1 warning generated.
clang + + -std=c + + 14 -Wall -O2 -L. miracl.a bls.o ecn.o zzn2.o ecn2.o zzn12a.o -o bls
coalbrother@MacBook-Air miracl % ./bls
Signature= 0 1296B58E158530D16AABEC2A34D7129EB2337405EA6156725C6EEFE2DB2EE799
Signature verifies

Now you can see that there are no errors and the bls file can be successfully executed!

Conclusion

Creation is not easy, I hope you can like it and support it

syntaxbug.com © 2021 All Rights Reserved.