xref: /reactos/dll/3rdparty/mbedtls/asn1parse.c (revision cbda039f)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  *  Generic ASN.1 parsing
3c2c66affSColin Finck  *
4218e2596SThomas Faber  *  Copyright The Mbed TLS Contributors
5e57126f5SThomas Faber  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6e57126f5SThomas Faber  *
7e57126f5SThomas Faber  *  This file is provided under the Apache License 2.0, or the
8e57126f5SThomas Faber  *  GNU General Public License v2.0 or later.
9e57126f5SThomas Faber  *
10e57126f5SThomas Faber  *  **********
11e57126f5SThomas Faber  *  Apache License 2.0:
12e57126f5SThomas Faber  *
13e57126f5SThomas Faber  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
14e57126f5SThomas Faber  *  not use this file except in compliance with the License.
15e57126f5SThomas Faber  *  You may obtain a copy of the License at
16e57126f5SThomas Faber  *
17e57126f5SThomas Faber  *  http://www.apache.org/licenses/LICENSE-2.0
18e57126f5SThomas Faber  *
19e57126f5SThomas Faber  *  Unless required by applicable law or agreed to in writing, software
20e57126f5SThomas Faber  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21e57126f5SThomas Faber  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22e57126f5SThomas Faber  *  See the License for the specific language governing permissions and
23e57126f5SThomas Faber  *  limitations under the License.
24e57126f5SThomas Faber  *
25e57126f5SThomas Faber  *  **********
26e57126f5SThomas Faber  *
27e57126f5SThomas Faber  *  **********
28e57126f5SThomas Faber  *  GNU General Public License v2.0 or later:
29c2c66affSColin Finck  *
30c2c66affSColin Finck  *  This program is free software; you can redistribute it and/or modify
31c2c66affSColin Finck  *  it under the terms of the GNU General Public License as published by
32c2c66affSColin Finck  *  the Free Software Foundation; either version 2 of the License, or
33c2c66affSColin Finck  *  (at your option) any later version.
34c2c66affSColin Finck  *
35c2c66affSColin Finck  *  This program is distributed in the hope that it will be useful,
36c2c66affSColin Finck  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
37c2c66affSColin Finck  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38c2c66affSColin Finck  *  GNU General Public License for more details.
39c2c66affSColin Finck  *
40c2c66affSColin Finck  *  You should have received a copy of the GNU General Public License along
41c2c66affSColin Finck  *  with this program; if not, write to the Free Software Foundation, Inc.,
42c2c66affSColin Finck  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43c2c66affSColin Finck  *
44e57126f5SThomas Faber  *  **********
45c2c66affSColin Finck  */
46c2c66affSColin Finck 
47c2c66affSColin Finck #if !defined(MBEDTLS_CONFIG_FILE)
48c2c66affSColin Finck #include "mbedtls/config.h"
49c2c66affSColin Finck #else
50c2c66affSColin Finck #include MBEDTLS_CONFIG_FILE
51c2c66affSColin Finck #endif
52c2c66affSColin Finck 
53c2c66affSColin Finck #if defined(MBEDTLS_ASN1_PARSE_C)
54c2c66affSColin Finck 
55c2c66affSColin Finck #include "mbedtls/asn1.h"
56*cbda039fSThomas Faber #include "mbedtls/platform_util.h"
57c2c66affSColin Finck 
58c2c66affSColin Finck #include <string.h>
59c2c66affSColin Finck 
60c2c66affSColin Finck #if defined(MBEDTLS_BIGNUM_C)
61c2c66affSColin Finck #include "mbedtls/bignum.h"
62c2c66affSColin Finck #endif
63c2c66affSColin Finck 
64c2c66affSColin Finck #if defined(MBEDTLS_PLATFORM_C)
65c2c66affSColin Finck #include "mbedtls/platform.h"
66c2c66affSColin Finck #else
67c2c66affSColin Finck #include <stdlib.h>
68c2c66affSColin Finck #define mbedtls_calloc    calloc
69c2c66affSColin Finck #define mbedtls_free       free
70c2c66affSColin Finck #endif
71c2c66affSColin Finck 
72c2c66affSColin Finck /*
73c2c66affSColin Finck  * ASN.1 DER decoding routines
74c2c66affSColin Finck  */
mbedtls_asn1_get_len(unsigned char ** p,const unsigned char * end,size_t * len)75c2c66affSColin Finck int mbedtls_asn1_get_len( unsigned char **p,
76c2c66affSColin Finck                   const unsigned char *end,
77c2c66affSColin Finck                   size_t *len )
78c2c66affSColin Finck {
79c2c66affSColin Finck     if( ( end - *p ) < 1 )
80c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
81c2c66affSColin Finck 
82c2c66affSColin Finck     if( ( **p & 0x80 ) == 0 )
83c2c66affSColin Finck         *len = *(*p)++;
84c2c66affSColin Finck     else
85c2c66affSColin Finck     {
86c2c66affSColin Finck         switch( **p & 0x7F )
87c2c66affSColin Finck         {
88c2c66affSColin Finck         case 1:
89c2c66affSColin Finck             if( ( end - *p ) < 2 )
90c2c66affSColin Finck                 return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
91c2c66affSColin Finck 
92c2c66affSColin Finck             *len = (*p)[1];
93c2c66affSColin Finck             (*p) += 2;
94c2c66affSColin Finck             break;
95c2c66affSColin Finck 
96c2c66affSColin Finck         case 2:
97c2c66affSColin Finck             if( ( end - *p ) < 3 )
98c2c66affSColin Finck                 return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
99c2c66affSColin Finck 
100c2c66affSColin Finck             *len = ( (size_t)(*p)[1] << 8 ) | (*p)[2];
101c2c66affSColin Finck             (*p) += 3;
102c2c66affSColin Finck             break;
103c2c66affSColin Finck 
104c2c66affSColin Finck         case 3:
105c2c66affSColin Finck             if( ( end - *p ) < 4 )
106c2c66affSColin Finck                 return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
107c2c66affSColin Finck 
108c2c66affSColin Finck             *len = ( (size_t)(*p)[1] << 16 ) |
109c2c66affSColin Finck                    ( (size_t)(*p)[2] << 8  ) | (*p)[3];
110c2c66affSColin Finck             (*p) += 4;
111c2c66affSColin Finck             break;
112c2c66affSColin Finck 
113c2c66affSColin Finck         case 4:
114c2c66affSColin Finck             if( ( end - *p ) < 5 )
115c2c66affSColin Finck                 return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
116c2c66affSColin Finck 
117c2c66affSColin Finck             *len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) |
118c2c66affSColin Finck                    ( (size_t)(*p)[3] << 8  ) |           (*p)[4];
119c2c66affSColin Finck             (*p) += 5;
120c2c66affSColin Finck             break;
121c2c66affSColin Finck 
122c2c66affSColin Finck         default:
123c2c66affSColin Finck             return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
124c2c66affSColin Finck         }
125c2c66affSColin Finck     }
126c2c66affSColin Finck 
127c2c66affSColin Finck     if( *len > (size_t) ( end - *p ) )
128c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
129c2c66affSColin Finck 
130c2c66affSColin Finck     return( 0 );
131c2c66affSColin Finck }
132c2c66affSColin Finck 
mbedtls_asn1_get_tag(unsigned char ** p,const unsigned char * end,size_t * len,int tag)133c2c66affSColin Finck int mbedtls_asn1_get_tag( unsigned char **p,
134c2c66affSColin Finck                   const unsigned char *end,
135c2c66affSColin Finck                   size_t *len, int tag )
136c2c66affSColin Finck {
137c2c66affSColin Finck     if( ( end - *p ) < 1 )
138c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
139c2c66affSColin Finck 
140c2c66affSColin Finck     if( **p != tag )
141c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
142c2c66affSColin Finck 
143c2c66affSColin Finck     (*p)++;
144c2c66affSColin Finck 
145c2c66affSColin Finck     return( mbedtls_asn1_get_len( p, end, len ) );
146c2c66affSColin Finck }
147c2c66affSColin Finck 
mbedtls_asn1_get_bool(unsigned char ** p,const unsigned char * end,int * val)148c2c66affSColin Finck int mbedtls_asn1_get_bool( unsigned char **p,
149c2c66affSColin Finck                    const unsigned char *end,
150c2c66affSColin Finck                    int *val )
151c2c66affSColin Finck {
152c2c66affSColin Finck     int ret;
153c2c66affSColin Finck     size_t len;
154c2c66affSColin Finck 
155c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_BOOLEAN ) ) != 0 )
156c2c66affSColin Finck         return( ret );
157c2c66affSColin Finck 
158c2c66affSColin Finck     if( len != 1 )
159c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
160c2c66affSColin Finck 
161c2c66affSColin Finck     *val = ( **p != 0 ) ? 1 : 0;
162c2c66affSColin Finck     (*p)++;
163c2c66affSColin Finck 
164c2c66affSColin Finck     return( 0 );
165c2c66affSColin Finck }
166c2c66affSColin Finck 
mbedtls_asn1_get_int(unsigned char ** p,const unsigned char * end,int * val)167c2c66affSColin Finck int mbedtls_asn1_get_int( unsigned char **p,
168c2c66affSColin Finck                   const unsigned char *end,
169c2c66affSColin Finck                   int *val )
170c2c66affSColin Finck {
171c2c66affSColin Finck     int ret;
172c2c66affSColin Finck     size_t len;
173c2c66affSColin Finck 
174c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
175c2c66affSColin Finck         return( ret );
176c2c66affSColin Finck 
177c2c66affSColin Finck     if( len == 0 || len > sizeof( int ) || ( **p & 0x80 ) != 0 )
178c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
179c2c66affSColin Finck 
180c2c66affSColin Finck     *val = 0;
181c2c66affSColin Finck 
182c2c66affSColin Finck     while( len-- > 0 )
183c2c66affSColin Finck     {
184c2c66affSColin Finck         *val = ( *val << 8 ) | **p;
185c2c66affSColin Finck         (*p)++;
186c2c66affSColin Finck     }
187c2c66affSColin Finck 
188c2c66affSColin Finck     return( 0 );
189c2c66affSColin Finck }
190c2c66affSColin Finck 
191c2c66affSColin Finck #if defined(MBEDTLS_BIGNUM_C)
mbedtls_asn1_get_mpi(unsigned char ** p,const unsigned char * end,mbedtls_mpi * X)192c2c66affSColin Finck int mbedtls_asn1_get_mpi( unsigned char **p,
193c2c66affSColin Finck                   const unsigned char *end,
194c2c66affSColin Finck                   mbedtls_mpi *X )
195c2c66affSColin Finck {
196c2c66affSColin Finck     int ret;
197c2c66affSColin Finck     size_t len;
198c2c66affSColin Finck 
199c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
200c2c66affSColin Finck         return( ret );
201c2c66affSColin Finck 
202c2c66affSColin Finck     ret = mbedtls_mpi_read_binary( X, *p, len );
203c2c66affSColin Finck 
204c2c66affSColin Finck     *p += len;
205c2c66affSColin Finck 
206c2c66affSColin Finck     return( ret );
207c2c66affSColin Finck }
208c2c66affSColin Finck #endif /* MBEDTLS_BIGNUM_C */
209c2c66affSColin Finck 
mbedtls_asn1_get_bitstring(unsigned char ** p,const unsigned char * end,mbedtls_asn1_bitstring * bs)210c2c66affSColin Finck int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
211c2c66affSColin Finck                         mbedtls_asn1_bitstring *bs)
212c2c66affSColin Finck {
213c2c66affSColin Finck     int ret;
214c2c66affSColin Finck 
215c2c66affSColin Finck     /* Certificate type is a single byte bitstring */
216c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 )
217c2c66affSColin Finck         return( ret );
218c2c66affSColin Finck 
219c2c66affSColin Finck     /* Check length, subtract one for actual bit string length */
220c2c66affSColin Finck     if( bs->len < 1 )
221c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
222c2c66affSColin Finck     bs->len -= 1;
223c2c66affSColin Finck 
224c2c66affSColin Finck     /* Get number of unused bits, ensure unused bits <= 7 */
225c2c66affSColin Finck     bs->unused_bits = **p;
226c2c66affSColin Finck     if( bs->unused_bits > 7 )
227c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_INVALID_LENGTH );
228c2c66affSColin Finck     (*p)++;
229c2c66affSColin Finck 
230c2c66affSColin Finck     /* Get actual bitstring */
231c2c66affSColin Finck     bs->p = *p;
232c2c66affSColin Finck     *p += bs->len;
233c2c66affSColin Finck 
234c2c66affSColin Finck     if( *p != end )
235c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
236c2c66affSColin Finck 
237c2c66affSColin Finck     return( 0 );
238c2c66affSColin Finck }
239c2c66affSColin Finck 
240c2c66affSColin Finck /*
241c2c66affSColin Finck  * Get a bit string without unused bits
242c2c66affSColin Finck  */
mbedtls_asn1_get_bitstring_null(unsigned char ** p,const unsigned char * end,size_t * len)243c2c66affSColin Finck int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
244c2c66affSColin Finck                              size_t *len )
245c2c66affSColin Finck {
246c2c66affSColin Finck     int ret;
247c2c66affSColin Finck 
248c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 )
249c2c66affSColin Finck         return( ret );
250c2c66affSColin Finck 
251c2c66affSColin Finck     if( (*len)-- < 2 || *(*p)++ != 0 )
252c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_INVALID_DATA );
253c2c66affSColin Finck 
254c2c66affSColin Finck     return( 0 );
255c2c66affSColin Finck }
256c2c66affSColin Finck 
257c2c66affSColin Finck 
258c2c66affSColin Finck 
259c2c66affSColin Finck /*
260c2c66affSColin Finck  *  Parses and splits an ASN.1 "SEQUENCE OF <tag>"
261c2c66affSColin Finck  */
mbedtls_asn1_get_sequence_of(unsigned char ** p,const unsigned char * end,mbedtls_asn1_sequence * cur,int tag)262c2c66affSColin Finck int mbedtls_asn1_get_sequence_of( unsigned char **p,
263c2c66affSColin Finck                           const unsigned char *end,
264c2c66affSColin Finck                           mbedtls_asn1_sequence *cur,
265c2c66affSColin Finck                           int tag)
266c2c66affSColin Finck {
267c2c66affSColin Finck     int ret;
268c2c66affSColin Finck     size_t len;
269c2c66affSColin Finck     mbedtls_asn1_buf *buf;
270c2c66affSColin Finck 
271c2c66affSColin Finck     /* Get main sequence tag */
272c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
273c2c66affSColin Finck             MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
274c2c66affSColin Finck         return( ret );
275c2c66affSColin Finck 
276c2c66affSColin Finck     if( *p + len != end )
277c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
278c2c66affSColin Finck 
279c2c66affSColin Finck     while( *p < end )
280c2c66affSColin Finck     {
281c2c66affSColin Finck         buf = &(cur->buf);
282c2c66affSColin Finck         buf->tag = **p;
283c2c66affSColin Finck 
284c2c66affSColin Finck         if( ( ret = mbedtls_asn1_get_tag( p, end, &buf->len, tag ) ) != 0 )
285c2c66affSColin Finck             return( ret );
286c2c66affSColin Finck 
287c2c66affSColin Finck         buf->p = *p;
288c2c66affSColin Finck         *p += buf->len;
289c2c66affSColin Finck 
290c2c66affSColin Finck         /* Allocate and assign next pointer */
291c2c66affSColin Finck         if( *p < end )
292c2c66affSColin Finck         {
293c2c66affSColin Finck             cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
294c2c66affSColin Finck                                             sizeof( mbedtls_asn1_sequence ) );
295c2c66affSColin Finck 
296c2c66affSColin Finck             if( cur->next == NULL )
297c2c66affSColin Finck                 return( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
298c2c66affSColin Finck 
299c2c66affSColin Finck             cur = cur->next;
300c2c66affSColin Finck         }
301c2c66affSColin Finck     }
302c2c66affSColin Finck 
303c2c66affSColin Finck     /* Set final sequence entry's next pointer to NULL */
304c2c66affSColin Finck     cur->next = NULL;
305c2c66affSColin Finck 
306c2c66affSColin Finck     if( *p != end )
307c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
308c2c66affSColin Finck 
309c2c66affSColin Finck     return( 0 );
310c2c66affSColin Finck }
311c2c66affSColin Finck 
mbedtls_asn1_get_alg(unsigned char ** p,const unsigned char * end,mbedtls_asn1_buf * alg,mbedtls_asn1_buf * params)312c2c66affSColin Finck int mbedtls_asn1_get_alg( unsigned char **p,
313c2c66affSColin Finck                   const unsigned char *end,
314c2c66affSColin Finck                   mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params )
315c2c66affSColin Finck {
316c2c66affSColin Finck     int ret;
317c2c66affSColin Finck     size_t len;
318c2c66affSColin Finck 
319c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
320c2c66affSColin Finck             MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
321c2c66affSColin Finck         return( ret );
322c2c66affSColin Finck 
323c2c66affSColin Finck     if( ( end - *p ) < 1 )
324c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_OUT_OF_DATA );
325c2c66affSColin Finck 
326c2c66affSColin Finck     alg->tag = **p;
327c2c66affSColin Finck     end = *p + len;
328c2c66affSColin Finck 
329c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 )
330c2c66affSColin Finck         return( ret );
331c2c66affSColin Finck 
332c2c66affSColin Finck     alg->p = *p;
333c2c66affSColin Finck     *p += alg->len;
334c2c66affSColin Finck 
335c2c66affSColin Finck     if( *p == end )
336c2c66affSColin Finck     {
337*cbda039fSThomas Faber         mbedtls_platform_zeroize( params, sizeof(mbedtls_asn1_buf) );
338c2c66affSColin Finck         return( 0 );
339c2c66affSColin Finck     }
340c2c66affSColin Finck 
341c2c66affSColin Finck     params->tag = **p;
342c2c66affSColin Finck     (*p)++;
343c2c66affSColin Finck 
344c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_len( p, end, &params->len ) ) != 0 )
345c2c66affSColin Finck         return( ret );
346c2c66affSColin Finck 
347c2c66affSColin Finck     params->p = *p;
348c2c66affSColin Finck     *p += params->len;
349c2c66affSColin Finck 
350c2c66affSColin Finck     if( *p != end )
351c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
352c2c66affSColin Finck 
353c2c66affSColin Finck     return( 0 );
354c2c66affSColin Finck }
355c2c66affSColin Finck 
mbedtls_asn1_get_alg_null(unsigned char ** p,const unsigned char * end,mbedtls_asn1_buf * alg)356c2c66affSColin Finck int mbedtls_asn1_get_alg_null( unsigned char **p,
357c2c66affSColin Finck                        const unsigned char *end,
358c2c66affSColin Finck                        mbedtls_asn1_buf *alg )
359c2c66affSColin Finck {
360c2c66affSColin Finck     int ret;
361c2c66affSColin Finck     mbedtls_asn1_buf params;
362c2c66affSColin Finck 
363c2c66affSColin Finck     memset( &params, 0, sizeof(mbedtls_asn1_buf) );
364c2c66affSColin Finck 
365c2c66affSColin Finck     if( ( ret = mbedtls_asn1_get_alg( p, end, alg, &params ) ) != 0 )
366c2c66affSColin Finck         return( ret );
367c2c66affSColin Finck 
368c2c66affSColin Finck     if( ( params.tag != MBEDTLS_ASN1_NULL && params.tag != 0 ) || params.len != 0 )
369c2c66affSColin Finck         return( MBEDTLS_ERR_ASN1_INVALID_DATA );
370c2c66affSColin Finck 
371c2c66affSColin Finck     return( 0 );
372c2c66affSColin Finck }
373c2c66affSColin Finck 
mbedtls_asn1_free_named_data(mbedtls_asn1_named_data * cur)374c2c66affSColin Finck void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur )
375c2c66affSColin Finck {
376c2c66affSColin Finck     if( cur == NULL )
377c2c66affSColin Finck         return;
378c2c66affSColin Finck 
379c2c66affSColin Finck     mbedtls_free( cur->oid.p );
380c2c66affSColin Finck     mbedtls_free( cur->val.p );
381c2c66affSColin Finck 
382*cbda039fSThomas Faber     mbedtls_platform_zeroize( cur, sizeof( mbedtls_asn1_named_data ) );
383c2c66affSColin Finck }
384c2c66affSColin Finck 
mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data ** head)385c2c66affSColin Finck void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
386c2c66affSColin Finck {
387c2c66affSColin Finck     mbedtls_asn1_named_data *cur;
388c2c66affSColin Finck 
389c2c66affSColin Finck     while( ( cur = *head ) != NULL )
390c2c66affSColin Finck     {
391c2c66affSColin Finck         *head = cur->next;
392c2c66affSColin Finck         mbedtls_asn1_free_named_data( cur );
393c2c66affSColin Finck         mbedtls_free( cur );
394c2c66affSColin Finck     }
395c2c66affSColin Finck }
396c2c66affSColin Finck 
mbedtls_asn1_find_named_data(mbedtls_asn1_named_data * list,const char * oid,size_t len)397c2c66affSColin Finck mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
398c2c66affSColin Finck                                        const char *oid, size_t len )
399c2c66affSColin Finck {
400c2c66affSColin Finck     while( list != NULL )
401c2c66affSColin Finck     {
402c2c66affSColin Finck         if( list->oid.len == len &&
403c2c66affSColin Finck             memcmp( list->oid.p, oid, len ) == 0 )
404c2c66affSColin Finck         {
405c2c66affSColin Finck             break;
406c2c66affSColin Finck         }
407c2c66affSColin Finck 
408c2c66affSColin Finck         list = list->next;
409c2c66affSColin Finck     }
410c2c66affSColin Finck 
411c2c66affSColin Finck     return( list );
412c2c66affSColin Finck }
413c2c66affSColin Finck 
414c2c66affSColin Finck #endif /* MBEDTLS_ASN1_PARSE_C */
415