some bugs fixed

This commit is contained in:
www-git-cn 2024-04-28 23:29:26 +08:00
parent 9ae943083c
commit f9aab3b79f
48 changed files with 11 additions and 4290 deletions

5
.gitignore vendored
View File

@ -21,3 +21,8 @@
# Go workspace file
go.work
# QtCreator CMake
CMakeLists.txt.user*
#CMake
build/

View File

@ -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()

View File

@ -1,418 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.0, 2024-04-28T16:42:20. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{7795ecad-0ea3-4fc2-a933-fbc01bf1ad55}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">2</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">2</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 6.5.3 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 6.5.3 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt6.653.win64_mingw_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="CMake.Build.Type">Debug</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="CMake.Build.Type">Release</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="CMake.Build.Type">RelWithDebInfo</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-RelWithDebInfo</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release with Debug Information</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.3">
<value type="QString" key="CMake.Build.Type">RelWithDebInfo</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.4">
<value type="QString" key="CMake.Build.Type">MinSizeRel</value>
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\KGC\build\Desktop_Qt_6_5_3_MinGW_64_bit-MinSizeRel</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.BuildPreset"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="CMakeProjectManager.MakeStep.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.UserEnvironmentChanges"/>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Minimum Size Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">5</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph &quot;dwarf,4096&quot; -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

View File

@ -1,11 +1,9 @@
#ifndef __ECURVE_H__
#define __ECURVE_H__
extern "C"
{
#include <stdbool.h>
#include "miracl.h"
#include "mirdef.h"
}
typedef struct ecc_params
{

View File

@ -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

View File

@ -1 +0,0 @@
main.go

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/cgo.iml" filepath="$PROJECT_DIR$/.idea/cgo.iml" />
</modules>
</component>
</project>

View File

@ -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}"
}
]
}

View File

@ -1,3 +0,0 @@
module example.com/m/v2
go 1.20

View File

View File

