我正在尝试将 openssl 代码替换为 CNG winapi 代码。下面是我拥有的准系统 openssl 代码。
const char *generator = ""; // 256 character hex string
const char *prime = ""; // 256 character hex string
dh = DH_new();
// Initialize dh's generator and prime
BN_hex2bn(&(dh->g), generator);
BN_hex2bn(&(dh->p), prime);
// Generate public and private keys
DH_generate_key(dh);
// Extract server's public key from init_msg's 'key'
BIGNUM *server_pub_key = BN_new();
BN_hex2bn(&server_pub_key, " *** 256 character server public key as hex string ***");
// Use DH to calculate the shared key
vector<unsigned char> shared_key;
shared_key.resize(DH_size(dh));
err = DH_compute_key(shared_key.data(), server_pub_key, dh);
上面的代码生成了一个 256 个字符的十六进制字符串(128 字节)的共享密钥。openssl 使用什么密钥协商函数来创建这样的密钥。提前致谢。