PROV: Add the beginning of a DER writing library
authorRichard Levitte <levitte@openssl.org>
Tue, 31 Mar 2020 14:54:43 +0000 (16:54 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 7 Apr 2020 09:16:56 +0000 (11:16 +0200)
commit1d39620b3489d957978ef038be4533300d7c4179
tree85cc10b7ac0a12e9dae84ff52fd22d566baf7d26
parent77de6bb38d3bc247eac548715969b01cc2b752bb
PROV: Add the beginning of a DER writing library

This library is meant to be small and quick.  It's based on WPACKET,
which was extended to support DER writing.  The way it's used is a
bit unusual, as it's used to write the structures backward into a
given buffer.  A typical quick call looks like this:

    /*
     * Fill in this structure:
     *
     * something ::= SEQUENCE {
     *     id OBJECT IDENTIFIER,
     *     x [0] INTEGER OPTIONAL,
     *     y [1] BOOLEAN OPTIONAL,
     *     n INTEGER
     * }
     */
    unsigned char buf[nnnn], *p = NULL;
    size_t encoded_len = 0;
    WPACKET pkt;
    int ok;

    ok =   WPACKET_init_der(&pkt, buf, sizeof(buf)
        && DER_w_start_sequence(&pkt, -1)
        && DER_w_bn(&pkt, -1, bn)
        && DER_w_boolean(&pkt, 1, bool)
        && DER_w_precompiled(&pkt, -1, OID, sizeof(OID))
        && DER_w_end_sequence(&pkt, -1)
        && WPACKET_finish(&pkt)
        && WPACKET_get_total_written(&pkt, &encoded_len)
        && (p = WPACKET_get_curr(&pkt)) != NULL;

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11450)
crypto/build.info
crypto/der_writer.c [new file with mode: 0644]
doc/internal/man3/DER_w_begin_sequence.pod [new file with mode: 0644]
doc/internal/man3/DER_w_bn.pod [new file with mode: 0644]
doc/internal/man3/DER_w_precompiled.pod [new file with mode: 0644]
doc/internal/man7/DERlib.pod [new file with mode: 0644]
include/internal/der.h [new file with mode: 0644]
providers/common/build.info
util/missingcrypto.txt