blob: 6ca3db5903b4f0370870b0c4e3d9d97fda22865e [file] [log] [blame]
Hanno Beckerf6bc8882019-05-02 13:05:58 +01001/**
2 * \file x509_internal.h
3 *
4 * \brief Internal X.509 functions
5 */
6/*
7 * Copyright (C) 2006-2019, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * This file is part of Mbed TLS (https://tls.mbed.org)
23 *
24 */
25#ifndef MBEDTLS_X509_INTERNAL_H
26#define MBEDTLS_X509_INTERNAL_H
27
28#include "x509.h"
Hanno Becker00d39032019-05-13 12:39:44 +010029#include "threading.h"
30
31/* Internal structure used for caching parsed data from an X.509 CRT. */
32
33struct mbedtls_x509_crt;
34struct mbedtls_pk_context;
35struct mbedtls_x509_crt_frame;
Hanno Becker2ba9fbd2019-05-28 16:11:43 +010036#define MBEDTLS_X509_CACHE_PK_READERS_MAX ((uint32_t) -1)
37#define MBEDTLS_X509_CACHE_FRAME_READERS_MAX ((uint32_t) -1)
Hanno Becker00d39032019-05-13 12:39:44 +010038typedef struct mbedtls_x509_crt_cache
39{
Hanno Beckerfc99a092019-06-28 14:45:26 +010040#if !defined(MBEDTLS_X509_ALWAYS_FLUSH) || \
41 defined(MBEDTLS_THREADING_C)
Hanno Becker2ba9fbd2019-05-28 16:11:43 +010042 uint32_t frame_readers;
43 uint32_t pk_readers;
Hanno Beckerfc99a092019-06-28 14:45:26 +010044#endif /* !MBEDTLS_X509_ALWAYS_FLUSH || MBEDTLS_THREADING_C */
Hanno Beckera4bfaa82019-06-28 10:34:23 +010045#if defined(MBEDTLS_THREADING_C)
Hanno Becker00d39032019-05-13 12:39:44 +010046 mbedtls_threading_mutex_t frame_mutex;
47 mbedtls_threading_mutex_t pk_mutex;
48#endif
49 mbedtls_x509_buf_raw pk_raw;
50 struct mbedtls_x509_crt_frame *frame;
51 struct mbedtls_pk_context *pk;
52} mbedtls_x509_crt_cache;
Hanno Beckerf6bc8882019-05-02 13:05:58 +010053
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010054/* Internal X.509 CRT cache handling functions. */
55
56int mbedtls_x509_crt_flush_cache_frame( struct mbedtls_x509_crt const *crt );
57int mbedtls_x509_crt_flush_cache_pk( struct mbedtls_x509_crt const *crt );
58
59int mbedtls_x509_crt_cache_provide_frame( struct mbedtls_x509_crt const *crt );
60int mbedtls_x509_crt_cache_provide_pk( struct mbedtls_x509_crt const *crt );
61
62/* Uncategorized internal X.509 functions */
63
Hanno Beckerf6bc8882019-05-02 13:05:58 +010064int mbedtls_x509_get_name( unsigned char *p, size_t len,
65 mbedtls_x509_name *cur );
66int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
67 mbedtls_x509_buf *alg );
68int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
69 mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
70#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
71int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
72 mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
73 int *salt_len );
74#endif
75int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
76int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end,
77 mbedtls_md_type_t *md_alg,
78 mbedtls_pk_type_t *pk_alg,
79 void **sig_opts );
80int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
81 mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
82 void **sig_opts );
83int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
84 mbedtls_x509_time *t );
85int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
86 mbedtls_x509_buf *serial );
87int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
88 mbedtls_x509_buf_raw const *b,
89 int (*check)( void *ctx,
90 mbedtls_x509_buf *oid,
91 mbedtls_x509_buf *val,
92 int next_merged ),
93 void *check_ctx );
94int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
Hanno Becker2656bfe2019-06-25 09:44:56 +010095 size_t len1, size_t len2 );
Hanno Beckerf6bc8882019-05-02 13:05:58 +010096int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
97 mbedtls_x509_buf *ext, int tag );
98
99#if !defined(MBEDTLS_X509_REMOVE_INFO)
100int mbedtls_x509_sig_alg_gets( char *buf, size_t size,
101 mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
102 const void *sig_opts );
103#endif
104int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
105int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
106int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
107 int critical, const unsigned char *val,
108 size_t val_len );
109int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
110 mbedtls_asn1_named_data *first );
111int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
112 mbedtls_asn1_named_data *first );
113int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
114 const char *oid, size_t oid_len,
115 unsigned char *sig, size_t size );
116
117#endif /* MBEDTLS_X509_INTERNAL_H */