【发布时间】:2019-07-05 10:23:59
【问题描述】:
即使我们使用本地函数设置 currentMethod.bytes 来生成随机数,RAND_bytes 也不会被调用。在我们设置RAND_set_rand_method(&cuurentMethod)之后。
这里我附上了我已经尝试过的链接 [https://github.com/openssl/openssl/blob/master/test/sm2_internal_test.c]。
int main()
{
unsigned char rand[16];
int ret;
RAND_METHOD *oldMethod,currentMethod,*temp;
oldMethod = RAND_get_rand_method();/*getting default method*/
currentMethod = *oldMethod;
currentMethod.bytes = local_function_rand;
if((ret = RAND_set_rand_method(¤tMethod))!= 1)
return 0;
/* Now we are printing both address of local_function_method_rand() and
temp->bytes , those address are same after getting. */
temp = RAND_get_rand_method();
/* after we are comparing with RAND_SSLeay() function , to find default or not*/
if((ret = RAND_bytes(rand,16)) != 1)
return 0;
return 1;
}
预期结果是我们的本地函数应该调用。另外,在Linux系统中调用RAND_bytes()是否需要设置fips模式?
【问题讨论】:
-
在您的问题正文中包含minimal reproducible example?
-
另外,
RAND_set_rand_method()不会返回任何东西……至少在 OpenSSL 1.1.1 中不会。它是否在该版本之前或之后的某个时间点更改了原型以返回一个值? -
另外,您似乎从
main()向后返回值。0/EXIT_SUCCESS成功,EXIT_FAILURE(通常定义为 1)错误... -
感谢您的回复,在 OpenSSL v2.1.0 中,RAND_set_rand_method() 是返回值(wiki.openssl.org/index.php/Random_Numbers),如果有任何与控制台上的 local_function_rand() 相关的日志打印,请告诉我。
-
OpenSSL 没有这样的版本...
标签: c openssl cryptography fips