纯汇编中的Secp256k1库(在x86_64上的曲线secp256k1上非常快速地实现算术)

问题描述 投票:0回答:1

我想加快 albertobsd 中 KeyHunt 中 secp256k1 的工作速度 (https://github.com/albertobsd/keyhunt)

我发现了这个: https://github.com/piggypiggy/secp256k1-x64

该库旨在提供 secp256k1 曲线算法最有效的实现。

我可以编译它,但如何使用,我不明白。

Openssl 包含类似的功能: https://www.openssl.org/docs/man1.0.2/man3/BN_mod_mul_montgomery.html

例如,我想在SECP256K1.cpp中使用函数secp256k1_sqr_mont:

Point Secp256K1::ComputePublicKey(Int *privKey) {
int i = 0;
uint8_t b;
Point Q;
BN_ULONG *res = NULL;
Q.Clear();
secp256k1_sqr_mont(Q, (const BN_ULONG*)privKey);
Q.Reduce();
return Q;

}

performance assembly implementation secp256k1
1个回答
0
投票

好吧,所以我认为您要问的是如何在您自己的项目中使用 https://github.com/piggypiggy/secp256k1-x64 库。有几个步骤可以实现此目的:

  1. 编译https://github.com/piggypiggy/secp256k1-x64

如果你去github页面,应该有两个文件,分别是BUILD_UNIX.txt和BUILD_WINDOWS.txt,它们告诉你如何编译程序。例如,如果您运行的是 Linux,您将运行以下命令:

cd build
cmake ..
make
make test 
sudo make install # (this installs the library and you probably need administrator privileges)
  1. 添加适当的链接器标志以使用该库。

make
命令之后,您应该有一个名为
bin/
的目录,然后在该 bin 目录中有一个名为
Release
的目录。要使用此库编译程序,您需要附加
-l:libsecp256k1_x64.a
-L<path_to_the_Release_directory>
,其中 path_to_the_Release_directory 是发布目录,例如对我来说它将是:
-L/home/cyberhacker/Asioita/Hakkerointi/secp256k1-x64/bin/Release
.

这是一个使用您描述的 sqrt 函数的示例程序:

#include <unistd.h>

// unsigned long
# define P256_LIMBS 4
int main(int argc, char** argv) {
    unsigned long r[P256_LIMBS], x[P256_LIMBS];
    // unsigned long is of size 8 bytes and P256_LIMBS is 4, therefore read 32 bytes from stdin
    read(0, x, 32);
    secp256k1_sqr_mont(r, x);
    return 0;
}

然后使用

gcc main.c -o main -l:libsecp256k1_x64.a -L/home/cyberhacker/Asioita/Hakkerointi/secp256k1-x64/bin/Release

进行编译
© www.soinside.com 2019 - 2024. All rights reserved.