Fixed leaks in key generation and other cleanups. Patch by Tomas Mraz.
[gnutls.git] / lib / x509 / common.h
blob5cc6a109c659d3f6cfda4f6e2108ce8ef0049b4c
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2010 Free Software
3 * Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS.
9 * The GnuTLS 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 COMMON_H
27 #define COMMON_H
29 #include <gnutls_algorithms.h>
31 #define MAX_STRING_LEN 512
33 #define GNUTLS_XML_SHOW_ALL 1
35 #define PEM_CRL "X509 CRL"
36 #define PEM_X509_CERT "X509 CERTIFICATE"
37 #define PEM_X509_CERT2 "CERTIFICATE"
38 #define PEM_PKCS7 "PKCS7"
39 #define PEM_PKCS12 "PKCS12"
41 /* public key algorithm's OIDs
43 #define PK_PKIX1_RSA_OID "1.2.840.113549.1.1.1"
44 #define PK_X509_RSA_OID "2.5.8.1.1"
45 #define PK_DSA_OID "1.2.840.10040.4.1"
46 #define PK_GOST_R3410_94_OID "1.2.643.2.2.20"
47 #define PK_GOST_R3410_2001_OID "1.2.643.2.2.19"
49 /* signature OIDs
51 #define SIG_DSA_SHA1_OID "1.2.840.10040.4.3"
52 /* those two from draft-ietf-pkix-sha2-dsa-ecdsa-06 */
53 #define SIG_DSA_SHA224_OID "2.16.840.1.101.3.4.3.1"
54 #define SIG_DSA_SHA256_OID "2.16.840.1.101.3.4.3.2"
56 #define SIG_RSA_MD5_OID "1.2.840.113549.1.1.4"
57 #define SIG_RSA_MD2_OID "1.2.840.113549.1.1.2"
58 #define SIG_RSA_SHA1_OID "1.2.840.113549.1.1.5"
59 #define SIG_RSA_SHA224_OID "1.2.840.113549.1.1.14"
60 #define SIG_RSA_SHA256_OID "1.2.840.113549.1.1.11"
61 #define SIG_RSA_SHA384_OID "1.2.840.113549.1.1.12"
62 #define SIG_RSA_SHA512_OID "1.2.840.113549.1.1.13"
63 #define SIG_RSA_RMD160_OID "1.3.36.3.3.1.2"
64 #define SIG_GOST_R3410_94_OID "1.2.643.2.2.4"
65 #define SIG_GOST_R3410_2001_OID "1.2.643.2.2.3"
67 #define ASN1_NULL "\x05\x00"
68 #define ASN1_NULL_SIZE 2
70 int _gnutls_x509_set_time (ASN1_TYPE c2, const char *where, time_t tim);
72 int _gnutls_x509_decode_octet_string (const char *string_type,
73 const opaque * der, size_t der_size,
74 opaque * output, size_t * output_size);
75 int _gnutls_x509_oid_data2string (const char *OID, void *value,
76 int value_size, char *res,
77 size_t * res_size);
78 int _gnutls_x509_data2hex (const opaque * data, size_t data_size,
79 opaque * out, size_t * sizeof_out);
81 const char *_gnutls_x509_oid2asn_string (const char *oid);
83 const char *_gnutls_x509_oid2ldap_string (const char *OID);
85 int _gnutls_x509_oid_data_choice (const char *OID);
86 int _gnutls_x509_oid_data_printable (const char *OID);
88 time_t _gnutls_x509_get_time (ASN1_TYPE c2, const char *when);
90 gnutls_x509_subject_alt_name_t _gnutls_x509_san_find_type (char *str_type);
92 int _gnutls_x509_der_encode_and_copy (ASN1_TYPE src, const char *src_name,
93 ASN1_TYPE dest, const char *dest_name,
94 int str);
95 int _gnutls_x509_der_encode (ASN1_TYPE src, const char *src_name,
96 gnutls_datum_t * res, int str);
98 int _gnutls_x509_export_int (ASN1_TYPE asn1_data,
99 gnutls_x509_crt_fmt_t format,
100 const char *pem_header,
101 unsigned char *output_data,
102 size_t * output_data_size);
104 int _gnutls_x509_export_int_named (ASN1_TYPE asn1_data, const char *name,
105 gnutls_x509_crt_fmt_t format,
106 const char *pem_header,
107 unsigned char *output_data,
108 size_t * output_data_size);
110 int _gnutls_x509_read_value (ASN1_TYPE c, const char *root,
111 gnutls_datum_t * ret, int str);
112 int _gnutls_x509_write_value (ASN1_TYPE c, const char *root,
113 const gnutls_datum_t * data, int str);
115 int _gnutls_x509_encode_and_write_attribute (const char *given_oid,
116 ASN1_TYPE asn1_struct,
117 const char *where,
118 const void *data,
119 int sizeof_data, int multi);
120 int _gnutls_x509_decode_and_read_attribute (ASN1_TYPE asn1_struct,
121 const char *where, char *oid,
122 int oid_size,
123 gnutls_datum_t * value, int multi,
124 int octet);
126 int _gnutls_x509_get_pk_algorithm (ASN1_TYPE src, const char *src_name,
127 unsigned int *bits);
129 int _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst,
130 const char *dst_name,
131 gnutls_pk_algorithm_t
132 pk_algorithm, bigint_t * params,
133 int params_size);
134 int _gnutls_asn1_copy_node (ASN1_TYPE * dst, const char *dst_name,
135 ASN1_TYPE src, const char *src_name);
137 int _gnutls_x509_get_signed_data (ASN1_TYPE src, const char *src_name,
138 gnutls_datum_t * signed_data);
139 int _gnutls_x509_get_signature (ASN1_TYPE src, const char *src_name,
140 gnutls_datum_t * signature);
142 gnutls_digest_algorithm_t _gnutls_dsa_q_to_hash (bigint_t q, unsigned int* hash_len);
144 int _gnutls_get_asn_mpis (ASN1_TYPE asn, const char *root,
145 bigint_t * params, int *params_size);
147 int _gnutls_get_key_id (gnutls_pk_algorithm_t pk, bigint_t * params,
148 int params_size, unsigned char *output_data,
149 size_t * output_data_size);
151 void _asnstr_append_name (char *name, size_t name_size, const char *part1,
152 const char *part2);
154 int pubkey_verify_sig (const gnutls_datum_t * tbs,
155 const gnutls_datum_t * hash,
156 const gnutls_datum_t * signature,
157 gnutls_pk_algorithm_t pk, bigint_t * issuer_params,
158 int issuer_params_size);
160 #endif