2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
6 * This file is part of OpenCDK.
8 * The OpenCDK library 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 3 of
11 * the License, or (at your option) any later version.
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.
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/>
28 #define _cdk_log_debug _gnutls_hard_log
29 #define _cdk_log_info _gnutls_debug_log
30 #define _cdk_get_log_level() _gnutls_log_level
32 #define cdk_malloc gnutls_malloc
33 #define cdk_free gnutls_free
34 #define cdk_calloc gnutls_calloc
35 #define cdk_realloc gnutls_realloc_fast
36 #define cdk_strdup gnutls_strdup
37 #define cdk_salloc gnutls_secure_calloc
39 #define map_gnutls_error _cdk_map_gnutls_error
41 cdk_error_t
map_gnutls_error (int err
);
43 /* The general size of a buffer for the variou modules. */
46 /* This is the default block size for the partial length packet mode. */
47 #define DEF_BLOCKSIZE 8192
48 #define DEF_BLOCKBITS 13 /* 2^13 = 8192 */
50 /* For now SHA-1 is used to create fingerprint for keys.
51 But if this will ever change, it is a good idea to
52 have a constant for it to avoid to change it in all files. */
53 #define KEY_FPR_LEN 20
57 /* The maximal amount of bits a multi precsion integer can have. */
58 #define MAX_MPI_BITS 16384
59 #define MAX_MPI_BYTES (MAX_MPI_BITS/8)
62 /* Because newer DSA variants are not limited to SHA-1, we must consider
63 that SHA-512 is used and increase the buffer size of the digest. */
64 #define MAX_DIGEST_LEN 64
66 /* Helper to find out if the signature were made over a user ID
67 or if the signature revokes a previous user ID. */
68 #define IS_UID_SIG(s) (((s)->sig_class & ~3) == 0x10)
69 #define IS_UID_REV(s) ((s)->sig_class == 0x30)
71 /* Helper to find out if a key has the requested capability. */
72 #define KEY_CAN_ENCRYPT(a) ((_cdk_pk_algo_usage ((a))) & CDK_KEY_USG_ENCR)
73 #define KEY_CAN_SIGN(a) ((_cdk_pk_algo_usage ((a))) & CDK_KEY_USG_SIGN)
74 #define KEY_CAN_AUTH(a) ((_cdk_pk_algo_usage ((a))) & CDK_KEY_USG_AUTH)
79 char *_cdk_passphrase_get (cdk_ctx_t hd
, const char *prompt
);
82 int _cdk_check_args (int overwrite
, const char *in
, const char *out
);
83 u32
_cdk_buftou32 (const byte
* buf
);
84 void _cdk_u32tobuf (u32 u
, byte
* buf
);
85 const char *_cdk_memistr (const char *buf
, size_t buflen
, const char *sub
);
86 FILE *_cdk_tmpfile (void);
88 /* Helper to provide case insentensive strstr version. */
89 #define stristr(haystack, needle) \
90 _cdk_memistr((haystack), strlen (haystack), (needle))
92 /*-- proc-packet.c --*/
93 cdk_error_t
_cdk_pkt_write2 (cdk_stream_t out
, int pkttype
, void *pktctx
);
96 u32
_cdk_pkt_get_keyid (cdk_packet_t pkt
, u32
* keyid
);
97 cdk_error_t
_cdk_pkt_get_fingerprint (cdk_packet_t pkt
, byte
* fpr
);
98 int _cdk_pk_algo_usage (int algo
);
99 int _cdk_pk_test_algo (int algo
, unsigned int usage
);
100 int _cdk_sk_get_csum (cdk_pkt_seckey_t sk
);
102 /*-- new-packet.c --*/
103 byte
*_cdk_subpkt_get_array (cdk_subpkt_t s
, int count
, size_t * r_nbytes
);
104 cdk_error_t
_cdk_subpkt_copy (cdk_subpkt_t
* r_dst
, cdk_subpkt_t src
);
105 void _cdk_pkt_detach_free (cdk_packet_t pkt
, int *r_pkttype
, void **ctx
);
107 /*-- sig-check.c --*/
108 cdk_error_t
_cdk_sig_check (cdk_pkt_pubkey_t pk
, cdk_pkt_signature_t sig
,
109 digest_hd_st
* digest
, int *r_expired
);
110 cdk_error_t
_cdk_hash_sig_data (cdk_pkt_signature_t sig
, digest_hd_st
* hd
);
111 cdk_error_t
_cdk_hash_userid (cdk_pkt_userid_t uid
, int sig_version
,
113 cdk_error_t
_cdk_hash_pubkey (cdk_pkt_pubkey_t pk
, digest_hd_st
* md
,
115 cdk_error_t
_cdk_pk_check_sig (cdk_keydb_hd_t hd
, cdk_kbnode_t knode
,
116 cdk_kbnode_t snode
, int *is_selfsig
,
120 void _cdk_kbnode_add (cdk_kbnode_t root
, cdk_kbnode_t node
);
121 void _cdk_kbnode_clone (cdk_kbnode_t node
);
124 cdk_error_t
_cdk_sk_unprotect_auto (cdk_ctx_t hd
, cdk_pkt_seckey_t sk
);
127 int _cdk_keydb_is_secret (cdk_keydb_hd_t db
);
128 cdk_error_t
_cdk_keydb_get_pk_byusage (cdk_keydb_hd_t hd
, const char *name
,
129 cdk_pkt_pubkey_t
* ret_pk
, int usage
);
130 cdk_error_t
_cdk_keydb_get_sk_byusage (cdk_keydb_hd_t hd
, const char *name
,
131 cdk_pkt_seckey_t
* ret_sk
, int usage
);
132 cdk_error_t
_cdk_keydb_check_userid (cdk_keydb_hd_t hd
, u32
* keyid
,
136 int _cdk_sig_hash_for (cdk_pkt_pubkey_t pk
);
137 void _cdk_trim_string (char *s
);
138 cdk_error_t
_cdk_sig_create (cdk_pkt_pubkey_t pk
, cdk_pkt_signature_t sig
);
139 cdk_error_t
_cdk_sig_complete (cdk_pkt_signature_t sig
, cdk_pkt_seckey_t sk
,
143 void _cdk_stream_set_compress_algo (cdk_stream_t s
, int algo
);
144 cdk_error_t
_cdk_stream_open_mode (const char *file
, const char *mode
,
145 cdk_stream_t
* ret_s
);
146 void *_cdk_stream_get_uint8_t (cdk_stream_t s
, int fid
);
147 const char *_cdk_stream_get_fname (cdk_stream_t s
);
148 FILE *_cdk_stream_get_fp (cdk_stream_t s
);
149 int _cdk_stream_gets (cdk_stream_t s
, char *buf
, size_t count
);
150 cdk_error_t
_cdk_stream_append (const char *file
, cdk_stream_t
* ret_s
);
151 int _cdk_stream_get_errno (cdk_stream_t s
);
152 cdk_error_t
_cdk_stream_set_blockmode (cdk_stream_t s
, size_t nbytes
);
153 int _cdk_stream_get_blockmode (cdk_stream_t s
);
154 int _cdk_stream_puts (cdk_stream_t s
, const char *buf
);
155 cdk_error_t
_cdk_stream_fpopen (FILE * fp
, unsigned write_mode
,
156 cdk_stream_t
* ret_out
);
159 /*-- read-packet.c --*/
160 size_t _cdk_pkt_read_len (FILE * inp
, size_t * ret_partial
);
162 /*-- write-packet.c --*/
163 cdk_error_t
_cdk_pkt_write_fp (FILE * out
, cdk_packet_t pkt
);
166 cdk_error_t
_cdk_s2k_copy (cdk_s2k_t
* r_dst
, cdk_s2k_t src
);
168 #define _cdk_pub_algo_to_pgp(algo) (algo)
169 #define _pgp_pub_algo_to_cdk(algo) (algo)
170 int _gnutls_hash_algo_to_pgp (int algo
);
171 int _pgp_hash_algo_to_gnutls (int algo
);
172 int _gnutls_cipher_to_pgp (int cipher
);
173 int _pgp_cipher_to_gnutls (int cipher
);
175 #endif /* CDK_MAIN_H */