summaryrefslogtreecommitdiffstats
path: root/lib/abstract_int.h
blob: cc839ccf843a6827eae95d688f34ced9dedfa057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (C) 2010-2012 Free Software Foundation, Inc.
 *
 * Author: Nikos Mavrogiannopoulos
 *
 * This file is part of GnuTLS.
 *
 * The GnuTLS is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
 *
 */

#ifndef GNUTLS_LIB_ABSTRACT_INT_H
#define GNUTLS_LIB_ABSTRACT_INT_H

#include <gnutls/abstract.h>

typedef int (*gnutls_privkey_pk_params_func) (gnutls_privkey_t key,
					      void *userdata,
					      gnutls_pk_params_st *params);

struct gnutls_privkey_st {
	gnutls_privkey_type_t type;
	gnutls_pk_algorithm_t pk_algorithm;

	union {
		gnutls_x509_privkey_t x509;
#ifdef ENABLE_PKCS11
		gnutls_pkcs11_privkey_t pkcs11;
#endif
		struct {
			gnutls_privkey_sign_func sign_func; /* raw like TLS 1.x */
			gnutls_privkey_sign_data_func sign_data_func;
			gnutls_privkey_sign_hash_func sign_hash_func;
			gnutls_privkey_decrypt_func decrypt_func;
			gnutls_privkey_decrypt_func2 decrypt_func2;
			gnutls_privkey_deinit_func deinit_func;
			gnutls_privkey_info_func info_func;
			gnutls_privkey_pk_params_func pk_params_func;
			void *userdata;
			unsigned bits;
		} ext;
	} key;

	unsigned int flags;
	struct pin_info_st pin;
};

struct gnutls_pubkey_st {
	unsigned int bits;	/* an indication of the security parameter */

	/* the size of params depends on the public
	 * key algorithm
	 * RSA: [0] is modulus
	 *      [1] is public exponent
	 * DSA: [0] is p
	 *      [1] is q
	 *      [2] is g
	 *      [3] is public key
	 */
	gnutls_pk_params_st params;

	unsigned int key_usage;	/* bits from GNUTLS_KEY_* */

	struct pin_info_st pin;
};

int _gnutls_privkey_get_public_mpis(gnutls_privkey_t key,
				    gnutls_pk_params_st *);

int _gnutls_privkey_get_spki_params(gnutls_privkey_t key,
				    gnutls_x509_spki_st * params);
int _gnutls_privkey_update_spki_params(gnutls_privkey_t key,
				     gnutls_pk_algorithm_t pk,
				     gnutls_digest_algorithm_t dig,
				     unsigned flags,
				     gnutls_x509_spki_st *params);

unsigned _gnutls_privkey_compatible_with_sig(gnutls_privkey_t key, gnutls_sign_algorithm_t sig);

void _gnutls_privkey_cleanup(gnutls_privkey_t key);

int privkey_sign_and_hash_data(gnutls_privkey_t signer,
			       const gnutls_sign_entry_st *se,
			       const gnutls_datum_t * data,
			       gnutls_datum_t * signature,
			       gnutls_x509_spki_st *params);
int
privkey_sign_raw_data(gnutls_privkey_t key,
		      const gnutls_sign_entry_st *se,
		      const gnutls_datum_t * data,
		      gnutls_datum_t * signature,
		      gnutls_x509_spki_st * params);

unsigned pubkey_to_bits(const gnutls_pk_params_st * params);
int _gnutls_pubkey_compatible_with_sig(gnutls_session_t,
				       gnutls_pubkey_t pubkey,
				       const version_entry_st * ver,
				       gnutls_sign_algorithm_t sign);
int
_gnutls_pubkey_get_mpis(gnutls_pubkey_t key, gnutls_pk_params_st * params);

int pubkey_verify_data(const gnutls_sign_entry_st *se,
		       const mac_entry_st *me,
		       const gnutls_datum_t * data,
		       const gnutls_datum_t * signature,
		       gnutls_pk_params_st * params,
		       gnutls_x509_spki_st * sign_params,
		       unsigned vflags);



const mac_entry_st *_gnutls_dsa_q_to_hash(const gnutls_pk_params_st *
					  params, unsigned int *hash_len);

int
_gnutls_privkey_get_mpis(gnutls_privkey_t key, gnutls_pk_params_st * params);

#endif /* GNUTLS_LIB_ABSTRACT_INT_H */