c - 使用 CyaSSL Keygen 时出现段错误

标签 c ssl wolfssl

我正在尝试使用此处第 7.7 节中的示例使 CyaSSL 的 Keygen 功能正常工作:http://www.yassl.com/yaSSL/Docs-cyassl-manual-7-keys-and-certificates.html

我正在使用带有 --enable-keygen 选项的 CyaSSL 3.2.0,但也无法使其与 3.1.0 一起使用。

这是代码:

#include <stdio.h>
#include <cyassl/ctaocrypt/asn.h>
#include <cyassl/ctaocrypt/rsa.h>

int main() {
        RsaKey genKey;
        RNG rng;
        int ret;

        printf("%d\n",InitRng(&rng));
        printf("%d\n",InitRsaKey(&genKey, 0));
        ret = MakeRsaKey(&genKey, 1024, 65537, &rng);

        printf("ret: %d\n",ret);

        return 0;
}

我在 InitRsaKey 行中遇到段错误,可能是由于无效写入或其他原因。

有人知道我的问题出在哪里吗?感谢任何帮助

最佳答案

早上好,请不要忘记包含 options.h header 。这将确保您在项目中获得正确的配置设置,例如,如果您使用 --enable-keygen 配置 CyaSSL,然后查看 cyassl/options.h,您将看到行 #undef CYASSL_KEY_GEN 后跟 #define CYASSL_KEY_GEN。同样在您的 makefile 中不要忘记包含 cyassl 库。这可以在构建行中使用 -lcyassl 来完成。请参阅下面的代码以供引用:

#include <stdio.h>
#include <cyassl/options.h> //pull in the define for CYASSL_KEY_GEN
#include <cyassl/ctaocrypt/asn.h>
#include <cyassl/ctaocrypt/rsa.h>

int main() {
        RsaKey genKey;
        RNG rng;
        int ret;

        printf("%d\n",InitRng(&rng));
        printf("%d\n",InitRsaKey(&genKey, 0));
        ret = MakeRsaKey(&genKey, 1024, 65537, &rng);

        printf("ret: %d\n",ret);

        return 0;
}

生成文件:

 CC=gcc       #you can use clang or other instead of gcc                                                                   
 CFLAGS=-Wall                                                                    
 LIBS=-lpthread -lcyassl #must have -lcyassl in makefile                                                         

 all: run                                                                        

 #NOTE: arrows denote a hard tab, replace them with hard tab in makefile                                                                             
 run: test.o                                                                     
 →→→→$(CC) -o $@ $(LIBS) $^ $(CFLAGS) #put $(LIBS) into build command                                            

 .PHONY: clean all                                                               

 clean:                                                                          
 →→→→rm -f *.o test.o run 

关于c - 使用 CyaSSL Keygen 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29218442/

相关文章:

c - 由于无效指针而出现段错误

javascript - 用 php 中的本地代理替换 whateverorigin.org 调用

ssl - 证书,在调用服务之前安装在本地机器上

c - 使用 WolfCrypt 的 ECB 模式下的 AES

c - 解释一下C语言中的函数指针

c - 在库本身中获取动态库的文件名

c - 文件范围内的可变修改数组

ssl - 证书管理器质询因连接超时而失败。可以从互联网手动连接到 URL。下一个调试步骤是什么?

ssl - wolfSSL_read() 返回 0

c - 如何使用 wc_EccPublicKeyDecode 在 Wolfssl 中导入 der 证书