@ -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 <http://www.gnu.org/licenses/>. *
*
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 <cstdlib>
//#include <cmath>
#include <cstdio>
#include "mirdef.h"
#ifdef MR_CPP
#include "miracl.h"
#else
extern "C"
{
#include "miracl.h"
}
#endif
#ifndef MR_NO_STANDARD_IO
#include <iostream>
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;i<BIGS;i++) a[i]=0;
#else
#define MR_INIT_BIG fn=mirvar(0);
#endif
class Big
{
big fn;
/*
#ifdef BIGS
char mem[mr_big_reserve(1,BIGS)];
#else
char *mem;
#endif
*/
#ifdef BIGS
mr_small a[BIGS];
bigtype b;
#endif
public:
Big() {MR_INIT_BIG }
Big(int j) {MR_INIT_BIG convert(j,fn); }
Big(unsigned int j) {MR_INIT_BIG uconvert(j,fn); }
Big(long lg) {MR_INIT_BIG lgconv(lg,fn);}
Big(unsigned long lg) {MR_INIT_BIG ulgconv(lg,fn);}
#ifdef MR_UTYPE_NOT_INT_OR_LONG
Big(mr_utype ut) {MR_INIT_BIG tconvert(ut,fn);}
#endif
#ifdef mr_dltype
#ifndef MR_DLTYPE_IS_INT
#ifndef MR_DLTYPE_IS_LONG
Big(mr_dltype dl) {MR_INIT_BIG dlconv(dl,fn);}
#endif
#endif
#endif
#ifndef MR_SIMPLE_IO
#ifdef MR_SIMPLE_BASE
Big(char* s) {MR_INIT_BIG instr(fn,s);}
#else
Big(char* s) {MR_INIT_BIG cinstr(fn,s);}
#endif
#endif
Big(big& c) {MR_INIT_BIG copy(c,fn);}
Big(const Big& c) {MR_INIT_BIG copy(c.fn,fn);}
Big(big* c) { fn=*c; }
Big& operator=(int i) {convert(i,fn); return *this;}
Big& operator=(long lg){lgconv(lg,fn); return *this;}
#ifdef MR_UTYPE_NOT_INT_OR_LONG
Big& operator=(mr_utype ut){tconvert(ut,fn); return *this;}
#endif
#ifdef mr_dltype
#ifndef MR_DLTYPE_IS_INT
#ifndef MR_DLTYPE_IS_LONG
Big& operator=(mr_dltype dl){dlconv(dl,fn); return *this;}
#endif
#endif
#endif
Big& operator=(mr_small s) {fn->len=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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>. *
*
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 <cstring>
#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

View File

@ -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 <http://www.gnu.org/licenses/>. *
*
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 <cstring>
#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

View File

@ -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

View File

@ -1,70 +0,0 @@
#include "ecurve.h"
#include <stdbool.h>
// 使用的椭圆曲线(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);
}

View File

@ -1,23 +0,0 @@
#ifndef __ECURVE_H__
#define __ECURVE_H__
#include "miracl.h"
#include "mirdef.h"
#include <stdbool.h>
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

View File

@ -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<BIGS;i++) a[i]=0;
#else
#define MR_FINIT_BIG fn=mirvar(0);
#endif
class Flash
{ /* Flash Class Definitions */
flash fn; /* pointer to actual data */
#ifdef BIGS
mr_small a[BIGS];
bigtype b;
#endif
public:
Flash() {MR_FINIT_BIG}
Flash(int j) {MR_FINIT_BIG convert(j,fn); }
Flash(unsigned int j) {MR_FINIT_BIG uconvert(j,fn); }
Flash(int x,int y) {MR_FINIT_BIG fconv(x,y,fn); }
#ifdef mr_dltype
#ifndef MR_DLTYPE_IS_INT
Flash(mr_dltype dl) {MR_FINIT_BIG dlconv(dl,fn);}
#endif
#else
Flash(long lg) {MR_FINIT_BIG lgconv(lg,fn);}
#endif
Flash(double d) {MR_FINIT_BIG dconv(d,fn);}
Flash(const Flash& f) {MR_FINIT_BIG copy(f.fn, fn);}
Flash(const Big& c) {MR_FINIT_BIG copy(c.fn, fn);}
Flash(const Big& n,const Big& d) {MR_FINIT_BIG mround(n.fn,d.fn,fn);}
Flash(char* s) {MR_FINIT_BIG cinstr(fn,s);}
Flash& operator=(int i) {convert(i,fn); return *this;}
#ifdef mr_dltype
#ifndef MR_DLTYPE_IS_INT
Flash& operator=(mr_dltype dl){dlconv(dl,fn); return *this;}
#endif
#else
Flash& operator=(long lg){lgconv(lg,fn); return *this;}
#endif
Flash& operator=(double& d) {dconv(d,fn); return *this;}
Flash& operator=(const Flash& f) {copy(f.fn, fn); return *this;}
Flash& operator=(const Big& b) {copy(b.fn, fn); return *this;}
Flash& operator=(char* s) {cinstr(fn,s);return *this;}
Flash& operator++() {fincr(fn,1,1,fn); return *this;}
Flash& operator--() {fincr(fn,-1,1,fn); return *this;}
Flash& operator+=(const Flash& f) {fadd(fn,f.fn,fn); return *this;}
Flash& operator-=(const Flash& f) {fsub(fn,f.fn,fn); return *this;}
Flash& operator*=(const Flash& f) {fmul(fn,f.fn,fn); return *this;}
Flash& operator*=(int n) {fpmul(fn,n,1,fn); return *this;}
Flash& operator/=(const Flash& f) {fdiv(fn,f.fn,fn); return *this;}
Flash& operator/=(int n) {fpmul(fn,1,n,fn); return *this;}
Flash& operator%=(const Flash& f) {fmodulo(fn,f.fn,fn); return *this;}
Big trunc(Flash *rem=NULL);
Big num(void);
Big den(void);
BOOL iszero() const;
friend Flash operator-(const Flash&); /* unary - */
/* binary ops */
friend Flash operator+(const Flash&, const Flash&);
friend Flash operator-(const Flash&, const Flash&);
friend Flash operator*(const Flash&, const Flash&);
friend Flash operator/(const Flash&, const Flash&);
friend Flash operator%(const Flash&,const Flash&);
/* relational ops */
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 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

View File

@ -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 <cmath>
#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

View File

@ -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 <http://www.gnu.org/licenses/>. *
*
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;i<GF2MS;i++) fn->w[i]=x->w[i];
#define MR_ZERO_GF2M {fn->len=0; for (int i=0;i<GF2MS;i++) fn->w[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;i<GF2MS;i++) a[i]=x->w[i];
#define MR_ZERO_GF2M {b.len=0; for (int i=0;i<GF2MS;i++) a[i]=0;}
#else
#define MR_INIT_GF2M fn=mirvar(0);
#define MR_CLONE_GF2M(x) copy(x,fn);
#define MR_ZERO_GF2M zero(fn);
#endif
class GF2m
{
big fn;
/*
#ifdef GF2MS
char mem[mr_big_reserve(1,GF2MS)];
#else
char *mem;
#endif
*/
#ifdef GF2MS
mr_small a[GF2MS];
bigtype b;
#endif
public:
GF2m() {MR_INIT_GF2M MR_ZERO_GF2M}
GF2m(int j) {MR_INIT_GF2M if (j==0) MR_ZERO_GF2M else {convert(j,fn); reduce2(fn,fn);}}
GF2m(const Big& c) {MR_INIT_GF2M reduce2(c.getbig(),fn); } /* Big -> 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;i<GF2MS;i++)
fn->w[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

View File

@ -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

View File

@ -1,22 +0,0 @@
#ifndef __KGC_H__
#define __KGC_H__
#include "ecurve.h"
#include "miracl.h"
#include "mirdef.h"
#include <stdbool.h>
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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -1,39 +0,0 @@
#ifndef __SIGN_H__
#define __SIGN_H__
#include "ecurve.h"
#include "miracl.h"
#include "mirdef.h"
#include <stdbool.h>
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

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>. *
*
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;i<ZZNS;i++) fn->w[i]=x->w[i];
#define MR_ZERO_ZZN {fn->len=0; for (int i=0;i<ZZNS;i++) fn->w[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;i<UZZNS;i++) a[i]=x->w[i];
#define MR_ZERO_ZZN {b.len=0; for (int i=0;i<UZZNS;i++) a[i]=0;}
#else
#define MR_INIT_ZZN fn=mirvar(0);
#define MR_CLONE_ZZN(x) copy(x,fn);
#define MR_ZERO_ZZN zero(fn);
#endif
class ZZn
{
big fn;
#ifdef ZZNS
mr_small a[UZZNS];
bigtype b;
#endif
/*
#ifdef ZZNS
char mem[mr_big_reserve(1,ZZNS)];
#else
char *mem;
#endif
*/
public:
ZZn() {MR_INIT_ZZN MR_ZERO_ZZN}
ZZn(int i) {MR_INIT_ZZN if (i==0) MR_ZERO_ZZN else {convert(i,fn); nres(fn,fn);} }
ZZn(const Big& c) {MR_INIT_ZZN nres(c.getbig(),fn); } /* Big -> 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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
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(&params) {
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(&params, msk, PK_pub)
C.outbig(msk, C.msk)
C.outpoint((&params).P, C.Public)
C.outpoint(PK_pub, C.PKP)
// 产生用户A的秘密值
C.genSecret(&params, x_A, X_A)
C.outbig(x_A, C.xA)
C.outpoint(X_A, C.XA)
// 产生用户A的部分私钥和用户的完整公钥
if !C.genPPK_std(&params, 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(&params, C.IDA, d_A, x_A, X_A, sa_A)
C.outbig(sa_A, C.saA)
// 签名Gowri Thumbur方案
C.sign_Thumbur(&params, C.IDA, C.M, sa_A, Q_A, U, PK_pub, val)
// 验签
if C.verify_Thumbur(&params, 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(&params)
C.mirexit() // 退出MIRACL系统
}

View File

@ -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.
用户IDchar* IDA = "1234567890111213141516171819202122232425";
用户私钥char str_sa_A[] = "6A7C930DDCFE3B505D5AD7824B63ABA9110883D261CE67C04AF01E395E248766";
用户公钥char str_Q_A_x[]= "6E87706053DD52225354602E031A1D025115B54B8C600D3C47AB66749D0852DC";
char str_Q_A_y[]= "71C165DCBF5E07903517A5AAB4919104229A1E65D6D57C23B95147ED79BA23E4";

View File

@ -1,61 +0,0 @@
#include <string.h>
#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
}

4
hash.h
View File

@ -1,11 +1,9 @@
#ifndef __HASH_H__
#define __HASH_H__
extern "C"
{
#include <stdbool.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);

84
kgc.cpp
View File

@ -1,84 +0,0 @@
#include <string.h>
#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;
}

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(Miracl)
project(Miracl LANGUAGES C)
include(GNUInstallDirs)

107
sign.cpp
View File

@ -1,107 +0,0 @@
#include <string.h>
#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;
}

View File

@ -1,76 +0,0 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#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);
}

View File

@ -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);