Answering my own question - I forgot the END of sequence in the marco. Functional code below. Dw.
#include <openssl/bn.h> #include <openssl/ec.h> #include <openssl/asn1.h> #include <openssl/asn1t.h> #include <err.h> #include <assert.h> #include <stdio.h> typedef struct X962_st { ASN1_INTEGER *p; ASN1_INTEGER *q; } X962; DECLARE_ASN1_FUNCTIONS(X962) ASN1_SEQUENCE(X962) = { ASN1_SIMPLE(X962, p, ASN1_INTEGER), ASN1_SIMPLE(X962, q, ASN1_INTEGER) }ASN1_SEQUENCE_END(X962); DECLARE_ASN1_ALLOC_FUNCTIONS(X962) IMPLEMENT_ASN1_FUNCTIONS(X962) int main(int argc, char **argv) { const unsigned char pbin[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; const unsigned char qbin[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; assert(sizeof(pbin) == 32); assert(sizeof(qbin) == 32); X962 *x962 = X962_new(); BIGNUM * p = BN_bin2bn(pbin, sizeof(pbin), NULL); assert(p); x962->p = BN_to_ASN1_INTEGER(p, NULL); fprintf(stderr,"P: %s\n",BN_bn2hex(p)); assert(x962->p); BIGNUM * q = BN_bin2bn(qbin, sizeof(qbin), NULL); assert(q); x962->q = BN_to_ASN1_INTEGER(q, NULL); fprintf(stderr,"Q: %s\n",BN_bn2hex(q)); assert(x962->q); int len = i2d_X962(x962, NULL); assert(len>0 && len < 1000); unsigned char buff[32 * 1024]; unsigned char *outp = buff; len = i2d_X962(x962, &outp ); for (size_t i = 0; i < len; i++) putchar(buff[i]); X962_free(x962); return (0); }; |