]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - common/mbedtls/asn1write.h
4 * \brief ASN.1 buffer writing functionality
7 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: GPL-2.0
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This file is part of mbed TLS (https://tls.mbed.org)
26 #ifndef MBEDTLS_ASN1_WRITE_H
27 #define MBEDTLS_ASN1_WRITE_H
31 #define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \
32 g += ret; } while( 0 )
39 * \brief Write a length field in ASN.1 format
40 * Note: function works backwards in data buffer
42 * \param p reference to current position pointer
43 * \param start start of the buffer (for bounds-checking)
44 * \param len the length to write
46 * \return the length written or a negative error code
48 int mbedtls_asn1_write_len( unsigned char **p
, unsigned char *start
, size_t len
);
51 * \brief Write a ASN.1 tag in ASN.1 format
52 * Note: function works backwards in data buffer
54 * \param p reference to current position pointer
55 * \param start start of the buffer (for bounds-checking)
56 * \param tag the tag to write
58 * \return the length written or a negative error code
60 int mbedtls_asn1_write_tag( unsigned char **p
, unsigned char *start
,
64 * \brief Write raw buffer data
65 * Note: function works backwards in data buffer
67 * \param p reference to current position pointer
68 * \param start start of the buffer (for bounds-checking)
69 * \param buf data buffer to write
70 * \param size length of the data buffer
72 * \return the length written or a negative error code
74 int mbedtls_asn1_write_raw_buffer( unsigned char **p
, unsigned char *start
,
75 const unsigned char *buf
, size_t size
);
77 #if defined(MBEDTLS_BIGNUM_C)
79 * \brief Write a big number (MBEDTLS_ASN1_INTEGER) in ASN.1 format
80 * Note: function works backwards in data buffer
82 * \param p reference to current position pointer
83 * \param start start of the buffer (for bounds-checking)
84 * \param X the MPI to write
86 * \return the length written or a negative error code
88 int mbedtls_asn1_write_mpi( unsigned char **p
, unsigned char *start
, const mbedtls_mpi
*X
);
89 #endif /* MBEDTLS_BIGNUM_C */
92 * \brief Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format
93 * Note: function works backwards in data buffer
95 * \param p reference to current position pointer
96 * \param start start of the buffer (for bounds-checking)
98 * \return the length written or a negative error code
100 int mbedtls_asn1_write_null( unsigned char **p
, unsigned char *start
);
103 * \brief Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format
104 * Note: function works backwards in data buffer
106 * \param p reference to current position pointer
107 * \param start start of the buffer (for bounds-checking)
108 * \param oid the OID to write
109 * \param oid_len length of the OID
111 * \return the length written or a negative error code
113 int mbedtls_asn1_write_oid( unsigned char **p
, unsigned char *start
,
114 const char *oid
, size_t oid_len
);
117 * \brief Write an AlgorithmIdentifier sequence in ASN.1 format
118 * Note: function works backwards in data buffer
120 * \param p reference to current position pointer
121 * \param start start of the buffer (for bounds-checking)
122 * \param oid the OID of the algorithm
123 * \param oid_len length of the OID
124 * \param par_len length of parameters, which must be already written.
125 * If 0, NULL parameters are added
127 * \return the length written or a negative error code
129 int mbedtls_asn1_write_algorithm_identifier( unsigned char **p
, unsigned char *start
,
130 const char *oid
, size_t oid_len
,
134 * \brief Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format
135 * Note: function works backwards in data buffer
137 * \param p reference to current position pointer
138 * \param start start of the buffer (for bounds-checking)
139 * \param boolean 0 or 1
141 * \return the length written or a negative error code
143 int mbedtls_asn1_write_bool( unsigned char **p
, unsigned char *start
, int boolean
);
146 * \brief Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format
147 * Note: function works backwards in data buffer
149 * \param p reference to current position pointer
150 * \param start start of the buffer (for bounds-checking)
151 * \param val the integer value
153 * \return the length written or a negative error code
155 int mbedtls_asn1_write_int( unsigned char **p
, unsigned char *start
, int val
);
158 * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and
159 * value in ASN.1 format
160 * Note: function works backwards in data buffer
162 * \param p reference to current position pointer
163 * \param start start of the buffer (for bounds-checking)
164 * \param text the text to write
165 * \param text_len length of the text
167 * \return the length written or a negative error code
169 int mbedtls_asn1_write_printable_string( unsigned char **p
, unsigned char *start
,
170 const char *text
, size_t text_len
);
173 * \brief Write an IA5 string tag (MBEDTLS_ASN1_IA5_STRING) and
174 * value in ASN.1 format
175 * Note: function works backwards in data buffer
177 * \param p reference to current position pointer
178 * \param start start of the buffer (for bounds-checking)
179 * \param text the text to write
180 * \param text_len length of the text
182 * \return the length written or a negative error code
184 int mbedtls_asn1_write_ia5_string( unsigned char **p
, unsigned char *start
,
185 const char *text
, size_t text_len
);
188 * \brief Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and
189 * value in ASN.1 format
190 * Note: function works backwards in data buffer
192 * \param p reference to current position pointer
193 * \param start start of the buffer (for bounds-checking)
194 * \param buf the bitstring
195 * \param bits the total number of bits in the bitstring
197 * \return the length written or a negative error code
199 int mbedtls_asn1_write_bitstring( unsigned char **p
, unsigned char *start
,
200 const unsigned char *buf
, size_t bits
);
203 * \brief Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and
204 * value in ASN.1 format
205 * Note: function works backwards in data buffer
207 * \param p reference to current position pointer
208 * \param start start of the buffer (for bounds-checking)
209 * \param buf data buffer to write
210 * \param size length of the data buffer
212 * \return the length written or a negative error code
214 int mbedtls_asn1_write_octet_string( unsigned char **p
, unsigned char *start
,
215 const unsigned char *buf
, size_t size
);
218 * \brief Create or find a specific named_data entry for writing in a
219 * sequence or list based on the OID. If not already in there,
220 * a new entry is added to the head of the list.
221 * Warning: Destructive behaviour for the val data!
223 * \param list Pointer to the location of the head of the list to seek
224 * through (will be updated in case of a new entry)
225 * \param oid The OID to look for
226 * \param oid_len Size of the OID
227 * \param val Data to store (can be NULL if you want to fill it by hand)
228 * \param val_len Minimum length of the data buffer needed
230 * \return NULL if if there was a memory allocation error, or a pointer
231 * to the new / existing entry.
233 mbedtls_asn1_named_data
*mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
**list
,
234 const char *oid
, size_t oid_len
,
235 const unsigned char *val
,
242 #endif /* MBEDTLS_ASN1_WRITE_H */