## Function

int cdk_armor_filter_use (CDK_STREAM inp )

### Arguments

CDK_STREAM inp
  the stream to check

### Description

Check if the stream contains armored data.

## Function

int cdk_file_armor (CDK_HD hd , const char * file , const char * output )

### Arguments

CDK_HD hd
  Handle
const char * file
  Name of the file to protect.
const char * output
  Output filename.

### Description

Protect a file with ASCII armor.

## Function

int cdk_file_dearmor (const char * file , const char * output )

### Arguments

const char * file
  Name of the file to unprotect.
const char * output
  Output filename.

### Description

Remove ASCII armor from a file.

## Function

int cdk_stream_encrypt (CDK_HD hd , CDK_STRLIST remusr , CDK_STREAM inp , CDK_STREAM out )

### Arguments

CDK_HD hd
  Handle
CDK_STRLIST remusr
  List of recipients
CDK_STREAM inp
  Input stream handle
CDK_STREAM out
  Output stream handle

### Description

If remusr is NULL, then symmetric encryption is used. Via the handle the caller can set or unset multiple options.

## Function

int cdk_file_encrypt (CDK_HD hd , CDK_STRLIST remusr , const char * file , const char * output )

### Arguments

CDK_HD hd
  Handle
CDK_STRLIST remusr
  List of recipient
const char * file
  Input file
const char * output
  Output file

## Function

int cdk_file_decrypt (CDK_HD hd , const char * file , const char * output )

### Arguments

CDK_HD hd
  Handle.
const char * file
  Name of the file to decrypt.
const char * output
  Output filename.

### Description

When the operation was successfull, hd can contain information about the signature (when present) and more.

## Function

int cdk_data_transform (CDK_HD hd , int mode , CDK_STRLIST locusr , CDK_STRLIST remusr , const void * inbuf , size_t insize , byte ** outbuf , size_t * outsize , int modval )

### Arguments

CDK_HD hd
  session handle
int mode
  crypto mode
CDK_STRLIST locusr
  local user list (sign mode only)
CDK_STRLIST remusr
  remote users 'recipients'
const void * inbuf
  input buffer with data
size_t insize
  length of data in bytes
byte ** outbuf
  pointer to the output data (will be allocated)
size_t * outsize
  size of the new data in bytes
int modval
  value for the modus (for example sign mode)

### Description

This function transforms data into the given openpgp mode. It works exactly like the cdk_file_xxx functions with the exception that it can be used with memory and not with streams or files.

## Function

CDK_KBNODE cdk_kbnode_new (CDK_PACKET * pkt )

### Arguments

CDK_PACKET * pkt
  the packet to add

### Description

Allocate a new key node and add the packet.

## Function

void cdk_kbnode_release (CDK_KBNODE node )

### Arguments

CDK_KBNODE node

### Description

Release the memory of the node.

## Function

void cdk_kbnode_delete (CDK_KBNODE node )

### Arguments

CDK_KBNODE node
  the ke keynode.

### Description

Delete @node.

## Function

void cdk_kbnode_insert (CDK_KBNODE root , CDK_KBNODE node , int pkttype )

### Arguments

CDK_KBNODE root
  the root key node
CDK_KBNODE node
  the node to add
int pkttype
  packet type

### Description

Insert @node into the list after @root but before a packet which is not of type @pkttype (only if @pkttype != 0).

## Function

CDK_KBNODE cdk_kbnode_find_prev (CDK_KBNODE root , CDK_KBNODE node , int pkttype )

### Arguments

CDK_KBNODE root
  the root key node
CDK_KBNODE node
  the key node
int pkttype
  packet type

### Description

Find the previous node (if @pkttype = 0) or the previous node with pkttype @pkttype in the list starting with @root of @node.

## Function

CDK_KBNODE cdk_kbnode_find_next (CDK_KBNODE node , int pkttype )

### Arguments

CDK_KBNODE node
  the key node
int pkttype
  packet type

### Description

Ditto, but find the next packet. The behaviour is trivial if @pkttype is 0 but if it is specified, the next node with a packet of this type is returned. The function has some knowledge about

### the valid ordering of packets

e.g. if the next signature packet is requested, the function will not return one if it encounters a user-id.

## Function

CDK_KBNODE cdk_kbnode_find (CDK_KBNODE node , int pkttype )

### Arguments

CDK_KBNODE node
  the key node
int pkttype
  packet type

### Description

Try to find the next node with the packettype @pkttype.

## Function

CDK_PACKET* cdk_kbnode_find_packet (CDK_KBNODE node , int pkttype )

### Arguments

