diff --git a/.gitignore b/.gitignore
index adf8f72..96418f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,8 @@
# Go workspace file
go.work
+# QtCreator CMake
+CMakeLists.txt.user*
+
+#CMake
+build/
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index deaefb0..fb2ad1c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21.0)
-project(KGC)
+project(KGC LANGUAGES C)
include(GNUInstallDirs)
@@ -52,7 +52,7 @@ elseif(WIN32)
COMMAND cd "${CMAKE_CURRENT_BINARY_DIR}/output/temp"
COMMAND ${CMAKE_AR} x "${CMAKE_CURRENT_BINARY_DIR}/output/temp/libMiracl.a"
COMMAND ${CMAKE_AR} x "${CMAKE_CURRENT_BINARY_DIR}/output/temp/lib${PROJECT_NAME}.a"
- COMMAND ${CMAKE_AR} crs "${CMAKE_CURRENT_BINARY_DIR}/output/lib/lib${PROJECT_NAME}All.a" "${CMAKE_CURRENT_BINARY_DIR}/output/temp/*.obj"
+ COMMAND ${CMAKE_AR} crs "${CMAKE_CURRENT_BINARY_DIR}/output/lib/lib${PROJECT_NAME}All.a" "*.obj"
DEPENDS ${PROJECT_NAME} Miracl
)
else()
@@ -63,7 +63,7 @@ else()
COMMAND cd "${CMAKE_CURRENT_BINARY_DIR}/output/temp"
COMMAND ${CMAKE_AR} x "${CMAKE_CURRENT_BINARY_DIR}/output/temp/libMiracl.a"
COMMAND ${CMAKE_AR} x "${CMAKE_CURRENT_BINARY_DIR}/output/temp/lib${PROJECT_NAME}.a"
- COMMAND ${CMAKE_AR} crs "${CMAKE_CURRENT_BINARY_DIR}/output/lib/lib${PROJECT_NAME}All.a" "${CMAKE_CURRENT_BINARY_DIR}/output/temp/*.o"
+ COMMAND ${CMAKE_AR} crs "${CMAKE_CURRENT_BINARY_DIR}/output/lib/lib${PROJECT_NAME}All.a" "*.o"
DEPENDS ${PROJECT_NAME} Miracl
)
endif()
diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user
deleted file mode 100644
index 9e23732..0000000
--- a/CMakeLists.txt.user
+++ /dev/null
@@ -1,418 +0,0 @@
-
-
-
-
-
- EnvironmentId
- {7795ecad-0ea3-4fc2-a933-fbc01bf1ad55}
-
-
- ProjectExplorer.Project.ActiveTarget
- 0
-
-
- ProjectExplorer.Project.EditorSettings
-
- true
- false
- true
-
- Cpp
-
- CppGlobal
-
-
-
- QmlJS
-
- QmlJSGlobal
-
-
- 2
- UTF-8
- false
- 4
- false
- 80
- true
- true
- 1
- 0
- false
- true
- false
- 2
- true
- true
- 0
- 8
- true
- false
- 1
- true
- true
- true
- *.md, *.MD, Makefile
- false
- true
- true
-
-
-
- ProjectExplorer.Project.PluginSettings
-
-
- true
- false
- true
- true
- true
- true
-
-
- 0
- true
-
- true
- true
- Builtin.DefaultTidyAndClazy
- 2
- true
-
-
-
- true
-
-
-
-
- ProjectExplorer.Project.Target.0
-
- Desktop
- Desktop Qt 6.5.3 MinGW 64-bit
- Desktop Qt 6.5.3 MinGW 64-bit
- qt.qt6.653.win64_mingw_kit
- 0
- 0
- 0
-
- Debug
- 2
- false
-
- -DCMAKE_GENERATOR:STRING=Ninja
--DCMAKE_BUILD_TYPE:STRING=Debug
--DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
--DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
--DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
--DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
--DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
--DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
- 0
- C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Debug
-
-
-
-
- all
-
- false
-
- true
- 构建
- CMakeProjectManager.MakeStep
-
- 1
- 构建
- 构建
- ProjectExplorer.BuildSteps.Build
-
-
-
-
-
- clean
-
- false
-
- true
- 构建
- CMakeProjectManager.MakeStep
-
- 1
- 清除
- 清除
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- false
-
- Debug
- CMakeProjectManager.CMakeBuildConfiguration
-
-
- Release
- 2
- false
-
- -DCMAKE_GENERATOR:STRING=Ninja
--DCMAKE_BUILD_TYPE:STRING=Release
--DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
--DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
--DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
--DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
--DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
--DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
- C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Release
-
-
-
-
- all
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 构建
- 构建
- ProjectExplorer.BuildSteps.Build
-
-
-
-
-
- clean
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 清除
- 清除
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- false
-
- Release
- CMakeProjectManager.CMakeBuildConfiguration
-
-
- RelWithDebInfo
- 2
- false
-
- -DCMAKE_GENERATOR:STRING=Ninja
--DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
--DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
--DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
--DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
--DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
--DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
--DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
- C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-RelWithDebInfo
-
-
-
-
- all
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 构建
- 构建
- ProjectExplorer.BuildSteps.Build
-
-
-
-
-
- clean
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 清除
- 清除
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- false
-
- Release with Debug Information
- CMakeProjectManager.CMakeBuildConfiguration
-
-
- RelWithDebInfo
- 2
- false
-
- -DCMAKE_GENERATOR:STRING=Ninja
--DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
--DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
--DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
--DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
--DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
--DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
--DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
- 0
- C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Profile
-
-
-
-
- all
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 构建
- 构建
- ProjectExplorer.BuildSteps.Build
-
-
-
-
-
- clean
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 清除
- 清除
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- false
-
- Profile
- CMakeProjectManager.CMakeBuildConfiguration
-
-
- MinSizeRel
- 2
- false
-
- -DCMAKE_GENERATOR:STRING=Ninja
--DCMAKE_BUILD_TYPE:STRING=MinSizeRel
--DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
--DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
--DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
--DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
--DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
--DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
- C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-MinSizeRel
-
-
-
-
- all
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 构建
- 构建
- ProjectExplorer.BuildSteps.Build
-
-
-
-
-
- clean
-
- false
-
- true
- CMakeProjectManager.MakeStep
-
- 1
- 清除
- 清除
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- false
-
- Minimum Size Release
- CMakeProjectManager.CMakeBuildConfiguration
-
- 5
-
-
- 0
- 部署
- 部署
- ProjectExplorer.BuildSteps.Deploy
-
- 1
-
- false
- ProjectExplorer.DefaultDeployConfiguration
-
- 1
-
- true
- true
- 0
- true
-
- 2
-
- false
- -e cpu-cycles --call-graph "dwarf,4096" -F 250
-
- ProjectExplorer.CustomExecutableRunConfiguration
-
- false
- true
- true
-
- 1
-
-
-
- ProjectExplorer.Project.TargetCount
- 1
-
-
- ProjectExplorer.Project.Updater.FileVersion
- 22
-
-
- Version
- 22
-
-
diff --git a/ecurve.cpp b/ecurve.c
similarity index 100%
rename from ecurve.cpp
rename to ecurve.c
diff --git a/ecurve.h b/ecurve.h
index 42c286e..540bbc3 100644
--- a/ecurve.h
+++ b/ecurve.h
@@ -1,11 +1,9 @@
#ifndef __ECURVE_H__
#define __ECURVE_H__
-extern "C"
-{
+#include
#include "miracl.h"
#include "mirdef.h"
-}
typedef struct ecc_params
{
diff --git a/generator_cgo/.idea/.gitignore b/generator_cgo/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/generator_cgo/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/generator_cgo/.idea/.name b/generator_cgo/.idea/.name
deleted file mode 100644
index 30de634..0000000
--- a/generator_cgo/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-main.go
\ No newline at end of file
diff --git a/generator_cgo/.idea/cgo.iml b/generator_cgo/.idea/cgo.iml
deleted file mode 100644
index 5e764c4..0000000
--- a/generator_cgo/.idea/cgo.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/generator_cgo/.idea/modules.xml b/generator_cgo/.idea/modules.xml
deleted file mode 100644
index 5f95085..0000000
--- a/generator_cgo/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/generator_cgo/.vscode/tasks.json b/generator_cgo/.vscode/tasks.json
deleted file mode 100644
index 38de289..0000000
--- a/generator_cgo/.vscode/tasks.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "version": "2.0.0",
- "tasks": [
- {
- "type": "go",
- "label": "go: build package",
- "command": "build",
- "args": [
- "${fileDirname}"
- ],
- "problemMatcher": [
- "$go"
- ],
- "group": "build",
- "detail": "cd c:\\Users\\25761\\Desktop\\cgo; go build ${fileDirname}"
- }
- ]
-}
\ No newline at end of file
diff --git a/generator_cgo/go.mod b/generator_cgo/go.mod
deleted file mode 100644
index e26fe90..0000000
--- a/generator_cgo/go.mod
+++ /dev/null
@@ -1,3 +0,0 @@
-module example.com/m/v2
-
-go 1.20
diff --git a/generator_cgo/go.sum b/generator_cgo/go.sum
deleted file mode 100644
index e69de29..0000000
diff --git a/generator_cgo/include/big.h b/generator_cgo/include/big.h
deleted file mode 100644
index bbc2b25..0000000
--- a/generator_cgo/include/big.h
+++ /dev/null
@@ -1,451 +0,0 @@
-
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-/*
- *
- * MIRACL C++ Header file big.h
- *
- * AUTHOR : N.Coghlan
- * Modified by M.Scott
- *
- * PURPOSE : Definition of class Big
- *
- * Bigs are normally created on the heap, but by defining BIGS=m
- * on the compiler command line, Bigs are instead mostly created from the
- * stack. Note that m must be same or less than the n in the main program
- * with for example
- *
- * Miracl precison(n,0);
- *
- * where n is the (fixed) size in words of each Big.
- *
- * This may be faster, as C++ tends to create and destroy lots of
- * temporaries. Especially recommended if m is small. Do not use
- * for program development
- *
- * However Bigs created from a string are always allocated from the heap.
- * This is useful for creating large read-only constants which are larger
- * than m.
- *
- * NOTE:- I/O conversion
- *
- * To convert a hex character string to a Big
- *
- * Big x;
- * char c[100];
- *
- * mip->IOBASE=16;
- * x=c;
- *
- * To convert a Big to a hex character string
- *
- * mip->IOBASE=16;
- * c << x;
- *
- * To convert to/from pure binary, see the from_binary()
- * and to_binary() friend functions.
- *
- * int len;
- * char c[100];
- * ...
- * Big x=from_binary(len,c); // creates Big x from len bytes of binary in c
- *
- * len=to_binary(x,100,c,FALSE); // converts Big x to len bytes binary in c[100]
- * len=to_binary(x,100,c,TRUE); // converts Big x to len bytes binary in c[100]
- * // (right justified with leading zeros)
- */
-
-#ifndef BIG_H
-#define BIG_H
-
-#include
-//#include
-#include
-
-#include "mirdef.h"
-
-#ifdef MR_CPP
-#include "miracl.h"
-#else
-extern "C"
-{
- #include "miracl.h"
-}
-#endif
-
-#ifndef MR_NO_STANDARD_IO
-#include
-using std::istream;
-using std::ostream;
-#endif
-
-#ifndef MIRACL_CLASS
-#define MIRACL_CLASS
-
-#ifdef __cplusplus
-#ifdef MR_GENERIC_MT
-#error "The generic method isn't supported for C++, its C only"
-#endif
-#endif
-
-class Miracl
-{ /* dummy class to initialise MIRACL - MUST be called before any Bigs *
- * are created. This could be a problem for static/global data declared *
- * in modules other than the main module */
- miracl *mr;
-public:
- Miracl(int nd,mr_small nb=0)
- {mr=mirsys(nd,nb);
-#ifdef MR_FLASH
-mr->RPOINT=TRUE;
-#endif
-}
- miracl *operator&() {return mr;}
- ~Miracl() {mirexit();}
-};
-
-#endif
-
-/*
-#ifdef BIGS
-#define MR_INIT_BIG memset(mem,0,mr_big_reserve(1,BIGS)); fn=(big)mirvar_mem_variable(mem,0,BIGS);
-#else
-#define MR_INIT_BIG mem=(char *)memalloc(1); fn=(big)mirvar_mem(mem,0);
-#endif
-*/
-
-#ifdef BIGS
-#define MR_INIT_BIG fn=&b; b.w=a; b.len=0; for (int i=0;ilen=1; fn->w[0]=s; return *this;}
- Big& operator=(const Big& b) {copy(b.fn,fn); return *this;}
- Big& operator=(big& b) {copy(b,fn); return *this;}
- Big& operator=(big* b) {fn=*b; return *this;}
-#ifndef MR_SIMPLE_IO
-#ifdef MR_SIMPLE_BASE
- Big& operator=(char* s){instr(fn,s);return *this;}
-#else
- Big& operator=(char* s){cinstr(fn,s);return *this;}
-#endif
-#endif
- Big& operator++() {incr(fn,1,fn); return *this;}
- Big& operator--() {decr(fn,1,fn); return *this;}
- Big& operator+=(int i) {incr(fn,i,fn); return *this;}
- Big& operator+=(const Big& b){add(fn,b.fn,fn); return *this;}
-
- Big& operator-=(int i) {decr(fn,i,fn); return *this;}
- Big& operator-=(const Big& b) {subtract(fn,b.fn,fn); return *this;}
-
- Big& operator*=(int i) {premult(fn,i,fn); return *this;}
- Big& operator*=(const Big& b) {multiply(fn,b.fn,fn); return *this;}
-
- Big& operator/=(int i) {subdiv(fn,i,fn); return *this;}
- Big& operator/=(const Big& b) {divide(fn,b.fn,fn); return *this;}
-
- Big& operator%=(int i) {convert(subdiv(fn,i,fn),fn); return *this;}
- Big& operator%=(const Big& b) {divide(fn,b.fn,b.fn); return *this;}
-
- Big& operator<<=(int i) {sftbit(fn,i,fn); return *this;}
- Big& operator>>=(int i) {sftbit(fn,-i,fn); return *this;}
-
- Big& shift(int n) {mr_shift(fn,n,fn); return *this;}
-
- mr_small& operator[](int i) {return fn->w[i];}
-
- void negate() const;
- BOOL iszero() const;
- BOOL isone() const;
- int get(int index) { int m; m=getdig(fn,index); return m; }
- void set(int index,int n) { putdig(n,fn,index);}
- int len() const;
-
- big getbig() const;
-
- friend class Flash;
-
- friend Big operator-(const Big&);
-
- friend Big operator+(const Big&,int);
- friend Big operator+(int,const Big&);
- friend Big operator+(const Big&,const Big&);
-
- friend Big operator-(const Big&, int);
- friend Big operator-(int,const Big&);
- friend Big operator-(const Big&,const Big&);
-
- friend Big operator*(const Big&, int);
- friend Big operator*(int,const Big&);
- friend Big operator*(const Big&,const Big&);
-
- friend BOOL fmth(int n,const Big&,const Big&,Big&); // fast mult - top half
-
- friend Big operator/(const Big&,int);
- friend Big operator/(const Big&,const Big&);
-
- friend int operator%(const Big&, int);
- friend Big operator%(const Big&, const Big&);
-
- friend Big operator<<(const Big&, int);
- friend Big operator>>(const Big&, int);
-
- friend BOOL operator<=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)<=0) return TRUE; else return FALSE;}
- friend BOOL operator>=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)>=0) return TRUE; else return FALSE;}
- friend BOOL operator==(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
- friend BOOL operator<(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)<0) return TRUE; else return FALSE;}
- friend BOOL operator>(const Big& b1,const Big& b2)
- {if (mr_compare(b1.fn,b2.fn)>0) return TRUE; else return FALSE;}
-
- friend Big from_binary(int,char *);
-
- friend int to_binary(const Big& b,int max,char *ptr,BOOL justify=FALSE)
- {
- return big_to_bytes(max,b.fn,ptr,justify);
- }
- //friend int to_binary(const Big&,int,char *,BOOL justify=FALSE);
- friend Big modmult(const Big&,const Big&,const Big&);
- friend Big mad(const Big&,const Big&,const Big&,const Big&,Big&);
- friend Big norm(const Big&);
- friend Big sqrt(const Big&);
- friend Big root(const Big&,int);
- friend Big gcd(const Big&,const Big&);
- friend void set_zzn3(int cnr,Big& sru) {get_mip()->cnr=cnr; nres(sru.fn,get_mip()->sru);}
- friend int recode(const Big& e,int t,int w,int i) {return recode(e.fn,t,w,i);}
-
-#ifndef MR_FP
- friend Big land(const Big&,const Big&); // logical AND
- friend Big lxor(const Big&,const Big&); // logical XOR
-#endif
- friend Big pow(const Big&,int); // x^m
- friend Big pow(const Big&, int, const Big&); // x^m mod n
- friend Big pow(int, const Big&, const Big&); // x^m mod n
- friend Big pow(const Big&, const Big&, const Big&); // x^m mod n
- friend Big pow(const Big&, const Big&, const Big&, const Big&, const Big&);
- // x^m.y^k mod n
- friend Big pow(int,Big *,Big *,Big); // x[0]^m[0].x[1].m[1]... mod n
-
- friend Big luc(const Big& b1,const Big& b2, const Big& b3, Big *b4=NULL)
- {
- Big z; if (b4!=NULL) lucas(b1.fn,b2.fn,b3.fn,b4->fn,z.fn);
- else lucas(b1.fn,b2.fn,b3.fn,z.fn,z.fn);
- return z;
- }
- //friend Big luc(const Big& ,const Big&, const Big&, Big *b4=NULL);
- friend Big moddiv(const Big&,const Big&,const Big&);
- friend Big inverse(const Big&, const Big&);
- friend void multi_inverse(int,Big*,const Big&,Big *);
-#ifndef MR_NO_RAND
- friend Big rand(const Big&); // 0 < rand < parameter
- friend Big rand(int,int); // (digits,base) e.g. (32,16)
- friend Big randbits(int); // n random bits
- friend Big strong_rand(csprng *,const Big&);
- friend Big strong_rand(csprng *,int,int);
-#endif
- friend Big abs(const Big&);
-// This next only works if MIRACL is using a binary base...
- friend int bit(const Big& b,int i) {return mr_testbit(b.fn,i);}
- friend int bits(const Big& b) {return logb2(b.fn);}
- friend int ham(const Big& b) {return hamming(b.fn);}
- friend int jacobi(const Big& b1,const Big& b2) {return jack(b1.fn,b2.fn);}
- friend int toint(const Big& b) {return size(b.fn);}
- friend BOOL prime(const Big& b) {return isprime(b.fn);}
- friend Big nextprime(const Big&);
- friend Big nextsafeprime(int type,int subset,const Big&);
- friend Big trial_divide(const Big& b);
- friend BOOL small_factors(const Big& b);
- friend BOOL perfect_power(const Big& b);
- friend Big sqrt(const Big&,const Big&);
-
- friend void ecurve(const Big&,const Big&,const Big&,int);
- friend BOOL ecurve2(int,int,int,int,const Big&,const Big&,BOOL,int);
- friend BOOL is_on_curve(const Big&);
- friend void modulo(const Big&);
- friend BOOL modulo(int,int,int,int,BOOL);
- friend Big get_modulus(void);
- friend int window(const Big& x,int i,int* nbs,int *nzs,int window_size=5)
- {
- return mr_window(x.fn,i,nbs,nzs,window_size);
- }
-
-
- //friend int window(const Big&,int,int*,int*,int window_size=5);
- friend int naf_window(const Big& x,const Big& x3,int i,int* nbs,int* nzs,int store=11)
- {
- return mr_naf_window(x.fn,x3.fn,i,nbs,nzs,store);
- }
-
-
- //friend int naf_window(const Big&,const Big&,int,int*,int*,int store=11);
- friend void jsf(const Big&,const Big&,Big&,Big&,Big&,Big&);
-
-/* Montgomery stuff */
-
- friend Big nres(const Big&);
- friend Big redc(const Big&);
-/*
- friend Big nres_negate(const Big&);
- friend Big nres_modmult(const Big&,const Big&);
- friend Big nres_premult(const Big&,int);
- friend Big nres_pow(const Big&,const Big&);
- friend Big nres_pow2(const Big&,const Big&,const Big&,const Big&);
- friend Big nres_pown(int,Big *,Big *);
- friend Big nres_luc(const Big&,const Big&,Big *b3=NULL);
- friend Big nres_sqrt(const Big&);
- friend Big nres_modadd(const Big&,const Big&);
- friend Big nres_modsub(const Big&,const Big&);
- friend Big nres_moddiv(const Big&,const Big&);
-*/
-/* these are faster.... */
-/*
- friend void nres_modmult(Big& a,const Big& b,Big& c)
- {nres_modmult(a.fn,b.fn,c.fn);}
- friend void nres_modadd(Big& a,const Big& b,Big& c)
- {nres_modadd(a.fn,b.fn,c.fn);}
- friend void nres_modsub(Big& a,const Big& b,Big& c)
- {nres_modsub(a.fn,b.fn,c.fn);}
- friend void nres_negate(Big& a,Big& b)
- {nres_negate(a.fn,b.fn);}
- friend void nres_premult(Big& a,int b,Big& c)
- {nres_premult(a.fn,b,c.fn);}
- friend void nres_moddiv(Big & a,const Big& b,Big& c)
- {nres_moddiv(a.fn,b.fn,c.fn);}
-*/
- friend Big shift(const Big&b,int n);
- friend int length(const Big&b);
-
-
-/* Note that when inputting text as a number the CR is NOT *
- * included in the text, unlike C I/O which does include CR. */
-
-#ifndef MR_NO_STANDARD_IO
-
- friend istream& operator>>(istream&, Big&);
- friend ostream& operator<<(ostream&, const Big&);
- friend ostream& otfloat(ostream&,const Big&,int);
-
-#endif
-
-// output Big to a String
- friend char * operator<<(char * s,const Big&);
-
- ~Big() {
- // zero(fn);
-#ifndef BIGS
- mr_free(fn);
-#endif
- }
-};
-
-extern BOOL modulo(int,int,int,int,BOOL);
-extern Big get_modulus(void);
-extern Big rand(int,int);
-extern Big strong_rand(csprng *,int,int);
-extern Big from_binary(int,char *);
-//extern int to_binary(const Big&,int,char *,BOOL);
-
-using namespace std;
-
-#endif
-
diff --git a/generator_cgo/include/brick.h b/generator_cgo/include/brick.h
deleted file mode 100644
index bf06b4b..0000000
--- a/generator_cgo/include/brick.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * MIRACL C++ Header file brick.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class Brick
- * Comb method for fast exponentiation with
- * precomputation
- * NOTE : Must be used in conjunction with big.cpp
- *
- */
-
-#ifndef BRICK_H
-#define BRICK_H
-
-#include "big.h"
-
-class Brick
-{
- BOOL created;
- brick b;
-public:
- Brick(Big g,Big n,int window,int nb)
- {brick_init(&b,g.getbig(),n.getbig(),window,nb); created=TRUE;}
-
- Brick(brick *bb) { b=*bb; created=FALSE; }
-
- brick *get(void) {return &b;}
-
- Big pow(Big &e) {Big w; pow_brick(&b,e.getbig(),w.getbig()); return w;}
-
- ~Brick() {if (created) brick_end(&b);}
-};
-
-#endif
-
diff --git a/generator_cgo/include/crt.h b/generator_cgo/include/crt.h
deleted file mode 100644
index 65e7ea2..0000000
--- a/generator_cgo/include/crt.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * MIRACL C++ Header file crt.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class Crt (Chinese Remainder Thereom)
- * NOTE : Must be used in conjunction with big.cpp
- * Can be used with either Big or utype moduli
- */
-
-#ifndef CRT_H
-#define CRT_H
-
-#include "big.h"
-
-#define MR_CRT_BIG 0
-#define MR_CRT_SMALL 1
-
-class Crt
-{
- big_chinese bc;
- small_chinese sc;
- int type;
-public:
- Crt(int,Big *);
- Crt(int,mr_utype *);
-
- Big eval(Big *);
- Big eval(mr_utype *);
-
- ~Crt()
- { /* destructor */
- if (type==MR_CRT_BIG) crt_end(&bc);
- if (type==MR_CRT_SMALL) scrt_end(&sc);
- }
-};
-
-#endif
-
diff --git a/generator_cgo/include/ebrick.h b/generator_cgo/include/ebrick.h
deleted file mode 100644
index f87effd..0000000
--- a/generator_cgo/include/ebrick.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * MIRACL C++ Header file ebrick.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class EBrick
- * Brickell et al's method for fast exponentiation with
- * precomputation - elliptic curve version GF(p)
- * NOTE : Must be used in conjunction with big.cpp
- *
- */
-
-#ifndef EBRICK_H
-#define EBRICK_H
-
-#include "big.h"
-
-class EBrick
-{
- BOOL created;
- ebrick B;
-public:
- EBrick(Big x,Big y,Big a,Big b,Big n,int window,int nb)
- {ebrick_init(&B,x.getbig(),y.getbig(),a.getbig(),b.getbig(),n.getbig(),window,nb);
- created=TRUE;}
-
- EBrick(ebrick *b) {B=*b; created=FALSE;} /* set structure */
-
- ebrick *get(void) {return &B;} /* get address of structure */
-
- int mul(Big &e,Big &x,Big &y) {int d=mul_brick(&B,e.getbig(),x.getbig(),y.getbig()); return d;}
-
- ~EBrick() {if (created) ebrick_end(&B);}
-};
-
-#endif
-
diff --git a/generator_cgo/include/ebrick2.h b/generator_cgo/include/ebrick2.h
deleted file mode 100644
index 1bd6b6a..0000000
--- a/generator_cgo/include/ebrick2.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * MIRACL C++ Header file ebrick2.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class EBrick2
- * Brickell et al's method for fast exponentiation with
- * precomputation - elliptic curve version GF(2^m)
- * NOTE : Must be used in conjunction with big.cpp
- */
-
-#ifndef EBRICK2_H
-#define EBRICK2_H
-
-#include "big.h"
-
-class EBrick2
-{
- BOOL created;
- ebrick2 B;
-public:
- EBrick2(Big x,Big y,Big a2,Big a6,int m,int a,int b,int c,int window,int nb)
- {ebrick2_init(&B,x.getbig(),y.getbig(),a2.getbig(),a6.getbig(),m,a,b,c,window,nb);
- created=TRUE;}
-
- EBrick2(ebrick2 *b) {B=*b; created=FALSE;} /* set structure */
-
- ebrick2 *get(void) {return &B;} /* get address of structure */
-
- int mul(Big &e,Big &x,Big &y) {int d=mul2_brick(&B,e.getbig(),x.getbig(),y.getbig()); return d;}
-
- ~EBrick2() {if (created) ebrick2_end(&B);}
-};
-
-#endif
-
diff --git a/generator_cgo/include/ec2.h b/generator_cgo/include/ec2.h
deleted file mode 100644
index 32f6a83..0000000
--- a/generator_cgo/include/ec2.h
+++ /dev/null
@@ -1,146 +0,0 @@
-
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-/*
- * MIRACL C++ Header file ec2.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class EC2 (Arithmetic on an Elliptic Curve,
- * over GF(2^m)
- *
- * NOTE : Must be used in conjunction with ec2.cpp and big.cpp
- * The active curve is set dynamically (via the Big ecurve2()
- * routine) - so beware the pitfalls implicit in declaring
- * static or global EC2's (which are initialised before the
- * curve is set!). Uninitialised data is OK
- */
-
-#ifndef EC2_H
-#define EC2_H
-
-#include
-#include "big.h"
-
-#ifdef GF2MS
-#define MR_INIT_EC2 memset(mem,0,mr_ecp_reserve(1,GF2MS)); p=(epoint *)epoint_init_mem_variable(mem,0,GF2MS);
-#else
-#define MR_INIT_EC2 mem=(char *)ecp_memalloc(1); p=(epoint *)epoint_init_mem(mem,0);
-#endif
-
-class EC2
-{
- epoint *p;
-#ifdef GF2MS
- char mem[mr_ecp_reserve(1,GF2MS)];
-#else
- char *mem;
-#endif
-
-public:
- EC2() { MR_INIT_EC2}
-
- EC2(const Big &x,const Big& y) {MR_INIT_EC2
- epoint2_set(x.getbig(),y.getbig(),0,p); }
-
- // This next constructor restores a point on the curve from "compressed"
- // data, that is the full x co-ordinate, and the LSB of y/x (0 or 1)
-
- EC2(const Big& x,int cb) {MR_INIT_EC2
- epoint2_set(x.getbig(),x.getbig(),cb,p); }
-
- EC2(const EC2 &b) {MR_INIT_EC2 epoint2_copy(b.p,p);}
-
- epoint *get_point() const;
-
- EC2& operator=(const EC2& b) {epoint2_copy(b.p,p);return *this;}
-
- EC2& operator+=(const EC2& b) {ecurve2_add(b.p,p); return *this;}
- EC2& operator-=(const EC2& b) {ecurve2_sub(b.p,p); return *this;}
-
- // Multiplication of a point by an integer.
-
- EC2& operator*=(const Big& k) {ecurve2_mult(k.getbig(),p,p); return *this;}
- big add(const EC2& b) {return ecurve2_add(b.p,p); }
- // returns line slope as a big
- big sub(const EC2& b) {return ecurve2_sub(b.p,p); }
-
- void clear() {epoint2_set(NULL,NULL,0,p);}
- BOOL set(const Big& x,const Big& y) {return epoint2_set(x.getbig(),y.getbig(),0,p);}
- int get(Big& x,Big& y) const;
- BOOL iszero() const;
- // This gets the point in compressed form. Return value is LSB of y-coordinate
- int get(Big& x) const;
-
- void getx(Big &x) const;
- void getxy(Big &x,Big& y) const;
- void getxyz(Big &x,Big &y,Big& z) const;
-
- // point compression
-
- // This sets the point from compressed form. cb is LSB of y/x
-
- BOOL set(const Big& x,int cb=0) {return epoint2_set(x.getbig(),x.getbig(),cb,p);}
-
- friend EC2 operator-(const EC2&);
- friend void multi_add(int,EC2 *,EC2 *);
-
- friend EC2 mul(const Big&, const EC2&, const Big&, const EC2&);
- friend EC2 mul(int, const Big *, EC2 *);
-
- friend void normalise(EC2 &e) {epoint2_norm(e.p);}
-
- friend BOOL operator==(const EC2& a,const EC2& b)
- {return epoint2_comp(a.p,b.p);}
- friend BOOL operator!=(const EC2& a,const EC2& b)
- {return (!epoint2_comp(a.p,b.p));}
-
- friend EC2 operator*(const Big &,const EC2&);
-
-#ifndef MR_NO_STANDARD_IO
-
- friend ostream& operator<<(ostream&,const EC2&);
-
-#endif
-
- ~EC2()
- {
-#ifndef GF2MS
- mr_free(mem);
-#endif
- }
-};
-
-#endif
-
diff --git a/generator_cgo/include/ecn.h b/generator_cgo/include/ecn.h
deleted file mode 100644
index df2f3b0..0000000
--- a/generator_cgo/include/ecn.h
+++ /dev/null
@@ -1,159 +0,0 @@
-
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-/*
- *
- * MIRACL C++ Header file ecn.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class ECn (Arithmetic on an Elliptic Curve,
- * mod n)
- *
- * NOTE : Must be used in conjunction with ecn.cpp and big.cpp
- * The active curve is set dynamically (via the Big ecurve()
- * routine) - so beware the pitfalls implicit in declaring
- * static or global ECn's (which are initialised before the
- * curve is set!). Uninitialised data is OK
- *
- */
-
-#ifndef ECN_H
-#define ECN_H
-
-#include
-#include "big.h"
-
-#ifdef ZZNS
-#define MR_INIT_ECN memset(mem,0,mr_ecp_reserve(1,ZZNS)); p=(epoint *)epoint_init_mem_variable(mem,0,ZZNS);
-#else
-#define MR_INIT_ECN mem=(char *)ecp_memalloc(1); p=(epoint *)epoint_init_mem(mem,0);
-#endif
-
-class ECn
-{
- epoint *p;
-#ifdef ZZNS
- char mem[mr_ecp_reserve(1,ZZNS)];
-#else
- char *mem;
-#endif
-public:
- ECn() {MR_INIT_ECN }
-
- ECn(const Big &x,const Big& y) {MR_INIT_ECN
- epoint_set(x.getbig(),y.getbig(),0,p); }
-
- // This next constructor restores a point on the curve from "compressed"
- // data, that is the full x co-ordinate, and the LSB of y (0 or 1)
-
-#ifndef MR_SUPPORT_COMPRESSION
- ECn(const Big& x,int cb) {MR_INIT_ECN
- epoint_set(x.getbig(),x.getbig(),cb,p); }
-#endif
-
- ECn(const ECn &b) {MR_INIT_ECN epoint_copy(b.p,p);}
-
- epoint *get_point() const;
- int get_status() {return p->marker;}
- ECn& operator=(const ECn& b) {epoint_copy(b.p,p);return *this;}
-
- ECn& operator+=(const ECn& b) {ecurve_add(b.p,p); return *this;}
-
- int add(const ECn&,big *,big *ex1=NULL,big *ex2=NULL) const;
- // returns line slope as a big
- int sub(const ECn&,big *,big *ex1=NULL,big *ex2=NULL) const;
-
- ECn& operator-=(const ECn& b) {ecurve_sub(b.p,p); return *this;}
-
- // Multiplication of a point by an integer.
-
- ECn& operator*=(const Big& k) {ecurve_mult(k.getbig(),p,p); return *this;}
-
- void clear() {epoint_set(NULL,NULL,0,p);}
- BOOL set(const Big& x,const Big& y) {return epoint_set(x.getbig(),y.getbig(),0,p);}
-#ifndef MR_AFFINE_ONLY
-// use with care if at all
- void setz(const Big& z) {nres(z.getbig(),p->Z); p->marker=MR_EPOINT_GENERAL;}
-#endif
- BOOL iszero() const;
- int get(Big& x,Big& y) const;
-
- // This gets the point in compressed form. Return value is LSB of y-coordinate
- int get(Big& x) const;
-
- // get raw coordinates
- void getx(Big &x) const;
- void getxy(Big &x,Big &y) const;
- void getxyz(Big &x,Big &y,Big &z) const;
-
- // point compression
-
- // This sets the point from compressed form. cb is LSB of y coordinate
-#ifndef MR_SUPPORT_COMPRESSION
- BOOL set(const Big& x,int cb=0) {return epoint_set(x.getbig(),x.getbig(),cb,p);}
-#endif
- friend ECn operator-(const ECn&);
- friend void multi_add(int,ECn *,ECn *);
- friend void double_add(ECn&,ECn&,ECn&,ECn&,big&,big&);
-
- friend ECn mul(const Big&, const ECn&, const Big&, const ECn&);
- friend ECn mul(int, const Big *, ECn *);
-
- friend void normalise(ECn &e) {epoint_norm(e.p);}
- friend void multi_norm(int,ECn *);
-
- friend BOOL operator==(const ECn& a,const ECn& b)
- {return epoint_comp(a.p,b.p);}
- friend BOOL operator!=(const ECn& a,const ECn& b)
- {return (!epoint_comp(a.p,b.p));}
-
- friend ECn operator*(const Big &,const ECn&);
-
-#ifndef MR_NO_STANDARD_IO
-
- friend ostream& operator<<(ostream&,const ECn&);
-
-#endif
-
- ~ECn() {
-#ifndef ZZNS
- mr_free(mem);
-#endif
- }
-
-};
-
-#endif
-
diff --git a/generator_cgo/include/ecnzzn.h b/generator_cgo/include/ecnzzn.h
deleted file mode 100644
index 4f7a028..0000000
--- a/generator_cgo/include/ecnzzn.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// Utility functions to force an ECn to be created from 2 or 3 ZZn
-// And to extract an ECn into ZZns
-//
-
-#ifndef ECNZZN_H
-#define ECNZZN_H
-
-#include "zzn.h"
-#include "ecn.h"
-
-#ifndef MR_AFFINE_ONLY
-
-extern void force(ZZn&,ZZn&,ZZn&,ECn&);
-extern void extract(ECn&,ZZn&,ZZn&,ZZn&);
-
-#endif
-
-extern void force(ZZn&,ZZn&,ECn&);
-extern void extract(ECn&,ZZn&,ZZn&);
-
-#endif
diff --git a/generator_cgo/include/ecurve.cpp b/generator_cgo/include/ecurve.cpp
deleted file mode 100644
index 5f3b5c6..0000000
--- a/generator_cgo/include/ecurve.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#include "ecurve.h"
-#include
-
-// 使用的椭圆曲线(SECP256K1)公开参数
-char Q[] = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"; // 有限域的模q
-char A[] = "0000000000000000000000000000000000000000000000000000000000000000"; // 曲线方程系数a
-char B[] = "0000000000000000000000000000000000000000000000000000000000000007"; // 曲线方程系数b
-char X[] = "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"; // 基点P的x坐标
-char Y[] = "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"; // 基点P的y坐标
-char P_N[] = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"; // 基点P的阶:令nP=O的最小整数
-
-bool setupEcurve(ECC_PARAMS *params)
-{
- // 初始化变量
- (*params).a = mirvar(0);
- (*params).b = mirvar(0);
- (*params).q = mirvar(0);
- (*params).p = mirvar(0);
- (*params).P_x = mirvar(0);
- (*params).P_y = mirvar(0);
- (*params).P = epoint_init();
-
- // 赋值
- cinstr((*params).a, A);
- cinstr((*params).b, B);
- cinstr((*params).q, Q);
- cinstr((*params).p, P_N);
-
- cinstr((*params).P_x, X);
- cinstr((*params).P_y, Y);
-
- // 椭圆曲线方程初始化
- ecurve_init((*params).a, (*params).b, (*params).q, MR_PROJECTIVE);
-
- // 设置点坐标(P_x,P_y)为点P,此函数同时能判断P是否在上面初始化成功的椭圆曲线上
- if (!epoint_set((*params).P_x, (*params).P_y, 0, (*params).P))
- {
- freeEcurve(params);
- return false;
- }
-
- // 判断P是否是阶为p的基点,判断依据:基点乘以阶为无穷远点
- bool bRv = false;
- epoint *P_test = epoint_init();
- ecurve_mult((*params).p, (*params).P, P_test);
- if (point_at_infinity(P_test))
- {
- bRv = true;
- }
- else
- {
- freeEcurve(params);
- bRv = false;
- }
- epoint_free(P_test);
-
- return bRv;
-}
-
-void freeEcurve(ECC_PARAMS *params)
-{
- mirkill((*params).a);
- mirkill((*params).b);
- mirkill((*params).q);
- mirkill((*params).p);
- mirkill((*params).P_x);
- mirkill((*params).P_y);
-
- epoint_free((*params).P);
-}
\ No newline at end of file
diff --git a/generator_cgo/include/ecurve.h b/generator_cgo/include/ecurve.h
deleted file mode 100644
index 76e754c..0000000
--- a/generator_cgo/include/ecurve.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __ECURVE_H__
-#define __ECURVE_H__
-
-#include "miracl.h"
-#include "mirdef.h"
-#include
-
-typedef struct ecc_params
-{
- big a; // 椭圆曲线方程系数a
- big b; // 椭圆曲线方程系数b
- big q; // 模
- big p; // 阶
- big P_x; // 基点横坐标
- big P_y; // 基点纵坐标
- epoint *P; // 基点
-} ECC_PARAMS;
-
-bool setupEcurve(ECC_PARAMS *params);
-
-void freeEcurve(ECC_PARAMS *params);
-
-#endif // ecurve.h
\ No newline at end of file
diff --git a/generator_cgo/include/flash.h b/generator_cgo/include/flash.h
deleted file mode 100644
index bac7750..0000000
--- a/generator_cgo/include/flash.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * MIRACL C++ Header file flash.h
- *
- * AUTHOR : N.Coghlan
- * Modified by M.Scott
- *
- * PURPOSE : Definition of class Flash
- *
- */
-
-#ifndef FLASH_H
-#define FLASH_H
-
-#include "big.h"
-
-#ifdef MR_FLASH
-
-#ifdef BIGS
-#define MR_FINIT_BIG fn=&b; b.w=a; b.len=0; for (int i=0;i=(const Flash& f1, const Flash& f2)
- {if (fcomp(f1.fn,f2.fn) >= 0) return TRUE; else return FALSE;}
- friend BOOL operator==(const Flash& f1, const Flash& f2)
- {if (fcomp(f1.fn,f2.fn) == 0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const Flash& f1, const Flash& f2)
- {if (fcomp(f1.fn,f2.fn) != 0) return TRUE; else return FALSE;}
- friend BOOL operator<(const Flash& f1, const Flash& f2)
- {if (fcomp(f1.fn,f2.fn) < 0) return TRUE; else return FALSE;}
- friend BOOL operator>(const Flash& f1, const Flash& f2)
- {if (fcomp(f1.fn,f2.fn) > 0) return TRUE; else return FALSE;}
-
- friend Flash inverse(const Flash&);
- friend Flash pi(void);
- friend Flash cos(const Flash&);
- friend Flash sin(const Flash&);
- friend Flash tan(const Flash&);
-
- friend Flash acos(const Flash&);
- friend Flash asin(const Flash&);
- friend Flash atan(const Flash&);
-
- friend Flash cosh(const Flash&);
- friend Flash sinh(const Flash&);
- friend Flash tanh(const Flash&);
-
- friend Flash acosh(const Flash&);
- friend Flash asinh(const Flash&);
- friend Flash atanh(const Flash&);
-
- friend Flash log(const Flash&);
- friend Flash exp(const Flash&);
- friend Flash pow(const Flash&,const Flash&);
- friend Flash sqrt(const Flash&);
- friend Flash nroot(const Flash&,int);
- friend Flash fabs(const Flash&);
-
- friend double todouble(const Flash& f) { return fdsize(f.fn);}
-
-#ifndef MR_NO_STANDARD_IO
-
- friend istream& operator>>(istream&, Flash&);
- friend ostream& operator<<(ostream&, const Flash&);
-
-#endif
-
-
-#ifdef BIGS
- ~Flash() { }
-#else
- ~Flash() {mirkill(fn);}
-#endif
-};
-
-extern Flash pi(void);
-
-#endif
-#endif
-
diff --git a/generator_cgo/include/floating.h b/generator_cgo/include/floating.h
deleted file mode 100644
index 5ab7c5f..0000000
--- a/generator_cgo/include/floating.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * MIRACL C++ Header file float.h
- *
- * AUTHOR : M.Scott
- *
- * PURPOSE : Definition of class Float
- *
- */
-
-#ifndef FLOAT_H
-#define FLOAT_H
-
-#include
-#include "big.h"
-
-extern void setprecision(int);
-
-class Float
-{
- int e; // exponent
- Big m; // mantissa
-public:
- Float() { }
- Float(int i) {m=i; e=1;}
- Float(const Float& f) {e=f.e; m=f.m; }
- Float(const Big &b) {m=b; e=length(b);}
- Float(const Big &b,int ex) {m=b; e=ex;}
- Float(double);
-
- Big trunc(Float *rem=NULL);
- void negate() const;
- BOOL iszero() const;
- BOOL isone() const;
- int sign() const;
- Float& operator=(double);
- BOOL add(const Float&);
- Float& operator+=(const Float&);
- BOOL sub(const Float&);
- Float& operator-=(const Float&);
- Float& operator*=(const Float&);
- Float& operator*=(int);
- Float& operator/=(const Float&);
- Float& operator/=(int);
- Float& operator=(const Float&);
-
- friend Float reciprocal(const Float&);
- friend double todouble(const Float&);
- friend Float makefloat(int,int);
- friend Float operator-(const Float&);
- friend Float operator+(const Float&,const Float&);
- friend Float operator-(const Float&,const Float&);
- friend Float operator*(const Float&,const Float&);
- friend Float operator*(const Float&,int);
- friend Float operator*(int,const Float&);
- friend Float operator/(const Float&,const Float&);
- friend Float operator/(const Float&,int);
- friend Float sqrt(const Float&);
- friend Float nroot(const Float&,int);
- friend Float exp(const Float&);
- friend Float sin(const Float&);
- friend Float cos(const Float&);
- friend Float pow(const Float&,int);
- friend Float fpi(void);
-
- friend Big trunc(const Float&);
- friend int norm(int,Float&);
- friend Float fabs(const Float&);
-
- /* relational ops */
- friend int fcomp(const Float&,const Float&);
-
- friend BOOL operator<=(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) <= 0) return TRUE; else return FALSE;}
- friend BOOL operator>=(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) >= 0) return TRUE; else return FALSE;}
- friend BOOL operator==(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) == 0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) != 0) return TRUE; else return FALSE;}
- friend BOOL operator<(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) < 0) return TRUE; else return FALSE;}
- friend BOOL operator>(const Float& f1, const Float& f2)
- {if (fcomp(f1,f2) > 0) return TRUE; else return FALSE;}
-
- friend ostream& operator<<(ostream&,const Float&);
-
- ~Float() { }
-};
-
-extern Float fpi(void);
-extern Float makefloat(int,int);
-
-#endif
-
diff --git a/generator_cgo/include/gf2m.h b/generator_cgo/include/gf2m.h
deleted file mode 100644
index cd95f65..0000000
--- a/generator_cgo/include/gf2m.h
+++ /dev/null
@@ -1,171 +0,0 @@
-
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-/*
- * MIRACL C++ Header file gf2m.h
- *
- * AUTHOR : M.Scott
- *
- * PURPOSE : Definition of class GF2m (Arithmetic in the field GF(2^m)
- *
- * NOTE: : The field basis is set dynamically via the modulo() routine.
- * Must be used with big.h and big.cpp
- */
-
-#ifndef GF2M_H
-#define GF2M_H
-
-#include "big.h"
-
-/*
-#ifdef GF2MS
-#define MR_INIT_GF2M memset(mem,0,mr_big_reserve(1,GF2MS)); fn=(big)mirvar_mem_variable(mem,0,GF2MS);
-#define MR_CLONE_GF2M(x) fn->len=x->len; for (int i=0;iw[i]=x->w[i];
-#define MR_ZERO_GF2M {fn->len=0; for (int i=0;iw[i]=0;}
-#else
-#define MR_INIT_GF2M mem=(char *)memalloc(1); fn=(big)mirvar_mem(mem,0);
-#define MR_CLONE_GF2M(x) copy(x,fn);
-#define MR_ZERO_GF2M zero(fn);
-#endif
-*/
-
-
-#ifdef GF2MS
-#define MR_INIT_GF2M fn=&b; b.w=a; b.len=GF2MS;
-#define MR_CLONE_GF2M(x) b.len=x->len; for (int i=0;iw[i];
-#define MR_ZERO_GF2M {b.len=0; for (int i=0;i GF2m */
- GF2m(big& c) {MR_INIT_GF2M MR_CLONE_GF2M(c)}
- GF2m(const GF2m& c) {MR_INIT_GF2M MR_CLONE_GF2M(c.fn)}
- GF2m(char *s) {MR_INIT_GF2M cinstr(fn,s); reduce2(fn,fn);}
-
- GF2m& operator=(const GF2m& c) {MR_CLONE_GF2M(c.fn) return *this;}
- GF2m& operator=(big c) {MR_CLONE_GF2M(c) return *this;}
-
- GF2m& operator=(int i) {if (i==0) MR_ZERO_GF2M else {convert(i,fn); reduce2(fn,fn);} return *this;}
- GF2m& operator=(const Big& b) { reduce2(b.getbig(),fn); return *this; }
- GF2m& operator=(char *s) { cinstr(fn,s); reduce2(fn,fn); return *this;}
- GF2m& operator++() {incr2(fn,1,fn); return *this; }
-
- GF2m& operator+=(const GF2m& c)
- {
-#ifdef GF2MS
- for (int i=0;iw[i]^=c.fn->w[i];
- fn->len=GF2MS;
- if (fn->w[GF2MS-1]==0) mr_lzero(fn);
-#else
- add2(fn,c.fn,fn);
-#endif
- return *this;
- }
-
- GF2m& operator+=(int i) {incr2(fn,i,fn); return *this; }
- GF2m& operator*=(const GF2m& b) {modmult2(fn,b.fn,fn); return *this;}
- GF2m& square() {modsquare2(fn,fn); return *this;}
- GF2m& inverse() {inverse2(fn,fn); return *this;}
- BOOL quadratic(GF2m& b) {return quad2(fn,b.fn);}
- int degree() {return degree2(fn);}
-
- BOOL iszero() const;
- BOOL isone() const;
- operator Big() {return (Big)fn;} /* GF2m -> Big */
- friend big getbig(GF2m& z) {return z.fn;}
- friend int trace(GF2m & z) {return trace2(z.fn);}
-
- GF2m& operator/=(const GF2m&);
-
- friend GF2m operator+(const GF2m&,const GF2m&);
- friend GF2m operator+(const GF2m&,int);
- friend GF2m operator*(const GF2m&,const GF2m&);
- friend GF2m operator/(const GF2m&,const GF2m&);
-
- friend BOOL operator==(const GF2m& b1,const GF2m& b2)
- { if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const GF2m& b1,const GF2m& b2)
- { if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
-
- friend GF2m square(const GF2m&);
- friend GF2m inverse(const GF2m&);
- friend GF2m pow(const GF2m&,int);
- friend GF2m sqrt(const GF2m&);
- friend GF2m halftrace(const GF2m&);
- friend GF2m quad(const GF2m&);
-#ifndef MR_NO_RAND
- friend GF2m random2(void);
-#endif
- friend GF2m gcd(const GF2m&,const GF2m&);
-
- friend void kar2x2(const GF2m*,const GF2m*,GF2m*);
- friend void kar3x3(const GF2m*,const GF2m*,GF2m*);
-
- friend int degree(const GF2m& x) {return degree2(x.fn);}
-
- ~GF2m()
- {
- // zero(fn);
-#ifndef GF2MS
- mr_free(fn);
-#endif
- }
-};
-#ifndef MR_NO_RAND
-extern GF2m random2(void);
-#endif
-#endif
diff --git a/generator_cgo/include/hash.h b/generator_cgo/include/hash.h
deleted file mode 100644
index 5f96cab..0000000
--- a/generator_cgo/include/hash.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef __HASH_H__
-#define __HASH_H__
-
-#include "miracl.h"
-#include "mirdef.h"
-
-//hash1(ID, Q, PK_pub, h_1_big)
-void hash1(char *ID, epoint *Q, epoint *PK_pub, big p, big h_1_big);
-
-//hash2(ID, X, h_2_big)
-void hash2(char *ID, epoint *X, big p, big h_2_big);
-
-//hash3(ID, msg, Q, U, PK_pub, h_3_big)
-void hash3(
- char *ID,
- char *msg,
- epoint *Q,
- epoint *U,
- epoint *PK_pub,
- big p,
- big h_3_big
-);
-
-#endif
\ No newline at end of file
diff --git a/generator_cgo/include/kgc.h b/generator_cgo/include/kgc.h
deleted file mode 100644
index f848b19..0000000
--- a/generator_cgo/include/kgc.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef __KGC_H__
-#define __KGC_H__
-
-#include "ecurve.h"
-#include "miracl.h"
-#include "mirdef.h"
-#include
-
-
-void genKGCkey(ECC_PARAMS *params, big msk, epoint *PK_pub);
-
-_Bool genPPK_std(
- ECC_PARAMS *params,
- big msk,
- epoint *PK_pub,
- char ID[],
- big d,
- epoint *Q,
- epoint *X
-);
-
-#endif
\ No newline at end of file
diff --git a/generator_cgo/include/miracl.h b/generator_cgo/include/miracl.h
deleted file mode 100644
index 558d19c..0000000
--- a/generator_cgo/include/miracl.h
+++ /dev/null
@@ -1,1563 +0,0 @@
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-
-#ifndef MIRACL_H
-#define MIRACL_H
-
-/*
- * main MIRACL header - miracl.h.
- */
-
-#include "mirdef.h"
-
-/* Some modifiable defaults... */
-
-/* Use a smaller buffer if space is limited, don't be so wasteful! */
-
-#ifdef MR_STATIC
-#define MR_DEFAULT_BUFFER_SIZE 260
-#else
-#define MR_DEFAULT_BUFFER_SIZE 1024
-#endif
-
-/* see mrgf2m.c */
-
-#ifndef MR_KARATSUBA
-#define MR_KARATSUBA 2
-#endif
-
-#ifndef MR_DOUBLE_BIG
-
-#ifdef MR_KCM
- #ifdef MR_FLASH
- #define MR_SPACES 32
- #else
- #define MR_SPACES 31
- #endif
-#else
- #ifdef MR_FLASH
- #define MR_SPACES 28
- #else
- #define MR_SPACES 27
- #endif
-#endif
-
-#else
-
-#ifdef MR_KCM
- #ifdef MR_FLASH
- #define MR_SPACES 44
- #else
- #define MR_SPACES 43
- #endif
-#else
- #ifdef MR_FLASH
- #define MR_SPACES 40
- #else
- #define MR_SPACES 39
- #endif
-#endif
-
-#endif
-
-/* To avoid name clashes - undefine this */
-
-/* #define compare mr_compare */
-
-#ifdef MR_AVR
-#include
-#endif
-
-/* size of bigs and elliptic curve points for memory allocation from stack or heap */
-
-#define MR_ROUNDUP(a,b) ((a)-1)/(b)+1
-
-#define MR_SL sizeof(long)
-
-#ifdef MR_STATIC
-
-#define MR_SIZE (((sizeof(struct bigtype)+(MR_STATIC+2)*sizeof(mr_utype))-1)/MR_SL+1)*MR_SL
-#define MR_BIG_RESERVE(n) ((n)*MR_SIZE+MR_SL)
-
-#ifdef MR_AFFINE_ONLY
-#define MR_ESIZE (((sizeof(epoint)+MR_BIG_RESERVE(2))-1)/MR_SL+1)*MR_SL
-#else
-#define MR_ESIZE (((sizeof(epoint)+MR_BIG_RESERVE(3))-1)/MR_SL+1)*MR_SL
-#endif
-#define MR_ECP_RESERVE(n) ((n)*MR_ESIZE+MR_SL)
-
-#define MR_ESIZE_A (((sizeof(epoint)+MR_BIG_RESERVE(2))-1)/MR_SL+1)*MR_SL
-#define MR_ECP_RESERVE_A(n) ((n)*MR_ESIZE_A+MR_SL)
-
-
-#endif
-
-/* useful macro to convert size of big in words, to size of required structure */
-
-#define mr_size(n) (((sizeof(struct bigtype)+((n)+2)*sizeof(mr_utype))-1)/MR_SL+1)*MR_SL
-#define mr_big_reserve(n,m) ((n)*mr_size(m)+MR_SL)
-
-#define mr_esize_a(n) (((sizeof(epoint)+mr_big_reserve(2,(n)))-1)/MR_SL+1)*MR_SL
-#define mr_ecp_reserve_a(n,m) ((n)*mr_esize_a(m)+MR_SL)
-
-#ifdef MR_AFFINE_ONLY
-#define mr_esize(n) (((sizeof(epoint)+mr_big_reserve(2,(n)))-1)/MR_SL+1)*MR_SL
-#else
-#define mr_esize(n) (((sizeof(epoint)+mr_big_reserve(3,(n)))-1)/MR_SL+1)*MR_SL
-#endif
-#define mr_ecp_reserve(n,m) ((n)*mr_esize(m)+MR_SL)
-
-
-/* if basic library is static, make sure and use static C++ */
-
-#ifdef MR_STATIC
- #ifndef BIGS
- #define BIGS MR_STATIC
- #endif
- #ifndef ZZNS
- #define ZZNS MR_STATIC
- #endif
- #ifndef GF2MS
- #define GF2MS MR_STATIC
- #endif
-#endif
-
-#ifdef __ia64__
-#if MIRACL==64
-#define MR_ITANIUM
-#include
-#endif
-#endif
-
-#ifdef _M_X64
-#ifdef _WIN64
-#if MIRACL==64
-#define MR_WIN64
-#include
-#endif
-#endif
-#endif
-
-#ifndef MR_NO_FILE_IO
-#include
-#endif
- /* error returns */
-
-#define MR_ERR_BASE_TOO_BIG 1
-#define MR_ERR_DIV_BY_ZERO 2
-#define MR_ERR_OVERFLOW 3
-#define MR_ERR_NEG_RESULT 4
-#define MR_ERR_BAD_FORMAT 5
-#define MR_ERR_BAD_BASE 6
-#define MR_ERR_BAD_PARAMETERS 7
-#define MR_ERR_OUT_OF_MEMORY 8
-#define MR_ERR_NEG_ROOT 9
-#define MR_ERR_NEG_POWER 10
-#define MR_ERR_BAD_ROOT 11
-#define MR_ERR_INT_OP 12
-#define MR_ERR_FLASH_OVERFLOW 13
-#define MR_ERR_TOO_BIG 14
-#define MR_ERR_NEG_LOG 15
-#define MR_ERR_DOUBLE_FAIL 16
-#define MR_ERR_IO_OVERFLOW 17
-#define MR_ERR_NO_MIRSYS 18
-#define MR_ERR_BAD_MODULUS 19
-#define MR_ERR_NO_MODULUS 20
-#define MR_ERR_EXP_TOO_BIG 21
-#define MR_ERR_NOT_SUPPORTED 22
-#define MR_ERR_NOT_DOUBLE_LEN 23
-#define MR_ERR_NOT_IRREDUC 24
-#define MR_ERR_NO_ROUNDING 25
-#define MR_ERR_NOT_BINARY 26
-#define MR_ERR_NO_BASIS 27
-#define MR_ERR_COMPOSITE_MODULUS 28
-#define MR_ERR_DEV_RANDOM 29
-
- /* some useful definitions */
-
-#define forever for(;;)
-
-#define mr_abs(x) ((x)<0? (-(x)) : (x))
-
-#ifndef TRUE
- #define TRUE 1
-#endif
-#ifndef FALSE
- #define FALSE 0
-#endif
-
-#define OFF 0
-#define ON 1
-#define PLUS 1
-#define MINUS (-1)
-
-#define M1 (MIRACL-1)
-#define M2 (MIRACL-2)
-#define M3 (MIRACL-3)
-#define M4 (MIRACL-4)
-#define TOPBIT ((mr_small)1<= MR_IBITS
-#define MR_TOOBIG (1<<(MR_IBITS-2))
-#else
-#define MR_TOOBIG (1<<(MIRACL-1))
-#endif
-
-#ifdef MR_FLASH
-#define MR_EBITS (8*sizeof(double) - MR_FLASH)
- /* no of Bits per double exponent */
-#define MR_BTS 16
-#define MR_MSK 0xFFFF
-
-#endif
-
-/* Default Hash function output size in bytes */
-#define MR_HASH_BYTES 32
-
-/* Marsaglia & Zaman Random number generator */
-/* constants alternatives */
-#define NK 37 /* 21 */
-#define NJ 24 /* 6 */
-#define NV 14 /* 8 */
-
-/* Use smaller values if memory is precious */
-
-#ifdef mr_dltype
-
-#ifdef MR_LITTLE_ENDIAN
-#define MR_BOT 0
-#define MR_TOP 1
-#endif
-#ifdef MR_BIG_ENDIAN
-#define MR_BOT 1
-#define MR_TOP 0
-#endif
-
-union doubleword
-{
- mr_large d;
- mr_small h[2];
-};
-
-#endif
-
-/* chinese remainder theorem structures */
-
-typedef struct {
-big *C;
-big *V;
-big *M;
-int NP;
-} big_chinese;
-
-typedef struct {
-mr_utype *C;
-mr_utype *V;
-mr_utype *M;
-int NP;
-} small_chinese;
-
-/* Cryptographically strong pseudo-random number generator */
-
-typedef struct {
-mr_unsign32 ira[NK]; /* random number... */
-int rndptr; /* ...array & pointer */
-mr_unsign32 borrow;
-int pool_ptr;
-char pool[MR_HASH_BYTES]; /* random pool */
-} csprng;
-
-/* secure hash Algorithm structure */
-
-typedef struct {
-mr_unsign32 length[2];
-mr_unsign32 h[8];
-mr_unsign32 w[80];
-} sha256;
-
-typedef sha256 sha;
-
-#ifdef mr_unsign64
-
-typedef struct {
-mr_unsign64 length[2];
-mr_unsign64 h[8];
-mr_unsign64 w[80];
-} sha512;
-
-typedef sha512 sha384;
-
-typedef struct {
-mr_unsign64 length;
-mr_unsign64 S[5][5];
-int rate,len;
-} sha3;
-
-#endif
-
-/* Symmetric Encryption algorithm structure */
-
-#define MR_ECB 0
-#define MR_CBC 1
-#define MR_CFB1 2
-#define MR_CFB2 3
-#define MR_CFB4 5
-#define MR_PCFB1 10
-#define MR_PCFB2 11
-#define MR_PCFB4 13
-#define MR_OFB1 14
-#define MR_OFB2 15
-#define MR_OFB4 17
-#define MR_OFB8 21
-#define MR_OFB16 29
-
-typedef struct {
-int Nk,Nr;
-int mode;
-mr_unsign32 fkey[60];
-mr_unsign32 rkey[60];
-char f[16];
-} aes;
-
-/* AES-GCM suppport. See mrgcm.c */
-
-#define GCM_ACCEPTING_HEADER 0
-#define GCM_ACCEPTING_CIPHER 1
-#define GCM_NOT_ACCEPTING_MORE 2
-#define GCM_FINISHED 3
-#define GCM_ENCRYPTING 0
-#define GCM_DECRYPTING 1
-
-typedef struct {
-mr_unsign32 table[128][4]; /* 2k bytes */
-MR_BYTE stateX[16];
-MR_BYTE Y_0[16];
-mr_unsign32 counter;
-mr_unsign32 lenA[2],lenC[2];
-int status;
-aes a;
-} gcm;
-
- /* Elliptic curve point status */
-
-#define MR_EPOINT_GENERAL 0
-#define MR_EPOINT_NORMALIZED 1
-#define MR_EPOINT_INFINITY 2
-
-#define MR_NOTSET 0
-#define MR_PROJECTIVE 0
-#define MR_AFFINE 1
-#define MR_BEST 2
-#define MR_TWIST 8
-
-#define MR_OVER 0
-#define MR_ADD 1
-#define MR_DOUBLE 2
-
-/* Twist type */
-
-#define MR_QUADRATIC 2
-#define MR_CUBIC_M 0x3A
-#define MR_CUBIC_D 0x3B
-#define MR_QUARTIC_M 0x4A
-#define MR_QUARTIC_D 0x4B
-#define MR_SEXTIC_M 0x6A
-#define MR_SEXTIC_D 0x6B
-
-
-/* Fractional Sliding Windows for ECC - how much precomputation storage to use ? */
-/* Note that for variable point multiplication there is an optimal value
- which can be reduced if space is short. For fixed points its a matter of
- how much ROM is available to store precomputed points.
- We are storing the k points (P,3P,5P,7P,...,[2k-1].P) */
-
-/* These values can be manually tuned for optimal performance... */
-
-#ifdef MR_SMALL_EWINDOW
-#define MR_ECC_STORE_N 3 /* point store for ecn variable point multiplication */
-#define MR_ECC_STORE_2M 3 /* point store for ec2m variable point multiplication */
-#define MR_ECC_STORE_N2 3 /* point store for ecn2 variable point multiplication */
-#else
-#define MR_ECC_STORE_N 8 /* 8/9 is close to optimal for 256 bit exponents */
-#define MR_ECC_STORE_2M 9
-#define MR_ECC_STORE_N2 8
-#endif
-
-/*#define MR_ECC_STORE_N2_PRECOMP MR_ECC_STORE_N2 */
- /* Might want to make this bigger.. */
-
-/* If multi-addition is of m points, and s precomputed values are required, this is max of m*s (=4.10?) */
-#define MR_MAX_M_T_S 64
-
-/* Elliptic Curve epoint structure. Uses projective (X,Y,Z) co-ordinates */
-
-typedef struct {
-int marker;
-big X;
-big Y;
-#ifndef MR_AFFINE_ONLY
-big Z;
-#endif
-} epoint;
-
-
-/* Structure for Comb method for finite *
- field exponentiation with precomputation */
-
-typedef struct {
-#ifdef MR_STATIC
- const mr_small *table;
-#else
- mr_small *table;
-#endif
- big n;
- int window;
- int max;
-} brick;
-
-/* Structure for Comb method for elliptic *
- curve exponentiation with precomputation */
-
-typedef struct {
-#ifdef MR_STATIC
- const mr_small *table;
-#else
- mr_small *table;
-#endif
- big a,b,n;
- int window;
- int max;
-} ebrick;
-
-typedef struct {
-#ifdef MR_STATIC
- const mr_small *table;
-#else
- mr_small *table;
-#endif
- big a6,a2;
- int m,a,b,c;
- int window;
- int max;
-} ebrick2;
-
-typedef struct
-{
- big a;
- big b;
-} zzn2;
-
-typedef struct
-{
- zzn2 a;
- zzn2 b;
- BOOL unitary;
-} zzn4;
-
-typedef struct
-{
- int marker;
- zzn2 x;
- zzn2 y;
-#ifndef MR_AFFINE_ONLY
- zzn2 z;
-#endif
-
-} ecn2;
-
-typedef struct
-{
- big a;
- big b;
- big c;
-} zzn3;
-
-typedef struct
-{
- zzn2 a;
- zzn2 b;
- zzn2 c;
-} zzn6_3x2;
-
-/* main MIRACL instance structure */
-
-/* ------------------------------------------------------------------------*/
-
-typedef struct {
-mr_small base; /* number base */
-mr_small apbase; /* apparent base */
-int pack; /* packing density */
-int lg2b; /* bits in base */
-mr_small base2; /* 2^mr_lg2b */
-BOOL (*user)(void); /* pointer to user supplied function */
-
-int nib; /* length of bigs */
-#ifndef MR_STRIPPED_DOWN
-int depth; /* error tracing ..*/
-int trace[MR_MAXDEPTH]; /* .. mechanism */
-#endif
-BOOL check; /* overflow check */
-BOOL fout; /* Output to file */
-BOOL fin; /* Input from file */
-BOOL active;
-
-#ifndef MR_NO_FILE_IO
-
-FILE *infile; /* Input file */
-FILE *otfile; /* Output file */
-
-#endif
-
-
-#ifndef MR_NO_RAND
-mr_unsign32 ira[NK]; /* random number... */
-int rndptr; /* ...array & pointer */
-mr_unsign32 borrow;
-#endif
-
- /* Montgomery constants */
-mr_small ndash;
-big modulus;
-big pR;
-BOOL ACTIVE;
-BOOL MONTY;
-
- /* Elliptic Curve details */
-#ifndef MR_NO_SS
-BOOL SS; /* True for Super-Singular */
-#endif
-#ifndef MR_NOKOBLITZ
-BOOL KOBLITZ; /* True for a Koblitz curve */
-#endif
-#ifndef MR_AFFINE_ONLY
-int coord;
-#endif
-int Asize,Bsize;
-
-int M,AA,BB,CC; /* for GF(2^m) curves */
-
-/*
-mr_small pm,mask;
-int e,k,Me,m; for GF(p^m) curves */
-
-
-#ifndef MR_STATIC
-
-int logN; /* constants for fast fourier fft multiplication */
-int nprimes,degree;
-mr_utype *prime,*cr;
-mr_utype *inverse,**roots;
-small_chinese chin;
-mr_utype const1,const2,const3;
-mr_small msw,lsw;
-mr_utype **s1,**s2; /* pre-computed tables for polynomial reduction */
-mr_utype **t; /* workspace */
-mr_utype *wa;
-mr_utype *wb;
-mr_utype *wc;
-
-#endif
-
-BOOL same;
-BOOL first_one;
-BOOL debug;
-
-big w0; /* workspace bigs */
-big w1,w2,w3,w4;
-big w5,w6,w7;
-big w8,w9,w10,w11;
-big w12,w13,w14,w15;
-big sru;
-big one;
-
-#ifdef MR_KCM
-big big_ndash;
-big ws,wt;
-#endif
-
-big A,B;
-
-/* User modifiables */
-
-#ifndef MR_SIMPLE_IO
-int IOBSIZ; /* size of i/o buffer */
-#endif
-BOOL ERCON; /* error control */
-int ERNUM; /* last error code */
-int NTRY; /* no. of tries for probablistic primality testing */
-#ifndef MR_SIMPLE_IO
-int INPLEN; /* input length */
-#ifndef MR_SIMPLE_BASE
-int IOBASE; /* base for input and output */
-
-#endif
-#endif
-#ifdef MR_FLASH
-BOOL EXACT; /* exact flag */
-BOOL RPOINT; /* =ON for radix point, =OFF for fractions in output */
-#endif
-#ifndef MR_STRIPPED_DOWN
-BOOL TRACER; /* turns trace tracker on/off */
-#endif
-
-#ifdef MR_STATIC
-const int *PRIMES; /* small primes array */
-#ifndef MR_SIMPLE_IO
-char IOBUFF[MR_DEFAULT_BUFFER_SIZE]; /* i/o buffer */
-#endif
-#else
-int *PRIMES; /* small primes array */
-#ifndef MR_SIMPLE_IO
-char *IOBUFF; /* i/o buffer */
-#endif
-#endif
-
-#ifdef MR_FLASH
-int workprec;
-int stprec; /* start precision */
-
-int RS,RD;
-double D;
-
-double db,n,p;
-int a,b,c,d,r,q,oldn,ndig;
-mr_small u,v,ku,kv;
-
-BOOL last,carryon;
-flash pi;
-
-#endif
-
-#ifdef MR_FP_ROUNDING
-mr_large inverse_base;
-#endif
-
-#ifndef MR_STATIC
-char *workspace;
-#else
-char workspace[MR_BIG_RESERVE(MR_SPACES)];
-#endif
-
-int TWIST; /* set to twisted curve */
-int qnr; /* a QNR -1 for p=3 mod 4, -2 for p=5 mod 8, 0 otherwise */
-int cnr; /* a cubic non-residue */
-int pmod8;
-int pmod9;
-BOOL NO_CARRY;
-} miracl;
-
-/* ------------------------------------------------------------------------*/
-
-
-#ifndef MR_GENERIC_MT
-
-#ifdef MR_WINDOWS_MT
-#define MR_OS_THREADS
-#endif
-
-#ifdef MR_UNIX_MT
-#define MR_OS_THREADS
-#endif
-
-#ifdef MR_OPENMP_MT
-#define MR_OS_THREADS
-#endif
-
-
-#ifndef MR_OS_THREADS
-
-extern miracl *mr_mip; /* pointer to MIRACL's only global variable */
-
-#endif
-
-#endif
-
-#ifdef MR_GENERIC_MT
-
-#ifdef MR_STATIC
-#define MR_GENERIC_AND_STATIC
-#endif
-
-#define _MIPT_ miracl *,
-#define _MIPTO_ miracl *
-#define _MIPD_ miracl *mr_mip,
-#define _MIPDO_ miracl *mr_mip
-#define _MIPP_ mr_mip,
-#define _MIPPO_ mr_mip
-
-#else
-
-#define _MIPT_
-#define _MIPTO_ void
-#define _MIPD_
-#define _MIPDO_ void
-#define _MIPP_
-#define _MIPPO_
-
-#endif
-
-/* Preamble and exit code for MIRACL routines. *
- * Not used if MR_STRIPPED_DOWN is defined */
-
-#ifdef MR_STRIPPED_DOWN
-#define MR_OUT
-#define MR_IN(N)
-#else
-#define MR_OUT mr_mip->depth--;
-#define MR_IN(N) mr_mip->depth++; if (mr_mip->depthtrace[mr_mip->depth]=(N); if (mr_mip->TRACER) mr_track(_MIPPO_); }
-#endif
-
-/* Function definitions */
-
-/* Group 0 - Internal routines */
-
-extern void mr_berror(_MIPT_ int);
-extern mr_small mr_shiftbits(mr_small,int);
-extern mr_small mr_setbase(_MIPT_ mr_small);
-extern void mr_track(_MIPTO_ );
-extern void mr_lzero(big);
-extern BOOL mr_notint(flash);
-extern int mr_lent(flash);
-extern void mr_padd(_MIPT_ big,big,big);
-extern void mr_psub(_MIPT_ big,big,big);
-extern void mr_pmul(_MIPT_ big,mr_small,big);
-#ifdef MR_FP_ROUNDING
-extern mr_large mr_invert(mr_small);
-extern mr_small imuldiv(mr_small,mr_small,mr_small,mr_small,mr_large,mr_small *);
-extern mr_small mr_sdiv(_MIPT_ big,mr_small,mr_large,big);
-#else
-extern mr_small mr_sdiv(_MIPT_ big,mr_small,big);
-extern void mr_and(big,big,big);
-extern void mr_xor(big,big,big);
-#endif
-extern void mr_shift(_MIPT_ big,int,big);
-extern miracl *mr_first_alloc(void);
-extern void *mr_alloc(_MIPT_ int,int);
-extern void mr_free(void *);
-extern void set_user_function(_MIPT_ BOOL (*)(void));
-extern void set_io_buffer_size(_MIPT_ int);
-extern int mr_testbit(_MIPT_ big,int);
-extern void mr_addbit(_MIPT_ big,int);
-extern int recode(_MIPT_ big ,int ,int ,int );
-extern int mr_window(_MIPT_ big,int,int *,int *,int);
-extern int mr_window2(_MIPT_ big,big,int,int *,int *);
-extern int mr_naf_window(_MIPT_ big,big,int,int *,int *,int);
-
-extern int mr_fft_init(_MIPT_ int,big,big,BOOL);
-extern void mr_dif_fft(_MIPT_ int,int,mr_utype *);
-extern void mr_dit_fft(_MIPT_ int,int,mr_utype *);
-extern void fft_reset(_MIPTO_);
-
-extern int mr_poly_mul(_MIPT_ int,big*,int,big*,big*);
-extern int mr_poly_sqr(_MIPT_ int,big*,big*);
-extern void mr_polymod_set(_MIPT_ int,big*,big*);
-extern int mr_poly_rem(_MIPT_ int,big *,big *);
-
-extern int mr_ps_big_mul(_MIPT_ int,big *,big *,big *);
-extern int mr_ps_zzn_mul(_MIPT_ int,big *,big *,big *);
-
-extern mr_small muldiv(mr_small,mr_small,mr_small,mr_small,mr_small *);
-extern mr_small muldvm(mr_small,mr_small,mr_small,mr_small *);
-extern mr_small muldvd(mr_small,mr_small,mr_small,mr_small *);
-extern void muldvd2(mr_small,mr_small,mr_small *,mr_small *);
-
-extern flash mirvar_mem_variable(char *,int,int);
-extern epoint* epoint_init_mem_variable(_MIPT_ char *,int,int);
-
-/* Group 1 - General purpose, I/O and basic arithmetic routines */
-
-extern unsigned int igcd(unsigned int,unsigned int);
-extern unsigned long lgcd(unsigned long,unsigned long);
-extern mr_small sgcd(mr_small,mr_small);
-extern unsigned int isqrt(unsigned int,unsigned int);
-extern unsigned long mr_lsqrt(unsigned long,unsigned long);
-extern void irand(_MIPT_ mr_unsign32);
-extern mr_small brand(_MIPTO_ );
-extern void zero(flash);
-extern void convert(_MIPT_ int,big);
-extern void uconvert(_MIPT_ unsigned int,big);
-extern void lgconv(_MIPT_ long,big);
-extern void ulgconv(_MIPT_ unsigned long,big);
-extern void tconvert(_MIPT_ mr_utype,big);
-
-#ifdef mr_dltype
-extern void dlconv(_MIPT_ mr_dltype,big);
-#endif
-
-extern flash mirvar(_MIPT_ int);
-extern flash mirvar_mem(_MIPT_ char *,int);
-extern void mirkill(big);
-extern void *memalloc(_MIPT_ int);
-extern void memkill(_MIPT_ char *,int);
-extern void mr_init_threading(void);
-extern void mr_end_threading(void);
-extern miracl *get_mip(void );
-extern void set_mip(miracl *);
-#ifdef MR_GENERIC_AND_STATIC
-extern miracl *mirsys(miracl *,int,mr_small);
-#else
-extern miracl *mirsys(int,mr_small);
-#endif
-extern miracl *mirsys_basic(miracl *,int,mr_small);
-extern void mirexit(_MIPTO_ );
-extern int exsign(flash);
-extern void insign(int,flash);
-extern int getdig(_MIPT_ big,int);
-extern int numdig(_MIPT_ big);
-extern void putdig(_MIPT_ int,big,int);
-extern void copy(flash,flash);
-extern void negify(flash,flash);
-extern void absol(flash,flash);
-extern int size(big);
-extern int mr_compare(big,big);
-extern void add(_MIPT_ big,big,big);
-extern void subtract(_MIPT_ big,big,big);
-extern void incr(_MIPT_ big,int,big);
-extern void decr(_MIPT_ big,int,big);
-extern void premult(_MIPT_ big,int,big);
-extern int subdiv(_MIPT_ big,int,big);
-extern BOOL subdivisible(_MIPT_ big,int);
-extern int remain(_MIPT_ big,int);
-extern void bytes_to_big(_MIPT_ int,const char *,big);
-extern int big_to_bytes(_MIPT_ int,big,char *,BOOL);
-extern mr_small normalise(_MIPT_ big,big);
-extern void multiply(_MIPT_ big,big,big);
-extern void fft_mult(_MIPT_ big,big,big);
-extern BOOL fastmultop(_MIPT_ int,big,big,big);
-extern void divide(_MIPT_ big,big,big);
-extern BOOL divisible(_MIPT_ big,big);
-extern void mad(_MIPT_ big,big,big,big,big,big);
-extern int instr(_MIPT_ flash,char *);
-extern int otstr(_MIPT_ flash,char *);
-extern int cinstr(_MIPT_ flash,char *);
-extern int cotstr(_MIPT_ flash,char *);
-extern epoint* epoint_init(_MIPTO_ );
-extern epoint* epoint_init_mem(_MIPT_ char *,int);
-extern void* ecp_memalloc(_MIPT_ int);
-void ecp_memkill(_MIPT_ char *,int);
-BOOL init_big_from_rom(big,int,const mr_small *,int ,int *);
-BOOL init_point_from_rom(epoint *,int,const mr_small *,int,int *);
-
-#ifndef MR_NO_FILE_IO
-
-extern int innum(_MIPT_ flash,FILE *);
-extern int otnum(_MIPT_ flash,FILE *);
-extern int cinnum(_MIPT_ flash,FILE *);
-extern int cotnum(_MIPT_ flash,FILE *);
-
-#endif
-
-/* Group 2 - Advanced arithmetic routines */
-
-extern mr_small smul(mr_small,mr_small,mr_small);
-extern mr_small spmd(mr_small,mr_small,mr_small);
-extern mr_small invers(mr_small,mr_small);
-extern mr_small sqrmp(mr_small,mr_small);
-extern int jac(mr_small,mr_small);
-
-extern void gprime(_MIPT_ int);
-extern int jack(_MIPT_ big,big);
-extern int egcd(_MIPT_ big,big,big);
-extern int xgcd(_MIPT_ big,big,big,big,big);
-extern int invmodp(_MIPT_ big,big,big);
-extern int logb2(_MIPT_ big);
-extern int hamming(_MIPT_ big);
-extern void expb2(_MIPT_ int,big);
-extern void bigbits(_MIPT_ int,big);
-extern void expint(_MIPT_ int,int,big);
-extern void sftbit(_MIPT_ big,int,big);
-extern void power(_MIPT_ big,long,big,big);
-extern void powmod(_MIPT_ big,big,big,big);
-extern void powmod2(_MIPT_ big,big,big,big,big,big);
-extern void powmodn(_MIPT_ int,big *,big *,big,big);
-extern int powltr(_MIPT_ int,big,big,big);
-extern BOOL double_inverse(_MIPT_ big,big,big,big,big);
-extern BOOL multi_inverse(_MIPT_ int,big*,big,big*);
-extern void lucas(_MIPT_ big,big,big,big,big);
-extern BOOL nroot(_MIPT_ big,int,big);
-extern BOOL sqroot(_MIPT_ big,big,big);
-extern void bigrand(_MIPT_ big,big);
-extern void bigdig(_MIPT_ int,int,big);
-extern int trial_division(_MIPT_ big,big);
-extern BOOL isprime(_MIPT_ big);
-extern BOOL nxprime(_MIPT_ big,big);
-extern BOOL nxsafeprime(_MIPT_ int,int,big,big);
-extern BOOL crt_init(_MIPT_ big_chinese *,int,big *);
-extern void crt(_MIPT_ big_chinese *,big *,big);
-extern void crt_end(big_chinese *);
-extern BOOL scrt_init(_MIPT_ small_chinese *,int,mr_utype *);
-extern void scrt(_MIPT_ small_chinese*,mr_utype *,big);
-extern void scrt_end(small_chinese *);
-#ifndef MR_STATIC
-extern BOOL brick_init(_MIPT_ brick *,big,big,int,int);
-extern void brick_end(brick *);
-#else
-extern void brick_init(brick *,const mr_small *,big,int,int);
-#endif
-extern void pow_brick(_MIPT_ brick *,big,big);
-#ifndef MR_STATIC
-extern BOOL ebrick_init(_MIPT_ ebrick *,big,big,big,big,big,int,int);
-extern void ebrick_end(ebrick *);
-#else
-extern void ebrick_init(ebrick *,const mr_small *,big,big,big,int,int);
-#endif
-extern int mul_brick(_MIPT_ ebrick*,big,big,big);
-#ifndef MR_STATIC
-extern BOOL ebrick2_init(_MIPT_ ebrick2 *,big,big,big,big,int,int,int,int,int,int);
-extern void ebrick2_end(ebrick2 *);
-#else
-extern void ebrick2_init(ebrick2 *,const mr_small *,big,big,int,int,int,int,int,int);
-#endif
-extern int mul2_brick(_MIPT_ ebrick2*,big,big,big);
-
-/* Montgomery stuff */
-
-extern mr_small prepare_monty(_MIPT_ big);
-extern void kill_monty(_MIPTO_ );
-extern void nres(_MIPT_ big,big);
-extern void redc(_MIPT_ big,big);
-
-extern void nres_negate(_MIPT_ big,big);
-extern void nres_modadd(_MIPT_ big,big,big);
-extern void nres_modsub(_MIPT_ big,big,big);
-extern void nres_lazy(_MIPT_ big,big,big,big,big,big);
-extern void nres_complex(_MIPT_ big,big,big,big);
-extern void nres_double_modadd(_MIPT_ big,big,big);
-extern void nres_double_modsub(_MIPT_ big,big,big);
-extern void nres_premult(_MIPT_ big,int,big);
-extern void nres_modmult(_MIPT_ big,big,big);
-extern int nres_moddiv(_MIPT_ big,big,big);
-extern void nres_dotprod(_MIPT_ int,big *,big *,big);
-extern void nres_powmod(_MIPT_ big,big,big);
-extern void nres_powltr(_MIPT_ int,big,big);
-extern void nres_powmod2(_MIPT_ big,big,big,big,big);
-extern void nres_powmodn(_MIPT_ int,big *,big *,big);
-extern BOOL nres_sqroot(_MIPT_ big,big);
-extern void nres_lucas(_MIPT_ big,big,big,big);
-extern BOOL nres_double_inverse(_MIPT_ big,big,big,big);
-extern BOOL nres_multi_inverse(_MIPT_ int,big *,big *);
-extern void nres_div2(_MIPT_ big,big);
-extern void nres_div3(_MIPT_ big,big);
-extern void nres_div5(_MIPT_ big,big);
-
-extern void shs_init(sha *);
-extern void shs_process(sha *,int);
-extern void shs_hash(sha *,char *);
-
-extern void shs256_init(sha256 *);
-extern void shs256_process(sha256 *,int);
-extern void shs256_hash(sha256 *,char *);
-
-#ifdef mr_unsign64
-
-extern void shs512_init(sha512 *);
-extern void shs512_process(sha512 *,int);
-extern void shs512_hash(sha512 *,char *);
-
-extern void shs384_init(sha384 *);
-extern void shs384_process(sha384 *,int);
-extern void shs384_hash(sha384 *,char *);
-
-extern void sha3_init(sha3 *,int);
-extern void sha3_process(sha3 *,int);
-extern void sha3_hash(sha3 *,char *);
-
-#endif
-
-extern BOOL aes_init(aes *,int,int,char *,char *);
-extern void aes_getreg(aes *,char *);
-extern void aes_ecb_encrypt(aes *,MR_BYTE *);
-extern void aes_ecb_decrypt(aes *,MR_BYTE *);
-extern mr_unsign32 aes_encrypt(aes *,char *);
-extern mr_unsign32 aes_decrypt(aes *,char *);
-extern void aes_reset(aes *,int,char *);
-extern void aes_end(aes *);
-
-extern void gcm_init(gcm *,int,char *,int,char *);
-extern BOOL gcm_add_header(gcm *,char *,int);
-extern BOOL gcm_add_cipher(gcm *,int,char *,int,char *);
-extern void gcm_finish(gcm *,char *);
-
-extern void FPE_encrypt(int ,aes *,mr_unsign32 ,mr_unsign32 ,char *,int);
-extern void FPE_decrypt(int ,aes *,mr_unsign32 ,mr_unsign32 ,char *,int);
-
-extern void strong_init(csprng *,int,char *,mr_unsign32);
-extern int strong_rng(csprng *);
-extern void strong_bigrand(_MIPT_ csprng *,big,big);
-extern void strong_bigdig(_MIPT_ csprng *,int,int,big);
-extern void strong_kill(csprng *);
-
-/* special modular multipliers */
-
-extern void comba_mult(big,big,big);
-extern void comba_square(big,big);
-extern void comba_redc(_MIPT_ big,big);
-extern void comba_modadd(_MIPT_ big,big,big);
-extern void comba_modsub(_MIPT_ big,big,big);
-extern void comba_double_modadd(_MIPT_ big,big,big);
-extern void comba_double_modsub(_MIPT_ big,big,big);
-extern void comba_negate(_MIPT_ big,big);
-extern void comba_add(big,big,big);
-extern void comba_sub(big,big,big);
-extern void comba_double_add(big,big,big);
-extern void comba_double_sub(big,big,big);
-
-extern void comba_mult2(_MIPT_ big,big,big);
-
-extern void fastmodmult(_MIPT_ big,big,big);
-extern void fastmodsquare(_MIPT_ big,big);
-
-extern void kcm_mul(_MIPT_ big,big,big);
-extern void kcm_sqr(_MIPT_ big,big);
-extern void kcm_redc(_MIPT_ big,big);
-
-extern void kcm_multiply(_MIPT_ int,big,big,big);
-extern void kcm_square(_MIPT_ int,big,big);
-extern BOOL kcm_top(_MIPT_ int,big,big,big);
-
-/* elliptic curve stuff */
-
-extern BOOL point_at_infinity(epoint *);
-
-extern void mr_jsf(_MIPT_ big,big,big,big,big,big);
-
-extern void ecurve_init(_MIPT_ big,big,big,int);
-extern int ecurve_add(_MIPT_ epoint *,epoint *);
-extern int ecurve_sub(_MIPT_ epoint *,epoint *);
-extern void ecurve_double_add(_MIPT_ epoint *,epoint *,epoint *,epoint *,big *,big *);
-extern void ecurve_multi_add(_MIPT_ int,epoint **,epoint **);
-extern void ecurve_double(_MIPT_ epoint*);
-extern int ecurve_mult(_MIPT_ big,epoint *,epoint *);
-extern void ecurve_mult2(_MIPT_ big,epoint *,big,epoint *,epoint *);
-extern void ecurve_multn(_MIPT_ int,big *,epoint**,epoint *);
-
-extern BOOL epoint_x(_MIPT_ big);
-extern BOOL epoint_set(_MIPT_ big,big,int,epoint*);
-extern int epoint_get(_MIPT_ epoint*,big,big);
-extern void epoint_getxyz(_MIPT_ epoint *,big,big,big);
-extern BOOL epoint_norm(_MIPT_ epoint *);
-extern BOOL epoint_multi_norm(_MIPT_ int,big *,epoint **);
-extern void epoint_free(epoint *);
-extern void epoint_copy(epoint *,epoint *);
-extern BOOL epoint_comp(_MIPT_ epoint *,epoint *);
-extern void epoint_negate(_MIPT_ epoint *);
-
-extern BOOL ecurve2_init(_MIPT_ int,int,int,int,big,big,BOOL,int);
-extern big ecurve2_add(_MIPT_ epoint *,epoint *);
-extern big ecurve2_sub(_MIPT_ epoint *,epoint *);
-extern void ecurve2_multi_add(_MIPT_ int,epoint **,epoint **);
-extern void ecurve2_mult(_MIPT_ big,epoint *,epoint *);
-extern void ecurve2_mult2(_MIPT_ big,epoint *,big,epoint *,epoint *);
-extern void ecurve2_multn(_MIPT_ int,big *,epoint**,epoint *);
-
-extern epoint* epoint2_init(_MIPTO_ );
-extern BOOL epoint2_set(_MIPT_ big,big,int,epoint*);
-extern int epoint2_get(_MIPT_ epoint*,big,big);
-extern void epoint2_getxyz(_MIPT_ epoint *,big,big,big);
-extern int epoint2_norm(_MIPT_ epoint *);
-extern void epoint2_free(epoint *);
-extern void epoint2_copy(epoint *,epoint *);
-extern BOOL epoint2_comp(_MIPT_ epoint *,epoint *);
-extern void epoint2_negate(_MIPT_ epoint *);
-
-/* GF(2) stuff */
-
-extern BOOL prepare_basis(_MIPT_ int,int,int,int,BOOL);
-extern int parity2(big);
-extern BOOL multi_inverse2(_MIPT_ int,big *,big *);
-extern void add2(big,big,big);
-extern void incr2(big,int,big);
-extern void reduce2(_MIPT_ big,big);
-extern void multiply2(_MIPT_ big,big,big);
-extern void modmult2(_MIPT_ big,big,big);
-extern void modsquare2(_MIPT_ big,big);
-extern void power2(_MIPT_ big,int,big);
-extern void sqroot2(_MIPT_ big,big);
-extern void halftrace2(_MIPT_ big,big);
-extern BOOL quad2(_MIPT_ big,big);
-extern BOOL inverse2(_MIPT_ big,big);
-extern void karmul2(int,mr_small *,mr_small *,mr_small *,mr_small *);
-extern void karmul2_poly(_MIPT_ int,big *,big *,big *,big *);
-extern void karmul2_poly_upper(_MIPT_ int,big *,big *,big *,big *);
-extern void gf2m_dotprod(_MIPT_ int,big *,big *,big);
-extern int trace2(_MIPT_ big);
-extern void rand2(_MIPT_ big);
-extern void gcd2(_MIPT_ big,big,big);
-extern int degree2(big);
-
-/* zzn2 stuff */
-
-extern BOOL zzn2_iszero(zzn2 *);
-extern BOOL zzn2_isunity(_MIPT_ zzn2 *);
-extern void zzn2_from_int(_MIPT_ int,zzn2 *);
-extern void zzn2_from_ints(_MIPT_ int,int,zzn2 *);
-extern void zzn2_copy(zzn2 *,zzn2 *);
-extern void zzn2_zero(zzn2 *);
-extern void zzn2_negate(_MIPT_ zzn2 *,zzn2 *);
-extern void zzn2_conj(_MIPT_ zzn2 *,zzn2 *);
-extern void zzn2_add(_MIPT_ zzn2 *,zzn2 *,zzn2 *);
-extern void zzn2_sub(_MIPT_ zzn2 *,zzn2 *,zzn2 *);
-extern void zzn2_smul(_MIPT_ zzn2 *,big,zzn2 *);
-extern void zzn2_mul(_MIPT_ zzn2 *,zzn2 *,zzn2 *);
-extern void zzn2_sqr(_MIPT_ zzn2 *,zzn2 *);
-extern void zzn2_inv(_MIPT_ zzn2 *);
-extern void zzn2_timesi(_MIPT_ zzn2 *);
-extern void zzn2_powl(_MIPT_ zzn2 *,big,zzn2 *);
-extern void zzn2_from_zzns(big,big,zzn2 *);
-extern void zzn2_from_bigs(_MIPT_ big,big,zzn2 *);
-extern void zzn2_from_zzn(big,zzn2 *);
-extern void zzn2_from_big(_MIPT_ big, zzn2 *);
-extern void zzn2_sadd(_MIPT_ zzn2 *,big,zzn2 *);
-extern void zzn2_ssub(_MIPT_ zzn2 *,big,zzn2 *);
-extern void zzn2_div2(_MIPT_ zzn2 *);
-extern void zzn2_div3(_MIPT_ zzn2 *);
-extern void zzn2_div5(_MIPT_ zzn2 *);
-extern void zzn2_imul(_MIPT_ zzn2 *,int,zzn2 *);
-extern BOOL zzn2_compare(zzn2 *,zzn2 *);
-extern void zzn2_txx(_MIPT_ zzn2 *);
-extern void zzn2_txd(_MIPT_ zzn2 *);
-extern BOOL zzn2_sqrt(_MIPT_ zzn2 *,zzn2 *);
-extern BOOL zzn2_qr(_MIPT_ zzn2 *);
-extern BOOL zzn2_multi_inverse(_MIPT_ int,zzn2 *,zzn2 *);
-
-
-/* zzn3 stuff */
-
-extern void zzn3_set(_MIPT_ int,big);
-extern BOOL zzn3_iszero(zzn3 *);
-extern BOOL zzn3_isunity(_MIPT_ zzn3 *);
-extern void zzn3_from_int(_MIPT_ int,zzn3 *);
-extern void zzn3_from_ints(_MIPT_ int,int,int,zzn3 *);
-extern void zzn3_copy(zzn3 *,zzn3 *);
-extern void zzn3_zero(zzn3 *);
-extern void zzn3_negate(_MIPT_ zzn3 *,zzn3 *);
-extern void zzn3_powq(_MIPT_ zzn3 *,zzn3 *);
-extern void zzn3_add(_MIPT_ zzn3 *,zzn3 *,zzn3 *);
-extern void zzn3_sub(_MIPT_ zzn3 *,zzn3 *,zzn3 *);
-extern void zzn3_smul(_MIPT_ zzn3 *,big,zzn3 *);
-extern void zzn3_mul(_MIPT_ zzn3 *,zzn3 *,zzn3 *);
-extern void zzn3_inv(_MIPT_ zzn3 *);
-extern void zzn3_timesi(_MIPT_ zzn3 *);
-extern void zzn3_timesi2(_MIPT_ zzn3 *);
-extern void zzn3_powl(_MIPT_ zzn3 *,big,zzn3 *);
-extern void zzn3_from_zzns(big,big,big,zzn3 *);
-extern void zzn3_from_bigs(_MIPT_ big,big,big,zzn3 *);
-extern void zzn3_from_zzn(big,zzn3 *);
-extern void zzn3_from_zzn_1(big,zzn3 *);
-extern void zzn3_from_zzn_2(big,zzn3 *);
-extern void zzn3_from_big(_MIPT_ big, zzn3 *);
-extern void zzn3_sadd(_MIPT_ zzn3 *,big,zzn3 *);
-extern void zzn3_ssub(_MIPT_ zzn3 *,big,zzn3 *);
-extern void zzn3_div2(_MIPT_ zzn3 *);
-extern void zzn3_imul(_MIPT_ zzn3 *,int,zzn3 *);
-extern BOOL zzn3_compare(zzn3 *,zzn3 *);
-
-/* zzn4 stuff */
-
-extern BOOL zzn4_iszero(zzn4 *);
-extern BOOL zzn4_isunity(_MIPT_ zzn4 *);
-extern void zzn4_from_int(_MIPT_ int,zzn4 *);
-extern void zzn4_copy(zzn4 *,zzn4 *);
-extern void zzn4_zero(zzn4 *);
-extern void zzn4_negate(_MIPT_ zzn4 *,zzn4 *);
-extern void zzn4_powq(_MIPT_ zzn2 *,zzn4 *);
-extern void zzn4_add(_MIPT_ zzn4 *,zzn4 *,zzn4 *);
-extern void zzn4_sub(_MIPT_ zzn4 *,zzn4 *,zzn4 *);
-extern void zzn4_smul(_MIPT_ zzn4 *,zzn2 *,zzn4 *);
-extern void zzn4_sqr(_MIPT_ zzn4 *,zzn4 *);
-extern void zzn4_mul(_MIPT_ zzn4 *,zzn4 *,zzn4 *);
-extern void zzn4_inv(_MIPT_ zzn4 *);
-extern void zzn4_timesi(_MIPT_ zzn4 *);
-extern void zzn4_tx(_MIPT_ zzn4 *);
-extern void zzn4_from_zzn2s(zzn2 *,zzn2 *,zzn4 *);
-extern void zzn4_from_zzn2(zzn2 *,zzn4 *);
-extern void zzn4_from_zzn2h(zzn2 *,zzn4 *);
-extern void zzn4_from_zzn(big,zzn4 *);
-extern void zzn4_from_big(_MIPT_ big , zzn4 *);
-extern void zzn4_sadd(_MIPT_ zzn4 *,zzn2 *,zzn4 *);
-extern void zzn4_ssub(_MIPT_ zzn4 *,zzn2 *,zzn4 *);
-extern void zzn4_div2(_MIPT_ zzn4 *);
-extern void zzn4_conj(_MIPT_ zzn4 *,zzn4 *);
-extern void zzn4_imul(_MIPT_ zzn4 *,int,zzn4 *);
-extern void zzn4_lmul(_MIPT_ zzn4 *,big,zzn4 *);
-extern BOOL zzn4_compare(zzn4 *,zzn4 *);
-
-/* ecn2 stuff */
-
-extern BOOL ecn2_iszero(ecn2 *);
-extern void ecn2_copy(ecn2 *,ecn2 *);
-extern void ecn2_zero(ecn2 *);
-extern BOOL ecn2_compare(_MIPT_ ecn2 *,ecn2 *);
-extern void ecn2_norm(_MIPT_ ecn2 *);
-extern void ecn2_get(_MIPT_ ecn2 *,zzn2 *,zzn2 *,zzn2 *);
-extern void ecn2_getxy(ecn2 *,zzn2 *,zzn2 *);
-extern void ecn2_getx(ecn2 *,zzn2 *);
-extern void ecn2_getz(_MIPT_ ecn2 *,zzn2 *);
-extern void ecn2_rhs(_MIPT_ zzn2 *,zzn2 *);
-extern BOOL ecn2_set(_MIPT_ zzn2 *,zzn2 *,ecn2 *);
-extern BOOL ecn2_setx(_MIPT_ zzn2 *,ecn2 *);
-extern void ecn2_setxyz(_MIPT_ zzn2 *,zzn2 *,zzn2 *,ecn2 *);
-extern void ecn2_negate(_MIPT_ ecn2 *,ecn2 *);
-extern BOOL ecn2_add3(_MIPT_ ecn2 *,ecn2 *,zzn2 *,zzn2 *,zzn2 *);
-extern BOOL ecn2_add2(_MIPT_ ecn2 *,ecn2 *,zzn2 *,zzn2 *);
-extern BOOL ecn2_add1(_MIPT_ ecn2 *,ecn2 *,zzn2 *);
-extern BOOL ecn2_add(_MIPT_ ecn2 *,ecn2 *);
-extern BOOL ecn2_sub(_MIPT_ ecn2 *,ecn2 *);
-extern BOOL ecn2_add_sub(_MIPT_ ecn2 *,ecn2 *,ecn2 *,ecn2 *);
-extern int ecn2_mul2_jsf(_MIPT_ big,ecn2 *,big,ecn2 *,ecn2 *);
-extern int ecn2_mul(_MIPT_ big,ecn2 *);
-extern void ecn2_psi(_MIPT_ zzn2 *,ecn2 *);
-extern BOOL ecn2_multi_norm(_MIPT_ int ,zzn2 *,ecn2 *);
-extern int ecn2_mul4_gls_v(_MIPT_ big *,int,ecn2 *,big *,ecn2 *,zzn2 *,ecn2 *);
-extern int ecn2_muln_engine(_MIPT_ int,int,int,int,big *,big *,big *,big *,ecn2 *,ecn2 *,ecn2 *);
-extern void ecn2_precomp_gls(_MIPT_ int,BOOL,ecn2 *,zzn2 *,ecn2 *);
-extern int ecn2_mul2_gls(_MIPT_ big *,ecn2 *,zzn2 *,ecn2 *);
-extern void ecn2_precomp(_MIPT_ int,BOOL,ecn2 *,ecn2 *);
-extern int ecn2_mul2(_MIPT_ big,int,ecn2 *,big,ecn2 *,ecn2 *);
-#ifndef MR_STATIC
-extern BOOL ecn2_brick_init(_MIPT_ ebrick *,zzn2 *,zzn2 *,big,big,big,int,int);
-extern void ecn2_brick_end(ebrick *);
-#else
-extern void ebrick_init(ebrick *,const mr_small *,big,big,big,int,int);
-#endif
-extern void ecn2_mul_brick_gls(_MIPT_ ebrick *B,big *,zzn2 *,zzn2 *,zzn2 *);
-extern void ecn2_multn(_MIPT_ int,big *,ecn2 *,ecn2 *);
-extern void ecn2_mult4(_MIPT_ big *,ecn2 *,ecn2 *);
-/* Group 3 - Floating-slash routines */
-
-#ifdef MR_FLASH
-extern void fpack(_MIPT_ big,big,flash);
-extern void numer(_MIPT_ flash,big);
-extern void denom(_MIPT_ flash,big);
-extern BOOL fit(big,big,int);
-extern void build(_MIPT_ flash,int (*)(_MIPT_ big,int));
-extern void mround(_MIPT_ big,big,flash);
-extern void flop(_MIPT_ flash,flash,int *,flash);
-extern void fmul(_MIPT_ flash,flash,flash);
-extern void fdiv(_MIPT_ flash,flash,flash);
-extern void fadd(_MIPT_ flash,flash,flash);
-extern void fsub(_MIPT_ flash,flash,flash);
-extern int fcomp(_MIPT_ flash,flash);
-extern void fconv(_MIPT_ int,int,flash);
-extern void frecip(_MIPT_ flash,flash);
-extern void ftrunc(_MIPT_ flash,big,flash);
-extern void fmodulo(_MIPT_ flash,flash,flash);
-extern void fpmul(_MIPT_ flash,int,int,flash);
-extern void fincr(_MIPT_ flash,int,int,flash);
-extern void dconv(_MIPT_ double,flash);
-extern double fdsize(_MIPT_ flash);
-extern void frand(_MIPT_ flash);
-
-/* Group 4 - Advanced Flash routines */
-
-extern void fpower(_MIPT_ flash,int,flash);
-extern BOOL froot(_MIPT_ flash,int,flash);
-extern void fpi(_MIPT_ flash);
-extern void fexp(_MIPT_ flash,flash);
-extern void flog(_MIPT_ flash,flash);
-extern void fpowf(_MIPT_ flash,flash,flash);
-extern void ftan(_MIPT_ flash,flash);
-extern void fatan(_MIPT_ flash,flash);
-extern void fsin(_MIPT_ flash,flash);
-extern void fasin(_MIPT_ flash,flash);
-extern void fcos(_MIPT_ flash,flash);
-extern void facos(_MIPT_ flash,flash);
-extern void ftanh(_MIPT_ flash,flash);
-extern void fatanh(_MIPT_ flash,flash);
-extern void fsinh(_MIPT_ flash,flash);
-extern void fasinh(_MIPT_ flash,flash);
-extern void fcosh(_MIPT_ flash,flash);
-extern void facosh(_MIPT_ flash,flash);
-#endif
-
-
-/* Test predefined Macros to determine compiler type, and hopefully
- selectively use fast in-line assembler (or other compiler specific
- optimisations. Note I am unsure of Microsoft version numbers. So I
- suspect are Microsoft.
-
- Note: It seems to be impossible to get the 16-bit Microsoft compiler
- to allow inline 32-bit op-codes. So I suspect that INLINE_ASM == 2 will
- never work with it. Pity.
-
-#define INLINE_ASM 1 -> generates 8086 inline assembly
-#define INLINE_ASM 2 -> generates mixed 8086 & 80386 inline assembly,
- so you can get some benefit while running in a
- 16-bit environment on 32-bit hardware (DOS, Windows
- 3.1...)
-#define INLINE_ASM 3 -> generate true 80386 inline assembly - (Using DOS
- extender, Windows '95/Windows NT)
- Actually optimised for Pentium
-
-#define INLINE_ASM 4 -> 80386 code in the GNU style (for (DJGPP)
-
-Small, medium, compact and large memory models are supported for the
-first two of the above.
-
-*/
-
-/* To allow for inline assembly */
-
-#ifdef __GNUC__
- #define ASM __asm__ __volatile__
-#endif
-
-#ifdef __TURBOC__
- #define ASM asm
-#endif
-
-#ifdef _MSC_VER
- #define ASM _asm
-#endif
-
-#ifndef MR_NOASM
-
-/* Win64 - inline the time critical function */
-#ifndef MR_NO_INTRINSICS
- #ifdef MR_WIN64
- #define muldvd(a,b,c,rp) (*(rp)=_umul128((a),(b),&(tm)),*(rp)+=(c),tm+=(*(rp)<(c)),tm)
- #define muldvd2(a,b,c,rp) (tr=_umul128((a),(b),&(tm)),tr+=(*(c)),tm+=(tr<(*(c))),tr+=(*(rp)),tm+=(tr<(*(rp))),*(rp)=tr,*(c)=tm)
- #endif
-
-/* Itanium - inline the time-critical functions */
-
- #ifdef MR_ITANIUM
- #define muldvd(a,b,c,rp) (tm=_m64_xmahu((a),(b),(c)),*(rp)=_m64_xmalu((a),(b),(c)),tm)
- #define muldvd2(a,b,c,rp) (tm=_m64_xmalu((a),(b),(*(c))),*(c)=_m64_xmahu((a),(b),(*(c))),tm+=*(rp),*(c)+=(tm<*(rp)),*(rp)=tm)
- #endif
-#endif
-/*
-
-SSE2 code. Works as for itanium - but in fact it is slower than the regular code so not recommended
-Would require a call to emmintrin.h or xmmintrin.h, and an __m128i variable tm to be declared in effected
-functions. But it works!
-
- #define muldvd(a,b,c,rp) (tm=_mm_add_epi64(_mm_mul_epu32(_mm_cvtsi32_si128((a)),_mm_cvtsi32_si128((b))),_mm_cvtsi32_si128((c))),*(rp)=_mm_cvtsi128_si32(tm),_mm_cvtsi128_si32(_mm_shuffle_epi32(tm,_MM_SHUFFLE(3,2,0,1))) )
- #define muldvd2(a,b,c,rp) (tm=_mm_add_epi64(_mm_add_epi64(_mm_mul_epu32(_mm_cvtsi32_si128((a)),_mm_cvtsi32_si128((b))),_mm_cvtsi32_si128(*(c))),_mm_cvtsi32_si128(*(rp))),*(rp)=_mm_cvtsi128_si32(tm),*(c)=_mm_cvtsi128_si32( _mm_shuffle_epi32(tm,_MM_SHUFFLE(3,2,0,1)) )
-*/
-
-/* Borland C/Turbo C */
-
- #ifdef __TURBOC__
- #ifndef __HUGE__
- #if defined(__COMPACT__) || defined(__LARGE__)
- #define MR_LMM
- #endif
-
- #if MIRACL==16
- #define INLINE_ASM 1
- #endif
-
- #if __TURBOC__>=0x410
- #if MIRACL==32
-#if defined(__SMALL__) || defined(__MEDIUM__) || defined(__LARGE__) || defined(__COMPACT__)
- #define INLINE_ASM 2
- #else
- #define INLINE_ASM 3
- #endif
- #endif
- #endif
- #endif
- #endif
-
-/* Microsoft C */
-
- #ifdef _MSC_VER
- #ifndef M_I86HM
- #if defined(M_I86CM) || defined(M_I86LM)
- #define MR_LMM
- #endif
- #if _MSC_VER>=600
- #if _MSC_VER<1200
- #if MIRACL==16
- #define INLINE_ASM 1
- #endif
- #endif
- #endif
- #if _MSC_VER>=1000
- #if _MSC_VER<1500
- #if MIRACL==32
- #define INLINE_ASM 3
- #endif
- #endif
- #endif
- #endif
- #endif
-
-/* DJGPP GNU C */
-
- #ifdef __GNUC__
- #ifdef i386
- #if MIRACL==32
- #define INLINE_ASM 4
- #endif
- #endif
- #endif
-
-#endif
-
-
-
-/*
- The following contribution is from Tielo Jongmans, Netherlands
- These inline assembler routines are suitable for Watcom 10.0 and up
-
- Added into miracl.h. Notice the override of the original declarations
- of these routines, which should be removed.
-
- The following pragma is optional, it is dangerous, but it saves a
- calling sequence
-*/
-
-/*
-
-#pragma off (check_stack);
-
-extern unsigned int muldiv(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int *);
-#pragma aux muldiv= \
- "mul edx" \
- "add eax,ebx" \
- "adc edx,0" \
- "div ecx" \
- "mov [esi],edx" \
- parm [eax] [edx] [ebx] [ecx] [esi] \
- value [eax] \
- modify [eax edx];
-
-extern unsigned int muldvm(unsigned int, unsigned int, unsigned int, unsigned int *);
-#pragma aux muldvm= \
- "div ebx" \
- "mov [ecx],edx" \
- parm [edx] [eax] [ebx] [ecx] \
- value [eax] \
- modify [eax edx];
-
-extern unsigned int muldvd(unsigned int, unsigned int, unsigned int, unsigned int *);
-#pragma aux muldvd= \
- "mul edx" \
- "add eax,ebx" \
- "adc edx,0" \
- "mov [ecx],eax" \
- "mov eax,edx" \
- parm [eax] [edx] [ebx] [ecx] \
- value [eax] \
- modify [eax edx];
-
-*/
-
-
-#endif
-
-
diff --git a/generator_cgo/include/mirdef.h b/generator_cgo/include/mirdef.h
deleted file mode 100644
index 54fa13a..0000000
--- a/generator_cgo/include/mirdef.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * MIRACL compiler/hardware definitions - mirdef.h
- */
-
-#define MR_LITTLE_ENDIAN
-#define MIRACL 64
-#define mr_utype long long
-#define mr_unsign64 unsigned long long
-#define MR_IBITS 32
-#define MR_LBITS 64
-#define mr_unsign32 unsigned int
-#define MR_FLASH 52
-#define MAXBASE ((mr_small)1<<(MIRACL-1))
-#define MR_BITSINCHAR 8
-
diff --git a/generator_cgo/include/sign.h b/generator_cgo/include/sign.h
deleted file mode 100644
index 20ca11f..0000000
--- a/generator_cgo/include/sign.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef __SIGN_H__
-#define __SIGN_H__
-
-#include "ecurve.h"
-#include "miracl.h"
-#include "mirdef.h"
-#include
-
-void getFullkey(
- ECC_PARAMS *params,
- char *ID, // 用户ID
- big d, // 用户部分私钥
- big x, // 用户秘密值
- epoint *X, // 用户公钥
- big sa // 用户完整私钥
-);
-
-void sign_Thumbur(
- ECC_PARAMS *params,
- char *ID, // 用户ID
- char *msg, // 签名消息
- big sa, // 用户完整私钥
- epoint *Q, // 用户完整公钥
- epoint *U, // 输出签名的随机数变换
- epoint *PK_pub, //kgc公钥
- big v // 输出签名的计算值
-);
-
-bool verify_Thumbur(
- ECC_PARAMS *params,
- char *ID,
- char *msg,
- epoint *Q,
- epoint *PK_pub,
- epoint *U,
- big v
-);
-
-#endif
\ No newline at end of file
diff --git a/generator_cgo/include/utils.h b/generator_cgo/include/utils.h
deleted file mode 100644
index 90ad46f..0000000
--- a/generator_cgo/include/utils.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef __UNTILS_H__
-#define __UNTILS_H__
-
-
-#include "miracl.h"
-#include "mirdef.h"
-#include "ecurve.h"
-
-void outbig(big num, char *val_name);
-
-void outpoint(epoint *PO, char *val_name);
-
-void setRandSeed();
-
-void sha256_update_string(sha256 sh, const char *data, long data_len);
-
-void sha256_update_point(sha256 sh, epoint *point);
-
-void genSecret(ECC_PARAMS *params, big x, epoint *X);
-
-bool Setup();
-
-
-#endif
\ No newline at end of file
diff --git a/generator_cgo/include/zzn.h b/generator_cgo/include/zzn.h
deleted file mode 100644
index 850df10..0000000
--- a/generator_cgo/include/zzn.h
+++ /dev/null
@@ -1,219 +0,0 @@
-
-/***************************************************************************
- *
-Copyright 2013 CertiVox UK Ltd. *
- *
-This file is part of CertiVox MIRACL Crypto SDK. *
- *
-The CertiVox MIRACL Crypto SDK provides developers with an *
-extensive and efficient set of cryptographic functions. *
-For further information about its features and functionalities please *
-refer to http://www.certivox.com *
- *
-* The CertiVox MIRACL Crypto SDK is free software: you can *
- redistribute it and/or modify it under the terms of the *
- GNU Affero General Public License as published by the *
- Free Software Foundation, either version 3 of the License, *
- or (at your option) any later version. *
- *
-* The CertiVox MIRACL Crypto SDK is distributed in the hope *
- that it will be useful, but WITHOUT ANY WARRANTY; without even the *
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- See the GNU Affero General Public License for more details. *
- *
-* You should have received a copy of the GNU Affero General Public *
- License along with CertiVox MIRACL Crypto SDK. *
- If not, see . *
- *
-You can be released from the requirements of the license by purchasing *
-a commercial license. Buying such a license is mandatory as soon as you *
-develop commercial activities involving the CertiVox MIRACL Crypto SDK *
-without disclosing the source code of your own applications, or shipping *
-the CertiVox MIRACL Crypto SDK with a closed source product. *
- *
-***************************************************************************/
-/*
- *
- * MIRACL C++ Header file zzn.h
- *
- * AUTHOR : M. Scott
- *
- * PURPOSE : Definition of class ZZn (Arithmetic mod n), using
- * Montgomery's Method for modular multiplication
- * NOTE : Must be used in conjunction with zzn.cpp
- * The modulus n is always set dynamically (via the modulo()
- * routine) - so beware the pitfalls implicit in declaring
- * static or global ZZn's (which are initialised before n is
- * set!). Uninitialised data is OK
- */
-
-#ifndef ZZN_H
-#define ZZN_H
-
-#include "big.h"
-
-/*
-
-#ifdef ZZNS
-#define MR_INIT_ZZN memset(mem,0,mr_big_reserve(1,ZZNS)); fn=(big)mirvar_mem_variable(mem,0,ZZNS);
-#define MR_CLONE_ZZN(x) fn->len=x->len; for (int i=0;iw[i]=x->w[i];
-#define MR_ZERO_ZZN {fn->len=0; for (int i=0;iw[i]=0;}
-#else
-#define MR_INIT_ZZN mem=(char *)memalloc(1); fn=(big)mirvar_mem(mem,0);
-#define MR_CLONE_ZZN(x) copy(x,fn);
-#define MR_ZERO_ZZN zero(fn);
-#endif
-
-*/
-
-#ifdef ZZNS
-#ifdef MR_COMBA
-#define UZZNS ZZNS
-#else
-#define UZZNS ZZNS+1 // one extra required in case of carry overflow in addition
-#endif
-#endif
-
-#ifdef ZZNS
-#define MR_INIT_ZZN fn=&b; b.w=a; b.len=UZZNS;
-#define MR_CLONE_ZZN(x) b.len=x->len; for (int i=0;iw[i];
-#define MR_ZERO_ZZN {b.len=0; for (int i=0;i ZZn */
- ZZn(big& c) {MR_INIT_ZZN MR_CLONE_ZZN(c);}
- ZZn(const ZZn& c) {MR_INIT_ZZN MR_CLONE_ZZN(c.fn);}
- ZZn(char* s) {MR_INIT_ZZN cinstr(fn,s); nres(fn,fn);}
-
- ZZn& operator=(const ZZn& c) {MR_CLONE_ZZN(c.fn) return *this;}
- ZZn& operator=(big c) {MR_CLONE_ZZN(c) return *this; }
-
- ZZn& operator=(int i) {if (i==0) MR_ZERO_ZZN else {convert(i,fn); nres(fn,fn);} return *this;}
- ZZn& operator=(char* s){cinstr(fn,s); nres(fn,fn); return *this;}
-
-
-/* Use fast in-line code */
-
- ZZn& operator++()
- {nres_modadd(fn,get_mip()->one,fn);return *this;}
- ZZn& operator--()
- {nres_modsub(fn,get_mip()->one,fn);return *this;}
- ZZn& operator+=(int i)
- {ZZn inc=i; nres_modadd(fn,inc.fn,fn);return *this;}
- ZZn& operator-=(int i)
- {ZZn dec=i; nres_modsub(fn,dec.fn,fn); return *this;}
- ZZn& operator+=(const ZZn& b)
- {nres_modadd(fn,b.fn,fn); return *this;}
- ZZn& operator-=(const ZZn& b)
- {nres_modsub(fn,b.fn,fn); return *this;}
- ZZn& operator*=(const ZZn& b)
- {nres_modmult(fn,b.fn,fn); return *this;}
- ZZn& operator*=(int i)
- {nres_premult(fn,i,fn); return *this;}
-
- ZZn& negate()
- {nres_negate(fn,fn); return *this;}
-
- BOOL iszero() const;
-
- operator Big() {Big c; redc(fn,c.getbig()); return c;} /* ZZn -> Big */
- friend big getbig(ZZn& z) {return z.fn;}
-
- ZZn& operator/=(const ZZn& b) {nres_moddiv(fn,b.fn,fn); return *this;}
- ZZn& operator/=(int);
-
- friend ZZn operator-(const ZZn&);
- friend ZZn operator+(const ZZn&,int);
- friend ZZn operator+(int, const ZZn&);
- friend ZZn operator+(const ZZn&, const ZZn&);
-
- friend ZZn operator-(const ZZn&, int);
- friend ZZn operator-(int, const ZZn&);
- friend ZZn operator-(const ZZn&, const ZZn&);
-
- friend ZZn operator*(const ZZn&,int);
- friend ZZn operator*(int, const ZZn&);
- friend ZZn operator*(const ZZn&, const ZZn&);
-
- friend ZZn operator/(const ZZn&, int);
- friend ZZn operator/(int, const ZZn&);
- friend ZZn operator/(const ZZn&, const ZZn&);
-
- friend BOOL operator==(const ZZn& b1,const ZZn& b2)
- { if (mr_compare(b1.fn,b2.fn)==0) return TRUE; else return FALSE;}
- friend BOOL operator!=(const ZZn& b1,const ZZn& b2)
- { if (mr_compare(b1.fn,b2.fn)!=0) return TRUE; else return FALSE;}
-
- friend ZZn one(void);
- friend ZZn pow( const ZZn&, const Big&);
- friend ZZn pow( const ZZn&,int);
- friend ZZn powl(const ZZn&, const Big&);
- friend ZZn pow( const ZZn&, const Big&, const ZZn&, const Big&);
- friend ZZn pow( int,ZZn *,Big *);
- friend int jacobi(const ZZn&);
-#ifndef MR_NO_RAND
- friend ZZn randn(void); // random number < modulus
-#endif
- friend BOOL qr(const ZZn&); // test for quadratic residue
- friend BOOL qnr(const ZZn&); // test for quadratic non-residue
- friend ZZn getA(void); // get A parameter of elliptic curve
- friend ZZn getB(void); // get B parameter of elliptic curve
-
- friend ZZn sqrt(const ZZn&); // only works if modulus is prime
-
- friend ZZn luc( const ZZn& b1, const Big& b2, ZZn* b3=NULL)
- {
- ZZn z; if (b3!=NULL) nres_lucas(b1.fn,b2.getbig(),b3->fn,z.fn);
- else nres_lucas(b1.fn,b2.getbig(),z.fn,z.fn);
- return z;
- }
-
- //friend ZZn luc( const ZZn&, const Big&, ZZn* b3=NULL);
-
- big getzzn(void) const;
-
-#ifndef MR_NO_STANDARD_IO
- friend ostream& operator<<(ostream&,const ZZn&);
-#endif
-
-
- ~ZZn()
- {
- // MR_ZERO_ZZN // slower but safer
-#ifndef ZZNS
- mr_free(fn);
-#endif
- }
-};
-#ifndef MR_NO_RAND
-extern ZZn randn(void);
-#endif
-extern ZZn getA(void);
-extern ZZn getB(void);
-extern ZZn one(void);
-
-#endif
-
diff --git a/generator_cgo/lib/libKGC.a b/generator_cgo/lib/libKGC.a
deleted file mode 100644
index ca2796e..0000000
Binary files a/generator_cgo/lib/libKGC.a and /dev/null differ
diff --git a/generator_cgo/lib/libKGCAll.a b/generator_cgo/lib/libKGCAll.a
deleted file mode 100644
index 45524e6..0000000
Binary files a/generator_cgo/lib/libKGCAll.a and /dev/null differ
diff --git a/generator_cgo/lib/libMiracl.a b/generator_cgo/lib/libMiracl.a
deleted file mode 100644
index 34cf199..0000000
Binary files a/generator_cgo/lib/libMiracl.a and /dev/null differ
diff --git a/generator_cgo/main.go b/generator_cgo/main.go
deleted file mode 100644
index 61e3130..0000000
--- a/generator_cgo/main.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package main
-
-/*
-#cgo CFLAGS: -I./include
-#cgo LDFLAGS: -L./lib -lKGCAll
-#include "miracl.h"
-#include "mirdef.h"
-#include "hash.h"
-#include "kgc.h"
-#include "utils.h"
-#include "ecurve.h"
-#include "sign.h"
-
-#include "utils.cpp"
-#include "ecurve.cpp"
-#include "hash.cpp"
-#include "sign.cpp"
-#include "kgc.cpp"
-#include
-#include
-#include
-char* IDA = "1234567890111213141516171819202122232425"; // 发送者ID
-char* IDB = "1448579437597582757693565726417498574267"; // 接受者ID
-char* M = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
-char* msk = "msk";
-char* PKP = "PK_pub";
-char* Public = "P_P";
-char* QA = "Q_A";
-char* dA = "d_A";
-char* xA = "x_A";
-char* XA = "X_A";
-char* saA = "sa_A";
-*/
-import "C"
-import "fmt"
-
-func main() {
-
- mip := C.mirsys(512, 16) // 初始化MIRACL系统,512位,16进制数
- mip.IOBASE = 16 // 设置大整数为16进制
- a := C.mirvar(0)
- C.mirkill(a)
- C.setRandSeed()
-
- // 建立椭圆曲线
- var params C.ECC_PARAMS
- if !C.setupEcurve(¶ms) {
- fmt.Println("ecurve setup failed")
- C.mirexit()
- panic("椭圆曲线建立失败!")
- }
-
- C.setRandSeed() // 随机数种子
- //初始化参数
- msk := C.mirvar(0) //私钥
- PK_pub := C.epoint_init() //公钥
- d_A := C.mirvar(0) //用户A产生的部分私钥
- x_A := C.mirvar(0) //用户产生的秘密值
- X_A := C.epoint_init()
- sa_A := C.mirvar(0) //用户完整私钥
- Q_A := C.epoint_init() //用户完整公钥
- val := C.mirvar(0) //用户返回的签名值
- U := C.epoint_init() //随机点值
-
- // 产生KGC密钥对: msk, PK_pub
- C.genKGCkey(¶ms, msk, PK_pub)
- C.outbig(msk, C.msk)
-
- C.outpoint((¶ms).P, C.Public)
- C.outpoint(PK_pub, C.PKP)
-
- // 产生用户A的秘密值
- C.genSecret(¶ms, x_A, X_A)
- C.outbig(x_A, C.xA)
- C.outpoint(X_A, C.XA)
-
- // 产生用户A的部分私钥和用户的完整公钥
- if !C.genPPK_std(¶ms, msk, PK_pub, C.IDA, d_A, Q_A, X_A) {
- fmt.Println("Generate PPK for IDA failed.")
- goto error
- }
- C.outbig(d_A, C.dA)
- C.outpoint(Q_A, C.QA)
-
- // 输出完整的用户私钥
- C.getFullkey(¶ms, C.IDA, d_A, x_A, X_A, sa_A)
- C.outbig(sa_A, C.saA)
-
- // 签名,Gowri Thumbur方案
- C.sign_Thumbur(¶ms, C.IDA, C.M, sa_A, Q_A, U, PK_pub, val)
-
- // 验签
- if C.verify_Thumbur(¶ms, C.IDA, C.M, Q_A, PK_pub, U, val) {
- fmt.Println("\nsignature valid.")
- } else {
- fmt.Println("\nverify failed.")
- }
-
-error:
- C.mirkill(msk)
- C.mirkill(d_A)
- C.mirkill(x_A)
- C.mirkill(sa_A)
- C.epoint_free(PK_pub)
- C.epoint_free(X_A)
- C.epoint_free(Q_A)
- C.epoint_free(U)
-
- C.freeEcurve(¶ms)
- C.mirexit() // 退出MIRACL系统
-
-}
diff --git a/generator_cgo/params.txt b/generator_cgo/params.txt
deleted file mode 100644
index 84ed46b..0000000
--- a/generator_cgo/params.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-char str_msk[] = "6D5DB11261A93275CD69A813F6CA4FE84A5613B346D27AFEFAF3D63D0DF307A7";
-char str_P_P_x[]= "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798";
-char str_P_P_y[]= "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8";
-char str_PK_pub_x[]= "6C723EBEDA3B3FF230BEFEB870DBCF38271F609A09E949FA06E512C74FEB4E76";
-char str_PK_pub_y[]= "5FAE4EB8F8B38B401C231D4EB682E53977A62663169B1B1908F4906E4758DD7C";
-char str_x_A[] = "80A80E35FB678995DE03E0DE6DCA75651D48D57C82923C4F8097A7CF80FFDC0F";
-char str_X_A_x[]= "3E9FD587517E568102447F7BFDA9955EAFF9F8984DE497813269546ADAB30D8A";
-char str_X_A_y[]= "3AC044504324E5FD14D16FC396133EE7FD4B4743E0F4F3245BF69F3634CD74F4";
-char str_d_A[] = "37F0619702B66C78D898A2135FAF59AFF5439BBA388FB114CEDA6180FF8E395C";
-char str_sa_A[] = "6A7C930DDCFE3B505D5AD7824B63ABA9110883D261CE67C04AF01E395E248766";
-char str_Q_A_x[]= "6E87706053DD52225354602E031A1D025115B54B8C600D3C47AB66749D0852DC";
-char str_Q_A_y[]= "71C165DCBF5E07903517A5AAB4919104229A1E65D6D57C23B95147ED79BA23E4";
-char str_v[] = "33979BEB2B89412DEA04EC7DD07FF8F98792F490A6A519AE64766BAE30B7874A";
-signature valid.
-
-用户ID:char* IDA = "1234567890111213141516171819202122232425";
-用户私钥:char str_sa_A[] = "6A7C930DDCFE3B505D5AD7824B63ABA9110883D261CE67C04AF01E395E248766";
-用户公钥:char str_Q_A_x[]= "6E87706053DD52225354602E031A1D025115B54B8C600D3C47AB66749D0852DC";
- char str_Q_A_y[]= "71C165DCBF5E07903517A5AAB4919104229A1E65D6D57C23B95147ED79BA23E4";
diff --git a/generator_cgo/include/hash.cpp b/hash.c
similarity index 100%
rename from generator_cgo/include/hash.cpp
rename to hash.c
diff --git a/hash.cpp b/hash.cpp
deleted file mode 100644
index 82e9d5b..0000000
--- a/hash.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-#include
-#include "hash.h"
-#include "ecurve.h"
-#include "utils.h"
-
-void hash1(char *ID, epoint *Q, epoint *PK_pub, big p, big h_1_big)
-{
- // 计算hash值H_1(ID, R, PK_pub)
- //hash1(ID, Q, PK_pub)
- sha256 sh;
- char h_1[33] = {0};
-
- shs256_init(&sh);
- sha256_update_string(sh, ID, strlen(ID));
- sha256_update_point(sh, Q);
- sha256_update_point(sh, PK_pub);
- shs256_hash(&sh, h_1);
-
- bytes_to_big(32, h_1, h_1_big);
- power(h_1_big, 1, p, h_1_big); // mod p
-}
-
-void hash2(char *ID, epoint *X, big p, big h_2_big)
-{
- // 计算hash值H_2(ID, X)
- sha256 sh;
- char h_2[33] = {0};
-
- shs256_init(&sh);
- sha256_update_string(sh, ID, strlen(ID));
- sha256_update_point(sh, X);
- shs256_hash(&sh, h_2);
-
- bytes_to_big(32, h_2, h_2_big);
- power(h_2_big, 1, p, h_2_big); // mod p
-}
-
-void hash3(
- char *ID,
- char *msg,
- epoint *Q,
- epoint *U,
- epoint *PK_pub,
- big p,
- big h_3_big
-)
-{
- sha256 sh;
- char h_3[33] = {0};
-
- shs256_init(&sh);
- sha256_update_string(sh, ID, strlen(ID));
- sha256_update_string(sh, msg, strlen(msg));
- sha256_update_point(sh, Q);
- sha256_update_point(sh, U);
- sha256_update_point(sh, PK_pub);
- shs256_hash(&sh, h_3);
-
- bytes_to_big(32, h_3, h_3_big);
- power(h_3_big, 1, p, h_3_big); // mod p
-}
diff --git a/hash.h b/hash.h
index aab82a8..5e3a0e8 100644
--- a/hash.h
+++ b/hash.h
@@ -1,11 +1,9 @@
#ifndef __HASH_H__
#define __HASH_H__
-extern "C"
-{
+#include
#include "miracl.h"
#include "mirdef.h"
-}
//hash1(ID, Q, PK_pub, h_1_big)
void hash1(char *ID, epoint *Q, epoint *PK_pub, big p, big h_1_big);
diff --git a/generator_cgo/include/kgc.cpp b/kgc.c
similarity index 100%
rename from generator_cgo/include/kgc.cpp
rename to kgc.c
diff --git a/kgc.cpp b/kgc.cpp
deleted file mode 100644
index 4d9e0aa..0000000
--- a/kgc.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-#include
-#include "kgc.h"
-#include "hash.h"
-
-void genKGCkey(ECC_PARAMS *params, big msk, epoint *PK_pub)
-{
- bigrand((*params).p, msk); // 产生小于p的随机数
- ecurve_mult(msk, (*params).P, PK_pub);
-}
-
-bool genPPK_std(
- ECC_PARAMS *params,
- big msk, // KGC私钥
- epoint *PK_pub, // KGC公钥
- char ID[], // 输入用户ID
- big d, // 输出部分私钥
- epoint *Q, // 产生的用户公钥
- epoint *X) // 输入用户秘密值
-{
- // 产生随机数r,计算R=rP
- epoint *R_A = epoint_init();
- big r = mirvar(0);
- bigrand((*params).p, r);
- ecurve_mult(r, (*params).P, R_A);
-
- //计算h_2 = H_2(ID,X)
- big h_2_big = mirvar(0);
- hash2(ID, X, (*params).p, h_2_big);
-
- //计算h_2 * X
- epoint *h2X = epoint_init();
- ecurve_mult(h_2_big, X, h2X);
-
- //计算Q = R + h_2 * X
- ecurve_add(R_A, Q);
- ecurve_add(h2X, Q);
-
- //计算h_1 = H_1(ID,Q,PK_pub)
- big h_1_big = mirvar(0);
- hash1(ID, Q, PK_pub, (*params).p, h_1_big);
-
- // 计算d = r + msk * h_1 mod p
- big tmp = mirvar(0);
- multiply(msk, h_1_big, tmp);
- add(r, tmp, d);
- power(d, 1, (*params).p, d); // mod p
-
- //计算h_1 * PK_pub
- epoint *h1PK = epoint_init();
- ecurve_mult(h_1_big, PK_pub, h1PK);
-
- // 用d * P = Q - h2 * X + h1 * PK_pub验证一下(d,Q)是否正确
- // 点的减法 pa = pa - a Function: void ecurve_sub(p,pa)
- epoint *left = epoint_init();
- ecurve_mult(d, (*params).P, left);
- epoint *right = epoint_init();
- ecurve_add(Q, right);
- ecurve_sub(h2X, right);
- ecurve_add(h1PK, right);
-
- bool bRv = false;
- if (epoint_comp(left, right))
- {
- bRv = true;
-
- }
- else
- {
- bRv = false;
- }
-
- mirkill(r);
- mirkill(h_1_big);
- mirkill(h_2_big);
- mirkill(tmp);
-
- epoint_free(R_A);
- epoint_free(left);
- epoint_free(right);
- epoint_free(h1PK);
- epoint_free(h2X);
-
- return bRv;
-}
\ No newline at end of file
diff --git a/miracl/CMakeLists.txt b/miracl/CMakeLists.txt
index f985024..60be99f 100644
--- a/miracl/CMakeLists.txt
+++ b/miracl/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
-project(Miracl)
+project(Miracl LANGUAGES C)
include(GNUInstallDirs)
diff --git a/generator_cgo/include/sign.cpp b/sign.c
similarity index 100%
rename from generator_cgo/include/sign.cpp
rename to sign.c
diff --git a/sign.cpp b/sign.cpp
deleted file mode 100644
index 852ee76..0000000
--- a/sign.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-
-#include
-#include "sign.h"
-#include "hash.h"
-#include "utils.h"
-
-void getFullkey(
- ECC_PARAMS *params,
- char *ID, // 用户ID
- big d, // 用户部分私钥
- big x, // 用户秘密值
- epoint *X, // 用户公钥
- big sa // 用户完整私钥
-)
-{
- // 计算hash值H_2(ID, X)
- big h_2_big = mirvar(0);
- hash2(ID, X, (*params).p, h_2_big);
-
- // 计算sa = d + h_2*x mod p
- big tmp = mirvar(0);
- multiply(x, h_2_big, tmp);
- add(d, tmp, sa);
- power(sa, 1, (*params).p, sa); // mod p
-
- mirkill(h_2_big);
- mirkill(tmp);
-}
-
-void sign_Thumbur(
- ECC_PARAMS *params,
- char *ID, // 用户ID
- char *msg, // 签名消息
- big sa, // 输入用户完整私钥
- epoint *Q, // 输入用户完整公钥
- epoint *U, // 输出签名的随机数变换
- epoint *PK_pub, //输入KGC的公钥
- big v // 输出签名的计算值
-)
-{
- // 产生随机数u,计算U=uP
- big u = mirvar(0);
- bigrand((*params).p, u);
- ecurve_mult(u, (*params).P, U);
-
- // 计算hash值H_3(ID, msg, Q, U, PK_pub)
- big h_3_big = mirvar(0);
- hash3(ID, msg, Q, U, PK_pub, (*params).p, h_3_big);
-
- // 计算签名值 v = u + h_3*sa
- big tmp = mirvar(0);
- multiply(sa, h_3_big, tmp);
- add(u, tmp, v);
- power(v, 1, (*params).p, v); // mod p
- outbig(v, "v");
-
- mirkill(u);
- mirkill(h_3_big);
- mirkill(tmp);
-}
-
-bool verify_Thumbur(
- ECC_PARAMS *params,
- char *ID,
- char *msg,
- epoint *Q,
- epoint *PK_pub,
- epoint *U,
- big v
-)
-{
- // 计算hash值H_1(ID, Q, PK_pub)
- big h_1_big = mirvar(0);
- hash1(ID, Q, PK_pub, (*params).p, h_1_big);
-
- // 计算hash值H_3(ID, msg, Q, U, PK_pub)
- big h_3_big = mirvar(0);
- hash3(ID, msg, Q, U, PK_pub, (*params).p, h_3_big);
-
- // 验签等式 v*P = U + h_3(Q + h_1*P_pub)
- // 等式左边:
- epoint *left = epoint_init();
- ecurve_mult(v, (*params).P, left);
-
- // 等式右边:
- epoint *tmp_p = epoint_init();
- ecurve_mult(h_1_big, PK_pub, tmp_p);
- ecurve_add(Q, tmp_p);
- ecurve_mult(h_3_big, tmp_p, tmp_p);
- ecurve_add(U, tmp_p);
-
- bool bRv = false;
- if (epoint_comp(left, tmp_p))
- {
- bRv = true;
- }
- else
- {
- bRv = false;
- }
-
- mirkill(h_1_big);
- mirkill(h_3_big);
- epoint_free(left);
- epoint_free(tmp_p);
- return bRv;
-}
\ No newline at end of file
diff --git a/generator_cgo/include/utils.cpp b/utils.c
similarity index 100%
rename from generator_cgo/include/utils.cpp
rename to utils.c
diff --git a/utils.cpp b/utils.cpp
deleted file mode 100644
index 394c78c..0000000
--- a/utils.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#include
-#include
-#include
-#include "utils.h"
-#include "ecurve.h"
-#include "kgc.h"
-
-//将big大数类型转为char*类型
-void outbig(big num, char *val_name)
-{
- char out_str[257] = {0};
- cotstr(num, out_str);
- printf("\nchar str_%s[] = \"%s\";", val_name, out_str);
-}
-
-//将big大数类型转为char*类型
-void outpoint(epoint *PO, char *val_name)
-{
- char out_str[257] = {0};
- big PO_x = mirvar(0);
- big PO_y = mirvar(0);
- epoint_get(PO, PO_x, PO_y);
- cotstr(PO_x, out_str);
- printf("\nchar str_%s_x[]= \"%s\";", val_name, out_str);
- cotstr(PO_y, out_str);
- printf("\nchar str_%s_y[]= \"%s\";", val_name, out_str);
-}
-
-// 设置随机数种子
-void setRandSeed()
-{
- time_t seed;
- time(&seed); // 用系统时间做种子
- irand((long)seed);
- return;
-}
-
-//
-void sha256_update_string(sha256 sh, const char *data, long data_len)
-{
- for (long i = 0; i < data_len; i++)
- {
- shs256_process(&sh, data[i]);
- }
-}
-
-void sha256_update_point(sha256 sh, epoint *point)
-{
- big point_x = mirvar(0);
- big point_y = mirvar(0);
- char point_x_string[256] = {0};
- char point_y_string[256] = {0};
- epoint_get(point, point_x, point_y);
- cotstr(point_x, point_x_string);
- cotstr(point_y, point_y_string);
-
- for (unsigned int i = 0; i < strlen(point_x_string); i++)
- {
- shs256_process(&sh, point_x_string[i]);
- }
-
- for (unsigned int i = 0; i < strlen(point_y_string); i++)
- {
- shs256_process(&sh, point_y_string[i]);
- }
-
- mirkill(point_x);
- mirkill(point_y);
-}
-
-//用户产生秘密值x,以及与基点点乘后的X
-void genSecret(ECC_PARAMS *params, big x, epoint *X)
-{
- bigrand((*params).p, x); //产生小于阶p的big值
- ecurve_mult(x, (*params).P, X);
-}
diff --git a/utils.h b/utils.h
index 10e70d6..9ad9669 100644
--- a/utils.h
+++ b/utils.h
@@ -1,11 +1,8 @@
#ifndef __UNTILS_H__
#define __UNTILS_H__
-extern "C"
-{
#include "miracl.h"
#include "mirdef.h"
-}
#include "ecurve.h"
void outbig(big num, char *val_name);