我試圖生成使用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