使用 CyaSSL Keygen 时出现分段错误
Segmentation fault when using CyaSSL Keygen
我正在尝试使用此处第 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.hheader。这将确保您在项目中获得正确的配置设置,例如,如果您使用 --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
我正在尝试使用此处第 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.hheader。这将确保您在项目中获得正确的配置设置,例如,如果您使用 --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