Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / lib / abstract_int.h
1 /*
2  * Copyright (C) 2010-2012 Free Software Foundation, Inc.
3  *
4  * Author: Nikos Mavrogiannopoulos
5  *
6  * This file is part of GnuTLS.
7  *
8  * The GnuTLS is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>
20  *
21  */
22
23 #ifndef _ABSTRACT_INT_H
24 #define _ABSTRACT_INT_H
25
26 #include <gnutls/abstract.h>
27
28 struct gnutls_privkey_st {
29         gnutls_privkey_type_t type;
30         gnutls_pk_algorithm_t pk_algorithm;
31
32         union {
33                 gnutls_x509_privkey_t x509;
34 #ifdef ENABLE_PKCS11
35                 gnutls_pkcs11_privkey_t pkcs11;
36 #endif
37 #ifdef ENABLE_OPENPGP
38                 gnutls_openpgp_privkey_t openpgp;
39 #endif
40                 struct {
41                         gnutls_privkey_sign_func sign_func;
42                         gnutls_privkey_decrypt_func decrypt_func;
43                         gnutls_privkey_deinit_func deinit_func;
44                         void *userdata;
45                 } ext;
46         } key;
47
48         unsigned int flags;
49         struct pin_info_st pin;
50 };
51
52 struct gnutls_pubkey_st {
53         gnutls_pk_algorithm_t pk_algorithm;
54         unsigned int bits;      /* an indication of the security parameter */
55
56         /* the size of params depends on the public
57          * key algorithm
58          * RSA: [0] is modulus
59          *      [1] is public exponent
60          * DSA: [0] is p
61          *      [1] is q
62          *      [2] is g
63          *      [3] is public key
64          */
65         gnutls_pk_params_st params;
66
67 #ifdef ENABLE_OPENPGP
68         uint8_t openpgp_key_id[GNUTLS_OPENPGP_KEYID_SIZE];
69         unsigned int openpgp_key_id_set;
70
71         uint8_t openpgp_key_fpr[GNUTLS_OPENPGP_V4_FINGERPRINT_SIZE];
72         unsigned int openpgp_key_fpr_set:1;
73 #endif
74
75         unsigned int key_usage; /* bits from GNUTLS_KEY_* */
76
77         struct pin_info_st pin;
78 };
79
80 int _gnutls_privkey_get_public_mpis(gnutls_privkey_t key,
81                                     gnutls_pk_params_st *);
82
83 void _gnutls_privkey_cleanup(gnutls_privkey_t key);
84
85 int pubkey_to_bits(gnutls_pk_algorithm_t pk, gnutls_pk_params_st * params);
86 int _gnutls_pubkey_compatible_with_sig(gnutls_session_t,
87                                        gnutls_pubkey_t pubkey,
88                                        const version_entry_st * ver,
89                                        gnutls_sign_algorithm_t sign);
90 int
91 _gnutls_pubkey_get_mpis(gnutls_pubkey_t key, gnutls_pk_params_st * params);
92
93 int
94 pubkey_verify_hashed_data(gnutls_pk_algorithm_t pk,
95                           const mac_entry_st * algo,
96                           const gnutls_datum_t * hash,
97                           const gnutls_datum_t * signature,
98                           gnutls_pk_params_st * issuer_params);
99
100 int pubkey_verify_data(gnutls_pk_algorithm_t pk,
101                        const mac_entry_st * algo,
102                        const gnutls_datum_t * data,
103                        const gnutls_datum_t * signature,
104                        gnutls_pk_params_st * issuer_params);
105
106
107
108 const mac_entry_st *_gnutls_dsa_q_to_hash(gnutls_pk_algorithm_t algo,
109                                           const gnutls_pk_params_st *
110                                           params, unsigned int *hash_len);
111
112 int
113 _gnutls_privkey_get_mpis(gnutls_privkey_t key, gnutls_pk_params_st * params);
114
115 #endif