我试图生成使用OpenSSL具有以下功能RSA密钥:分割故障,则产生RSA密钥使用OpenSSL的
RSA *genRSA() {
clear();
mvprintw(0, 0, "Generating RSA key...\n");
RAND_load_file("/dev/random", 4096);
BIGNUM *e = BN_new();
BN_set_word(e, RSA_F4);
RSA *rsa;
while (getch() != '\n'); // the program does reach this point
if (!RSA_generate_key_ex(rsa, 4096, e, 0)) { // seg fault must occur on this line
while (getch() != '\n'); // never gets here
printw("ERROR: Failed to create RSA key\n");
return NULL;
}
while (getch() != '\n'); // or here
BN_free(e);
if (!RSA_check_key(rsa)) {
printw("ERROR: Key failed validation\n");
return NULL;
}
printw("Key generation completed successfully\n");
return rsa;
}
我没有收到比一些过时的OS X之外的其他任何编译器警告(即可以造成问题?)。为什么我会遇到seg错误?
如果你确定它是RSA_generate_key_ex()函数中的错误,那么它可能是你的输入参数。验证每个函数是否与预期的一样。 – Ender 2014-08-29 05:32:54
这也可能是一个问题:''RAND_load_file(“/ dev/random”,4096);'。你要求的是字节,而不是位。还有很多。它可能会耗尽设备,并且可能会阻塞很长时间。要达到相当于4096位密钥,您需要大约140位的安全级别。 140/8 = 17.5字节:'RAND_load_file(“/ dev/random”,18);'。 – jww 2014-08-29 06:48:27
@jww对我来说幸运的是,这并不需要太长时间,但我会将你的建议纳入思考。 – carloabelli 2014-08-29 06:49:55