CDK_KBNODE node
  the key node
int pkttype
  packet type

### Description

Same as cdk_kbnode_find but it returns the packet instead of the node.

## Function

CDK_PACKET * cdk_kbnode_get_packet (CDK_KBNODE node )

### Arguments

CDK_KBNODE node
  the key node

### Description

Return the packet which is stored inside the node in @node.

## Function

int cdk_kbnode_read_from_mem (CDK_KBNODE * ret_node , const byte * buf , size_t buflen )

### Arguments

CDK_KBNODE * ret_node
  the new key node
const byte * buf
  the buffer which stores the key sequence
size_t buflen
  the length of the buffer

### Description

Try to read a key node from the memory buffer @buf.

## Function

int cdk_kbnode_write_to_mem (CDK_KBNODE node , byte * buf , size_t * r_nbytes )

### Arguments

CDK_KBNODE node
  the key node
byte * buf
  the buffer to store the node data
size_t * r_nbytes
  the new length of the buffer.

### Description

Try to write the contents of the key node to the buffer @buf and return the length of it in @r_nbytes. If buff is zerok, only the length of the node is calculated and returned in @r_nbytes.

## Function

int cdk_keydb_idx_rebuild (CDK_KEYDB_HD hd )

### Arguments

CDK_KEYDB_HD hd
  key database handle

### Description

Rebuild the key index files for the given key database.

## Function

int cdk_keydb_new (CDK_KEYDB_HD * r_hd , int type , void * data , size_t count )

### Arguments

CDK_KEYDB_HD * r_hd
  handle to store the new keydb object
int type
  type of the keyring
void * data
  data which depends on the keyring type
size_t count
  length of the data

### Description

Create a new keydb object

## Function

void cdk_keydb_free (CDK_KEYDB_HD hd )

### Arguments

CDK_KEYDB_HD hd
  the keydb object

### Description

Free the keydb object.

## Function

int cdk_keydb_open (CDK_KEYDB_HD hd , CDK_STREAM * ret_kr )

### Arguments

CDK_KEYDB_HD hd
  keydb object
CDK_STREAM * ret_kr
  the STREAM object which contains the data of the keyring

### Description

Open a STREAM with the contents of the keyring from @hd

## Function

int cdk_keydb_search_new (CDK_DBSEARCH * r_dbs , int type , void * desc )

### Arguments

CDK_DBSEARCH * r_dbs
  object to store the new keydb search object
int type
  specifies the search type
void * desc
  description which depends on the type

### Description

Create a new keydb search object.

## Function

void cdk_keydb_search_free (CDK_DBSEARCH dbs )

### Arguments

CDK_DBSEARCH dbs
  the keydb search object

### Description

Free the keydb oject.

## Function

int cdk_keydb_search (CDK_KEYDB_HD hd , CDK_DBSEARCH ks , CDK_KBNODE * ret_key )

### Arguments

CDK_KEYDB_HD hd
  the keydb object
CDK_DBSEARCH ks
  the keydb search object
CDK_KBNODE * ret_key
  kbnode object to store the key

### Description

Search for a key in the given keyring. The search mode is handled via @ks. If the key was found, @ret_key contains the key data.

## Function

int cdk_keygen_set_prefs (CDK_KEYGEN_CTX hd , int type , const byte * array , size_t n )

### Arguments

CDK_KEYGEN_CTX hd
  the preference type
int type
const byte * array
  one-octet array with algorithm numers
size_t n

## Function

void cdk_keygen_set_name (CDK_KEYGEN_CTX hd , const char * name )

### Arguments

CDK_KEYGEN_CTX hd
  the keygen object
const char * name
  name

### Description

The name will be encoded in UTF8 to avoid problems.

## Function

int cdk_keygen_set_algo_info (CDK_KEYGEN_CTX hd , int type , int algo , int bits )

### Arguments

CDK_KEYGEN_CTX hd
  the keygen object.
int type
  key type (primary=0, subkey=1)
int algo
  algorithm compliant with rfc2440
int bits
  lengt of the key in bits

## Function

void cdk_keygen_set_mdc_feature (CDK_KEYGEN_CTX hd , int val )

### Arguments

CDK_KEYGEN_CTX hd
  keygen object
int val
  boolean( yes=1, no=0)

### Description

if you want a RFC2440 compliant key, you've to disable this feature until the rfc2440-bis6 becomes the next standard.

## Function

void cdk_keygen_set_expire_date (CDK_KEYGEN_CTX hd , int type , long timestamp )

### Arguments

CDK_KEYGEN_CTX hd
  keygen object
int type
  key type( 0=primary, 1=seconardy)
