【发布时间】:2020-01-23 20:57:34
【问题描述】:
我在为现有的学习代码构建解决方案时遇到了错误。我定义的预处理器是 Win32(应该如此),代码本身来自 https://www.nayuki.io/page/bitcoin-cryptography-library。该错误似乎是由long 值创建的,该值可能是导致此错误的原因(使用的是win32 而不是win64)。我试图克服以不同方式编写它(使用long/ulong/int)但没有成功。
static long long opsCount;
void countOps(long n){
opsCount += n;
}
有什么建议可以用其他方式编写并解决错误列表中的这种恶劣天气吗?
/*
* A runnable main program that calculates and prints the approximate
* number of 32-bit arithmetic operations needed to perform
* elliptic curve point multiplication, in this C++ implementation.
*
* Bitcoin cryptography library
* Copyright (c) Project Nayuki
*
* https://www.nayuki.io/page/bitcoin-cryptography-library
* https://github.com/nayuki/Bitcoin-Cryptography-Library
*/
#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <string>
#include "CountOps.hpp"
#include "CurvePoint.hpp"
#include "Ecdsa.hpp"
#include "FieldInt.hpp"
#include "Sha256.hpp"
#include "Sha256Hash.hpp"
#include "Uint256.hpp"
static long long opsCount;
void countOps(long n){
opsCount += n;
}
static void printOps(const char *name);
static void doUint256();
static void doFieldInt();
static void doCurvePoint();
static void doEcdsa();
int main() {
doUint256();
doFieldInt();
doCurvePoint();
doEcdsa();
return EXIT_SUCCESS;
}
static void doUint256() {
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x.replace(y, 1);
printOps("uiReplace");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x.swap(y, 1);
printOps("uiSwap");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x == y;
printOps("uiEquals");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x < y;
printOps("uiLessThan");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x.add(y);
printOps("uiAdd");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = Uint256::ONE;
opsCount = 0;
x.subtract(y);
printOps("uiSubtract");
}
{
Uint256 x = Uint256::ONE;
opsCount = 0;
x.shiftLeft1();
printOps("uiShiftLeft1");
}
{
Uint256 x = Uint256::ONE;
opsCount = 0;
x.shiftRight1();
printOps("uiShiftRight1");
}
{
Uint256 x = Uint256::ONE;
Uint256 y = CurvePoint::ORDER;
opsCount = 0;
x.reciprocal(y);
printOps("uiReciprocal");
}
std::cout << std::endl;
}
static void doFieldInt() {
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x.replace(y, 1);
printOps("fiReplace");
}
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x == y;
printOps("fiEquals");
}
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x < y;
printOps("fiLessThan");
}
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x.add(y);
printOps("fiAdd");
}
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x.subtract(y);
printOps("fiSubtract");
}
{
FieldInt x(Uint256::ONE);
opsCount = 0;
x.multiply2();
printOps("fiMultiply2");
}
{
FieldInt x(Uint256::ONE);
FieldInt y(Uint256::ONE);
opsCount = 0;
x.multiply(y);
printOps("fiMultiply");
}
{
FieldInt x(Uint256::ONE);
opsCount = 0;
x.square();
printOps("fiSquare");
}
{
FieldInt x(Uint256::ONE);
opsCount = 0;
x.reciprocal();
printOps("fiReciprocal");
}
std::cout << std::endl;
}
static void doCurvePoint() {
{
CurvePoint x = CurvePoint::G;
CurvePoint y = CurvePoint::G;
opsCount = 0;
x.replace(y, 1);
printOps("cpReplace");
}
{
CurvePoint x = CurvePoint::G;
opsCount = 0;
x.isZero();
printOps("cpIsZero");
}
{
CurvePoint x = CurvePoint::G;
CurvePoint y = CurvePoint::G;
opsCount = 0;
x == y;
printOps("cpEquals");
}
{
CurvePoint x = CurvePoint::G;
opsCount = 0;
x.twice();
printOps("cpTwice");
}
{
CurvePoint x = CurvePoint::G;
CurvePoint y = CurvePoint::G;
opsCount = 0;
x.add(y);
printOps("cpAdd");
}
{
CurvePoint x = CurvePoint::G;
Uint256 y = Uint256::ONE;
opsCount = 0;
x.multiply(y);
printOps("cpMultiply");
}
{
CurvePoint x = CurvePoint::G;
opsCount = 0;
x.normalize();
printOps("cpNormalize");
}
{
CurvePoint x = CurvePoint::G;
opsCount = 0;
x.isOnCurve();
printOps("cpIsOnCurve");
}
std::cout << std::endl;
}
static void doEcdsa() {
{
Uint256 privKey = Uint256::ONE;
Sha256Hash msgHash = Sha256::getHash(nullptr, 0);
Uint256 nonce = Uint256::ONE;
Uint256 outR, outS;
opsCount = 0;
Ecdsa::sign(privKey, msgHash, nonce, outR, outS);
printOps("edSign");
}
{
CurvePoint pubKey = CurvePoint::G;
Sha256Hash msgHash = Sha256::getHash(nullptr, 0);
Uint256 r = Uint256::ONE;
Uint256 s = Uint256::ONE;
opsCount = 0;
Ecdsa::verify(pubKey, msgHash, r, s);
printOps("edVerify");
}
std::cout << std::endl;
}
static void printOps(const char *name) {
std::string s = std::to_string(opsCount);
while (s.size() < 9)
s.insert(0, " ", 1);
for (std::size_t i = s.size(); i >= 4; i -= 3)
s.insert(i - 3, " ", 1);
std::cout << s << " " << name << std::endl;
}
以下是错误:
【问题讨论】:
-
错误是什么?它与天气有什么关系?请发帖minimal reproducible example
-
该代码看起来有效。错误一定来自其他原因。
-
好点添加了 3 个将显示的错误并更新了文件的完整代码,并且关于恶劣天气有点糟糕的笑话,因为添加标签时需要花费大量时间并与网站“争论”不赞成发布我认为更相关的标签,对此深表歉意。
-
您包含的其中一个头文件中可能存在错误(例如,在类定义后缺少分号)。
-
回复:“我还不能添加图片”——不要发布错误信息的图片。像你一样发布文本。
标签: c++ cryptography win32-process long-long error-list