Sync with TP.
[gnutls.git] / lib / gnutls_cert.h
blob179a18684560df149eb0079cc97c967510a4665d
1 /*
2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2010 Free
3 * Software Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GNUTLS.
9 * The GNUTLS library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 * USA
26 #ifndef GNUTLS_CERT_H
27 # define GNUTLS_CERT_H
29 #include <gnutls_pk.h>
30 #include "x509/x509_int.h"
31 #include <gnutls/openpgp.h>
33 #define MAX_PUBLIC_PARAMS_SIZE 4 /* ok for RSA and DSA */
35 /* parameters should not be larger than this limit */
36 #define DSA_PUBLIC_PARAMS 4
37 #define RSA_PUBLIC_PARAMS 2
39 /* For key Usage, test as:
40 * if (st.key_usage & KEY_DIGITAL_SIGNATURE) ...
42 #define KEY_DIGITAL_SIGNATURE 128
43 #define KEY_NON_REPUDIATION 64
44 #define KEY_KEY_ENCIPHERMENT 32
45 #define KEY_DATA_ENCIPHERMENT 16
46 #define KEY_KEY_AGREEMENT 8
47 #define KEY_KEY_CERT_SIGN 4
48 #define KEY_CRL_SIGN 2
49 #define KEY_ENCIPHER_ONLY 1
50 #define KEY_DECIPHER_ONLY 32768
52 typedef struct gnutls_cert
54 /* the size of params depends on the public
55 * key algorithm
56 * RSA: [0] is modulus
57 * [1] is public exponent
58 * DSA: [0] is p
59 * [1] is q
60 * [2] is g
61 * [3] is public key
63 bigint_t params[MAX_PUBLIC_PARAMS_SIZE];
64 int params_size; /* holds the size of MPI params */
66 gnutls_pk_algorithm_t subject_pk_algorithm;
68 unsigned int key_usage; /* bits from KEY_*
71 unsigned int version;
72 /* holds the type (PGP, X509)
74 gnutls_certificate_type_t cert_type;
75 gnutls_sign_algorithm_t sign_algo;
77 gnutls_datum_t raw;
79 #ifdef ENABLE_OPENPGP
80 int use_subkey;
81 gnutls_openpgp_keyid_t subkey_id;
82 #endif
83 } gnutls_cert;
85 typedef struct gnutls_privkey_int
87 /* the size of params depends on the public
88 * key algorithm
89 * RSA: [0] is modulus
90 * [1] is public exponent
91 * [2] is private exponent
92 * [3] is prime1 (p)
93 * [4] is prime2 (q)
94 * [5] is coefficient (u == inverse of p mod q)
95 * DSA: [0] is p
96 * [1] is q
97 * [2] is g
98 * [3] is y (public key)
99 * [4] is x (private key)
101 bigint_t params[MAX_PRIV_PARAMS_SIZE];
102 int params_size; /* holds the number of params */
104 gnutls_pk_algorithm_t pk_algorithm;
105 } gnutls_privkey;
107 /* because gnutls_session_t is not defined when this file is included */
108 struct gnutls_session_int;
110 typedef enum ConvFlags
112 CERT_NO_COPY = 2,
113 CERT_ONLY_PUBKEY = 4,
114 CERT_ONLY_EXTENSIONS = 16
115 } ConvFlags;
117 int _gnutls_x509_raw_cert_to_gcert (gnutls_cert * gcert,
118 const gnutls_datum_t * derCert,
119 int flags);
120 int _gnutls_x509_crt_to_gcert (gnutls_cert * gcert, gnutls_x509_crt_t cert,
121 unsigned int flags);
123 void _gnutls_gkey_deinit (gnutls_privkey * key);
124 void _gnutls_gcert_deinit (gnutls_cert * cert);
126 int _gnutls_selected_cert_supported_kx (struct gnutls_session_int *session,
127 gnutls_kx_algorithm_t ** alg,
128 int *alg_size);
130 #endif