【问题标题】:openssl api funtion reference issueopenssl api 函数参考问题
【发布时间】:2018-06-26 20:07:36
【问题描述】:

我正在尝试生成并使用 openssl 椭圆曲线。运行这个:从文档中

EC_GROUP *curve;
if(NULL == (curve = EC_GROUP_new_by_curve_name(NID_secp224r1)))
      handleErrors(); 
EC_KEY *key;
if(NULL == (key = EC_KEY_new_by_curve_name(NID_secp224r1)))
     handleErrors();
if(1 != EC_KEY_generate_key(key)) handleErrors();

这些包括:

#include <openssl/obj_mac.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

我查看了 ec.h 文件,它具有我正在调用的功能。我的错误是这样的:

key_gen.c:(.text+0x15): undefined reference to `EC_GROUP_new_by_curve_name'
key_gen.c:(.text+0x2a): undefined reference to `handleErrors'
key_gen.c:(.text+0x34): undefined reference to `EC_KEY_new_by_curve_name'
key_gen.c:(.text+0x49): undefined reference to `handleErrors'
key_gen.c:(.text+0x55): undefined reference to `EC_KEY_generate_key'
key_gen.c:(.text+0x64): undefined reference to `handleErrors'

我还需要包含更多内容吗?

【问题讨论】:

    标签: c openssl cryptography signature elliptic-curve


    【解决方案1】:

    编译时需要在OpenSSL加密库中链接:

    gcc -g -Wall -Wextra -o key_gen key_gen.c -lcrypto
    

    【讨论】:

    • 谢谢。曲线和键函数已链接,但 handleErrors 函数调用仍未定义。你知道我需要包含哪些内容吗?
    • @NoahPerkovich 该函数不是 OpenSSL 库的一部分。您需要从获得此示例代码的任何地方提取它。
    • 我是从wiki.openssl.org/index.php/Elliptic_Curve_Cryptography 得到的。有没有更好的方法来调用密钥生成函数?
    • handleErrors() 函数应该是“在此处填写您自己的代码”的提示。
    【解决方案2】:

    你需要定义handleErrors();自己。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 2020-12-29
    • 2014-10-03
    相关资源
    最近更新 更多