- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在实现 Diffie-Hellman使用 OpenSSL 库进行 BIGNUM
操作的嵌入式设备与使用 System.Numerics.BigInteger
方法计算 secret 共享 key 生成的 C# 软件之间的 key 交换算法。
但是Alice和Bob交换 key 后,他们计算出不同的共享 secret 。
key 打印在每一面 (PubA, PrivA, PubB, PrivB, DHPrime, DHGenerator)
我可以看到它们是相同的。
我怀疑存在关于小/大字节序的问题,或者 openssl 可能不关心指数的负数,我不知道如何调试这些操作。我现在没有代码,但所有操作都保持简单,就像这样。
C# 端
BigInteger bintA = new BigInteger(baByteArrayReceived);
BigInteger bintb = new BigInteger(baRandomBobSecret);
BigInteger bintDHPrime = new BigInteger(baDHPrime2048);
BigInteger bintSharedSecret = bintA.ModPow(bintb,bintDHPrime);
C面
BIGNUM *bnB = BN_new();
BIGNUM *bna = BN_new();
BIGNUM *bnDHPrime = BN_new();
BIGNUM *bnResult = BN_new();
BN_CTX *bnctx = BN_CTX_new();
BN_bin2bn(baBReceived, 256,bnB);
BN_bin2bn(baRandomAliceSecret, 256,bna);
BN_bin2bn(baDHPrime2048, 256,bnDHPrime);
BN_mod_exp(bnResult,bnB,bna,bnDHPrime,bnctx);
OpenSSL 的 C 方法的一些附加信息:>
BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret);
BN_bin2bn sets |*ret| to the value of |len| bytes from |in|, interpreted as a big-endian number, and returns |ret|. If |ret| is NULL then a fresh |BIGNUM| is allocated and returned. It returns NULL on allocation failure.
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx);BN_mod_exp sets |r| equal to |a|^{|p|} mod |m|. It does so with the best algorithm for the values provided and can run in constant time if |BN_FLG_CONSTTIME| is set for |p|. It returns one on success or zero otherwise.
而且它们会产生不同的结果。
我该怎么办?你接下来要检查什么?
提前致谢。
最佳答案
通过使用 BouncyCaSTLe Crypto Library 的 BigInteger 方法解决。无法告诉 System.Numerics.BigInteger 我们正在使用大端无符号字符进行初始化。
关于c# - Diffie-Hellman 与 BIGNUM (OpenSSL) 与 BigInteger (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28005253/
一些快速背景。我使用 rclone 将数据传输到 SFTP 服务器。 rclone 是用 Golang 编写的,并在底层使用 lib crypto。当我们尝试与 SFTP 服务器建立 ssh 连接时,
我将 FIPS 186-3 推荐的曲线用于 Diffie-Hellman 椭圆曲线。我正在尝试确定私钥的最大长度,根据 RFC 5915 应该是: 天花板 (log2(n)/8) ,其中 n 是曲线的
我正在做一个项目,Alice 和 Bob 使用 Diffie-Hellman key 交换相互发送消息。让我陷入困境的是如何将他们正在使用的证书合并到其中,以便我可以获得他们的 secret 消息。
也许在这里问这个问题不太合适......无论如何,我正在尝试使用 gmp 库来实现 DH,但我遇到的问题是: 有一次,当我进行测试以观察输出时,尽管选择了较大的素数和私钥值: p 的十进制长度大约超过
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我在 JavaCard 上遇到 DiffieHellman 问题。我有这门课: https://pastebin.com/2F2sQ2Pe (https://github.com/ASKGLab/DH
所以我正在尝试进行客户端-服务器 diffie hellman 加密。我使用这个:serverPublicKey = (int)Math.pow(generator,serverPrivateKey)
上下文 我在看这个视频DHE explained 它讲的是两个人如何在没有吸管的情况下交换 key 以了解更多信息。 根据视频实现 // INITIALIZERS (video's values)--
我有一个像这样的 Diffie–Hellman 安全类: public class AESSecurityCap { private PublicKey publicKey; KeyA
嗨,我正在尝试实现 Diffie–Hellman key 交换 public static Integer secret = 100000; public static BigInteger g =
我遇到了一个挑战,它与测试 friend 的加密过程有关。 这是一个Diffie-Hellman交换过程,这里是已知的变量/常量: P, G 我生成的私钥(可变) 我生成的公钥(变量) 收件人公钥(常
我有下面这行代码来生成私钥: int Xa = randomNo.nextInt(10000); int Ya = (int) Math.pow(G, Xa) % P; G 和 P 是静态数字。而 X
我正在编写 Pohlig-Hellman 算法,但我在根据算法定义理解算法中的步骤时遇到问题。 通过 algorithm 的 Wiki : 我知道第一部分 1) 是计算 p-1 的素数 - 这很好。
我正在尝试设计一种安全方案,用于加密 silverlight 客户端和我创建的 php web 服务之间的应用程序级数据。由于我正在处理一个公共(public)网站,因此我从服务中提取的信息是公开的,
所以我在阅读 this并对莱姆斯的回答感到惊讶。因为我认为情况正好相反。 所以,至于我的问题。为什么使用 diffie-hellman key 交换来确定共享 key 来加密/解密消息的程序(通常)不
是否有实现 diffie helman 的 Python 标准库? 我已经查看了 python pyopenssl 中的 openssl 包装器,但它没有涵盖它。 我也无法在 NaCl 或 crypt
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
我正在尝试实现 Diffie-Hellman key 交换。我对生成后如何使用 key 有点困惑。 如输出所示,2 个 key 是在 key 交换中使用相同的质数和基数生成的,并在生成 key 时交换
我需要进行单元测试来检查 Diffie-Hellman key 协议(protocol)协议(protocol)的实现是否正常,所以我需要测试向量来验证。问题是我在互联网上的任何地方都找不到它们。 R
Elliptic 曲线 diffie hellman 计算看起来与此处定义的标准曲线有什么不同: /* * The basic Diffie-Hell
我是一名优秀的程序员,十分优秀!