The ASN.1 structure iterator just be declared but not implemented

142 Views Asked by At

This is my sample code:

#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>

typedef struct key_st {
    X509_ALGOR *algorithm_id;
    RSA *key_material;
} KEY;

DECLARE_ASN1_FUNCTIONS(KEY)

IMPLEMENT_ASN1_FUNCTIONS(KEY)

int main()
{
    return 0;
}

when I compile it, the following error reported:

$ gcc -o ssltest ssltest.c -lssl -lcrypto
/tmp/cch0HA77.o: In function `d2i_KEY':
ssltest.c:(.text+0x21): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `i2d_KEY':
ssltest.c:(.text+0x48): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `KEY_new':
ssltest.c:(.text+0x5e): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `KEY_free':
ssltest.c:(.text+0x7a): undefined reference to `KEY_it'
collect2: error: ld returned 1 exit status

After check the macro-extended code, I found the KEY_it is declared as:

extern const ASN1_ITEM KEY_it;

So the linker report undefined references. How can I fix it? Thank you very much!

1

There are 1 best solutions below

0
progquester On

It was fix after I add the sequence definition for KEY:

ASN1_SEQUENCE(KEY) = { 
    ASN1_SIMPLE(KEY, algorithm_id, X509_ALGOR), 
    ASN1_SIMPLE(KEY, key_material, RSAPublicKey) 
} ASN1_SEQUENCE_END(KEY)