1*b077aed3SPierre Pronchery /* 2*b077aed3SPierre Pronchery * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved. 3*b077aed3SPierre Pronchery * 4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*b077aed3SPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*b077aed3SPierre Pronchery * in the file LICENSE in the source distribution or at 7*b077aed3SPierre Pronchery * https://www.openssl.org/source/license.html 8*b077aed3SPierre Pronchery */ 9*b077aed3SPierre Pronchery 10*b077aed3SPierre Pronchery #include <openssl/bn.h> 11*b077aed3SPierre Pronchery #include "internal/packet.h" 12*b077aed3SPierre Pronchery 13*b077aed3SPierre Pronchery /* 14*b077aed3SPierre Pronchery * NOTE: X.690 numbers the identifier octet bits 1 to 8. 15*b077aed3SPierre Pronchery * We use the same numbering in comments here. 16*b077aed3SPierre Pronchery */ 17*b077aed3SPierre Pronchery 18*b077aed3SPierre Pronchery /* Well known primitive tags */ 19*b077aed3SPierre Pronchery 20*b077aed3SPierre Pronchery /* 21*b077aed3SPierre Pronchery * DER UNIVERSAL tags, occupying bits 1-5 in the DER identifier byte 22*b077aed3SPierre Pronchery * These are only valid for the UNIVERSAL class. With the other classes, 23*b077aed3SPierre Pronchery * these bits have a different meaning. 24*b077aed3SPierre Pronchery */ 25*b077aed3SPierre Pronchery #define DER_P_EOC 0 /* BER End Of Contents tag */ 26*b077aed3SPierre Pronchery #define DER_P_BOOLEAN 1 27*b077aed3SPierre Pronchery #define DER_P_INTEGER 2 28*b077aed3SPierre Pronchery #define DER_P_BIT_STRING 3 29*b077aed3SPierre Pronchery #define DER_P_OCTET_STRING 4 30*b077aed3SPierre Pronchery #define DER_P_NULL 5 31*b077aed3SPierre Pronchery #define DER_P_OBJECT 6 32*b077aed3SPierre Pronchery #define DER_P_OBJECT_DESCRIPTOR 7 33*b077aed3SPierre Pronchery #define DER_P_EXTERNAL 8 34*b077aed3SPierre Pronchery #define DER_P_REAL 9 35*b077aed3SPierre Pronchery #define DER_P_ENUMERATED 10 36*b077aed3SPierre Pronchery #define DER_P_UTF8STRING 12 37*b077aed3SPierre Pronchery #define DER_P_SEQUENCE 16 38*b077aed3SPierre Pronchery #define DER_P_SET 17 39*b077aed3SPierre Pronchery #define DER_P_NUMERICSTRING 18 40*b077aed3SPierre Pronchery #define DER_P_PRINTABLESTRING 19 41*b077aed3SPierre Pronchery #define DER_P_T61STRING 20 42*b077aed3SPierre Pronchery #define DER_P_VIDEOTEXSTRING 21 43*b077aed3SPierre Pronchery #define DER_P_IA5STRING 22 44*b077aed3SPierre Pronchery #define DER_P_UTCTIME 23 45*b077aed3SPierre Pronchery #define DER_P_GENERALIZEDTIME 24 46*b077aed3SPierre Pronchery #define DER_P_GRAPHICSTRING 25 47*b077aed3SPierre Pronchery #define DER_P_ISO64STRING 26 48*b077aed3SPierre Pronchery #define DER_P_GENERALSTRING 27 49*b077aed3SPierre Pronchery #define DER_P_UNIVERSALSTRING 28 50*b077aed3SPierre Pronchery #define DER_P_BMPSTRING 30 51*b077aed3SPierre Pronchery 52*b077aed3SPierre Pronchery /* DER Flags, occupying bit 6 in the DER identifier byte */ 53*b077aed3SPierre Pronchery #define DER_F_PRIMITIVE 0x00 54*b077aed3SPierre Pronchery #define DER_F_CONSTRUCTED 0x20 55*b077aed3SPierre Pronchery 56*b077aed3SPierre Pronchery /* DER classes tags, occupying bits 7-8 in the DER identifier byte */ 57*b077aed3SPierre Pronchery #define DER_C_UNIVERSAL 0x00 58*b077aed3SPierre Pronchery #define DER_C_APPLICATION 0x40 59*b077aed3SPierre Pronchery #define DER_C_CONTEXT 0x80 60*b077aed3SPierre Pronchery #define DER_C_PRIVATE 0xC0 61*b077aed3SPierre Pronchery 62*b077aed3SPierre Pronchery /* 63*b077aed3SPierre Pronchery * Run-time constructors. 64*b077aed3SPierre Pronchery * 65*b077aed3SPierre Pronchery * They all construct DER backwards, so care should be taken to use them 66*b077aed3SPierre Pronchery * that way. 67*b077aed3SPierre Pronchery */ 68*b077aed3SPierre Pronchery 69*b077aed3SPierre Pronchery /* This can be used for all items that don't have a context */ 70*b077aed3SPierre Pronchery #define DER_NO_CONTEXT -1 71*b077aed3SPierre Pronchery 72*b077aed3SPierre Pronchery int ossl_DER_w_precompiled(WPACKET *pkt, int tag, 73*b077aed3SPierre Pronchery const unsigned char *precompiled, 74*b077aed3SPierre Pronchery size_t precompiled_n); 75*b077aed3SPierre Pronchery 76*b077aed3SPierre Pronchery int ossl_DER_w_boolean(WPACKET *pkt, int tag, int b); 77*b077aed3SPierre Pronchery int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v); 78*b077aed3SPierre Pronchery int ossl_DER_w_bn(WPACKET *pkt, int tag, const BIGNUM *v); 79*b077aed3SPierre Pronchery int ossl_DER_w_null(WPACKET *pkt, int tag); 80*b077aed3SPierre Pronchery int ossl_DER_w_octet_string(WPACKET *pkt, int tag, 81*b077aed3SPierre Pronchery const unsigned char *data, size_t data_n); 82*b077aed3SPierre Pronchery int ossl_DER_w_octet_string_uint32(WPACKET *pkt, int tag, uint32_t value); 83*b077aed3SPierre Pronchery 84*b077aed3SPierre Pronchery /* 85*b077aed3SPierre Pronchery * All constructors for constructed elements have a begin and a end function 86*b077aed3SPierre Pronchery */ 87*b077aed3SPierre Pronchery int ossl_DER_w_begin_sequence(WPACKET *pkt, int tag); 88*b077aed3SPierre Pronchery int ossl_DER_w_end_sequence(WPACKET *pkt, int tag); 89