1 /* opencdk.h - Open Crypto Development Kit (OpenCDK)
2 * Copyright (C) 2006, 2007 Free Software Foundation, Inc.
3 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
5 * This file is part of OpenCDK.
7 * OpenCDK is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * OpenCDK is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with OpenCDK; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #define OPENCDK_VERSION "0.5.11"
36 /* General contexts */
38 typedef struct cdk_ctx_s
*cdk_ctx_t
;
41 typedef struct cdk_strlist_s
*cdk_strlist_t
;
44 typedef struct cdk_sesskey_s
*cdk_sesskey_t
;
47 typedef struct cdk_listkey_s
*cdk_listkey_t
;
50 typedef struct cdk_mpi_s
*cdk_mpi_t
;
53 typedef struct cdk_dek_s
*cdk_dek_t
;
56 typedef struct cdk_s2k_s
*cdk_s2k_t
;
59 typedef struct cdk_stream_s
*cdk_stream_t
;
61 struct cdk_prefitem_s
;
62 typedef struct cdk_prefitem_s
*cdk_prefitem_t
;
65 typedef struct cdk_kbnode_s
*cdk_kbnode_t
;
67 struct cdk_keydb_hd_s
;
68 typedef struct cdk_keydb_hd_s
*cdk_keydb_hd_t
;
71 typedef struct cdk_keylist_s
*cdk_keylist_t
;
74 typedef struct cdk_subpkt_s
*cdk_subpkt_t
;
76 struct cdk_keygen_ctx_s
;
77 typedef struct cdk_keygen_ctx_s
*cdk_keygen_ctx_t
;
79 struct cdk_desig_revoker_s
;
80 typedef struct cdk_desig_revoker_s
*cdk_desig_revoker_t
;
83 typedef struct cdk_md_hd_s
*cdk_md_hd_t
;
85 struct cdk_cipher_hd_s
;
86 typedef struct cdk_cipher_hd_s
*cdk_cipher_hd_t
;
92 CDK_General_Error
= 1,
97 CDK_Not_Implemented
= 6,
100 CDK_Armor_CRC_Error
= 9,
103 CDK_Error_No_Key
= 12,
104 CDK_Chksum_Error
= 13,
105 CDK_Time_Conflict
= 14,
108 CDK_Out_Of_Core
= 17,
109 CDK_Wrong_Seckey
= 18,
112 CDK_Error_No_Keyring
= 21,
113 CDK_Wrong_Format
= 22,
114 CDK_Inv_Packet_Ver
= 23,
116 CDK_Unusable_Key
= 25
120 enum cdk_control_flags
{
126 CDK_CTL_COMPRESS
= 13,
128 CDK_CTL_OVERWRITE
= 15,
130 CDK_CTL_KEYCACHE_ON
= 17,
131 CDK_CTL_KEYCACHE_FREE
= 18,
132 CDK_CTL_FORCE_DIGEST
= 19,
133 CDK_CTL_TRUSTMODEL
= 20
136 enum cdk_log_level_t
{
142 enum cdk_compress_algo_t
{
143 CDK_COMPRESS_NONE
= 0,
144 CDK_COMPRESS_ZIP
= 1,
145 CDK_COMPRESS_ZLIB
= 2
163 CDK_MD_TIGER
= 6, /* will be removed and thus: reserved */
167 enum cdk_cipher_algo_t
{
171 CDK_CIPHER_CAST5
= 3,
172 CDK_CIPHER_BLOWFISH
= 4,
173 CDK_CIPHER_SAFER_SK128
= 5, /* will be removed and thus: reserved */
174 CDK_CIPHER_DES_SK
= 6, /* will be removed and thus: reserved */
176 CDK_CIPHER_AES192
= 8,
177 CDK_CIPHER_AES256
= 9,
178 CDK_CIPHER_TWOFISH
= 10
181 enum cdk_s2k_type_t
{
184 CDK_S2K_ITERSALTED
= 3
187 enum cdk_pref_type_t
{
188 CDK_PREFTYPE_NONE
= 0,
189 CDK_PREFTYPE_SYM
= 1,
190 CDK_PREFTYPE_HASH
= 2,
194 enum cdk_sig_subpacket_t
{
195 CDK_SIGSUBPKT_NONE
= 0,
196 CDK_SIGSUBPKT_SIG_CREATED
= 2,
197 CDK_SIGSUBPKT_SIG_EXPIRE
= 3,
198 CDK_SIGSUBPKT_EXPORTABLE
= 4,
199 CDK_SIGSUBPKT_TRUST
= 5,
200 CDK_SIGSUBPKT_REGEXP
= 6,
201 CDK_SIGSUBPKT_REVOCABLE
= 7,
202 CDK_SIGSUBPKT_KEY_EXPIRE
= 9,
203 CDK_SIGSUBPKT_PREFS_SYM
= 11,
204 CDK_SIGSUBPKT_REV_KEY
= 12,
205 CDK_SIGSUBPKT_ISSUER
= 16,
206 CDK_SIGSUBPKT_NOTATION
= 20,
207 CDK_SIGSUBPKT_PREFS_HASH
= 21,
208 CDK_SIGSUBPKT_PREFS_ZIP
= 22,
209 CDK_SIGSUBPKT_KS_FLAGS
= 23,
210 CDK_SIGSUBPKT_PREF_KS
= 24,
211 CDK_SIGSUBPKT_PRIMARY_UID
= 25,
212 CDK_SIGSUBPKT_POLICY
= 26,
213 CDK_SIGSUBPKT_KEY_FLAGS
= 27,
214 CDK_SIGSUBPKT_SIGNERS_UID
= 28,
215 CDK_SIGSUBPKT_REVOC_REASON
= 29,
216 CDK_SIGSUBPKT_FEATURES
= 30
220 enum cdk_revoc_code_t
{
221 CDK_REVCOD_NOREASON
= 0x00,
222 CDK_REVCOD_SUPERCEDED
= 0x01,
223 CDK_REVCOD_COMPROMISED
= 0x02,
224 CDK_REVCOD_NOLONGUSED
= 0x03
227 enum cdk_armor_type_t
{
228 CDK_ARMOR_MESSAGE
= 0,
229 CDK_ARMOR_PUBKEY
= 1,
230 CDK_ARMOR_SECKEY
= 2,
231 CDK_ARMOR_SIGNATURE
= 3,
232 CDK_ARMOR_CLEARSIG
= 4
235 enum cdk_stream_control_t
{
236 CDK_STREAMCTL_DISABLE
= 2,
237 CDK_STREAMCTL_COMPRESSED
= 3
240 enum cdk_keydb_flag_t
{
241 /* database search modes */
242 CDK_DBSEARCH_EXACT
= 1,
243 CDK_DBSEARCH_SUBSTR
= 2, /* sub string search */
244 CDK_DBSEARCH_SHORT_KEYID
= 3, /* 32-bit keyid search */
245 CDK_DBSEARCH_KEYID
= 4, /* 64-bit keyid search */
246 CDK_DBSEARCH_FPR
= 5, /* 160-bit fingerprint search */
247 CDK_DBSEARCH_NEXT
= 6, /* enumerate all keys */
248 CDK_DBSEARCH_AUTO
= 7, /* try automagically class search */
250 CDK_DBTYPE_PK_KEYRING
= 100,
251 CDK_DBTYPE_SK_KEYRING
= 101,
252 CDK_DBTYPE_DATA
= 102
256 enum cdk_crypto_mode_t
{
257 CDK_CRYPTYPE_NONE
= 0,
258 CDK_CRYPTYPE_ENCRYPT
= 1,
259 CDK_CRYPTYPE_DECRYPT
= 2,
260 CDK_CRYPTYPE_SIGN
= 3,
261 CDK_CRYPTYPE_VERIFY
= 4,
262 CDK_CRYPTYPE_EXPORT
= 5,
263 CDK_CRYPTYPE_IMPORT
= 6
266 enum cdk_key_flag_t
{
268 CDK_KEY_INVALID
= 1, /* missing or wrong self signature */
274 enum cdk_trust_flag_t
{
275 CDK_TRUST_UNKNOWN
= 0,
276 CDK_TRUST_EXPIRED
= 1,
277 CDK_TRUST_UNDEFINED
= 2,
279 CDK_TRUST_MARGINAL
= 4,
281 CDK_TRUST_ULTIMATE
= 6,
283 CDK_TFLAG_REVOKED
= 32,
284 CDK_TFLAG_SUB_REVOKED
= 64,
285 CDK_TFLAG_DISABLED
= 128
289 enum cdk_signature_id_t
{
290 /* signature status */
291 CDK_SIGSTAT_NONE
= 0,
292 CDK_SIGSTAT_GOOD
= 1,
294 CDK_SIGSTAT_NOKEY
= 3,
295 /* signature modes */
296 CDK_SIGMODE_NORMAL
= 100,
297 CDK_SIGMODE_DETACHED
= 101,
298 CDK_SIGMODE_CLEAR
= 102
301 enum cdk_attribute_t
{
303 CDK_ATTR_CREATED
= 1,
307 CDK_ATTR_NOTATION
= 5,
308 CDK_ATTR_ALGO_PK
= 6,
309 CDK_ATTR_ALGO_MD
= 7,
310 CDK_ATTR_VERSION
= 8,
318 CDK_FLAG_KEY_REVOKED
= 256,
319 CDK_FLAG_KEY_EXPIRED
= 512,
320 CDK_FLAG_SIG_EXPIRED
= 1024
324 enum cdk_callback_id_t
{
326 CDK_CB_PUBKEY_ENC
= 1
331 CDK_PKT_RESERVED
= 0,
332 CDK_PKT_PUBKEY_ENC
= 1,
333 CDK_PKT_SIGNATURE
= 2,
334 CDK_PKT_SYMKEY_ENC
= 3,
335 CDK_PKT_ONEPASS_SIG
= 4,
336 CDK_PKT_SECRET_KEY
= 5,
337 CDK_PKT_PUBLIC_KEY
= 6,
338 CDK_PKT_SECRET_SUBKEY
= 7,
339 CDK_PKT_COMPRESSED
= 8,
340 CDK_PKT_ENCRYPTED
= 9,
342 CDK_PKT_LITERAL
= 11,
343 CDK_PKT_RING_TRUST
= 12,
344 CDK_PKT_USER_ID
= 13,
345 CDK_PKT_PUBLIC_SUBKEY
= 14,
346 CDK_PKT_OLD_COMMENT
= 16,
347 CDK_PKT_ATTRIBUTE
= 17,
348 CDK_PKT_ENCRYPTED_MDC
= 18,
352 #define CDK_PKT_IS_ENCRYPTED(pkttype) (\
353 ((pkttype)==CDK_PKT_ENCRYPTED_MDC) \
354 || ((pkttype)==CDK_PKT_ENCRYPTED) \
357 struct cdk_pkt_userid_s
{
359 unsigned is_primary
:1;
360 unsigned is_revoked
:1;
361 unsigned mdc_feature
:1;
362 cdk_prefitem_t prefs
;
363 unsigned char * attrib_img
; /* Tag 17 if not null */
366 unsigned int created
;
369 typedef struct cdk_pkt_userid_s
*cdk_pkt_userid_t
;
371 struct cdk_pkt_pubkey_s
{
372 unsigned char version
;
373 unsigned char pubkey_algo
;
374 unsigned char fpr
[20];
375 unsigned int keyid
[2];
376 unsigned int main_keyid
[2];
377 unsigned int timestamp
;
378 unsigned int expiredate
;
380 unsigned is_revoked
:1;
381 unsigned is_invalid
:1;
382 unsigned has_expired
:1;
384 cdk_pkt_userid_t uid
;
385 cdk_prefitem_t prefs
;
387 cdk_desig_revoker_t revkeys
;
389 typedef struct cdk_pkt_pubkey_s
*cdk_pkt_pubkey_t
;
391 struct cdk_pkt_seckey_s
{
393 unsigned int expiredate
;
396 unsigned int keyid
[2];
397 unsigned int main_keyid
[2];
398 unsigned char s2k_usage
;
401 unsigned char sha1chk
; /* SHA1 is used instead of a 16 bit checksum */
403 unsigned char iv
[16];
408 unsigned char * encdata
;
410 unsigned char is_protected
;
411 unsigned is_primary
:1;
412 unsigned has_expired
:1;
413 unsigned is_revoked
:1;
415 typedef struct cdk_pkt_seckey_s
*cdk_pkt_seckey_t
;
417 struct cdk_pkt_signature_s
{
418 unsigned char version
;
419 unsigned char sig_class
;
420 unsigned int timestamp
;
421 unsigned int expiredate
;
422 unsigned int keyid
[2];
423 unsigned char pubkey_algo
;
424 unsigned char digest_algo
;
425 unsigned char digest_start
[2];
426 unsigned short hashed_size
;
428 unsigned short unhashed_size
;
429 cdk_subpkt_t unhashed
;
431 cdk_desig_revoker_t revkeys
;
433 unsigned exportable
:1;
434 unsigned revocable
:1;
435 unsigned policy_url
:1;
440 unsigned missing_key
:1;
442 unsigned int key
[2]; /* only valid for key signatures */
444 typedef struct cdk_pkt_signature_s
*cdk_pkt_signature_t
;
446 struct cdk_pkt_onepass_sig_s
{
447 unsigned char version
;
448 unsigned int keyid
[2];
449 unsigned char sig_class
;
450 unsigned char digest_algo
;
451 unsigned char pubkey_algo
;
454 typedef struct cdk_pkt_onepass_sig_s
* cdk_pkt_onepass_sig_t
;
457 struct cdk_pkt_pubkey_enc_s
{
458 unsigned char version
;
459 unsigned int keyid
[2];
461 unsigned char pubkey_algo
;
464 typedef struct cdk_pkt_pubkey_enc_s
* cdk_pkt_pubkey_enc_t
;
467 struct cdk_pkt_symkey_enc_s
{
468 unsigned char version
;
469 unsigned char cipher_algo
;
471 unsigned char seskeylen
;
472 unsigned char seskey
[32];
474 typedef struct cdk_pkt_symkey_enc_s
*cdk_pkt_symkey_enc_t
;
477 struct cdk_pkt_encrypted_s
{
480 unsigned char mdc_method
;
483 typedef struct cdk_pkt_encrypted_s
*cdk_pkt_encrypted_t
;
486 struct cdk_pkt_mdc_s
{
487 unsigned char hash
[20];
489 typedef struct cdk_pkt_mdc_s
*cdk_pkt_mdc_t
;
492 struct cdk_pkt_literal_s
{
496 unsigned int timestamp
;
500 typedef struct cdk_pkt_literal_s
*cdk_pkt_literal_t
;
503 struct cdk_pkt_compressed_s
{
508 typedef struct cdk_pkt_compressed_s
*cdk_pkt_compressed_t
;
511 struct cdk_packet_s
{
512 size_t pktlen
; /* real packet length */
513 size_t pktsize
; /* length with all headers */
515 cdk_packet_type_t pkttype
;
518 cdk_pkt_userid_t user_id
;
519 cdk_pkt_pubkey_t public_key
;
520 cdk_pkt_seckey_t secret_key
;
521 cdk_pkt_signature_t signature
;
522 cdk_pkt_pubkey_enc_t pubkey_enc
;
523 cdk_pkt_symkey_enc_t symkey_enc
;
524 cdk_pkt_compressed_t compressed
;
525 cdk_pkt_encrypted_t encrypted
;
526 cdk_pkt_literal_t literal
;
527 cdk_pkt_onepass_sig_t onepass_sig
;
530 typedef struct cdk_packet_s CDK_PACKET
;
531 typedef struct cdk_packet_s
*cdk_packet_t
;
534 /* memory routines */
535 typedef void (*cdk_log_fnc_t
) (void *, int, const char *, va_list);
536 void cdk_set_log_level (int lvl
);
537 void cdk_set_log_handler (cdk_log_fnc_t logfnc
, void * opaque
);
538 const char* cdk_strerror (int ec
);
539 void cdk_set_malloc_hooks (void *(*new_alloc_func
) (size_t n
),
540 void *(*new_alloc_secure_func
) (size_t n
),
541 void *(*new_realloc_func
) (void * p
, size_t n
),
542 void *(*new_calloc_func
) (size_t m
, size_t n
),
543 void (*new_free_func
) (void *));
544 int cdk_malloc_hook_initialized (void);
545 void * cdk_malloc (size_t size
);
546 void * cdk_calloc (size_t n
, size_t m
);
547 void * cdk_realloc (void * ptr
, size_t size
);
548 void * cdk_salloc (size_t size
, int clear
);
549 char * cdk_strdup (const char * ptr
);
550 void cdk_free (void * ptr
);
551 /* session handle routines */
552 int cdk_handle_new (cdk_ctx_t
* r_ctx
);
553 void cdk_handle_free (cdk_ctx_t hd
);
554 void cdk_handle_set_keydb (cdk_ctx_t hd
, cdk_keydb_hd_t db
);
555 cdk_keydb_hd_t
cdk_handle_get_keydb( cdk_ctx_t hd
, int type
);
556 int cdk_handle_control( cdk_ctx_t hd
, int action
, int cmd
, ... );
557 void cdk_handle_set_callback (cdk_ctx_t hd
,
558 void (*cb
) (void *opa
, int type
, const char * s
),
560 void cdk_handle_set_passphrase_cb( cdk_ctx_t hd
,
561 char *(*cb
) (void *opa
, const char *prompt
),
564 /* shortcuts for some controls */
565 #define cdk_handle_set_armor( a, val ) \
566 cdk_handle_control( (a), CDK_CTLF_SET, CDK_CTL_ARMOR, (val) )
568 #define cdk_handle_set_compress( a, algo, level ) \
569 cdk_handle_control( (a), CDK_CTLF_SET, CDK_CTL_COMPRESS, (algo), (level) )
573 void cdk_set_progress_handler (void (*cb
)(void * hd
, unsigned off
,
574 unsigned size
), void * cb_value
);
576 /*-- new-packet.c --*/
577 cdk_error_t
cdk_pkt_new( cdk_packet_t
* r_pkt
);
578 void cdk_pkt_init( cdk_packet_t pkt
);
579 cdk_error_t
cdk_pkt_alloc( cdk_packet_t
* r_pkt
, int pkttype
);
580 void cdk_pkt_free( cdk_packet_t pkt
);
581 void cdk_pkt_release( cdk_packet_t pkt
);
582 cdk_error_t
cdk_pkt_read( cdk_stream_t inp
, cdk_packet_t pkt
);
583 cdk_error_t
cdk_pkt_write( cdk_stream_t out
, cdk_packet_t pkt
);
584 /* sub packet routines */
585 cdk_subpkt_t
cdk_subpkt_new( size_t size
);
586 void cdk_subpkt_free( cdk_subpkt_t ctx
);
587 cdk_subpkt_t
cdk_subpkt_find( cdk_subpkt_t ctx
, int type
);
588 cdk_error_t
cdk_subpkt_add( cdk_subpkt_t root
, cdk_subpkt_t node
);
589 const unsigned char * cdk_subpkt_get_data( cdk_subpkt_t ctx
,
590 int * r_type
, size_t * r_nbytes
);
591 void cdk_subpkt_init( cdk_subpkt_t node
, int type
,
592 const void *buf
, size_t buflen
);
593 unsigned char * cdk_userid_pref_get_array( cdk_pkt_userid_t id
, int type
,
595 const unsigned char* cdk_key_desig_revoker_walk( cdk_desig_revoker_t root
,
596 cdk_desig_revoker_t
* ctx
,
597 int *r_class
, int *r_algid
);
600 #define is_RSA(a) ((a) == CDK_PK_RSA \
601 || (a) == CDK_PK_RSA_E \
602 || (a) == CDK_PK_RSA_S)
603 #define is_ELG(a) ((a) == CDK_PK_ELG || (a) == CDK_PK_ELG_E)
604 #define is_DSA(a) ((a) == CDK_PK_DSA)
606 cdk_error_t
cdk_pk_encrypt (cdk_pkt_pubkey_t pk
, cdk_pkt_pubkey_enc_t pke
,
608 cdk_error_t
cdk_pk_decrypt (cdk_pkt_seckey_t sk
, cdk_pkt_pubkey_enc_t pke
,
609 cdk_sesskey_t
*r_sk
);
610 cdk_error_t
cdk_pk_sign (cdk_pkt_seckey_t sk
, cdk_pkt_signature_t sig
,
611 const unsigned char * md
);
612 cdk_error_t
cdk_pk_verify (cdk_pkt_pubkey_t pk
, cdk_pkt_signature_t sig
,
613 const unsigned char * md
);
614 cdk_error_t
cdk_pk_get_mpi (cdk_pkt_pubkey_t pk
, int idx
,
615 unsigned char * buf
, size_t * r_count
, size_t * r_nbits
);
616 cdk_error_t
cdk_sk_get_mpi (cdk_pkt_seckey_t sk
, int idx
,
617 unsigned char * buf
, size_t * r_count
, size_t * r_nbits
);
618 int cdk_pk_get_nbits (cdk_pkt_pubkey_t pk
);
619 int cdk_pk_get_npkey (int algo
);
620 int cdk_pk_get_nskey (int algo
);
621 int cdk_pk_get_nsig (int algo
);
622 int cdk_pk_get_nenc (int algo
);
623 int cdk_pk_get_fingerprint (cdk_pkt_pubkey_t pk
, unsigned char * fpr
);
624 unsigned int cdk_pk_fingerprint_get_keyid (const unsigned char * fpr
,
626 unsigned int * keyid
);
627 unsigned int cdk_pk_get_keyid (cdk_pkt_pubkey_t pk
, unsigned int * keyid
);
628 unsigned int cdk_sk_get_keyid (cdk_pkt_seckey_t sk
, unsigned int * keyid
);
629 unsigned int cdk_sig_get_keyid (cdk_pkt_signature_t sig
,
630 unsigned int * keyid
);
631 cdk_error_t
cdk_sk_unprotect( cdk_pkt_seckey_t sk
, const char * pw
);
632 cdk_error_t
cdk_sk_protect( cdk_pkt_seckey_t sk
, const char * pw
);
633 cdk_error_t
cdk_pk_from_secret_key( cdk_pkt_seckey_t sk
,
634 cdk_pkt_pubkey_t
*ret_pk
);
635 cdk_error_t
cdk_pubkey_to_sexp (cdk_pkt_pubkey_t pk
,
636 char **sexp
, size_t * len
);
637 cdk_error_t
cdk_seckey_to_sexp (cdk_pkt_seckey_t sk
,
638 char **sexp
, size_t * len
);
641 cdk_error_t
cdk_sesskey_new( cdk_sesskey_t
* r_sk
);
642 void cdk_sesskey_free( cdk_sesskey_t sk
);
643 cdk_error_t
cdk_dek_new( cdk_dek_t
* r_dek
);
644 void cdk_dek_free( cdk_dek_t dek
);
645 cdk_error_t
cdk_dek_set_cipher( cdk_dek_t dek
, int algo
);
646 cdk_error_t
cdk_dek_set_key( cdk_dek_t dek
, const unsigned char *key
,
648 cdk_error_t
cdk_dek_from_passphrase( cdk_dek_t
* ret_dek
, int cipher_algo
,
649 cdk_s2k_t s2k
, int mode
,
651 cdk_error_t
cdk_dek_encode_pkcs1( cdk_dek_t dek
, int nbits
,
652 cdk_sesskey_t
* r_esk
);
653 cdk_error_t
cdk_dek_decode_pkcs1( cdk_dek_t
* ret_dek
, cdk_sesskey_t esk
);
654 cdk_error_t
cdk_dek_extract( cdk_dek_t
* ret_dek
, cdk_ctx_t hd
,
655 cdk_pkt_pubkey_enc_t enc
,
656 cdk_pkt_seckey_t sk
);
657 void cdk_dek_set_mdc_flag( cdk_dek_t dek
, int val
);
659 cdk_error_t
cdk_s2k_new (cdk_s2k_t
* ret_s2k
, int mode
, int algo
,
660 const unsigned char * salt
);
661 void cdk_s2k_free (cdk_s2k_t s2k
);
664 cdk_error_t
cdk_file_armor( cdk_ctx_t hd
, const char * file
,
665 const char * output
);
666 cdk_error_t
cdk_file_dearmor( const char * file
, const char * output
);
667 cdk_error_t
cdk_armor_filter_use (cdk_stream_t inp
);
670 int cdk_stream_control (cdk_stream_t s
, int ctl
, int val
);
671 cdk_error_t
cdk_stream_open (const char * file
, cdk_stream_t
* ret_s
);
672 cdk_error_t
cdk_stream_new (const char * file
, cdk_stream_t
* ret_s
);
673 cdk_error_t
cdk_stream_create (const char * file
, cdk_stream_t
* ret_s
);
674 cdk_stream_t
cdk_stream_tmp (void);
675 cdk_stream_t
cdk_stream_tmp_from_mem (const void * buf
, size_t count
);
676 void cdk_stream_tmp_set_mode (cdk_stream_t s
, int val
);
677 cdk_error_t
cdk_stream_flush (cdk_stream_t s
);
678 cdk_error_t
cdk_stream_set_cache (cdk_stream_t s
, int val
);
679 cdk_error_t
cdk_stream_filter_disable (cdk_stream_t s
, int type
);
680 cdk_error_t
cdk_stream_close (cdk_stream_t s
);
681 unsigned cdk_stream_get_length (cdk_stream_t s
);
682 int cdk_stream_read (cdk_stream_t s
, void * buf
, size_t count
);
683 int cdk_stream_write (cdk_stream_t s
, const void * buf
, size_t count
);
684 int cdk_stream_putc (cdk_stream_t s
, int c
);
685 int cdk_stream_getc (cdk_stream_t s
);
686 int cdk_stream_eof (cdk_stream_t s
);
687 long cdk_stream_tell (cdk_stream_t s
);
688 cdk_error_t
cdk_stream_seek (cdk_stream_t s
, long offset
);
689 cdk_error_t
cdk_stream_set_armor_flag (cdk_stream_t s
, int type
);
690 cdk_error_t
cdk_stream_set_literal_flag (cdk_stream_t s
, int mode
, const char * fname
);
691 cdk_error_t
cdk_stream_set_cipher_flag (cdk_stream_t s
, cdk_dek_t dek
,
693 cdk_error_t
cdk_stream_set_compress_flag (cdk_stream_t s
, int algo
, int level
);
694 cdk_error_t
cdk_stream_set_hash_flag (cdk_stream_t s
, int algo
);
695 cdk_error_t
cdk_stream_set_text_flag (cdk_stream_t s
, const char * lf
);
696 cdk_error_t
cdk_stream_kick_off (cdk_stream_t inp
, cdk_stream_t out
);
697 cdk_error_t
cdk_stream_mmap( cdk_stream_t s
, unsigned char ** ret_buf
,
698 size_t * ret_count
);
699 int cdk_stream_peek( cdk_stream_t inp
, unsigned char *s
, size_t count
);
702 cdk_error_t
cdk_keydb_new( cdk_keydb_hd_t
* r_hd
, int type
, void * data
,
704 cdk_error_t
cdk_keydb_open( cdk_keydb_hd_t hd
, cdk_stream_t
* ret_kr
);
705 int cdk_keydb_check_sk( cdk_keydb_hd_t hd
, unsigned int * keyid
);
706 cdk_error_t
cdk_keydb_search_start( cdk_keydb_hd_t db
, int type
, void * desc
);
707 cdk_error_t
cdk_keydb_search( cdk_keydb_hd_t hd
, cdk_kbnode_t
* ret_key
);
708 void cdk_keydb_free( cdk_keydb_hd_t hd
);
709 cdk_error_t
cdk_keydb_get_bykeyid( cdk_keydb_hd_t hd
, unsigned int * keyid
,
710 cdk_kbnode_t
* ret_pk
);
711 cdk_error_t
cdk_keydb_get_byfpr( cdk_keydb_hd_t hd
, const unsigned char * fpr
,
712 cdk_kbnode_t
* ret_pk
);
713 cdk_error_t
cdk_keydb_get_bypattern( cdk_keydb_hd_t hd
, const char * patt
,
714 cdk_kbnode_t
* ret_pk
);
715 cdk_error_t
cdk_keydb_get_pk( cdk_keydb_hd_t khd
, unsigned int * keyid
,
716 cdk_pkt_pubkey_t
* ret_pk
);
717 cdk_error_t
cdk_keydb_get_sk( cdk_keydb_hd_t khd
, unsigned int * keyid
,
718 cdk_pkt_seckey_t
* ret_sk
);
719 cdk_error_t
cdk_keydb_get_keyblock( cdk_stream_t inp
, cdk_kbnode_t
* ret_key
);
720 cdk_error_t
cdk_keydb_idx_rebuild( cdk_keydb_hd_t hd
);
721 cdk_error_t
cdk_keydb_export( cdk_keydb_hd_t hd
, cdk_stream_t out
,
722 cdk_strlist_t remusr
);
723 cdk_error_t
cdk_keydb_import( cdk_keydb_hd_t hd
, cdk_kbnode_t knode
,
725 cdk_error_t
cdk_keydb_pk_cache_sigs( cdk_kbnode_t pk
, cdk_keydb_hd_t hd
);
728 cdk_error_t
cdk_listkey_start( cdk_listkey_t
* r_ctx
, cdk_keydb_hd_t db
,
729 const char * patt
, cdk_strlist_t fpatt
);
730 void cdk_listkey_close( cdk_listkey_t ctx
);
731 cdk_error_t
cdk_listkey_next( cdk_listkey_t ctx
, cdk_kbnode_t
* ret_key
);
734 cdk_kbnode_t
cdk_kbnode_new (cdk_packet_t pkt
);
735 cdk_error_t
cdk_kbnode_read_from_mem (cdk_kbnode_t
* ret_node
,
736 const unsigned char * buf
,
738 cdk_error_t
cdk_kbnode_write_to_mem (cdk_kbnode_t node
,
739 unsigned char * buf
, size_t * r_nbytes
);
740 void cdk_kbnode_release (cdk_kbnode_t node
);
741 cdk_kbnode_t
cdk_kbnode_walk (cdk_kbnode_t root
, cdk_kbnode_t
* ctx
, int all
);
742 cdk_packet_t
cdk_kbnode_find_packet (cdk_kbnode_t node
, int pkttype
);
743 cdk_packet_t
cdk_kbnode_get_packet (cdk_kbnode_t node
);
744 cdk_kbnode_t
cdk_kbnode_find (cdk_kbnode_t node
, int pkttype
);
745 cdk_kbnode_t
cdk_kbnode_find_prev( cdk_kbnode_t root
, cdk_kbnode_t node
,
747 cdk_kbnode_t
cdk_kbnode_find_next (cdk_kbnode_t node
, int pkttype
);
748 void * cdk_kbnode_get_attr( cdk_kbnode_t node
, int pkttype
, int attr
);
749 cdk_error_t
cdk_kbnode_hash( cdk_kbnode_t node
, cdk_md_hd_t md
, int is_v4
,
750 int pkttype
, int flags
);
752 /*-- sig-check.c --*/
753 cdk_error_t
cdk_pk_check_sigs( cdk_kbnode_t knode
, cdk_keydb_hd_t hd
,
757 int cdk_pklist_select_algo( cdk_keylist_t pkl
, int preftype
);
758 int cdk_pklist_use_mdc (cdk_keylist_t pkl
);
759 cdk_error_t
cdk_pklist_build( cdk_keylist_t
*ret_pkl
, cdk_keydb_hd_t hd
,
760 cdk_strlist_t remusr
, int use
);
761 void cdk_pklist_release (cdk_keylist_t pkl
);
762 cdk_error_t
cdk_pklist_encrypt (cdk_keylist_t pk_list
, cdk_dek_t dek
,
764 /* secret key list */
765 cdk_error_t
cdk_sklist_build( cdk_keylist_t
* ret_skl
,
766 cdk_keydb_hd_t db
, cdk_ctx_t hd
,
767 cdk_strlist_t locusr
,
768 int unlock
, unsigned int use
);
769 void cdk_sklist_release (cdk_keylist_t skl
);
770 cdk_error_t
cdk_sklist_write (cdk_keylist_t skl
, cdk_stream_t outp
,
772 int sigclass
, int sigver
);
773 cdk_error_t
cdk_sklist_write_onepass( cdk_keylist_t skl
, cdk_stream_t outp
,
774 int sigclass
, int mdalgo
);
777 cdk_error_t
cdk_stream_encrypt (cdk_ctx_t hd
, cdk_strlist_t remusr
,
778 cdk_stream_t inp
, cdk_stream_t out
);
779 cdk_error_t
cdk_stream_decrypt (cdk_ctx_t hd
, cdk_stream_t inp
,
781 cdk_error_t
cdk_file_encrypt (cdk_ctx_t hd
, cdk_strlist_t remusr
,
782 const char * file
, const char * output
);
783 cdk_error_t
cdk_file_decrypt (cdk_ctx_t hd
, const char * file
,
784 const char * output
);
785 cdk_error_t
cdk_data_transform( cdk_ctx_t hd
, enum cdk_crypto_mode_t mode
,
786 cdk_strlist_t locusr
, cdk_strlist_t remusr
,
787 const void * inbuf
, size_t insize
,
788 unsigned char ** outbuf
, size_t * outsize
,
792 cdk_error_t
cdk_stream_sign( cdk_ctx_t hd
, cdk_stream_t inp
, cdk_stream_t out
,
793 cdk_strlist_t locusr
, cdk_strlist_t remusr
,
794 int encryptflag
, int sigmode
);
795 cdk_error_t
cdk_file_sign( cdk_ctx_t hd
, cdk_strlist_t locusr
,
796 cdk_strlist_t remusr
,
797 const char * file
, const char * output
,
798 int sigmode
, int encryptflag
);
801 cdk_error_t
cdk_stream_verify( cdk_ctx_t hd
, cdk_stream_t inp
,
803 cdk_error_t
cdk_file_verify( cdk_ctx_t hd
, const char * file
,
804 const char * output
);
805 unsigned long cdk_sig_get_ulong_attr( cdk_ctx_t hd
, int idx
, int what
);
806 const void * cdk_sig_get_data_attr( cdk_ctx_t hd
, int idx
, int what
);
809 int cdk_trustdb_get_validity( cdk_stream_t inp
, cdk_pkt_userid_t id
,
811 int cdk_trustdb_get_ownertrust( cdk_stream_t inp
, cdk_pkt_pubkey_t pk
,
812 int * r_val
, int * r_flags
);
815 void cdk_strlist_free (cdk_strlist_t sl
);
816 cdk_strlist_t
cdk_strlist_add (cdk_strlist_t
* list
, const char * string
);
817 const char * cdk_strlist_walk (cdk_strlist_t root
, cdk_strlist_t
* context
);
818 const char * cdk_check_version (const char * req_version
);
820 char * cdk_utf8_encode( const char * string
);
821 char * cdk_utf8_decode( const char * string
, size_t length
, int delim
);
823 /*-- keyserver.c --*/
824 cdk_error_t
cdk_keyserver_recv_key( const char * host
, int port
,
825 const unsigned char * keyid
, int kid_type
,
826 cdk_kbnode_t
* ret_key
);
829 cdk_error_t
cdk_keygen_new( cdk_keygen_ctx_t
* r_hd
);
830 void cdk_keygen_free( cdk_keygen_ctx_t hd
);
831 cdk_error_t
cdk_keygen_set_prefs( cdk_keygen_ctx_t hd
,
832 enum cdk_pref_type_t type
,
833 const unsigned char * array
, size_t n
);
834 cdk_error_t
cdk_keygen_set_algo_info( cdk_keygen_ctx_t hd
, int type
,
835 enum cdk_pk_algo_t algo
, int bits
);
836 void cdk_keygen_set_mdc_feature( cdk_keygen_ctx_t hd
, int val
);
837 void cdk_keygen_set_keyserver_flags( cdk_keygen_ctx_t hd
, int no_modify
,
838 const char *pref_url
);
839 void cdk_keygen_set_expire_date( cdk_keygen_ctx_t hd
, int type
,
840 long int timestamp
);
841 void cdk_keygen_set_name( cdk_keygen_ctx_t hd
, const char * name
);
842 void cdk_keygen_set_passphrase( cdk_keygen_ctx_t hd
, const char * pass
);
843 cdk_error_t
cdk_keygen_start( cdk_keygen_ctx_t hd
);
844 cdk_error_t
cdk_keygen_save( cdk_keygen_ctx_t hd
,
845 const char * pubf
, const char * secf
);
851 #endif /* OPENCDK_H */