blob: 3816c361151d900e16ae1a36b02d37282df3c834 [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{
40#if defined(MBEDTLS_THREADING_C)
Hanno Becker2ba9fbd2019-05-28 16:11:43 +010041 uint32_t frame_readers;
42 uint32_t pk_readers;
Hanno Becker00d39032019-05-13 12:39:44 +010043 mbedtls_threading_mutex_t frame_mutex;
44 mbedtls_threading_mutex_t pk_mutex;
45#endif
46 mbedtls_x509_buf_raw pk_raw;
47 struct mbedtls_x509_crt_frame *frame;
48 struct mbedtls_pk_context *pk;
49} mbedtls_x509_crt_cache;
Hanno Beckerf6bc8882019-05-02 13:05:58 +010050
Hanno Beckera4dfc0d2019-05-13 13:45:11 +010051/* Internal X.509 CRT cache handling functions. */
52
53int mbedtls_x509_crt_flush_cache_frame( struct mbedtls_x509_crt const *crt );
54int mbedtls_x509_crt_flush_cache_pk( struct mbedtls_x509_crt const *crt );
55
56int mbedtls_x509_crt_cache_provide_frame( struct mbedtls_x509_crt const *crt );
57int mbedtls_x509_crt_cache_provide_pk( struct mbedtls_x509_crt const *crt );
58
59/* Uncategorized internal X.509 functions */
60
Hanno Beckerf6bc8882019-05-02 13:05:58 +010061int mbedtls_x509_get_name( unsigned char *p, size_t len,
62 mbedtls_x509_name *cur );
63int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
64 mbedtls_x509_buf *alg );
65int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
66 mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
67#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
68int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
69 mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
70 int *salt_len );
71#endif
72int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
73int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end,
74 mbedtls_md_type_t *md_alg,
75 mbedtls_pk_type_t *pk_alg,
76 void **sig_opts );
77int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
78 mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
79 void **sig_opts );
80int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
81 mbedtls_x509_time *t );
82int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
83 mbedtls_x509_buf *serial );
84int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
85 mbedtls_x509_buf_raw const *b,
86 int (*check)( void *ctx,
87 mbedtls_x509_buf *oid,
88 mbedtls_x509_buf *val,
89 int next_merged ),
90 void *check_ctx );
91int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
92 size_t len1, size_t lend2 );
93int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
94 mbedtls_x509_buf *ext, int tag );
95
96#if !defined(MBEDTLS_X509_REMOVE_INFO)
97int mbedtls_x509_sig_alg_gets( char *buf, size_t size,
98 mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
99 const void *sig_opts );
100#endif
101int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
102int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
103int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
104 int critical, const unsigned char *val,
105 size_t val_len );
106int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
107 mbedtls_asn1_named_data *first );
108int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
109 mbedtls_asn1_named_data *first );
110int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
111 const char *oid, size_t oid_len,
112 unsigned char *sig, size_t size );
113
114#endif /* MBEDTLS_X509_INTERNAL_H */