Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CyaSSL Keygen时出现分段错误_C_Ssl_Wolfssl - Fatal编程技术网

使用CyaSSL Keygen时出现分段错误

使用CyaSSL Keygen时出现分段错误,c,ssl,wolfssl,C,Ssl,Wolfssl,我试图使用第7.7节中的示例使CyaSSL的Keygen函数工作: 我正在使用Cyassl3.2.0和--enableKeyGen选项,但也无法使其与3.1.0一起工作 代码如下: #include <stdio.h> #include <cyassl/ctaocrypt/asn.h> #include <cyassl/ctaocrypt/rsa.h> int main() { RsaKey genKey; RNG rng;

我试图使用第7.7节中的示例使CyaSSL的Keygen函数工作:

我正在使用Cyassl3.2.0和--enableKeyGen选项,但也无法使其与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;
}
#包括
#包括
#包括
int main(){
RsaKey-genKey;
RNG-RNG;
int ret;
printf(“%d\n”,InitRng(&rng));
printf(“%d\n”,InitRsaKey(&genKey,0));
ret=MakeRsaKey(&genKey,102465537,&rng);
printf(“ret:%d\n”,ret);
返回0;
}
我在InitRsaKey行中遇到了一个分段错误,可能是因为写入无效或其他原因


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

早上好,请不要忘记包括选项.h标题。这将确保您在项目中获得正确的配置设置,例如,如果您使用--enable keygen配置CyaSSL,然后查看CyaSSL/options。h您将看到行
#undef CyaSSL\u KEY\u GEN
,后跟
#define CyaSSL\u KEY\u 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