long timestamp
  the date the key should expire

## Function

int cdk_keygen_start (CDK_KEYGEN_CTX hd )

### Arguments

CDK_KEYGEN_CTX hd
  the keygen object

## Function

int cdk_keygen_save (CDK_KEYGEN_CTX hd , const char * pub , const char * sec )

### Arguments

CDK_KEYGEN_CTX hd
  the keygen object
const char * pub
  name of the file to store the public key
const char * sec
  name of the file to store the secret key

## Function

void cdk_keygen_free (CDK_KEYGEN_CTX hd )

### Arguments

CDK_KEYGEN_CTX hd
  the keygen object

## Function

int cdk_keygen_new (CDK_KEYGEN_CTX * r_hd )

### Arguments

CDK_KEYGEN_CTX * r_hd
  the new object

## Function

int cdk_pklist_select_algo (CDK_KEYLIST pkl )

### Arguments

CDK_KEYLIST pkl
  the keylist

### Description

Select a symmetric cipher algorithm from a list of public keys. This algorithm is present in all key preferences.

## Function

void cdk_pklist_release (CDK_KEYLIST pkl )

### Arguments

CDK_KEYLIST pkl
  the keylist

### Description

Free the memory of the key list.

## Function

int cdk_pklist_build (CDK_KEYDB_HD hd , CDK_STRLIST remusr , CDK_KEYLIST * ret_pkl , int use )

### Arguments

CDK_KEYDB_HD hd
  the session handle
CDK_STRLIST remusr
  the string list of the recipients
CDK_KEYLIST * ret_pkl
  the new keylist
int use
  public key usage

### Description

Create a public key list based on the recipient names in @remusr.

## Function

int cdk_pklist_encrypt (CDK_KEYLIST pkl , CDK_DEK dek , CDK_STREAM outp )

### Arguments

CDK_KEYLIST pkl
  the keylist
CDK_DEK dek
  the data encryption key
CDK_STREAM outp
  the stream to write in the data

### Description

Encrypt the session key with each key of the list and wrap it into a PUBKEY_ENC packet and write it to @outp.

## Function

void cdk_sklist_release (CDK_KEYLIST skl )

### Arguments

CDK_KEYLIST skl
  secret keylist

### Description

Free the memory of the secret keylist.

## Function

int cdk_sklist_write_onepass (CDK_KEYLIST skl , CDK_STREAM outp , int sigclass , int mdalgo )

### Arguments

CDK_KEYLIST skl
  secret keylist
CDK_STREAM outp
  the stream to write in the data
int sigclass
  the class of the sig to create
int mdalgo
  the message digest algorithm

### Description

Write a one-pass signature for each key in the list into @outp.

## Function

int cdk_sklist_write (CDK_KEYLIST skl , CDK_STREAM outp , void * mdctx , int sigclass , int sigver )

### Arguments

CDK_KEYLIST skl
  secret keylist
CDK_STREAM outp
  the stream to write in the data
void * mdctx
  opaque handle for the message digest operations
int sigclass
  the class of the sig
int sigver
  version of the sig

### Description

Complete the sig based on @mdctx and write all signatures to @outp.

## Function

int cdk_keyserver_recv_key (const char * host , int port , const byte * keyid , int kid_type , CDK_KBNODE * ret_key )

### Arguments

const char * host
  URL or hostname of the keyserver
int port
  The port to use for the connection
const byte * keyid
  KeyID of the key to retrieve
int kid_type
  KeyID type (long, short, fingerprint)
CDK_KBNODE * ret_key

### Description

Receive a key from a keyserver.

## Function

const char * cdk_strerror (int ec )

### Arguments

int ec
  the error number

### Description

Return an error text for the given id.

## Function

void cdk_set_malloc_hooks (void * (*new_alloc_func )

### Arguments

void * (*new_alloc_func

### Description

Set private memory hooks for the lib.

## Function

int cdk_malloc_hook_initialized ( void )

### Arguments

void

### Description

Return if the malloc hooks are already initialized.

## Function

void cdk_set_log_handler (CDK_LOG_FNC logfnc , void * opaque )

### Arguments

CDK_LOG_FNC logfnc
  the function pointer
void * opaque
  a private values for the function

### Description

set a private handler for logging.

## Function

void cdk_set_log_level (int lvl )

### Arguments

int lvl
  the level

### Description

set the verbosity level.

## Function

int cdk_handle_control (CDK_HD hd , int action , int cmd , ... )

### Arguments

CDK_HD hd
  session handle
int action
  flag which indicates whether put or get is requested
int cmd
  command id
...

### Description

Perform various control operations for the current session.

## Function

int cdk_handle_new (CDK_HD * r_ctx )

### Arguments

CDK_HD * r_ctx
  context to store the handle

### Description

create a new session handle.

## Function

void cdk_handle_set_keydb (CDK_HD hd , CDK_KEYDB_HD db )

### Arguments

CDK_HD hd
  session handle
CDK_KEYDB_HD db
  the database handle

### Description

set the key database handle. the function automatically detects whether this is a public or secret keyring and the right handle is set.

## Function

CDK_KEYDB_HD cdk_handle_get_keydb (CDK_HD hd , int type )

### Arguments

CDK_HD hd
  session handle
int type
  type of the keyring

### Description

Return the keydb handle from the session handle.

## Function

void cdk_handle_set_callback (CDK_HD hd , void (*cb )

### Arguments

CDK_HD hd
  the handle
void (*cb

### Description

set the callback for filter operations.

## Function

void cdk_handle_set_passphrase_cb (CDK_HD hd , char * (*cb )

### Arguments

CDK_HD hd
  session handle
char * (*cb

### Description

set the passphrase callback.

## Function

void cdk_handle_free (CDK_HD hd )

### Arguments

CDK_HD hd
  the handle

### Description

free the main handle.

## Function

const char * cdk_check_version (const char * req_version )

### Arguments

const char * req_version
  The requested version

### Description

Check that the the version of the library is at minimum the requested one and return the version string; return NULL if the condition is not satisfied. If a NULL is passed to this function, no check is done, but the version string is simply returned.

## Function

int cdk_pk_encrypt (cdkPKT_public_key * pk , cdkPKT_pubkey_enc * pke , CDK_SESSKEY esk )

### Arguments

cdkPKT_public_key * pk
  the public key
cdkPKT_pubkey_enc * pke
  the public key encrypted packet
CDK_SESSKEY esk
  the actual session key

### Description

Encrypt the session key in @esk and write its encrypted content into the @pke struct.

## Function

int cdk_pk_decrypt (cdkPKT_secret_key * sk , cdkPKT_pubkey_enc * pke , CDK_SESSKEY * r_sk )

### Arguments

cdkPKT_secret_key * sk
  the secret key
cdkPKT_pubkey_enc * pke
  public key encrypted packet
CDK_SESSKEY * r_sk
  the object to store the plain session key

### Description

Decrypt the encrypted session key from @pke into @r_sk.

## Function

int cdk_pk_sign (cdkPKT_secret_key * sk , cdkPKT_signature * sig , const byte * md )

### Arguments

cdkPKT_secret_key * sk
  secret key
cdkPKT_signature * sig
  signature
const byte * md
  the message digest

### Description

Sign the message digest from @md and write the result into @sig.

## Function

int cdk_pk_verify (cdkPKT_public_key * pk , cdkPKT_signature * sig , const byte * md )

### Arguments

cdkPKT_public_key * pk
  the public key
cdkPKT_signature * sig
  signature
const byte * md
  the message digest

### Description

Verify the signature in @sig and compare it with the message digest in @md.

## Function

int cdk_pk_from_secret_key (cdkPKT_secret_key * sk , cdkPKT_public_key ** ret_pk )

### Arguments

cdkPKT_secret_key * sk
  the secret key
cdkPKT_public_key ** ret_pk
  the new public key

### Description

Create a new public key from a secret key.

## Function

int cdk_pkt_parse (CDK_STREAM inp , CDK_PACKET * pkt )

### Arguments

CDK_STREAM inp
  the input stream
CDK_PACKET * pkt
  allocated packet handle to store the packet

### Description

Parse the next packet on the @inp stream and return its contents in @pkt.

## Function

int cdk_pk_check_sigs (CDK_KBNODE knode , CDK_KEYDB_HD hd , int * r_status )

### Arguments

CDK_KBNODE knode
  the key node
CDK_KEYDB_HD hd
  the session handle
int * r_status
  variable to store the status of the key

### Description

Check all signatures. When no key is available for checking, the sigstat is marked as 'NOKEY'. The @r_status contains the key flags which are or-ed or zero when there are no flags.

## Function

int cdk_stream_sign (CDK_HD hd , CDK_STREAM inp , CDK_STREAM out , CDK_STRLIST locusr , CDK_STRLIST remusr , int encryptflag , int sigmode )

### Arguments

CDK_HD hd
  session handle
CDK_STREAM inp
  input stream
CDK_STREAM out
  output stream
CDK_STRLIST locusr
  local user list for signing
CDK_STRLIST remusr
int encryptflag
  shall the output be encrypted? (1/0)
int sigmode
  signature mode

### Description

Sign the data from the STREAM @inp.

## Function

int cdk_file_sign (CDK_HD hd , CDK_STRLIST locusr , CDK_STRLIST remusr , const char * file , const char * output , int sigmode , int encryptflag )

### Arguments

CDK_HD hd
CDK_STRLIST locusr
  List of userid which should be used for signing
CDK_STRLIST remusr
  If encrypt is valid, the list of recipients
const char * file
  Name of the input file
const char * output
  Name of the output file
int sigmode
  Signature mode
int encryptflag

### Description

Sign a file.

## Function

int cdk_stream_open (const char * file , CDK_STREAM * ret_s )

### Arguments

const char * file
  The file to open
CDK_STREAM * ret_s
  The new STREAM object

## Function

int cdk_stream_new (const char * file , CDK_STREAM * ret_s )

### Arguments

const char * file
  The name of the new file
CDK_STREAM * ret_s
  The new STREAM object

## Function

int cdk_stream_create (const char * file , CDK_STREAM * ret_s )

### Arguments

const char * file
  the filename
CDK_STREAM * ret_s
  the object

### Description

The difference to cdk_stream_new is, that no filtering can be used with this kind of stream and everything is written directly to the stream.

## Function

int cdk_stream_close (CDK_STREAM s )

### Arguments

CDK_STREAM s
  The STREAM object.

### Description

This function work different for read or write streams. When the stream is for reading, the filtering is already done and we can simply close the file and all buffers. But for the case it's a write stream, we need to apply all registered filters now. The file is closed in the filter function and not here.

## Function

int cdk_stream_eof (CDK_STREAM s )

### Arguments

CDK_STREAM s
  The STREAM object.

### Description

This function will only work with read streams.

## Function

unsigned cdk_stream_get_length (CDK_STREAM s )

### Arguments

CDK_STREAM s
  The STREAM object.

### Description

This file only works for read stream because it's likely that the write stream is not flushed or even no data was inserted.

## Function

int cdk_stream_filter_disable (CDK_STREAM s , int type )

### Arguments

CDK_STREAM s
  The STREAM object
int type
  The numberic filter ID.

## Function

int cdk_stream_read (CDK_STREAM s , void * buf , size_t count )

### Arguments

CDK_STREAM s
  The STREAM object.
void * buf
  The buffer to insert the readed bytes.
size_t count
  Request so much bytes.

### Description

When this function is called the first time, it can take a while because all filters need to be processed. Please remember that you need to add the filters in reserved order.

## Function

int cdk_stream_write (CDK_STREAM s , const void * buf , size_t count )

### Arguments

CDK_STREAM s
  The STREAM object
const void * buf
  The buffer with the values to write.
size_t count
  The size of the buffer.

### Description

In this function we simply write the bytes to the stream. We can't use the filters here because it would mean they have to support partial flushing.

## Function

int cdk_stream_mmap (CDK_STREAM s , byte ** ret_buf , size_t * ret_count )

### Arguments

CDK_STREAM s
  the stream
byte ** ret_buf
  the buffer to store the content
size_t * ret_count
  length of the buffer

### Description

Map the data of the given stream into a memory section. @ret_count contains the length of the buffer.

## Function

int cdk_file_verify (CDK_HD hd , const char * file , const char * output )

### Arguments

CDK_HD hd
  the session handle
const char * file
  the input file
const char * output
  the output file

### Description

Verify a signature.

## Function

byte * cdk_sig_get_info_as_xml (CDK_HD hd , int advanced )

### Arguments

CDK_HD hd
  session handle
int advanced
  flag to indicate whether to include extended data

### Description

Return an XML fragment which contains the status of the verification procedure. If no signature is present, the fragment is empty.

## Function

u32 cdk_sig_get_ulong_attr (CDK_HD hd , int idx , int what )

### Arguments

CDK_HD hd
  session handle
int idx
  index of the signature
int what
  attribute id

### Description

Extract the requested attribute of the signature. The returned value is always an integer (max. 32-bit).

## Function

const void * cdk_sig_get_data_attr (CDK_HD hd , int idx , int what )

### Arguments

CDK_HD hd
  session handle
int idx
  index of the signature
int what
  attribute id.

### Description

Extract the requested attribute of the signature. The returned value is always a constant object to the data.

## Function

int cdk_pkt_build (CDK_STREAM out , CDK_PACKET * pkt )

### Arguments

CDK_STREAM out
  the output stream handle
CDK_PACKET * pkt
  the packet itself

### Description

Write the contents of @pkt into the @out stream.