diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-06 16:41:04 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-06 16:41:04 +0300 |
commit | c3917bef1d9a681fe81a78a96267ddadfec0828f (patch) | |
tree | 45f1f335d04cbdc88b270e05ce4cc368f83e2768 | |
parent | 81b0ccbb0815e1c713b700e0a03e2049440af1bd (diff) |
new file: assuan.h
new file: gcrypt-module.h
new file: gcrypt.h
new file: gpg-error.h
new file: gpgme.h
new file: ksba.h
-rw-r--r-- | assuan.h | 636 | ||||
-rw-r--r-- | gcrypt-module.h | 233 | ||||
-rw-r--r-- | gcrypt.h | 1839 | ||||
-rw-r--r-- | gpg-error.h | 703 | ||||
-rw-r--r-- | gpgme.h | 2101 | ||||
-rw-r--r-- | ksba.h | 526 |
6 files changed, 6038 insertions, 0 deletions
diff --git a/assuan.h b/assuan.h new file mode 100644 index 0000000..0cd943b --- /dev/null +++ b/assuan.h @@ -0,0 +1,636 @@ +/* assuan.h - Definitions for the Assuan IPC library + Copyright (C) 2001-2003, 2005, 2007-2009 Free Software Foundation, Inc. + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ASSUAN_H +#define ASSUAN_H + +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <stdarg.h> + +#ifndef _ASSUAN_NO_SOCKET_WRAPPER +#ifdef _WIN32 +#include <ws2tcpip.h> +#else +#include <sys/socket.h> +#endif +#endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/ + +#ifdef _WIN32 +typedef void *assuan_msghdr_t; +#else +typedef struct msghdr *assuan_msghdr_t; +#endif + +#include <gpg-error.h> + +/* Compile time configuration: + + #define _ASSUAN_NO_SOCKET_WRAPPER + + Do not include the definitions for the socket wrapper feature. */ + + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + + +/* Check for compiler features. */ +#if __GNUC__ +#define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _ASSUAN_GCC_VERSION > 30100 +#define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__)) +#endif +#endif +#ifndef _ASSUAN_DEPRECATED +#define _ASSUAN_DEPRECATED +#endif + + +#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */ + +struct assuan_context_s; +typedef struct assuan_context_s *assuan_context_t; + +/* Because we use system handles and not libc low level file + descriptors on W32, we need to declare them as HANDLE (which + actually is a plain pointer). This is required to eventually + support 64 bit Windows systems. */ +#ifdef _WIN32 +typedef void *assuan_fd_t; +#define ASSUAN_INVALID_FD ((void*)(-1)) +#define ASSUAN_INVALID_PID ((pid_t) -1) +static inline assuan_fd_t +assuan_fd_from_posix_fd (int fd) +{ + if (fd < 0) + return ASSUAN_INVALID_FD; + else + return (assuan_fd_t) _get_osfhandle (fd); +} +#else +typedef int assuan_fd_t; +#define ASSUAN_INVALID_FD (-1) +#define ASSUAN_INVALID_PID ((pid_t) -1) +static inline assuan_fd_t +assuan_fd_from_posix_fd (int fd) +{ + return fd; +} +#endif + +assuan_fd_t assuan_fdopen (int fd); + + +/* Assuan features an emulation of Unix domain sockets based on a + local TCP connections. To implement access permissions based on + file permissions a nonce is used which is expected by th server as + the first bytes received. This structure is used by the server to + save the nonce created initially by bind. On POSIX systems this is + a dummy operation. */ +struct assuan_sock_nonce_s +{ + size_t length; +#ifdef _WIN32 + char nonce[16]; +#endif +}; +typedef struct assuan_sock_nonce_s assuan_sock_nonce_t; + +/* Define the Unix domain socket structure for Windows. */ +#if defined(_WIN32) && !defined(_ASSUAN_NO_SOCKET_WRAPPER) +#ifndef AF_LOCAL +#define AF_LOCAL AF_UNIX +#endif +#define EADDRINUSE WSAEADDRINUSE +struct sockaddr_un +{ + short sun_family; + unsigned short sun_port; + struct in_addr sun_addr; + char sun_path[108-2-4]; +}; +#endif + + +/* Global interface. */ + +struct assuan_malloc_hooks +{ + void *(*malloc) (size_t cnt); + void *(*realloc) (void *ptr, size_t cnt); + void (*free) (void *ptr); +}; +typedef struct assuan_malloc_hooks *assuan_malloc_hooks_t; + +/* Categories for log messages. */ +#define ASSUAN_LOG_INIT 1 +#define ASSUAN_LOG_CTX 2 +#define ASSUAN_LOG_ENGINE 3 +#define ASSUAN_LOG_DATA 4 +#define ASSUAN_LOG_SYSIO 5 + +/* If MSG is NULL, return true/false depending on if this category is + logged. This is used to probe before expensive log message + generation (buffer dumps). */ +typedef int (*assuan_log_cb_t) (assuan_context_t ctx, void *hook, + unsigned int cat, const char *msg); + +/* Set the default gpg error source. */ +void assuan_set_gpg_err_source (gpg_err_source_t errsource); + +/* Get the default gpg error source. */ +gpg_err_source_t assuan_get_gpg_err_source (void); + + +/* Set the default malloc hooks. */ +void assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks); + +/* Get the default malloc hooks. */ +assuan_malloc_hooks_t assuan_get_malloc_hooks (void); + + +/* Set the default log callback handler. */ +void assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data); + +/* Get the default log callback handler. */ +void assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data); + + +/* Create a new Assuan context. The initial parameters are all needed + in the creation of the context. */ +gpg_error_t assuan_new_ext (assuan_context_t *ctx, gpg_err_source_t errsource, + assuan_malloc_hooks_t malloc_hooks, + assuan_log_cb_t log_cb, void *log_cb_data); + +/* Create a new context with default arguments. */ +gpg_error_t assuan_new (assuan_context_t *ctx); + +/* Release all resources associated with the given context. */ +void assuan_release (assuan_context_t ctx); + + +/* Set user-data in a context. */ +void assuan_set_pointer (assuan_context_t ctx, void *pointer); + +/* Get user-data in a context. */ +void *assuan_get_pointer (assuan_context_t ctx); + + +/* Definitions of flags for assuan_set_flag(). */ +typedef unsigned int assuan_flag_t; + +/* When using a pipe server, by default Assuan will wait for the + forked process to die in assuan_release. In certain cases this + is not desirable. By setting this flag, the waitpid will be + skipped and the caller is responsible to cleanup a forked + process. */ +#define ASSUAN_NO_WAITPID 1 +/* This flag indicates whether Assuan logging is in confidential mode. + You can use assuan_{begin,end}_condidential to change the mode. */ +#define ASSUAN_CONFIDENTIAL 2 +/* This flag suppresses fix up of signal handlers for pipes. */ +#define ASSUAN_NO_FIXSIGNALS 3 + +/* For context CTX, set the flag FLAG to VALUE. Values for flags + are usually 1 or 0 but certain flags might allow for other values; + see the description of the type assuan_flag_t for details. */ +void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value); + +/* Return the VALUE of FLAG in context CTX. */ +int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag); + + +/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1). */ +void assuan_begin_confidential (assuan_context_t ctx); + +/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0). */ +void assuan_end_confidential (assuan_context_t ctx); + + +/* Direction values for assuan_set_io_monitor. */ +#define ASSUAN_IO_FROM_PEER 0 +#define ASSUAN_IO_TO_PEER 1 + +/* Return flags of I/O monitor. */ +#define ASSUAN_IO_MONITOR_NOLOG 1 +#define ASSUAN_IO_MONITOR_IGNORE 2 + +/* The IO monitor gets to see all I/O on the context, and can return + ASSUAN_IO_MONITOR_* bits to control actions on it. */ +typedef unsigned int (*assuan_io_monitor_t) (assuan_context_t ctx, void *hook, + int inout, const char *line, + size_t linelen); + +/* Set the IO monitor function. */ +void assuan_set_io_monitor (assuan_context_t ctx, + assuan_io_monitor_t io_monitor, void *hook_data); + + +#define ASSUAN_SYSTEM_HOOKS_VERSION 1 +#define ASSUAN_SPAWN_DETACHED 128 +struct assuan_system_hooks +{ + /* Always set to ASSUAN_SYTEM_HOOKS_VERSION. */ + int version; + + /* Sleep for the given number of microseconds. */ + void (*usleep) (assuan_context_t ctx, unsigned int usec); + + /* Create a pipe with an inheritable end. */ + int (*pipe) (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx); + + /* Close the given file descriptor, created with _assuan_pipe or one + of the socket functions. */ + int (*close) (assuan_context_t ctx, assuan_fd_t fd); + + + ssize_t (*read) (assuan_context_t ctx, assuan_fd_t fd, void *buffer, + size_t size); + ssize_t (*write) (assuan_context_t ctx, assuan_fd_t fd, + const void *buffer, size_t size); + + int (*recvmsg) (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags); + int (*sendmsg) (assuan_context_t ctx, assuan_fd_t fd, + const assuan_msghdr_t msg, int flags); + + /* If NAME is NULL, don't exec, just fork. FD_CHILD_LIST is + modified to reflect the value of the FD in the peer process (on + Windows). */ + int (*spawn) (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, + assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags); + + /* If action is 0, like waitpid. If action is 1, just release the PID? */ + pid_t (*waitpid) (assuan_context_t ctx, pid_t pid, + int action, int *status, int options); + int (*socketpair) (assuan_context_t ctx, int _namespace, int style, + int protocol, assuan_fd_t filedes[2]); +}; +typedef struct assuan_system_hooks *assuan_system_hooks_t; + + +/* Configuration of the default log handler. */ + +/* Set the prefix to be used at the start of a line emitted by assuan + on the log stream. The default is the empty string. Note, that + this function is not thread-safe and should in general be used + right at startup. */ +void assuan_set_assuan_log_prefix (const char *text); + +/* Return a prefix to be used at the start of a line emitted by assuan + on the log stream. The default implementation returns the empty + string, i.e. "" */ +const char *assuan_get_assuan_log_prefix (void); + +/* Global default log stream. */ +void assuan_set_assuan_log_stream (FILE *fp); + +/* Set the per context log stream for the default log handler. */ +void assuan_set_log_stream (assuan_context_t ctx, FILE *fp); + + +typedef gpg_error_t (*assuan_handler_t) (assuan_context_t, char *); + +/*-- assuan-handler.c --*/ +gpg_error_t assuan_register_command (assuan_context_t ctx, + const char *cmd_string, + assuan_handler_t handler, + const char *help_string); +gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx, + void (*fnc)(assuan_context_t, + gpg_error_t)); +gpg_error_t assuan_register_bye_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_reset_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_cancel_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_input_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_output_notify (assuan_context_t ctx, + assuan_handler_t handler); + +gpg_error_t assuan_register_option_handler (assuan_context_t ctx, + gpg_error_t (*fnc)(assuan_context_t, + const char*, + const char*)); + +gpg_error_t assuan_process (assuan_context_t ctx); +gpg_error_t assuan_process_next (assuan_context_t ctx, int *done); +gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc); +int assuan_get_active_fds (assuan_context_t ctx, int what, + assuan_fd_t *fdarray, int fdarraysize); + +const char *assuan_get_command_name (assuan_context_t ctx); + +FILE *assuan_get_data_fp (assuan_context_t ctx); +gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_write_status (assuan_context_t ctx, + const char *keyword, const char *text); + +/* Negotiate a file descriptor. If LINE contains "FD=N", returns N + assuming a local file descriptor. If LINE contains "FD" reads a + file descriptor via CTX and stores it in *RDF (the CTX must be + capable of passing file descriptors). Under W32 the returned FD is + a libc-type one. */ +gpg_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line, + assuan_fd_t *rfd); + + +/*-- assuan-listen.c --*/ +gpg_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_accept (assuan_context_t ctx); +assuan_fd_t assuan_get_input_fd (assuan_context_t ctx); +assuan_fd_t assuan_get_output_fd (assuan_context_t ctx); +gpg_error_t assuan_close_input_fd (assuan_context_t ctx); +gpg_error_t assuan_close_output_fd (assuan_context_t ctx); + + +/*-- assuan-pipe-server.c --*/ +gpg_error_t assuan_init_pipe_server (assuan_context_t ctx, + assuan_fd_t filedes[2]); + +/*-- assuan-socket-server.c --*/ +#define ASSUAN_SOCKET_SERVER_FDPASSING 1 +#define ASSUAN_SOCKET_SERVER_ACCEPTED 2 +gpg_error_t assuan_init_socket_server (assuan_context_t ctx, + assuan_fd_t listen_fd, + unsigned int flags); +void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce); + +/*-- assuan-pipe-connect.c --*/ +#define ASSUAN_PIPE_CONNECT_FDPASSING 1 +#define ASSUAN_PIPE_CONNECT_DETACHED 128 +gpg_error_t assuan_pipe_connect (assuan_context_t ctx, + const char *name, + const char *argv[], + assuan_fd_t *fd_child_list, + void (*atfork) (void *, int), + void *atforkvalue, + unsigned int flags); + +/*-- assuan-socket-connect.c --*/ +#define ASSUAN_SOCKET_CONNECT_FDPASSING 1 +gpg_error_t assuan_socket_connect (assuan_context_t ctx, const char *name, + pid_t server_pid, unsigned int flags); + +/*-- assuan-connect.c --*/ +pid_t assuan_get_pid (assuan_context_t ctx); +struct _assuan_peercred +{ +#ifdef _WIN32 + /* Empty struct not allowed on some compilers. */ + unsigned int _dummy; +#else + pid_t pid; + uid_t uid; + gid_t gid; +#endif +}; +typedef struct _assuan_peercred *assuan_peercred_t; + +gpg_error_t assuan_get_peercred (assuan_context_t ctx, + assuan_peercred_t *peercred); + + + +/* Client interface. */ +#define ASSUAN_RESPONSE_ERROR 0 +#define ASSUAN_RESPONSE_OK 1 +#define ASSUAN_RESPONSE_DATA 2 +#define ASSUAN_RESPONSE_INQUIRE 3 +#define ASSUAN_RESPONSE_STATUS 4 +#define ASSUAN_RESPONSE_END 5 +#define ASSUAN_RESPONSE_COMMENT 6 +typedef int assuan_response_t; + +/* This already de-escapes data lines. */ +gpg_error_t assuan_client_read_response (assuan_context_t ctx, + char **line, int *linelen); + +gpg_error_t assuan_client_parse_response (assuan_context_t ctx, + char *line, int linelen, + assuan_response_t *response, + int *off); + +/*-- assuan-client.c --*/ +gpg_error_t +assuan_transact (assuan_context_t ctx, + const char *command, + gpg_error_t (*data_cb)(void *, const void *, size_t), + void *data_cb_arg, + gpg_error_t (*inquire_cb)(void*, const char *), + void *inquire_cb_arg, + gpg_error_t (*status_cb)(void*, const char *), + void *status_cb_arg); + + +/*-- assuan-inquire.c --*/ +gpg_error_t assuan_inquire (assuan_context_t ctx, const char *keyword, + unsigned char **r_buffer, size_t *r_length, + size_t maxlen); +gpg_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword, + size_t maxlen, + gpg_error_t (*cb) (void *cb_data, + gpg_error_t rc, + unsigned char *buf, + size_t buf_len), + void *cb_data); +/*-- assuan-buffer.c --*/ +gpg_error_t assuan_read_line (assuan_context_t ctx, + char **line, size_t *linelen); +int assuan_pending_line (assuan_context_t ctx); +gpg_error_t assuan_write_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_send_data (assuan_context_t ctx, + const void *buffer, size_t length); + +/* The file descriptor must be pending before assuan_receivefd is + called. This means that assuan_sendfd should be called *before* the + trigger is sent (normally via assuan_write_line ("INPUT FD")). */ +gpg_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd); +gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd); + + +/*-- assuan-util.c --*/ +gpg_error_t assuan_set_error (assuan_context_t ctx, gpg_error_t err, + const char *text); + + + +/*-- assuan-socket.c --*/ + +/* These are socket wrapper functions to support an emulation of Unix + domain sockets on Windows W32. */ +gpg_error_t assuan_sock_init (void); +void assuan_sock_deinit (void); +int assuan_sock_close (assuan_fd_t fd); +assuan_fd_t assuan_sock_new (int domain, int type, int proto); +int assuan_sock_connect (assuan_fd_t sockfd, + struct sockaddr *addr, int addrlen); +int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen); +int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, + assuan_sock_nonce_t *nonce); +int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce); + + +/* Set the default or per context system callbacks. This is + irreversible. */ +void assuan_set_system_hooks (assuan_system_hooks_t system_hooks); + +void assuan_ctx_set_system_hooks (assuan_context_t ctx, + assuan_system_hooks_t system_hooks); + +void __assuan_usleep (assuan_context_t ctx, unsigned int usec); +int __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx); +int __assuan_close (assuan_context_t ctx, assuan_fd_t fd); +int __assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags); +int __assuan_socketpair (assuan_context_t ctx, int _namespace, int style, + int protocol, assuan_fd_t filedes[2]); + +#ifdef _WIN32 +#define _ASSUAN_SYSTEM_PTH_IMPL \ + static int _assuan_pth_recvmsg (assuan_context_t ctx, assuan_fd_t fd, \ + assuan_msghdr_t msg, int flags) \ + { \ + (void) ctx; \ + errno = ENOSYS; \ + return -1; \ + } \ + static int _assuan_pth_sendmsg (assuan_context_t ctx, assuan_fd_t fd, \ + const assuan_msghdr_t msg, int flags) \ + { \ + (void) ctx; \ + errno = ENOSYS; \ + return -1; \ + } +#else +#define _ASSUAN_SYSTEM_PTH_IMPL \ + static int _assuan_pth_recvmsg (assuan_context_t ctx, assuan_fd_t fd, \ + assuan_msghdr_t msg, int flags) \ + { \ + /* Pth does not provide a recvmsg function. We implement it. */ \ + int ret; \ + int fdmode; \ + \ + (void) ctx; \ + fdmode = pth_fdmode (fd, PTH_FDMODE_POLL); \ + if (fdmode == PTH_FDMODE_ERROR) \ + { \ + errno = EBADF; \ + return -1; \ + } \ + if (fdmode == PTH_FDMODE_BLOCK) \ + { \ + fd_set fds; \ + \ + FD_ZERO (&fds); \ + FD_SET (fd, &fds); \ + while ((ret = pth_select (fd + 1, &fds, NULL, NULL, NULL)) < 0 \ + && errno == EINTR) \ + ; \ + if (ret < 0) \ + return -1; \ + } \ + \ + while ((ret = recvmsg (fd, msg, flags)) == -1 && errno == EINTR) \ + ; \ + return ret; \ + } \ + static int _assuan_pth_sendmsg (assuan_context_t ctx, assuan_fd_t fd, \ + const assuan_msghdr_t msg, int flags) \ + { \ + /* Pth does not provide a sendmsg function. We implement it. */ \ + int ret; \ + int fdmode; \ + \ + (void) ctx; \ + fdmode = pth_fdmode (fd, PTH_FDMODE_POLL); \ + if (fdmode == PTH_FDMODE_ERROR) \ + { \ + errno = EBADF; \ + return -1; \ + } \ + if (fdmode == PTH_FDMODE_BLOCK) \ + { \ + fd_set fds; \ + \ + FD_ZERO (&fds); \ + FD_SET (fd, &fds); \ + while ((ret = pth_select (fd + 1, NULL, &fds, NULL, NULL)) < 0 \ + && errno == EINTR) \ + ; \ + if (ret < 0) \ + return -1; \ + } \ + \ + while ((ret = sendmsg (fd, msg, flags)) == -1 && errno == EINTR) \ + ; \ + return ret; \ + } +#endif + + +#define ASSUAN_SYSTEM_PTH_IMPL \ + static void _assuan_pth_usleep (assuan_context_t ctx, unsigned int usec) \ + { (void) ctx; pth_usleep (usec); } \ + static ssize_t _assuan_pth_read (assuan_context_t ctx, assuan_fd_t fd, \ + void *buffer, size_t size) \ + { (void) ctx; return pth_read (fd, buffer, size); } \ + static ssize_t _assuan_pth_write (assuan_context_t ctx, assuan_fd_t fd, \ + const void *buffer, size_t size) \ + { (void) ctx; return pth_write (fd, buffer, size); } \ + _ASSUAN_SYSTEM_PTH_IMPL \ + static pid_t _assuan_pth_waitpid (assuan_context_t ctx, pid_t pid, \ + int nowait, int *status, int options) \ + { (void) ctx; \ + if (!nowait) return pth_waitpid (pid, status, options); \ + else return 0; } \ + \ + struct assuan_system_hooks _assuan_system_pth = \ + { ASSUAN_SYSTEM_HOOKS_VERSION, _assuan_pth_usleep, __assuan_pipe, \ + __assuan_close, _assuan_pth_read, _assuan_pth_write, \ + _assuan_pth_recvmsg, _assuan_pth_sendmsg, \ + __assuan_spawn, _assuan_pth_waitpid, __assuan_socketpair } + +extern struct assuan_system_hooks _assuan_system_pth; +#define ASSUAN_SYSTEM_PTH &_assuan_system_pth + + +#ifdef __cplusplus +} +#endif +#endif /* ASSUAN_H */ diff --git a/gcrypt-module.h b/gcrypt-module.h new file mode 100644 index 0000000..e717b70 --- /dev/null +++ b/gcrypt-module.h @@ -0,0 +1,233 @@ +/* gcrypt-module.h - GNU Cryptographic Library Interface + Copyright (C) 2003, 2007 Free Software Foundation, Inc. + + This file is part of Libgcrypt. + + Libgcrypt is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Libgcrypt is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +/* + This file contains the necessary declarations/definitions for + working with Libgcrypt modules. + */ + +#ifndef _GCRYPT_MODULE_H +#define _GCRYPT_MODULE_H + +#ifdef __cplusplus +extern "C" { +#if 0 /* keep Emacsens's auto-indent happy */ +} +#endif +#endif + +/* The interfaces using the module system reserve a certain range of + IDs for application use. These IDs are not valid within Libgcrypt + but Libgcrypt makes sure never to allocate such a module ID. */ +#define GCRY_MODULE_ID_USER 1024 +#define GCRY_MODULE_ID_USER_LAST 4095 + + +/* This type represents a `module'. */ +typedef struct gcry_module *gcry_module_t; + +/* Check that the library fulfills the version requirement. */ + +/* Type for the cipher_setkey function. */ +typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c, + const unsigned char *key, + unsigned keylen); + +/* Type for the cipher_encrypt function. */ +typedef void (*gcry_cipher_encrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf); + +/* Type for the cipher_decrypt function. */ +typedef void (*gcry_cipher_decrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf); + +/* Type for the cipher_stencrypt function. */ +typedef void (*gcry_cipher_stencrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf, + unsigned int n); + +/* Type for the cipher_stdecrypt function. */ +typedef void (*gcry_cipher_stdecrypt_t) (void *c, + unsigned char *outbuf, + const unsigned char *inbuf, + unsigned int n); + +typedef struct gcry_cipher_oid_spec +{ + const char *oid; + int mode; +} gcry_cipher_oid_spec_t; + +/* Module specification structure for ciphers. */ +typedef struct gcry_cipher_spec +{ + const char *name; + const char **aliases; + gcry_cipher_oid_spec_t *oids; + size_t blocksize; + size_t keylen; + size_t contextsize; + gcry_cipher_setkey_t setkey; + gcry_cipher_encrypt_t encrypt; + gcry_cipher_decrypt_t decrypt; + gcry_cipher_stencrypt_t stencrypt; + gcry_cipher_stdecrypt_t stdecrypt; +} gcry_cipher_spec_t; + +/* Register a new cipher module whose specification can be found in + CIPHER. On success, a new algorithm ID is stored in ALGORITHM_ID + and a pointer representing this module is stored in MODULE. */ +gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *cipher, + int *algorithm_id, + gcry_module_t *module); + +/* Unregister the cipher identified by MODULE, which must have been + registered with gcry_cipher_register. */ +void gcry_cipher_unregister (gcry_module_t module); + +/* ********************** */ + +/* Type for the pk_generate function. */ +typedef gcry_err_code_t (*gcry_pk_generate_t) (int algo, + unsigned int nbits, + unsigned long use_e, + gcry_mpi_t *skey, + gcry_mpi_t **retfactors); + +/* Type for the pk_check_secret_key function. */ +typedef gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo, + gcry_mpi_t *skey); + +/* Type for the pk_encrypt function. */ +typedef gcry_err_code_t (*gcry_pk_encrypt_t) (int algo, + gcry_mpi_t *resarr, + gcry_mpi_t data, + gcry_mpi_t *pkey, + int flags); + +/* Type for the pk_decrypt function. */ +typedef gcry_err_code_t (*gcry_pk_decrypt_t) (int algo, + gcry_mpi_t *result, + gcry_mpi_t *data, + gcry_mpi_t *skey, + int flags); + +/* Type for the pk_sign function. */ +typedef gcry_err_code_t (*gcry_pk_sign_t) (int algo, + gcry_mpi_t *resarr, + gcry_mpi_t data, + gcry_mpi_t *skey); + +/* Type for the pk_verify function. */ +typedef gcry_err_code_t (*gcry_pk_verify_t) (int algo, + gcry_mpi_t hash, + gcry_mpi_t *data, + gcry_mpi_t *pkey, + int (*cmp) (void *, gcry_mpi_t), + void *opaquev); + +/* Type for the pk_get_nbits function. */ +typedef unsigned (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey); + +/* Module specification structure for message digests. */ +typedef struct gcry_pk_spec +{ + const char *name; + const char **aliases; + const char *elements_pkey; + const char *elements_skey; + const char *elements_enc; + const char *elements_sig; + const char *elements_grip; + int use; + gcry_pk_generate_t generate; + gcry_pk_check_secret_key_t check_secret_key; + gcry_pk_encrypt_t encrypt; + gcry_pk_decrypt_t decrypt; + gcry_pk_sign_t sign; + gcry_pk_verify_t verify; + gcry_pk_get_nbits_t get_nbits; +} gcry_pk_spec_t; + +/* Register a new pubkey module whose specification can be found in + PUBKEY. On success, a new algorithm ID is stored in ALGORITHM_ID + and a pointer representhing this module is stored in MODULE. */ +gcry_error_t gcry_pk_register (gcry_pk_spec_t *pubkey, + unsigned int *algorithm_id, + gcry_module_t *module); + +/* Unregister the pubkey identified by ID, which must have been + registered with gcry_pk_register. */ +void gcry_pk_unregister (gcry_module_t module); + +/* ********************** */ + +/* Type for the md_init function. */ +typedef void (*gcry_md_init_t) (void *c); + +/* Type for the md_write function. */ +typedef void (*gcry_md_write_t) (void *c, const void *buf, size_t nbytes); + +/* Type for the md_final function. */ +typedef void (*gcry_md_final_t) (void *c); + +/* Type for the md_read function. */ +typedef unsigned char *(*gcry_md_read_t) (void *c); + +typedef struct gcry_md_oid_spec +{ + const char *oidstring; +} gcry_md_oid_spec_t; + +/* Module specification structure for message digests. */ +typedef struct gcry_md_spec +{ + const char *name; + unsigned char *asnoid; + int asnlen; + gcry_md_oid_spec_t *oids; + int mdlen; + gcry_md_init_t init; + gcry_md_write_t write; + gcry_md_final_t final; + gcry_md_read_t read; + size_t contextsize; /* allocate this amount of context */ +} gcry_md_spec_t; + +/* Register a new digest module whose specification can be found in + DIGEST. On success, a new algorithm ID is stored in ALGORITHM_ID + and a pointer representhing this module is stored in MODULE. */ +gcry_error_t gcry_md_register (gcry_md_spec_t *digest, + unsigned int *algorithm_id, + gcry_module_t *module); + +/* Unregister the digest identified by ID, which must have been + registered with gcry_digest_register. */ +void gcry_md_unregister (gcry_module_t module); + +#if 0 /* keep Emacsens's auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/gcrypt.h b/gcrypt.h new file mode 100644 index 0000000..fc42535 --- /dev/null +++ b/gcrypt.h @@ -0,0 +1,1839 @@ +/* gcrypt.h - GNU Cryptographic Library Interface -*- c -*- + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 + 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of Libgcrypt. + + Libgcrypt is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Libgcrypt is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see <http://www.gnu.org/licenses/>. + + File: src/gcrypt.h. Generated from gcrypt.h.in by configure. */ + +#ifndef _GCRYPT_H +#define _GCRYPT_H + +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> + +#include <gpg-error.h> + +#include <sys/types.h> + +#if defined _WIN32 || defined __WIN32__ +# include <winsock2.h> +# include <ws2tcpip.h> +# include <time.h> +# ifndef __GNUC__ + typedef long ssize_t; + typedef int pid_t; +# endif /*!__GNUC__*/ +#else +# include <sys/socket.h> +# include <sys/time.h> +#endif /*!_WIN32*/ + +typedef int gcry_socklen_t; + + +/* This is required for error code compatibility. */ +#define _GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GCRYPT + +#ifdef __cplusplus +extern "C" { +#if 0 /* (Keep Emacsens' auto-indent happy.) */ +} +#endif +#endif + +/* The version of this header should match the one of the library. It + should not be used by a program because gcry_check_version() should + return the same version. The purpose of this macro is to let + autoconf (using the AM_PATH_GCRYPT macro) check that this header + matches the installed library. */ +#define GCRYPT_VERSION "1.4.6" + +/* Internal: We can't use the convenience macros for the multi + precision integer functions when building this library. */ +#ifdef _GCRYPT_IN_LIBGCRYPT +#ifndef GCRYPT_NO_MPI_MACROS +#define GCRYPT_NO_MPI_MACROS 1 +#endif +#endif + +/* We want to use gcc attributes when possible. Warning: Don't use + these macros in your programs: As indicated by the leading + underscore they are subject to change without notice. */ +#ifdef __GNUC__ + +#define _GCRY_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _GCRY_GCC_VERSION >= 30100 +#define _GCRY_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#if _GCRY_GCC_VERSION >= 29600 +#define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__)) +#endif + +#if _GCRY_GCC_VERSION >= 30200 +#define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__)) +#endif + +#endif /*__GNUC__*/ + +#ifndef _GCRY_GCC_ATTR_DEPRECATED +#define _GCRY_GCC_ATTR_DEPRECATED +#endif +#ifndef _GCRY_GCC_ATTR_PURE +#define _GCRY_GCC_ATTR_PURE +#endif +#ifndef _GCRY_GCC_ATTR_MALLOC +#define _GCRY_GCC_ATTR_MALLOC +#endif + +/* Some members in a public type should only be used internally. + There is no "internal" attribute, so we abuse the deprecated + attribute to discourage external use. */ +#ifdef _GCRYPT_IN_LIBGCRYPT +#define _GCRY_ATTR_INTERNAL +#else +#define _GCRY_ATTR_INTERNAL _GCRY_GCC_ATTR_DEPRECATED +#endif + +/* Wrappers for the libgpg-error library. */ + +typedef gpg_error_t gcry_error_t; +typedef gpg_err_code_t gcry_err_code_t; +typedef gpg_err_source_t gcry_err_source_t; + +static GPG_ERR_INLINE gcry_error_t +gcry_err_make (gcry_err_source_t source, gcry_err_code_t code) +{ + return gpg_err_make (source, code); +} + +/* The user can define GPG_ERR_SOURCE_DEFAULT before including this + file to specify a default source for gpg_error. */ +#ifndef GCRY_ERR_SOURCE_DEFAULT +#define GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 +#endif + +static GPG_ERR_INLINE gcry_error_t +gcry_error (gcry_err_code_t code) +{ + return gcry_err_make (GCRY_ERR_SOURCE_DEFAULT, code); +} + +static GPG_ERR_INLINE gcry_err_code_t +gcry_err_code (gcry_error_t err) +{ + return gpg_err_code (err); +} + + +static GPG_ERR_INLINE gcry_err_source_t +gcry_err_source (gcry_error_t err) +{ + return gpg_err_source (err); +} + +/* Return a pointer to a string containing a description of the error + code in the error value ERR. */ +const char *gcry_strerror (gcry_error_t err); + +/* Return a pointer to a string containing a description of the error + source in the error value ERR. */ +const char *gcry_strsource (gcry_error_t err); + +/* Retrieve the error code for the system error ERR. This returns + GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report + this). */ +gcry_err_code_t gcry_err_code_from_errno (int err); + +/* Retrieve the system error for the error code CODE. This returns 0 + if CODE is not a system error code. */ +int gcry_err_code_to_errno (gcry_err_code_t code); + +/* Return an error value with the error source SOURCE and the system + error ERR. */ +gcry_error_t gcry_err_make_from_errno (gcry_err_source_t source, int err); + +/* Return an error value with the system error ERR. */ +gcry_err_code_t gcry_error_from_errno (int err); + + +/* This enum is deprecated; it is only declared for the sake of + complete API compatibility. */ +enum gcry_thread_option + { + _GCRY_THREAD_OPTION_DUMMY + } _GCRY_GCC_ATTR_DEPRECATED; + + +/* Constants defining the thread model to use. Used with the OPTION + field of the struct gcry_thread_cbs. */ +#define GCRY_THREAD_OPTION_DEFAULT 0 +#define GCRY_THREAD_OPTION_USER 1 +#define GCRY_THREAD_OPTION_PTH 2 +#define GCRY_THREAD_OPTION_PTHREAD 3 + +/* The version number encoded in the OPTION field of the struct + gcry_thread_cbs. */ +#define GCRY_THREAD_OPTION_VERSION 0 + +/* Wrapper for struct ath_ops. */ +struct gcry_thread_cbs +{ + /* The OPTION field encodes the thread model and the version number + of this structure. + Bits 7 - 0 are used for the thread model + Bits 15 - 8 are used for the version number. + */ + unsigned int option; + + int (*init) (void); + int (*mutex_init) (void **priv); + int (*mutex_destroy) (void **priv); + int (*mutex_lock) (void **priv); + int (*mutex_unlock) (void **priv); + ssize_t (*read) (int fd, void *buf, size_t nbytes); + ssize_t (*write) (int fd, const void *buf, size_t nbytes); +#ifdef _WIN32 + ssize_t (*select) (int nfd, void *rset, void *wset, void *eset, + struct timeval *timeout); + ssize_t (*waitpid) (pid_t pid, int *status, int options); + int (*accept) (int s, void *addr, int *length_ptr); + int (*connect) (int s, void *addr, gcry_socklen_t length); + int (*sendmsg) (int s, const void *msg, int flags); + int (*recvmsg) (int s, void *msg, int flags); +#else + ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, + struct timeval *timeout); + ssize_t (*waitpid) (pid_t pid, int *status, int options); + int (*accept) (int s, struct sockaddr *addr, gcry_socklen_t *length_ptr); + int (*connect) (int s, struct sockaddr *addr, gcry_socklen_t length); + int (*sendmsg) (int s, const struct msghdr *msg, int flags); + int (*recvmsg) (int s, struct msghdr *msg, int flags); +#endif +}; + +#ifdef _WIN32 +# define _GCRY_THREAD_OPTION_PTH_IMPL_NET \ +static ssize_t gcry_pth_select (int nfd, void *rset, void *wset, \ + void *eset, struct timeval *timeout) \ + { return pth_select (nfd, rset, wset, eset, timeout); } \ +static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options) \ + { return pth_waitpid (pid, status, options); } \ +static int gcry_pth_accept (int s, void *addr, \ + gcry_socklen_t *length_ptr) \ + { return pth_accept (s, addr, length_ptr); } \ +static int gcry_pth_connect (int s, void *addr, \ + gcry_socklen_t length) \ + { return pth_connect (s, addr, length); } +#else /*!_WIN32*/ +# define _GCRY_THREAD_OPTION_PTH_IMPL_NET \ +static ssize_t gcry_pth_select (int nfd, fd_set *rset, fd_set *wset, \ + fd_set *eset, struct timeval *timeout) \ + { return pth_select (nfd, rset, wset, eset, timeout); } \ +static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options) \ + { return pth_waitpid (pid, status, options); } \ +static int gcry_pth_accept (int s, struct sockaddr *addr, \ + gcry_socklen_t *length_ptr) \ + { return pth_accept (s, addr, length_ptr); } \ +static int gcry_pth_connect (int s, struct sockaddr *addr, \ + gcry_socklen_t length) \ + { return pth_connect (s, addr, length); } +#endif /*!_WIN32*/ + + + +#define GCRY_THREAD_OPTION_PTH_IMPL \ +static int gcry_pth_init (void) \ +{ return (pth_init () == FALSE) ? errno : 0; } \ +static int gcry_pth_mutex_init (void **priv) \ +{ \ + int err = 0; \ + pth_mutex_t *lock = malloc (sizeof (pth_mutex_t)); \ + \ + if (!lock) \ + err = ENOMEM; \ + if (!err) \ + { \ + err = pth_mutex_init (lock); \ + if (err == FALSE) \ + err = errno; \ + else \ + err = 0; \ + if (err) \ + free (lock); \ + else \ + *priv = lock; \ + } \ + return err; \ +} \ +static int gcry_pth_mutex_destroy (void **lock) \ + { /* GNU Pth has no destructor function. */ free (*lock); return 0; } \ +static int gcry_pth_mutex_lock (void **lock) \ + { return ((pth_mutex_acquire (*lock, 0, NULL)) == FALSE) \ + ? errno : 0; } \ +static int gcry_pth_mutex_unlock (void **lock) \ + { return ((pth_mutex_release (*lock)) == FALSE) \ + ? errno : 0; } \ +static ssize_t gcry_pth_read (int fd, void *buf, size_t nbytes) \ + { return pth_read (fd, buf, nbytes); } \ +static ssize_t gcry_pth_write (int fd, const void *buf, size_t nbytes) \ + { return pth_write (fd, buf, nbytes); } \ +_GCRY_THREAD_OPTION_PTH_IMPL_NET \ + \ +/* Note: GNU Pth is missing pth_sendmsg and pth_recvmsg. */ \ +static struct gcry_thread_cbs gcry_threads_pth = { \ + (GCRY_THREAD_OPTION_PTH | (GCRY_THREAD_OPTION_VERSION << 8)), \ + gcry_pth_init, gcry_pth_mutex_init, gcry_pth_mutex_destroy, \ + gcry_pth_mutex_lock, gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, \ + gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, \ + NULL, NULL } + + +#define GCRY_THREAD_OPTION_PTHREAD_IMPL \ +static int gcry_pthread_mutex_init (void **priv) \ +{ \ + int err = 0; \ + pthread_mutex_t *lock = (pthread_mutex_t*)malloc (sizeof (pthread_mutex_t));\ + \ + if (!lock) \ + err = ENOMEM; \ + if (!err) \ + { \ + err = pthread_mutex_init (lock, NULL); \ + if (err) \ + free (lock); \ + else \ + *priv = lock; \ + } \ + return err; \ +} \ +static int gcry_pthread_mutex_destroy (void **lock) \ + { int err = pthread_mutex_destroy ((pthread_mutex_t*)*lock); \ + free (*lock); return err; } \ +static int gcry_pthread_mutex_lock (void **lock) \ + { return pthread_mutex_lock ((pthread_mutex_t*)*lock); } \ +static int gcry_pthread_mutex_unlock (void **lock) \ + { return pthread_mutex_unlock ((pthread_mutex_t*)*lock); } \ + \ +static struct gcry_thread_cbs gcry_threads_pthread = { \ + (GCRY_THREAD_OPTION_PTHREAD | (GCRY_THREAD_OPTION_VERSION << 8)), \ + NULL, gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, \ + gcry_pthread_mutex_lock, gcry_pthread_mutex_unlock, \ + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } + + +/* The data object used to hold a multi precision integer. */ +struct gcry_mpi; +typedef struct gcry_mpi *gcry_mpi_t; + +#ifndef GCRYPT_NO_DEPRECATED +typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED; +typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED; +#endif + + + +/* Check that the library fulfills the version requirement. */ +const char *gcry_check_version (const char *req_version); + +/* Codes for function dispatchers. */ + +/* Codes used with the gcry_control function. */ +enum gcry_ctl_cmds + { + GCRYCTL_SET_KEY = 1, + GCRYCTL_SET_IV = 2, + GCRYCTL_CFB_SYNC = 3, + GCRYCTL_RESET = 4, /* e.g. for MDs */ + GCRYCTL_FINALIZE = 5, + GCRYCTL_GET_KEYLEN = 6, + GCRYCTL_GET_BLKLEN = 7, + GCRYCTL_TEST_ALGO = 8, + GCRYCTL_IS_SECURE = 9, + GCRYCTL_GET_ASNOID = 10, + GCRYCTL_ENABLE_ALGO = 11, + GCRYCTL_DISABLE_ALGO = 12, + GCRYCTL_DUMP_RANDOM_STATS = 13, + GCRYCTL_DUMP_SECMEM_STATS = 14, + GCRYCTL_GET_ALGO_NPKEY = 15, + GCRYCTL_GET_ALGO_NSKEY = 16, + GCRYCTL_GET_ALGO_NSIGN = 17, + GCRYCTL_GET_ALGO_NENCR = 18, + GCRYCTL_SET_VERBOSITY = 19, + GCRYCTL_SET_DEBUG_FLAGS = 20, + GCRYCTL_CLEAR_DEBUG_FLAGS = 21, + GCRYCTL_USE_SECURE_RNDPOOL= 22, + GCRYCTL_DUMP_MEMORY_STATS = 23, + GCRYCTL_INIT_SECMEM = 24, + GCRYCTL_TERM_SECMEM = 25, + GCRYCTL_DISABLE_SECMEM_WARN = 27, + GCRYCTL_SUSPEND_SECMEM_WARN = 28, + GCRYCTL_RESUME_SECMEM_WARN = 29, + GCRYCTL_DROP_PRIVS = 30, + GCRYCTL_ENABLE_M_GUARD = 31, + GCRYCTL_START_DUMP = 32, + GCRYCTL_STOP_DUMP = 33, + GCRYCTL_GET_ALGO_USAGE = 34, + GCRYCTL_IS_ALGO_ENABLED = 35, + GCRYCTL_DISABLE_INTERNAL_LOCKING = 36, + GCRYCTL_DISABLE_SECMEM = 37, + GCRYCTL_INITIALIZATION_FINISHED = 38, + GCRYCTL_INITIALIZATION_FINISHED_P = 39, + GCRYCTL_ANY_INITIALIZATION_P = 40, + GCRYCTL_SET_CBC_CTS = 41, + GCRYCTL_SET_CBC_MAC = 42, + GCRYCTL_SET_CTR = 43, + GCRYCTL_ENABLE_QUICK_RANDOM = 44, + GCRYCTL_SET_RANDOM_SEED_FILE = 45, + GCRYCTL_UPDATE_RANDOM_SEED_FILE = 46, + GCRYCTL_SET_THREAD_CBS = 47, + GCRYCTL_FAST_POLL = 48, + GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49, + GCRYCTL_USE_RANDOM_DAEMON = 50, + GCRYCTL_FAKED_RANDOM_P = 51, + GCRYCTL_SET_RNDEGD_SOCKET = 52, + GCRYCTL_PRINT_CONFIG = 53, + GCRYCTL_OPERATIONAL_P = 54, + GCRYCTL_FIPS_MODE_P = 55, + GCRYCTL_FORCE_FIPS_MODE = 56, + GCRYCTL_SELFTEST = 57 + /* Note: 58 .. 62 are used internally. */ + }; + +/* Perform various operations defined by CMD. */ +gcry_error_t gcry_control (enum gcry_ctl_cmds CMD, ...); + + +/* S-expression management. */ + +/* The object to represent an S-expression as used with the public key + functions. */ +struct gcry_sexp; +typedef struct gcry_sexp *gcry_sexp_t; + +#ifndef GCRYPT_NO_DEPRECATED +typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED; +typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED; +#endif + +/* The possible values for the S-expression format. */ +enum gcry_sexp_format + { + GCRYSEXP_FMT_DEFAULT = 0, + GCRYSEXP_FMT_CANON = 1, + GCRYSEXP_FMT_BASE64 = 2, + GCRYSEXP_FMT_ADVANCED = 3 + }; + +/* Create an new S-expression object from BUFFER of size LENGTH and + return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER + is expected to be in canonized format. */ +gcry_error_t gcry_sexp_new (gcry_sexp_t *retsexp, + const void *buffer, size_t length, + int autodetect); + + /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the + effect to transfer ownership of BUFFER to the created object. */ +gcry_error_t gcry_sexp_create (gcry_sexp_t *retsexp, + void *buffer, size_t length, + int autodetect, void (*freefnc) (void *)); + +/* Scan BUFFER and return a new S-expression object in RETSEXP. This + function expects a printf like string in BUFFER. */ +gcry_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff, + const char *buffer, size_t length); + +/* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus + only be used for certain encodings. */ +gcry_error_t gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, + const char *format, ...); + +/* Like gcry_sexp_build, but uses an array instead of variable + function arguments. */ +gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff, + const char *format, void **arg_list); + +/* Release the S-expression object SEXP */ +void gcry_sexp_release (gcry_sexp_t sexp); + +/* Calculate the length of an canonized S-expresion in BUFFER and + check for a valid encoding. */ +size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length, + size_t *erroff, gcry_error_t *errcode); + +/* Copies the S-expression object SEXP into BUFFER using the format + specified in MODE. */ +size_t gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer, + size_t maxlength); + +/* Dumps the S-expression object A in a format suitable for debugging + to Libgcrypt's logging stream. */ +void gcry_sexp_dump (const gcry_sexp_t a); + +gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b); +gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array); +gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...); +gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n); +gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n); + +/* Scan the S-expression for a sublist with a type (the car of the + list) matching the string TOKEN. If TOKLEN is not 0, the token is + assumed to be raw memory of this length. The function returns a + newly allocated S-expression consisting of the found sublist or + `NULL' when not found. */ +gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list, + const char *tok, size_t toklen); +/* Return the length of the LIST. For a valid S-expression this + should be at least 1. */ +int gcry_sexp_length (const gcry_sexp_t list); + +/* Create and return a new S-expression from the element with index + NUMBER in LIST. Note that the first element has the index 0. If + there is no such element, `NULL' is returned. */ +gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number); + +/* Create and return a new S-expression from the first element in + LIST; this called the "type" and should always exist and be a + string. `NULL' is returned in case of a problem. */ +gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list); + +/* Create and return a new list form all elements except for the first + one. Note, that this function may return an invalid S-expression + because it is not guaranteed, that the type exists and is a string. + However, for parsing a complex S-expression it might be useful for + intermediate lists. Returns `NULL' on error. */ +gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list); + +gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list); + + +/* This function is used to get data from a LIST. A pointer to the + actual data with index NUMBER is returned and the length of this + data will be stored to DATALEN. If there is no data at the given + index or the index represents another list, `NULL' is returned. + *Note:* The returned pointer is valid as long as LIST is not + modified or released. */ +const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number, + size_t *datalen); + +/* This function is used to get and convert data from a LIST. The + data is assumed to be a Nul terminated string. The caller must + release the returned value using `gcry_free'. If there is no data + at the given index, the index represents a list or the value can't + be converted to a string, `NULL' is returned. */ +char *gcry_sexp_nth_string (gcry_sexp_t list, int number); + +/* This function is used to get and convert data from a LIST. This + data is assumed to be an MPI stored in the format described by + MPIFMT and returned as a standard Libgcrypt MPI. The caller must + release this returned value using `gcry_mpi_release'. If there is + no data at the given index, the index represents a list or the + value can't be converted to an MPI, `NULL' is returned. */ +gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt); + + + +/******************************************* + * * + * Multi Precision Integer Functions * + * * + *******************************************/ + +/* Different formats of external big integer representation. */ +enum gcry_mpi_format + { + GCRYMPI_FMT_NONE= 0, + GCRYMPI_FMT_STD = 1, /* Twos complement stored without length. */ + GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (unsigned only). */ + GCRYMPI_FMT_SSH = 3, /* As used by SSH (like STD but with length). */ + GCRYMPI_FMT_HEX = 4, /* Hex format. */ + GCRYMPI_FMT_USG = 5 /* Like STD but unsigned. */ + }; + +/* Flags used for creating big integers. */ +enum gcry_mpi_flag + { + GCRYMPI_FLAG_SECURE = 1, /* Allocate the number in "secure" memory. */ + GCRYMPI_FLAG_OPAQUE = 2 /* The number is not a real one but just + a way to store some bytes. This is + useful for encrypted big integers. */ + }; + + +/* Allocate a new big integer object, initialize it with 0 and + initially allocate memory for a number of at least NBITS. */ +gcry_mpi_t gcry_mpi_new (unsigned int nbits); + +/* Same as gcry_mpi_new() but allocate in "secure" memory. */ +gcry_mpi_t gcry_mpi_snew (unsigned int nbits); + +/* Release the number A and free all associated resources. */ +void gcry_mpi_release (gcry_mpi_t a); + +/* Create a new number with the same value as A. */ +gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a); + +/* Store the big integer value U in W. */ +gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u); + +/* Store the unsigned integer value U in W. */ +gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u); + +/* Swap the values of A and B. */ +void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b); + +/* Compare the big integer number U and V returning 0 for equality, a + positive value for U > V and a negative for U < V. */ +int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v); + +/* Compare the big integer number U with the unsigned integer V + returning 0 for equality, a positive value for U > V and a negative + for U < V. */ +int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v); + +/* Convert the external representation of an integer stored in BUFFER + with a length of BUFLEN into a newly create MPI returned in + RET_MPI. If NSCANNED is not NULL, it will receive the number of + bytes actually scanned after a successful operation. */ +gcry_error_t gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format, + const void *buffer, size_t buflen, + size_t *nscanned); + +/* Convert the big integer A into the external representation + described by FORMAT and store it in the provided BUFFER which has + been allocated by the user with a size of BUFLEN bytes. NWRITTEN + receives the actual length of the external representation unless it + has been passed as NULL. */ +gcry_error_t gcry_mpi_print (enum gcry_mpi_format format, + unsigned char *buffer, size_t buflen, + size_t *nwritten, + const gcry_mpi_t a); + +/* Convert the big integer A int the external representation described + by FORMAT and store it in a newly allocated buffer which address + will be put into BUFFER. NWRITTEN receives the actual lengths of the + external representation. */ +gcry_error_t gcry_mpi_aprint (enum gcry_mpi_format format, + unsigned char **buffer, size_t *nwritten, + const gcry_mpi_t a); + +/* Dump the value of A in a format suitable for debugging to + Libgcrypt's logging stream. Note that one leading space but no + trailing space or linefeed will be printed. It is okay to pass + NULL for A. */ +void gcry_mpi_dump (const gcry_mpi_t a); + + +/* W = U + V. */ +void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); + +/* W = U + V. V is an unsigned integer. */ +void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v); + +/* W = U + V mod M. */ +void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); + +/* W = U - V. */ +void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); + +/* W = U - V. V is an unsigned integer. */ +void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); + +/* W = U - V mod M */ +void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); + +/* W = U * V. */ +void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v); + +/* W = U * V. V is an unsigned integer. */ +void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v ); + +/* W = U * V mod M. */ +void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m); + +/* W = U * (2 ^ CNT). */ +void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt); + +/* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR, + Q or R may be passed as NULL. ROUND should be negative or 0. */ +void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r, + gcry_mpi_t dividend, gcry_mpi_t divisor, int round); + +/* R = DIVIDEND % DIVISOR */ +void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor); + +/* W = B ^ E mod M. */ +void gcry_mpi_powm (gcry_mpi_t w, + const gcry_mpi_t b, const gcry_mpi_t e, + const gcry_mpi_t m); + +/* Set G to the greatest common divisor of A and B. + Return true if the G is 1. */ +int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b); + +/* Set X to the multiplicative inverse of A mod M. + Return true if the value exists. */ +int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m); + + +/* Return the number of bits required to represent A. */ +unsigned int gcry_mpi_get_nbits (gcry_mpi_t a); + +/* Return true when bit number N (counting from 0) is set in A. */ +int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n); + +/* Set bit number N in A. */ +void gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n); + +/* Clear bit number N in A. */ +void gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n); + +/* Set bit number N in A and clear all bits greater than N. */ +void gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n); + +/* Clear bit number N in A and all bits greater than N. */ +void gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n); + +/* Shift the value of A by N bits to the right and store the result in X. */ +void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); + +/* Shift the value of A by N bits to the left and store the result in X. */ +void gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); + +/* Store NBITS of the value P points to in A and mark A as an opaque + value. WARNING: Never use an opaque MPI for anything thing else then + gcry_mpi_release, gcry_mpi_get_opaque. */ +gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits); + +/* Return a pointer to an opaque value stored in A and return its size + in NBITS. Note that the returned pointer is still owned by A and + that the function should never be used for an non-opaque MPI. */ +void *gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits); + +/* Set the FLAG for the big integer A. Currently only the flag + GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger + stored in "secure" memory. */ +void gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); + +/* Clear FLAG for the big integer A. Note that this function is + currently useless as no flags are allowed. */ +void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); + +/* Return true when the FLAG is set for A. */ +int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); + +/* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of + convenience macros for the big integer functions. */ +#ifndef GCRYPT_NO_MPI_MACROS +#define mpi_new(n) gcry_mpi_new( (n) ) +#define mpi_secure_new( n ) gcry_mpi_snew( (n) ) +#define mpi_release(a) \ + do \ + { \ + gcry_mpi_release ((a)); \ + (a) = NULL; \ + } \ + while (0) + +#define mpi_copy( a ) gcry_mpi_copy( (a) ) +#define mpi_set( w, u) gcry_mpi_set( (w), (u) ) +#define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) ) +#define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) ) +#define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) ) + +#define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v)) +#define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v)) +#define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m)) +#define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v)) +#define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v)) +#define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m)) +#define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v)) +#define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v)) +#define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v)) +#define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m)) +#define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) ) +#define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0) +#define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1) +#define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m)) +#define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) ) +#define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) ) + +#define mpi_get_nbits(a) gcry_mpi_get_nbits ((a)) +#define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b)) +#define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b)) +#define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b)) +#define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b)) +#define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b)) +#define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c)) +#define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c)) + +#define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) ) +#define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) ) +#endif /* GCRYPT_NO_MPI_MACROS */ + + + +/************************************ + * * + * Symmetric Cipher Functions * + * * + ************************************/ + +/* The data object used to hold a handle to an encryption object. */ +struct gcry_cipher_handle; +typedef struct gcry_cipher_handle *gcry_cipher_hd_t; + +#ifndef GCRYPT_NO_DEPRECATED +typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED; +typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED; +#endif + +/* All symmetric encryption algorithms are identified by their IDs. + More IDs may be registered at runtime. */ +enum gcry_cipher_algos + { + GCRY_CIPHER_NONE = 0, + GCRY_CIPHER_IDEA = 1, + GCRY_CIPHER_3DES = 2, + GCRY_CIPHER_CAST5 = 3, + GCRY_CIPHER_BLOWFISH = 4, + GCRY_CIPHER_SAFER_SK128 = 5, + GCRY_CIPHER_DES_SK = 6, + GCRY_CIPHER_AES = 7, + GCRY_CIPHER_AES192 = 8, + GCRY_CIPHER_AES256 = 9, + GCRY_CIPHER_TWOFISH = 10, + + /* Other cipher numbers are above 300 for OpenPGP reasons. */ + GCRY_CIPHER_ARCFOUR = 301, /* Fully compatible with RSA's RC4 (tm). */ + GCRY_CIPHER_DES = 302, /* Yes, this is single key 56 bit DES. */ + GCRY_CIPHER_TWOFISH128 = 303, + GCRY_CIPHER_SERPENT128 = 304, + GCRY_CIPHER_SERPENT192 = 305, + GCRY_CIPHER_SERPENT256 = 306, + GCRY_CIPHER_RFC2268_40 = 307, /* Ron's Cipher 2 (40 bit). */ + GCRY_CIPHER_RFC2268_128 = 308, /* Ron's Cipher 2 (128 bit). */ + GCRY_CIPHER_SEED = 309, /* 128 bit cipher described in RFC4269. */ + GCRY_CIPHER_CAMELLIA128 = 310, + GCRY_CIPHER_CAMELLIA192 = 311, + GCRY_CIPHER_CAMELLIA256 = 312 + }; + +/* The Rijndael algorithm is basically AES, so provide some macros. */ +#define GCRY_CIPHER_AES128 GCRY_CIPHER_AES +#define GCRY_CIPHER_RIJNDAEL GCRY_CIPHER_AES +#define GCRY_CIPHER_RIJNDAEL128 GCRY_CIPHER_AES128 +#define GCRY_CIPHER_RIJNDAEL192 GCRY_CIPHER_AES192 +#define GCRY_CIPHER_RIJNDAEL256 GCRY_CIPHER_AES256 + +/* The supported encryption modes. Note that not all of them are + supported for each algorithm. */ +enum gcry_cipher_modes + { + GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */ + GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */ + GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */ + GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */ + GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */ + GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */ + GCRY_CIPHER_MODE_CTR = 6, /* Counter. */ + GCRY_CIPHER_MODE_AESWRAP= 7 /* AES-WRAP algorithm. */ + }; + +/* Flags used with the open function. */ +enum gcry_cipher_flags + { + GCRY_CIPHER_SECURE = 1, /* Allocate in secure memory. */ + GCRY_CIPHER_ENABLE_SYNC = 2, /* Enable CFB sync mode. */ + GCRY_CIPHER_CBC_CTS = 4, /* Enable CBC cipher text stealing (CTS). */ + GCRY_CIPHER_CBC_MAC = 8 /* Enable CBC message auth. code (MAC). */ + }; + + +/* Create a handle for algorithm ALGO to be used in MODE. FLAGS may + be given as an bitwise OR of the gcry_cipher_flags values. */ +gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle, + int algo, int mode, unsigned int flags); + +/* Close the cioher handle H and release all resource. */ +void gcry_cipher_close (gcry_cipher_hd_t h); + +/* Perform various operations on the cipher object H. */ +gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, + size_t buflen); + +/* Retrieve various information about the cipher object H. */ +gcry_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer, + size_t *nbytes); + +/* Retrieve various information about the cipher algorithm ALGO. */ +gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer, + size_t *nbytes); + +/* Map the cipher algorithm whose ID is contained in ALGORITHM to a + string representation of the algorithm name. For unknown algorithm + IDs this function returns "?". */ +const char *gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; + +/* Map the algorithm name NAME to an cipher algorithm ID. Return 0 if + the algorithm name is not known. */ +int gcry_cipher_map_name (const char *name) _GCRY_GCC_ATTR_PURE; + +/* Given an ASN.1 object identifier in standard IETF dotted decimal + format in STRING, return the encryption mode associated with that + OID or 0 if not known or applicable. */ +int gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE; + +/* Encrypt the plaintext of size INLEN in IN using the cipher handle H + into the buffer OUT which has an allocated length of OUTSIZE. For + most algorithms it is possible to pass NULL for in and 0 for INLEN + and do a in-place decryption of the data provided in OUT. */ +gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h, + void *out, size_t outsize, + const void *in, size_t inlen); + +/* The counterpart to gcry_cipher_encrypt. */ +gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h, + void *out, size_t outsize, + const void *in, size_t inlen); + +/* Set KEY of length KEYLEN bytes for the cipher handle HD. */ +gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t hd, + const void *key, size_t keylen); + + +/* Set initialization vector IV of length IVLEN for the cipher handle HD. */ +gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t hd, + const void *iv, size_t ivlen); + + +/* Reset the handle to the state after open. */ +#define gcry_cipher_reset(h) gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0) + +/* Perform the OpenPGP sync operation if this is enabled for the + cipher handle H. */ +#define gcry_cipher_sync(h) gcry_cipher_ctl( (h), GCRYCTL_CFB_SYNC, NULL, 0) + +/* Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only. */ +#define gcry_cipher_cts(h,on) gcry_cipher_ctl( (h), GCRYCTL_SET_CBC_CTS, \ + NULL, on ) + +/* Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of + block size length, or (NULL,0) to set the CTR to the all-zero block. */ +gpg_error_t gcry_cipher_setctr (gcry_cipher_hd_t hd, + const void *ctr, size_t ctrlen); + +/* Retrieved the key length in bytes used with algorithm A. */ +size_t gcry_cipher_get_algo_keylen (int algo); + +/* Retrieve the block length in bytes used with algorithm A. */ +size_t gcry_cipher_get_algo_blklen (int algo); + +/* Return 0 if the algorithm A is available for use. */ +#define gcry_cipher_test_algo(a) \ + gcry_cipher_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) + +/* Get a list consisting of the IDs of the loaded cipher modules. If + LIST is zero, write the number of loaded cipher modules to + LIST_LENGTH and return. If LIST is non-zero, the first + *LIST_LENGTH algorithm IDs are stored in LIST, which must be of + according size. In case there are less cipher modules than + *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ +gcry_error_t gcry_cipher_list (int *list, int *list_length); + + +/************************************ + * * + * Asymmetric Cipher Functions * + * * + ************************************/ + +/* The algorithms and their IDs we support. */ +enum gcry_pk_algos + { + GCRY_PK_RSA = 1, + GCRY_PK_RSA_E = 2, /* (deprecated) */ + GCRY_PK_RSA_S = 3, /* (deprecated) */ + GCRY_PK_ELG_E = 16, + GCRY_PK_DSA = 17, + GCRY_PK_ELG = 20, + GCRY_PK_ECDSA = 301 + }; + +/* Flags describing usage capabilities of a PK algorithm. */ +#define GCRY_PK_USAGE_SIGN 1 /* Good for signatures. */ +#define GCRY_PK_USAGE_ENCR 2 /* Good for encryption. */ +#define GCRY_PK_USAGE_CERT 4 /* Good to certify other keys. */ +#define GCRY_PK_USAGE_AUTH 8 /* Good for authentication. */ +#define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */ + +/* Encrypt the DATA using the public key PKEY and store the result as + a newly created S-expression at RESULT. */ +gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result, + gcry_sexp_t data, gcry_sexp_t pkey); + +/* Decrypt the DATA using the private key SKEY and store the result as + a newly created S-expression at RESULT. */ +gcry_error_t gcry_pk_decrypt (gcry_sexp_t *result, + gcry_sexp_t data, gcry_sexp_t skey); + +/* Sign the DATA using the private key SKEY and store the result as + a newly created S-expression at RESULT. */ +gcry_error_t gcry_pk_sign (gcry_sexp_t *result, + gcry_sexp_t data, gcry_sexp_t skey); + +/* Check the signature SIGVAL on DATA using the public key PKEY. */ +gcry_error_t gcry_pk_verify (gcry_sexp_t sigval, + gcry_sexp_t data, gcry_sexp_t pkey); + +/* Check that private KEY is sane. */ +gcry_error_t gcry_pk_testkey (gcry_sexp_t key); + +/* Generate a new key pair according to the parameters given in + S_PARMS. The new key pair is returned in as an S-expression in + R_KEY. */ +gcry_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms); + +/* Catch all function for miscellaneous operations. */ +gcry_error_t gcry_pk_ctl (int cmd, void *buffer, size_t buflen); + +/* Retrieve information about the public key algorithm ALGO. */ +gcry_error_t gcry_pk_algo_info (int algo, int what, + void *buffer, size_t *nbytes); + +/* Map the public key algorithm whose ID is contained in ALGORITHM to + a string representation of the algorithm name. For unknown + algorithm IDs this functions returns "?". */ +const char *gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE; + +/* Map the algorithm NAME to a public key algorithm Id. Return 0 if + the algorithm name is not known. */ +int gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE; + +/* Return what is commonly referred as the key length for the given + public or private KEY. */ +unsigned int gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE; + +/* Please note that keygrip is still experimental and should not be + used without contacting the author. */ +unsigned char *gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array); + +/* Return 0 if the public key algorithm A is available for use. */ +#define gcry_pk_test_algo(a) \ + gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) + +/* Get a list consisting of the IDs of the loaded pubkey modules. If + LIST is zero, write the number of loaded pubkey modules to + LIST_LENGTH and return. If LIST is non-zero, the first + *LIST_LENGTH algorithm IDs are stored in LIST, which must be of + according size. In case there are less pubkey modules than + *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ +gcry_error_t gcry_pk_list (int *list, int *list_length); + + + +/************************************ + * * + * Cryptograhic Hash Functions * + * * + ************************************/ + +/* Algorithm IDs for the hash functions we know about. Not all of them + are implemnted. */ +enum gcry_md_algos + { + GCRY_MD_NONE = 0, + GCRY_MD_MD5 = 1, + GCRY_MD_SHA1 = 2, + GCRY_MD_RMD160 = 3, + GCRY_MD_MD2 = 5, + GCRY_MD_TIGER = 6, /* TIGER/192 as used by GnuPG <= 1.3.2. */ + GCRY_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */ + GCRY_MD_SHA256 = 8, + GCRY_MD_SHA384 = 9, + GCRY_MD_SHA512 = 10, + GCRY_MD_SHA224 = 11, + GCRY_MD_MD4 = 301, + GCRY_MD_CRC32 = 302, + GCRY_MD_CRC32_RFC1510 = 303, + GCRY_MD_CRC24_RFC2440 = 304, + GCRY_MD_WHIRLPOOL = 305, + GCRY_MD_TIGER1 = 306, /* TIGER (fixed). */ + GCRY_MD_TIGER2 = 307 /* TIGER2 variant. */ + }; + +/* Flags used with the open function. */ +enum gcry_md_flags + { + GCRY_MD_FLAG_SECURE = 1, /* Allocate all buffers in "secure" memory. */ + GCRY_MD_FLAG_HMAC = 2 /* Make an HMAC out of this algorithm. */ + }; + +/* (Forward declaration.) */ +struct gcry_md_context; + +/* This object is used to hold a handle to a message digest object. + This structure is private - only to be used by the public gcry_md_* + macros. */ +typedef struct gcry_md_handle +{ + /* Actual context. */ + struct gcry_md_context *ctx; + + /* Buffer management. */ + int bufpos; + int bufsize; + unsigned char buf[1]; +} *gcry_md_hd_t; + +/* Compatibility types, do not use them. */ +#ifndef GCRYPT_NO_DEPRECATED +typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED; +typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED; +#endif + +/* Create a message digest object for algorithm ALGO. FLAGS may be + given as an bitwise OR of the gcry_md_flags values. ALGO may be + given as 0 if the algorithms to be used are later set using + gcry_md_enable. */ +gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags); + +/* Release the message digest object HD. */ +void gcry_md_close (gcry_md_hd_t hd); + +/* Add the message digest algorithm ALGO to the digest object HD. */ +gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo); + +/* Create a new digest object as an exact copy of the object HD. */ +gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd); + +/* Reset the digest object HD to its initial state. */ +void gcry_md_reset (gcry_md_hd_t hd); + +/* Perform various operations on the digest object HD. */ +gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, + void *buffer, size_t buflen); + +/* Pass LENGTH bytes of data in BUFFER to the digest object HD so that + it can update the digest values. This is the actual hash + function. */ +void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length); + +/* Read out the final digest from HD return the digest value for + algorithm ALGO. */ +unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo); + +/* Convenience function to calculate the hash from the data in BUFFER + of size LENGTH using the algorithm ALGO avoiding the creating of a + hash object. The hash is returned in the caller provided buffer + DIGEST which must be large enough to hold the digest of the given + algorithm. */ +void gcry_md_hash_buffer (int algo, void *digest, + const void *buffer, size_t length); + +/* Retrieve the algorithm used with HD. This does not work reliable + if more than one algorithm is enabled in HD. */ +int gcry_md_get_algo (gcry_md_hd_t hd); + +/* Retrieve the length in bytes of the digest yielded by algorithm + ALGO. */ +unsigned int gcry_md_get_algo_dlen (int algo); + +/* Return true if the the algorithm ALGO is enabled in the digest + object A. */ +int gcry_md_is_enabled (gcry_md_hd_t a, int algo); + +/* Return true if the digest object A is allocated in "secure" memory. */ +int gcry_md_is_secure (gcry_md_hd_t a); + +/* Retrieve various information about the object H. */ +gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer, + size_t *nbytes); + +/* Retrieve various information about the algorithm ALGO. */ +gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer, + size_t *nbytes); + +/* Map the digest algorithm id ALGO to a string representation of the + algorithm name. For unknown algorithms this function returns + "?". */ +const char *gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE; + +/* Map the algorithm NAME to a digest algorithm Id. Return 0 if + the algorithm name is not known. */ +int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE; + +/* For use with the HMAC feature, the set MAC key to the KEY of + KEYLEN bytes. */ +gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen); + +/* Start or stop debugging for digest handle HD; i.e. create a file + named dbgmd-<n>.<suffix> while hashing. If SUFFIX is NULL, + debugging stops and the file will be closed. */ +void gcry_md_debug (gcry_md_hd_t hd, const char *suffix); + + +/* Update the hash(s) of H with the character C. This is a buffered + version of the gcry_md_write function. */ +#define gcry_md_putc(h,c) \ + do { \ + gcry_md_hd_t h__ = (h); \ + if( (h__)->bufpos == (h__)->bufsize ) \ + gcry_md_write( (h__), NULL, 0 ); \ + (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \ + } while(0) + +/* Finalize the digest calculation. This is not really needed because + gcry_md_read() does this implicitly. */ +#define gcry_md_final(a) \ + gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0) + +/* Return 0 if the algorithm A is available for use. */ +#define gcry_md_test_algo(a) \ + gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL ) + +/* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N + must point to size_t variable with the available size of buffer B. + After return it will receive the actual size of the returned + OID. */ +#define gcry_md_get_asnoid(a,b,n) \ + gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n)) + +/* Enable debugging for digest object A; i.e. create files named + dbgmd-<n>.<string> while hashing. B is a string used as the suffix + for the filename. This macro is deprecated, use gcry_md_debug. */ +#ifndef GCRYPT_NO_DEPRECATED +#define gcry_md_start_debug(a,b) \ + gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 ) + +/* Disable the debugging of A. This macro is deprecated, use + gcry_md_debug. */ +#define gcry_md_stop_debug(a,b) \ + gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 ) +#endif + +/* Get a list consisting of the IDs of the loaded message digest + modules. If LIST is zero, write the number of loaded message + digest modules to LIST_LENGTH and return. If LIST is non-zero, the + first *LIST_LENGTH algorithm IDs are stored in LIST, which must be + of according size. In case there are less message digest modules + than *LIST_LENGTH, *LIST_LENGTH is updated to the correct + number. */ +gcry_error_t gcry_md_list (int *list, int *list_length); + + + +/* Alternative interface for asymmetric cryptography. This interface + is deprecated. */ + +/* The algorithm IDs. */ +typedef enum gcry_ac_id + { + GCRY_AC_RSA = 1, + GCRY_AC_DSA = 17, + GCRY_AC_ELG = 20, + GCRY_AC_ELG_E = 16 + } +gcry_ac_id_t; + +/* Key types. */ +typedef enum gcry_ac_key_type + { + GCRY_AC_KEY_SECRET, + GCRY_AC_KEY_PUBLIC + } +gcry_ac_key_type_t; + +/* Encoding methods. */ +typedef enum gcry_ac_em + { + GCRY_AC_EME_PKCS_V1_5, + GCRY_AC_EMSA_PKCS_V1_5 + } +gcry_ac_em_t; + +/* Encryption and Signature schemes. */ +typedef enum gcry_ac_scheme + { + GCRY_AC_ES_PKCS_V1_5, + GCRY_AC_SSA_PKCS_V1_5 + } +gcry_ac_scheme_t; + +/* AC data. */ +#define GCRY_AC_FLAG_DEALLOC (1 << 0) +#define GCRY_AC_FLAG_COPY (1 << 1) +#define GCRY_AC_FLAG_NO_BLINDING (1 << 2) + +/* This type represents a `data set'. */ +typedef struct gcry_ac_data *gcry_ac_data_t; + +/* This type represents a single `key', either a secret one or a + public one. */ +typedef struct gcry_ac_key *gcry_ac_key_t; + +/* This type represents a `key pair' containing a secret and a public + key. */ +typedef struct gcry_ac_key_pair *gcry_ac_key_pair_t; + +/* This type represents a `handle' that is needed by functions + performing cryptographic operations. */ +typedef struct gcry_ac_handle *gcry_ac_handle_t; + +typedef gpg_error_t (*gcry_ac_data_read_cb_t) (void *opaque, + unsigned char *buffer, + size_t *buffer_n); + +typedef gpg_error_t (*gcry_ac_data_write_cb_t) (void *opaque, + unsigned char *buffer, + size_t buffer_n); + +typedef enum + { + GCRY_AC_IO_READABLE, + GCRY_AC_IO_WRITABLE + } +gcry_ac_io_mode_t; + +typedef enum + { + GCRY_AC_IO_STRING, + GCRY_AC_IO_CALLBACK + } +gcry_ac_io_type_t; + +typedef struct gcry_ac_io +{ + /* This is an INTERNAL structure, do NOT use manually. */ + gcry_ac_io_mode_t mode _GCRY_ATTR_INTERNAL; + gcry_ac_io_type_t type _GCRY_ATTR_INTERNAL; + union + { + union + { + struct + { + gcry_ac_data_read_cb_t cb; + void *opaque; + } callback; + struct + { + unsigned char *data; + size_t data_n; + } string; + void *opaque; + } readable; + union + { + struct + { + gcry_ac_data_write_cb_t cb; + void *opaque; + } callback; + struct + { + unsigned char **data; + size_t *data_n; + } string; + void *opaque; + } writable; + } io _GCRY_ATTR_INTERNAL; +} +gcry_ac_io_t; + +/* The caller of gcry_ac_key_pair_generate can provide one of these + structures in order to influence the key generation process in an + algorithm-specific way. */ +typedef struct gcry_ac_key_spec_rsa +{ + gcry_mpi_t e; /* E to use. */ +} gcry_ac_key_spec_rsa_t; + +/* Structure used for passing data to the implementation of the + `EME-PKCS-V1_5' encoding method. */ +typedef struct gcry_ac_eme_pkcs_v1_5 +{ + size_t key_size; +} gcry_ac_eme_pkcs_v1_5_t; + +typedef enum gcry_md_algos gcry_md_algo_t; + +/* Structure used for passing data to the implementation of the + `EMSA-PKCS-V1_5' encoding method. */ +typedef struct gcry_ac_emsa_pkcs_v1_5 +{ + gcry_md_algo_t md; + size_t em_n; +} gcry_ac_emsa_pkcs_v1_5_t; + +/* Structure used for passing data to the implementation of the + `SSA-PKCS-V1_5' signature scheme. */ +typedef struct gcry_ac_ssa_pkcs_v1_5 +{ + gcry_md_algo_t md; +} gcry_ac_ssa_pkcs_v1_5_t; + +/* Returns a new, empty data set in DATA. */ +gcry_error_t gcry_ac_data_new (gcry_ac_data_t *data); + +/* Destroy the data set DATA. */ +void gcry_ac_data_destroy (gcry_ac_data_t data); + +/* Create a copy of the data set DATA and store it in DATA_CP. */ +gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *data_cp, + gcry_ac_data_t data); + +/* Return the number of named MPI values inside of the data set + DATA. */ +unsigned int gcry_ac_data_length (gcry_ac_data_t data); + +/* Destroy any values contained in the data set DATA. */ +void gcry_ac_data_clear (gcry_ac_data_t data); + +/* Add the value MPI to DATA with the label NAME. If FLAGS contains + GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of NAME + and MPI. If FLAGS contains GCRY_AC_FLAG_DATA_DEALLOC or + GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will + be deallocated when they are to be removed from the data set. */ +gcry_error_t gcry_ac_data_set (gcry_ac_data_t data, unsigned int flags, + const char *name, gcry_mpi_t mpi); + +/* Store the value labelled with NAME found in DATA in MPI. If FLAGS + contains GCRY_AC_FLAG_COPY, store a copy of the MPI value contained + in the data set. MPI may be NULL. */ +gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t data, unsigned int flags, + const char *name, gcry_mpi_t *mpi); + +/* Stores in NAME and MPI the named MPI value contained in the data + set DATA with the index IDX. If FLAGS contains GCRY_AC_FLAG_COPY, + store copies of the values contained in the data set. NAME or MPI + may be NULL. */ +gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t data, unsigned int flags, + unsigned int idx, + const char **name, gcry_mpi_t *mpi); + +/* Convert the data set DATA into a new S-Expression, which is to be + stored in SEXP, according to the identifiers contained in + IDENTIFIERS. */ +gcry_error_t gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, + const char **identifiers); + +/* Create a new data set, which is to be stored in DATA_SET, from the + S-Expression SEXP, according to the identifiers contained in + IDENTIFIERS. */ +gcry_error_t gcry_ac_data_from_sexp (gcry_ac_data_t *data, gcry_sexp_t sexp, + const char **identifiers); + +/* Initialize AC_IO according to MODE, TYPE and the variable list of + arguments. The list of variable arguments to specify depends on + the given TYPE. */ +void gcry_ac_io_init (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode, + gcry_ac_io_type_t type, ...); + +/* Initialize AC_IO according to MODE, TYPE and the variable list of + arguments AP. The list of variable arguments to specify depends on + the given TYPE. */ +void gcry_ac_io_init_va (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode, + gcry_ac_io_type_t type, va_list ap); + +/* Create a new ac handle. */ +gcry_error_t gcry_ac_open (gcry_ac_handle_t *handle, + gcry_ac_id_t algorithm, unsigned int flags); + +/* Destroy an ac handle. */ +void gcry_ac_close (gcry_ac_handle_t handle); + +/* Initialize a key from a given data set. */ +gcry_error_t gcry_ac_key_init (gcry_ac_key_t *key, gcry_ac_handle_t handle, + gcry_ac_key_type_t type, gcry_ac_data_t data); + +/* Generates a new key pair via the handle HANDLE of NBITS bits and + stores it in KEY_PAIR. In case non-standard settings are wanted, a + pointer to a structure of type gcry_ac_key_spec_<algorithm>_t, + matching the selected algorithm, can be given as KEY_SPEC. + MISC_DATA is not used yet. */ +gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t handle, + unsigned int nbits, void *spec, + gcry_ac_key_pair_t *key_pair, + gcry_mpi_t **misc_data); + +/* Returns the key of type WHICH out of the key pair KEY_PAIR. */ +gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair, + gcry_ac_key_type_t which); + +/* Returns the data set contained in the key KEY. */ +gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t key); + +/* Verifies that the key KEY is sane via HANDLE. */ +gcry_error_t gcry_ac_key_test (gcry_ac_handle_t handle, gcry_ac_key_t key); + +/* Stores the number of bits of the key KEY in NBITS via HANDLE. */ +gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t handle, + gcry_ac_key_t key, unsigned int *nbits); + +/* Writes the 20 byte long key grip of the key KEY to KEY_GRIP via + HANDLE. */ +gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t handle, gcry_ac_key_t key, + unsigned char *key_grip); + +/* Destroy a key. */ +void gcry_ac_key_destroy (gcry_ac_key_t key); + +/* Destroy a key pair. */ +void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair); + +/* Encodes a message according to the encoding method METHOD. OPTIONS + must be a pointer to a method-specific structure + (gcry_ac_em*_t). */ +gcry_error_t gcry_ac_data_encode (gcry_ac_em_t method, + unsigned int flags, void *options, + gcry_ac_io_t *io_read, + gcry_ac_io_t *io_write); + +/* Decodes a message according to the encoding method METHOD. OPTIONS + must be a pointer to a method-specific structure + (gcry_ac_em*_t). */ +gcry_error_t gcry_ac_data_decode (gcry_ac_em_t method, + unsigned int flags, void *options, + gcry_ac_io_t *io_read, + gcry_ac_io_t *io_write); + +/* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under + the control of the flags FLAGS and store the resulting data set + into DATA_ENCRYPTED. */ +gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t handle, + unsigned int flags, + gcry_ac_key_t key, + gcry_mpi_t data_plain, + gcry_ac_data_t *data_encrypted); + +/* Decrypt the decrypted data contained in the data set DATA_ENCRYPTED + with the key KEY under the control of the flags FLAGS and store the + resulting plain text MPI value in DATA_PLAIN. */ +gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t handle, + unsigned int flags, + gcry_ac_key_t key, + gcry_mpi_t *data_plain, + gcry_ac_data_t data_encrypted); + +/* Sign the data contained in DATA with the key KEY and store the + resulting signature in the data set DATA_SIGNATURE. */ +gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t handle, + gcry_ac_key_t key, + gcry_mpi_t data, + gcry_ac_data_t *data_signature); + +/* Verify that the signature contained in the data set DATA_SIGNATURE + is indeed the result of signing the data contained in DATA with the + secret key belonging to the public key KEY. */ +gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t handle, + gcry_ac_key_t key, + gcry_mpi_t data, + gcry_ac_data_t data_signature); + +/* Encrypts the plain text readable from IO_MESSAGE through HANDLE + with the public key KEY according to SCHEME, FLAGS and OPTS. If + OPTS is not NULL, it has to be a pointer to a structure specific to + the chosen scheme (gcry_ac_es_*_t). The encrypted message is + written to IO_CIPHER. */ +gcry_error_t gcry_ac_data_encrypt_scheme (gcry_ac_handle_t handle, + gcry_ac_scheme_t scheme, + unsigned int flags, void *opts, + gcry_ac_key_t key, + gcry_ac_io_t *io_message, + gcry_ac_io_t *io_cipher); + +/* Decrypts the cipher text readable from IO_CIPHER through HANDLE + with the secret key KEY according to SCHEME, @var{flags} and OPTS. + If OPTS is not NULL, it has to be a pointer to a structure specific + to the chosen scheme (gcry_ac_es_*_t). The decrypted message is + written to IO_MESSAGE. */ +gcry_error_t gcry_ac_data_decrypt_scheme (gcry_ac_handle_t handle, + gcry_ac_scheme_t scheme, + unsigned int flags, void *opts, + gcry_ac_key_t key, + gcry_ac_io_t *io_cipher, + gcry_ac_io_t *io_message); + +/* Signs the message readable from IO_MESSAGE through HANDLE with the + secret key KEY according to SCHEME, FLAGS and OPTS. If OPTS is not + NULL, it has to be a pointer to a structure specific to the chosen + scheme (gcry_ac_ssa_*_t). The signature is written to + IO_SIGNATURE. */ +gcry_error_t gcry_ac_data_sign_scheme (gcry_ac_handle_t handle, + gcry_ac_scheme_t scheme, + unsigned int flags, void *opts, + gcry_ac_key_t key, + gcry_ac_io_t *io_message, + gcry_ac_io_t *io_signature); + +/* Verifies through HANDLE that the signature readable from + IO_SIGNATURE is indeed the result of signing the message readable + from IO_MESSAGE with the secret key belonging to the public key KEY + according to SCHEME and OPTS. If OPTS is not NULL, it has to be an + anonymous structure (gcry_ac_ssa_*_t) specific to the chosen + scheme. */ +gcry_error_t gcry_ac_data_verify_scheme (gcry_ac_handle_t handle, + gcry_ac_scheme_t scheme, + unsigned int flags, void *opts, + gcry_ac_key_t key, + gcry_ac_io_t *io_message, + gcry_ac_io_t *io_signature); + +/* Store the textual representation of the algorithm whose id is given + in ALGORITHM in NAME. This function is deprecated; use + gcry_pk_algo_name. */ +#ifndef GCRYPT_NO_DEPRECATED +gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t algorithm, + const char **name) + /* */ _GCRY_GCC_ATTR_DEPRECATED; +/* Store the numeric ID of the algorithm whose textual representation + is contained in NAME in ALGORITHM. This function is deprecated; + use gcry_pk_map_name. */ +gcry_error_t gcry_ac_name_to_id (const char *name, + gcry_ac_id_t *algorithm) + /* */ _GCRY_GCC_ATTR_DEPRECATED; +#endif + + +/************************************ + * * + * Random Generating Functions * + * * + ************************************/ + +/* The possible values for the random quality. The rule of thumb is + to use STRONG for session keys and VERY_STRONG for key material. + WEAK is usually an alias for STRONG and should not be used anymore + (except with gcry_mpi_randomize); use gcry_create_nonce instead. */ +typedef enum gcry_random_level + { + GCRY_WEAK_RANDOM = 0, + GCRY_STRONG_RANDOM = 1, + GCRY_VERY_STRONG_RANDOM = 2 + } +gcry_random_level_t; + +/* Fill BUFFER with LENGTH bytes of random, using random numbers of + quality LEVEL. */ +void gcry_randomize (void *buffer, size_t length, + enum gcry_random_level level); + +/* Add the external random from BUFFER with LENGTH bytes into the + pool. QUALITY should either be -1 for unknown or in the range of 0 + to 100 */ +gcry_error_t gcry_random_add_bytes (const void *buffer, size_t length, + int quality); + +/* If random numbers are used in an application, this macro should be + called from time to time so that new stuff gets added to the + internal pool of the RNG. */ +#define gcry_fast_random_poll() gcry_control (GCRYCTL_FAST_POLL, NULL) + + +/* Return NBYTES of allocated random using a random numbers of quality + LEVEL. */ +void *gcry_random_bytes (size_t nbytes, enum gcry_random_level level) + _GCRY_GCC_ATTR_MALLOC; + +/* Return NBYTES of allocated random using a random numbers of quality + LEVEL. The random numbers are created returned in "secure" + memory. */ +void *gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level) + _GCRY_GCC_ATTR_MALLOC; + + +/* Set the big integer W to a random value of NBITS using a random + generator with quality LEVEL. Note that by using a level of + GCRY_WEAK_RANDOM gcry_create_nonce is used internally. */ +void gcry_mpi_randomize (gcry_mpi_t w, + unsigned int nbits, enum gcry_random_level level); + + +/* Create an unpredicable nonce of LENGTH bytes in BUFFER. */ +void gcry_create_nonce (void *buffer, size_t length); + + + + + +/*******************************/ +/* */ +/* Prime Number Functions */ +/* */ +/*******************************/ + +/* Mode values passed to a gcry_prime_check_func_t. */ +#define GCRY_PRIME_CHECK_AT_FINISH 0 +#define GCRY_PRIME_CHECK_AT_GOT_PRIME 1 +#define GCRY_PRIME_CHECK_AT_MAYBE_PRIME 2 + +/* The function should return 1 if the operation shall continue, 0 to + reject the prime candidate. */ +typedef int (*gcry_prime_check_func_t) (void *arg, int mode, + gcry_mpi_t candidate); + +/* Flags for gcry_prime_generate(): */ + +/* Allocate prime numbers and factors in secure memory. */ +#define GCRY_PRIME_FLAG_SECRET (1 << 0) + +/* Make sure that at least one prime factor is of size + `FACTOR_BITS'. */ +#define GCRY_PRIME_FLAG_SPECIAL_FACTOR (1 << 1) + +/* Generate a new prime number of PRIME_BITS bits and store it in + PRIME. If FACTOR_BITS is non-zero, one of the prime factors of + (prime - 1) / 2 must be FACTOR_BITS bits long. If FACTORS is + non-zero, allocate a new, NULL-terminated array holding the prime + factors and store it in FACTORS. FLAGS might be used to influence + the prime number generation process. */ +gcry_error_t gcry_prime_generate (gcry_mpi_t *prime, + unsigned int prime_bits, + unsigned int factor_bits, + gcry_mpi_t **factors, + gcry_prime_check_func_t cb_func, + void *cb_arg, + gcry_random_level_t random_level, + unsigned int flags); + +/* Find a generator for PRIME where the factorization of (prime-1) is + in the NULL terminated array FACTORS. Return the generator as a + newly allocated MPI in R_G. If START_G is not NULL, use this as + teh start for the search. */ +gcry_error_t gcry_prime_group_generator (gcry_mpi_t *r_g, + gcry_mpi_t prime, + gcry_mpi_t *factors, + gcry_mpi_t start_g); + + +/* Convenience function to release the FACTORS array. */ +void gcry_prime_release_factors (gcry_mpi_t *factors); + + +/* Check wether the number X is prime. */ +gcry_error_t gcry_prime_check (gcry_mpi_t x, unsigned int flags); + + + +/************************************ + * * + * Miscellaneous Stuff * + * * + ************************************/ + +/* Log levels used by the internal logging facility. */ +enum gcry_log_levels + { + GCRY_LOG_CONT = 0, /* (Continue the last log line.) */ + GCRY_LOG_INFO = 10, + GCRY_LOG_WARN = 20, + GCRY_LOG_ERROR = 30, + GCRY_LOG_FATAL = 40, + GCRY_LOG_BUG = 50, + GCRY_LOG_DEBUG = 100 + }; + +/* Type for progress handlers. */ +typedef void (*gcry_handler_progress_t) (void *, const char *, int, int, int); + +/* Type for memory allocation handlers. */ +typedef void *(*gcry_handler_alloc_t) (size_t n); + +/* Type for secure memory check handlers. */ +typedef int (*gcry_handler_secure_check_t) (const void *); + +/* Type for memory reallocation handlers. */ +typedef void *(*gcry_handler_realloc_t) (void *p, size_t n); + +/* Type for memory free handlers. */ +typedef void (*gcry_handler_free_t) (void *); + +/* Type for out-of-memory handlers. */ +typedef int (*gcry_handler_no_mem_t) (void *, size_t, unsigned int); + +/* Type for fatal error handlers. */ +typedef void (*gcry_handler_error_t) (void *, int, const char *); + +/* Type for logging handlers. */ +typedef void (*gcry_handler_log_t) (void *, int, const char *, va_list); + +/* Certain operations can provide progress information. This function + is used to register a handler for retrieving these information. */ +void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data); + + +/* Register a custom memory allocation functions. */ +void gcry_set_allocation_handler ( + gcry_handler_alloc_t func_alloc, + gcry_handler_alloc_t func_alloc_secure, + gcry_handler_secure_check_t func_secure_check, + gcry_handler_realloc_t func_realloc, + gcry_handler_free_t func_free); + +/* Register a function used instead of the internal out of memory + handler. */ +void gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque); + +/* Register a function used instead of the internal fatal error + handler. */ +void gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque); + +/* Register a function used instead of the internal logging + facility. */ +void gcry_set_log_handler (gcry_handler_log_t f, void *opaque); + +/* Reserved for future use. */ +void gcry_set_gettext_handler (const char *(*f)(const char*)); + +/* Libgcrypt uses its own memory allocation. It is important to use + gcry_free () to release memory allocated by libgcrypt. */ +void *gcry_malloc (size_t n) _GCRY_GCC_ATTR_MALLOC; +void *gcry_calloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; +void *gcry_malloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC; +void *gcry_calloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; +void *gcry_realloc (void *a, size_t n); +char *gcry_strdup (const char *string) _GCRY_GCC_ATTR_MALLOC; +void *gcry_xmalloc (size_t n) _GCRY_GCC_ATTR_MALLOC; +void *gcry_xcalloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; +void *gcry_xmalloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC; +void *gcry_xcalloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC; +void *gcry_xrealloc (void *a, size_t n); +char *gcry_xstrdup (const char * a) _GCRY_GCC_ATTR_MALLOC; +void gcry_free (void *a); + +/* Return true if A is allocated in "secure" memory. */ +int gcry_is_secure (const void *a) _GCRY_GCC_ATTR_PURE; + +/* Return true if Libgcrypt is in FIPS mode. */ +#define gcry_fips_mode_active() !!gcry_control (GCRYCTL_FIPS_MODE_P, 0) + + +/* Include support for Libgcrypt modules. */ +#include <gcrypt-module.h> + +#if 0 /* (Keep Emacsens' auto-indent happy.) */ +{ +#endif +#ifdef __cplusplus +} +#endif +#endif /* _GCRYPT_H */ diff --git a/gpg-error.h b/gpg-error.h new file mode 100644 index 0000000..d2f9746 --- /dev/null +++ b/gpg-error.h @@ -0,0 +1,703 @@ +/* Output of mkheader.awk. DO NOT EDIT. -*- buffer-read-only: t -*- */ + +/* gpg-error.h - Public interface to libgpg-error. + Copyright (C) 2003, 2004, 2010 g10 Code GmbH + + This file is part of libgpg-error. + + libgpg-error is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + libgpg-error is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef GPG_ERROR_H +#define GPG_ERROR_H 1 + +#include <stddef.h> + +#ifdef __GNUC__ +#define GPG_ERR_INLINE __inline__ +#elif __STDC_VERSION__ >= 199901L +#define GPG_ERR_INLINE inline +#else +#ifndef GPG_ERR_INLINE +#define GPG_ERR_INLINE +#endif +#endif + + +#ifdef __cplusplus +extern "C" { +#if 0 /* just to make Emacs auto-indent happy */ +} +#endif +#endif /* __cplusplus */ + +/* The GnuPG project consists of many components. Error codes are + exchanged between all components. The common error codes and their + user-presentable descriptions are kept into a shared library to + allow adding new error codes and components without recompiling any + of the other components. The interface will not change in a + backward incompatible way. + + An error code together with an error source build up an error + value. As the error value is been passed from one component to + another, it preserver the information about the source and nature + of the error. + + A component of the GnuPG project can define the following macros to + tune the behaviour of the library: + + GPG_ERR_SOURCE_DEFAULT: Define to an error source of type + gpg_err_source_t to make that source the default for gpg_error(). + Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. + + GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the + internal gettext API to standard names. This has only an effect on + Windows platforms. */ + + +/* The error source type gpg_err_source_t. + + Where as the Poo out of a welle small + Taketh his firste springing and his sours. + --Chaucer. */ + +/* Only use free slots, never change or reorder the existing + entries. */ +typedef enum + { + GPG_ERR_SOURCE_UNKNOWN = 0, + GPG_ERR_SOURCE_GCRYPT = 1, + GPG_ERR_SOURCE_GPG = 2, + GPG_ERR_SOURCE_GPGSM = 3, + GPG_ERR_SOURCE_GPGAGENT = 4, + GPG_ERR_SOURCE_PINENTRY = 5, + GPG_ERR_SOURCE_SCD = 6, + GPG_ERR_SOURCE_GPGME = 7, + GPG_ERR_SOURCE_KEYBOX = 8, + GPG_ERR_SOURCE_KSBA = 9, + GPG_ERR_SOURCE_DIRMNGR = 10, + GPG_ERR_SOURCE_GSTI = 11, + GPG_ERR_SOURCE_GPA = 12, + GPG_ERR_SOURCE_KLEO = 13, + GPG_ERR_SOURCE_G13 = 14, + GPG_ERR_SOURCE_ANY = 31, + GPG_ERR_SOURCE_USER_1 = 32, + GPG_ERR_SOURCE_USER_2 = 33, + GPG_ERR_SOURCE_USER_3 = 34, + GPG_ERR_SOURCE_USER_4 = 35, + + /* This is one more than the largest allowed entry. */ + GPG_ERR_SOURCE_DIM = 128 + } gpg_err_source_t; + + +/* The error code type gpg_err_code_t. */ + +/* Only use free slots, never change or reorder the existing + entries. */ +typedef enum + { + GPG_ERR_NO_ERROR = 0, + GPG_ERR_GENERAL = 1, + GPG_ERR_UNKNOWN_PACKET = 2, + GPG_ERR_UNKNOWN_VERSION = 3, + GPG_ERR_PUBKEY_ALGO = 4, + GPG_ERR_DIGEST_ALGO = 5, + GPG_ERR_BAD_PUBKEY = 6, + GPG_ERR_BAD_SECKEY = 7, + GPG_ERR_BAD_SIGNATURE = 8, + GPG_ERR_NO_PUBKEY = 9, + GPG_ERR_CHECKSUM = 10, + GPG_ERR_BAD_PASSPHRASE = 11, + GPG_ERR_CIPHER_ALGO = 12, + GPG_ERR_KEYRING_OPEN = 13, + GPG_ERR_INV_PACKET = 14, + GPG_ERR_INV_ARMOR = 15, + GPG_ERR_NO_USER_ID = 16, + GPG_ERR_NO_SECKEY = 17, + GPG_ERR_WRONG_SECKEY = 18, + GPG_ERR_BAD_KEY = 19, + GPG_ERR_COMPR_ALGO = 20, + GPG_ERR_NO_PRIME = 21, + GPG_ERR_NO_ENCODING_METHOD = 22, + GPG_ERR_NO_ENCRYPTION_SCHEME = 23, + GPG_ERR_NO_SIGNATURE_SCHEME = 24, + GPG_ERR_INV_ATTR = 25, + GPG_ERR_NO_VALUE = 26, + GPG_ERR_NOT_FOUND = 27, + GPG_ERR_VALUE_NOT_FOUND = 28, + GPG_ERR_SYNTAX = 29, + GPG_ERR_BAD_MPI = 30, + GPG_ERR_INV_PASSPHRASE = 31, + GPG_ERR_SIG_CLASS = 32, + GPG_ERR_RESOURCE_LIMIT = 33, + GPG_ERR_INV_KEYRING = 34, + GPG_ERR_TRUSTDB = 35, + GPG_ERR_BAD_CERT = 36, + GPG_ERR_INV_USER_ID = 37, + GPG_ERR_UNEXPECTED = 38, + GPG_ERR_TIME_CONFLICT = 39, + GPG_ERR_KEYSERVER = 40, + GPG_ERR_WRONG_PUBKEY_ALGO = 41, + GPG_ERR_TRIBUTE_TO_D_A = 42, + GPG_ERR_WEAK_KEY = 43, + GPG_ERR_INV_KEYLEN = 44, + GPG_ERR_INV_ARG = 45, + GPG_ERR_BAD_URI = 46, + GPG_ERR_INV_URI = 47, + GPG_ERR_NETWORK = 48, + GPG_ERR_UNKNOWN_HOST = 49, + GPG_ERR_SELFTEST_FAILED = 50, + GPG_ERR_NOT_ENCRYPTED = 51, + GPG_ERR_NOT_PROCESSED = 52, + GPG_ERR_UNUSABLE_PUBKEY = 53, + GPG_ERR_UNUSABLE_SECKEY = 54, + GPG_ERR_INV_VALUE = 55, + GPG_ERR_BAD_CERT_CHAIN = 56, + GPG_ERR_MISSING_CERT = 57, + GPG_ERR_NO_DATA = 58, + GPG_ERR_BUG = 59, + GPG_ERR_NOT_SUPPORTED = 60, + GPG_ERR_INV_OP = 61, + GPG_ERR_TIMEOUT = 62, + GPG_ERR_INTERNAL = 63, + GPG_ERR_EOF_GCRYPT = 64, + GPG_ERR_INV_OBJ = 65, + GPG_ERR_TOO_SHORT = 66, + GPG_ERR_TOO_LARGE = 67, + GPG_ERR_NO_OBJ = 68, + GPG_ERR_NOT_IMPLEMENTED = 69, + GPG_ERR_CONFLICT = 70, + GPG_ERR_INV_CIPHER_MODE = 71, + GPG_ERR_INV_FLAG = 72, + GPG_ERR_INV_HANDLE = 73, + GPG_ERR_TRUNCATED = 74, + GPG_ERR_INCOMPLETE_LINE = 75, + GPG_ERR_INV_RESPONSE = 76, + GPG_ERR_NO_AGENT = 77, + GPG_ERR_AGENT = 78, + GPG_ERR_INV_DATA = 79, + GPG_ERR_ASSUAN_SERVER_FAULT = 80, + GPG_ERR_ASSUAN = 81, + GPG_ERR_INV_SESSION_KEY = 82, + GPG_ERR_INV_SEXP = 83, + GPG_ERR_UNSUPPORTED_ALGORITHM = 84, + GPG_ERR_NO_PIN_ENTRY = 85, + GPG_ERR_PIN_ENTRY = 86, + GPG_ERR_BAD_PIN = 87, + GPG_ERR_INV_NAME = 88, + GPG_ERR_BAD_DATA = 89, + GPG_ERR_INV_PARAMETER = 90, + GPG_ERR_WRONG_CARD = 91, + GPG_ERR_NO_DIRMNGR = 92, + GPG_ERR_DIRMNGR = 93, + GPG_ERR_CERT_REVOKED = 94, + GPG_ERR_NO_CRL_KNOWN = 95, + GPG_ERR_CRL_TOO_OLD = 96, + GPG_ERR_LINE_TOO_LONG = 97, + GPG_ERR_NOT_TRUSTED = 98, + GPG_ERR_CANCELED = 99, + GPG_ERR_BAD_CA_CERT = 100, + GPG_ERR_CERT_EXPIRED = 101, + GPG_ERR_CERT_TOO_YOUNG = 102, + GPG_ERR_UNSUPPORTED_CERT = 103, + GPG_ERR_UNKNOWN_SEXP = 104, + GPG_ERR_UNSUPPORTED_PROTECTION = 105, + GPG_ERR_CORRUPTED_PROTECTION = 106, + GPG_ERR_AMBIGUOUS_NAME = 107, + GPG_ERR_CARD = 108, + GPG_ERR_CARD_RESET = 109, + GPG_ERR_CARD_REMOVED = 110, + GPG_ERR_INV_CARD = 111, + GPG_ERR_CARD_NOT_PRESENT = 112, + GPG_ERR_NO_PKCS15_APP = 113, + GPG_ERR_NOT_CONFIRMED = 114, + GPG_ERR_CONFIGURATION = 115, + GPG_ERR_NO_POLICY_MATCH = 116, + GPG_ERR_INV_INDEX = 117, + GPG_ERR_INV_ID = 118, + GPG_ERR_NO_SCDAEMON = 119, + GPG_ERR_SCDAEMON = 120, + GPG_ERR_UNSUPPORTED_PROTOCOL = 121, + GPG_ERR_BAD_PIN_METHOD = 122, + GPG_ERR_CARD_NOT_INITIALIZED = 123, + GPG_ERR_UNSUPPORTED_OPERATION = 124, + GPG_ERR_WRONG_KEY_USAGE = 125, + GPG_ERR_NOTHING_FOUND = 126, + GPG_ERR_WRONG_BLOB_TYPE = 127, + GPG_ERR_MISSING_VALUE = 128, + GPG_ERR_HARDWARE = 129, + GPG_ERR_PIN_BLOCKED = 130, + GPG_ERR_USE_CONDITIONS = 131, + GPG_ERR_PIN_NOT_SYNCED = 132, + GPG_ERR_INV_CRL = 133, + GPG_ERR_BAD_BER = 134, + GPG_ERR_INV_BER = 135, + GPG_ERR_ELEMENT_NOT_FOUND = 136, + GPG_ERR_IDENTIFIER_NOT_FOUND = 137, + GPG_ERR_INV_TAG = 138, + GPG_ERR_INV_LENGTH = 139, + GPG_ERR_INV_KEYINFO = 140, + GPG_ERR_UNEXPECTED_TAG = 141, + GPG_ERR_NOT_DER_ENCODED = 142, + GPG_ERR_NO_CMS_OBJ = 143, + GPG_ERR_INV_CMS_OBJ = 144, + GPG_ERR_UNKNOWN_CMS_OBJ = 145, + GPG_ERR_UNSUPPORTED_CMS_OBJ = 146, + GPG_ERR_UNSUPPORTED_ENCODING = 147, + GPG_ERR_UNSUPPORTED_CMS_VERSION = 148, + GPG_ERR_UNKNOWN_ALGORITHM = 149, + GPG_ERR_INV_ENGINE = 150, + GPG_ERR_PUBKEY_NOT_TRUSTED = 151, + GPG_ERR_DECRYPT_FAILED = 152, + GPG_ERR_KEY_EXPIRED = 153, + GPG_ERR_SIG_EXPIRED = 154, + GPG_ERR_ENCODING_PROBLEM = 155, + GPG_ERR_INV_STATE = 156, + GPG_ERR_DUP_VALUE = 157, + GPG_ERR_MISSING_ACTION = 158, + GPG_ERR_MODULE_NOT_FOUND = 159, + GPG_ERR_INV_OID_STRING = 160, + GPG_ERR_INV_TIME = 161, + GPG_ERR_INV_CRL_OBJ = 162, + GPG_ERR_UNSUPPORTED_CRL_VERSION = 163, + GPG_ERR_INV_CERT_OBJ = 164, + GPG_ERR_UNKNOWN_NAME = 165, + GPG_ERR_LOCALE_PROBLEM = 166, + GPG_ERR_NOT_LOCKED = 167, + GPG_ERR_PROTOCOL_VIOLATION = 168, + GPG_ERR_INV_MAC = 169, + GPG_ERR_INV_REQUEST = 170, + GPG_ERR_UNKNOWN_EXTN = 171, + GPG_ERR_UNKNOWN_CRIT_EXTN = 172, + GPG_ERR_LOCKED = 173, + GPG_ERR_UNKNOWN_OPTION = 174, + GPG_ERR_UNKNOWN_COMMAND = 175, + GPG_ERR_NOT_OPERATIONAL = 176, + GPG_ERR_NO_PASSPHRASE = 177, + GPG_ERR_NO_PIN = 178, + GPG_ERR_NOT_ENABLED = 179, + GPG_ERR_NO_ENGINE = 180, + GPG_ERR_UNFINISHED = 199, + GPG_ERR_BUFFER_TOO_SHORT = 200, + GPG_ERR_SEXP_INV_LEN_SPEC = 201, + GPG_ERR_SEXP_STRING_TOO_LONG = 202, + GPG_ERR_SEXP_UNMATCHED_PAREN = 203, + GPG_ERR_SEXP_NOT_CANONICAL = 204, + GPG_ERR_SEXP_BAD_CHARACTER = 205, + GPG_ERR_SEXP_BAD_QUOTATION = 206, + GPG_ERR_SEXP_ZERO_PREFIX = 207, + GPG_ERR_SEXP_NESTED_DH = 208, + GPG_ERR_SEXP_UNMATCHED_DH = 209, + GPG_ERR_SEXP_UNEXPECTED_PUNC = 210, + GPG_ERR_SEXP_BAD_HEX_CHAR = 211, + GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212, + GPG_ERR_SEXP_BAD_OCT_CHAR = 213, + GPG_ERR_ASS_GENERAL = 257, + GPG_ERR_ASS_ACCEPT_FAILED = 258, + GPG_ERR_ASS_CONNECT_FAILED = 259, + GPG_ERR_ASS_INV_RESPONSE = 260, + GPG_ERR_ASS_INV_VALUE = 261, + GPG_ERR_ASS_INCOMPLETE_LINE = 262, + GPG_ERR_ASS_LINE_TOO_LONG = 263, + GPG_ERR_ASS_NESTED_COMMANDS = 264, + GPG_ERR_ASS_NO_DATA_CB = 265, + GPG_ERR_ASS_NO_INQUIRE_CB = 266, + GPG_ERR_ASS_NOT_A_SERVER = 267, + GPG_ERR_ASS_NOT_A_CLIENT = 268, + GPG_ERR_ASS_SERVER_START = 269, + GPG_ERR_ASS_READ_ERROR = 270, + GPG_ERR_ASS_WRITE_ERROR = 271, + GPG_ERR_ASS_TOO_MUCH_DATA = 273, + GPG_ERR_ASS_UNEXPECTED_CMD = 274, + GPG_ERR_ASS_UNKNOWN_CMD = 275, + GPG_ERR_ASS_SYNTAX = 276, + GPG_ERR_ASS_CANCELED = 277, + GPG_ERR_ASS_NO_INPUT = 278, + GPG_ERR_ASS_NO_OUTPUT = 279, + GPG_ERR_ASS_PARAMETER = 280, + GPG_ERR_ASS_UNKNOWN_INQUIRE = 281, + GPG_ERR_USER_1 = 1024, + GPG_ERR_USER_2 = 1025, + GPG_ERR_USER_3 = 1026, + GPG_ERR_USER_4 = 1027, + GPG_ERR_USER_5 = 1028, + GPG_ERR_USER_6 = 1029, + GPG_ERR_USER_7 = 1030, + GPG_ERR_USER_8 = 1031, + GPG_ERR_USER_9 = 1032, + GPG_ERR_USER_10 = 1033, + GPG_ERR_USER_11 = 1034, + GPG_ERR_USER_12 = 1035, + GPG_ERR_USER_13 = 1036, + GPG_ERR_USER_14 = 1037, + GPG_ERR_USER_15 = 1038, + GPG_ERR_USER_16 = 1039, + GPG_ERR_MISSING_ERRNO = 16381, + GPG_ERR_UNKNOWN_ERRNO = 16382, + GPG_ERR_EOF = 16383, + + /* The following error codes are used to map system errors. */ +#define GPG_ERR_SYSTEM_ERROR (1 << 15) + GPG_ERR_E2BIG = GPG_ERR_SYSTEM_ERROR | 0, + GPG_ERR_EACCES = GPG_ERR_SYSTEM_ERROR | 1, + GPG_ERR_EADDRINUSE = GPG_ERR_SYSTEM_ERROR | 2, + GPG_ERR_EADDRNOTAVAIL = GPG_ERR_SYSTEM_ERROR | 3, + GPG_ERR_EADV = GPG_ERR_SYSTEM_ERROR | 4, + GPG_ERR_EAFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 5, + GPG_ERR_EAGAIN = GPG_ERR_SYSTEM_ERROR | 6, + GPG_ERR_EALREADY = GPG_ERR_SYSTEM_ERROR | 7, + GPG_ERR_EAUTH = GPG_ERR_SYSTEM_ERROR | 8, + GPG_ERR_EBACKGROUND = GPG_ERR_SYSTEM_ERROR | 9, + GPG_ERR_EBADE = GPG_ERR_SYSTEM_ERROR | 10, + GPG_ERR_EBADF = GPG_ERR_SYSTEM_ERROR | 11, + GPG_ERR_EBADFD = GPG_ERR_SYSTEM_ERROR | 12, + GPG_ERR_EBADMSG = GPG_ERR_SYSTEM_ERROR | 13, + GPG_ERR_EBADR = GPG_ERR_SYSTEM_ERROR | 14, + GPG_ERR_EBADRPC = GPG_ERR_SYSTEM_ERROR | 15, + GPG_ERR_EBADRQC = GPG_ERR_SYSTEM_ERROR | 16, + GPG_ERR_EBADSLT = GPG_ERR_SYSTEM_ERROR | 17, + GPG_ERR_EBFONT = GPG_ERR_SYSTEM_ERROR | 18, + GPG_ERR_EBUSY = GPG_ERR_SYSTEM_ERROR | 19, + GPG_ERR_ECANCELED = GPG_ERR_SYSTEM_ERROR | 20, + GPG_ERR_ECHILD = GPG_ERR_SYSTEM_ERROR | 21, + GPG_ERR_ECHRNG = GPG_ERR_SYSTEM_ERROR | 22, + GPG_ERR_ECOMM = GPG_ERR_SYSTEM_ERROR | 23, + GPG_ERR_ECONNABORTED = GPG_ERR_SYSTEM_ERROR | 24, + GPG_ERR_ECONNREFUSED = GPG_ERR_SYSTEM_ERROR | 25, + GPG_ERR_ECONNRESET = GPG_ERR_SYSTEM_ERROR | 26, + GPG_ERR_ED = GPG_ERR_SYSTEM_ERROR | 27, + GPG_ERR_EDEADLK = GPG_ERR_SYSTEM_ERROR | 28, + GPG_ERR_EDEADLOCK = GPG_ERR_SYSTEM_ERROR | 29, + GPG_ERR_EDESTADDRREQ = GPG_ERR_SYSTEM_ERROR | 30, + GPG_ERR_EDIED = GPG_ERR_SYSTEM_ERROR | 31, + GPG_ERR_EDOM = GPG_ERR_SYSTEM_ERROR | 32, + GPG_ERR_EDOTDOT = GPG_ERR_SYSTEM_ERROR | 33, + GPG_ERR_EDQUOT = GPG_ERR_SYSTEM_ERROR | 34, + GPG_ERR_EEXIST = GPG_ERR_SYSTEM_ERROR | 35, + GPG_ERR_EFAULT = GPG_ERR_SYSTEM_ERROR | 36, + GPG_ERR_EFBIG = GPG_ERR_SYSTEM_ERROR | 37, + GPG_ERR_EFTYPE = GPG_ERR_SYSTEM_ERROR | 38, + GPG_ERR_EGRATUITOUS = GPG_ERR_SYSTEM_ERROR | 39, + GPG_ERR_EGREGIOUS = GPG_ERR_SYSTEM_ERROR | 40, + GPG_ERR_EHOSTDOWN = GPG_ERR_SYSTEM_ERROR | 41, + GPG_ERR_EHOSTUNREACH = GPG_ERR_SYSTEM_ERROR | 42, + GPG_ERR_EIDRM = GPG_ERR_SYSTEM_ERROR | 43, + GPG_ERR_EIEIO = GPG_ERR_SYSTEM_ERROR | 44, + GPG_ERR_EILSEQ = GPG_ERR_SYSTEM_ERROR | 45, + GPG_ERR_EINPROGRESS = GPG_ERR_SYSTEM_ERROR | 46, + GPG_ERR_EINTR = GPG_ERR_SYSTEM_ERROR | 47, + GPG_ERR_EINVAL = GPG_ERR_SYSTEM_ERROR | 48, + GPG_ERR_EIO = GPG_ERR_SYSTEM_ERROR | 49, + GPG_ERR_EISCONN = GPG_ERR_SYSTEM_ERROR | 50, + GPG_ERR_EISDIR = GPG_ERR_SYSTEM_ERROR | 51, + GPG_ERR_EISNAM = GPG_ERR_SYSTEM_ERROR | 52, + GPG_ERR_EL2HLT = GPG_ERR_SYSTEM_ERROR | 53, + GPG_ERR_EL2NSYNC = GPG_ERR_SYSTEM_ERROR | 54, + GPG_ERR_EL3HLT = GPG_ERR_SYSTEM_ERROR | 55, + GPG_ERR_EL3RST = GPG_ERR_SYSTEM_ERROR | 56, + GPG_ERR_ELIBACC = GPG_ERR_SYSTEM_ERROR | 57, + GPG_ERR_ELIBBAD = GPG_ERR_SYSTEM_ERROR | 58, + GPG_ERR_ELIBEXEC = GPG_ERR_SYSTEM_ERROR | 59, + GPG_ERR_ELIBMAX = GPG_ERR_SYSTEM_ERROR | 60, + GPG_ERR_ELIBSCN = GPG_ERR_SYSTEM_ERROR | 61, + GPG_ERR_ELNRNG = GPG_ERR_SYSTEM_ERROR | 62, + GPG_ERR_ELOOP = GPG_ERR_SYSTEM_ERROR | 63, + GPG_ERR_EMEDIUMTYPE = GPG_ERR_SYSTEM_ERROR | 64, + GPG_ERR_EMFILE = GPG_ERR_SYSTEM_ERROR | 65, + GPG_ERR_EMLINK = GPG_ERR_SYSTEM_ERROR | 66, + GPG_ERR_EMSGSIZE = GPG_ERR_SYSTEM_ERROR | 67, + GPG_ERR_EMULTIHOP = GPG_ERR_SYSTEM_ERROR | 68, + GPG_ERR_ENAMETOOLONG = GPG_ERR_SYSTEM_ERROR | 69, + GPG_ERR_ENAVAIL = GPG_ERR_SYSTEM_ERROR | 70, + GPG_ERR_ENEEDAUTH = GPG_ERR_SYSTEM_ERROR | 71, + GPG_ERR_ENETDOWN = GPG_ERR_SYSTEM_ERROR | 72, + GPG_ERR_ENETRESET = GPG_ERR_SYSTEM_ERROR | 73, + GPG_ERR_ENETUNREACH = GPG_ERR_SYSTEM_ERROR | 74, + GPG_ERR_ENFILE = GPG_ERR_SYSTEM_ERROR | 75, + GPG_ERR_ENOANO = GPG_ERR_SYSTEM_ERROR | 76, + GPG_ERR_ENOBUFS = GPG_ERR_SYSTEM_ERROR | 77, + GPG_ERR_ENOCSI = GPG_ERR_SYSTEM_ERROR | 78, + GPG_ERR_ENODATA = GPG_ERR_SYSTEM_ERROR | 79, + GPG_ERR_ENODEV = GPG_ERR_SYSTEM_ERROR | 80, + GPG_ERR_ENOENT = GPG_ERR_SYSTEM_ERROR | 81, + GPG_ERR_ENOEXEC = GPG_ERR_SYSTEM_ERROR | 82, + GPG_ERR_ENOLCK = GPG_ERR_SYSTEM_ERROR | 83, + GPG_ERR_ENOLINK = GPG_ERR_SYSTEM_ERROR | 84, + GPG_ERR_ENOMEDIUM = GPG_ERR_SYSTEM_ERROR | 85, + GPG_ERR_ENOMEM = GPG_ERR_SYSTEM_ERROR | 86, + GPG_ERR_ENOMSG = GPG_ERR_SYSTEM_ERROR | 87, + GPG_ERR_ENONET = GPG_ERR_SYSTEM_ERROR | 88, + GPG_ERR_ENOPKG = GPG_ERR_SYSTEM_ERROR | 89, + GPG_ERR_ENOPROTOOPT = GPG_ERR_SYSTEM_ERROR | 90, + GPG_ERR_ENOSPC = GPG_ERR_SYSTEM_ERROR | 91, + GPG_ERR_ENOSR = GPG_ERR_SYSTEM_ERROR | 92, + GPG_ERR_ENOSTR = GPG_ERR_SYSTEM_ERROR | 93, + GPG_ERR_ENOSYS = GPG_ERR_SYSTEM_ERROR | 94, + GPG_ERR_ENOTBLK = GPG_ERR_SYSTEM_ERROR | 95, + GPG_ERR_ENOTCONN = GPG_ERR_SYSTEM_ERROR | 96, + GPG_ERR_ENOTDIR = GPG_ERR_SYSTEM_ERROR | 97, + GPG_ERR_ENOTEMPTY = GPG_ERR_SYSTEM_ERROR | 98, + GPG_ERR_ENOTNAM = GPG_ERR_SYSTEM_ERROR | 99, + GPG_ERR_ENOTSOCK = GPG_ERR_SYSTEM_ERROR | 100, + GPG_ERR_ENOTSUP = GPG_ERR_SYSTEM_ERROR | 101, + GPG_ERR_ENOTTY = GPG_ERR_SYSTEM_ERROR | 102, + GPG_ERR_ENOTUNIQ = GPG_ERR_SYSTEM_ERROR | 103, + GPG_ERR_ENXIO = GPG_ERR_SYSTEM_ERROR | 104, + GPG_ERR_EOPNOTSUPP = GPG_ERR_SYSTEM_ERROR | 105, + GPG_ERR_EOVERFLOW = GPG_ERR_SYSTEM_ERROR | 106, + GPG_ERR_EPERM = GPG_ERR_SYSTEM_ERROR | 107, + GPG_ERR_EPFNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 108, + GPG_ERR_EPIPE = GPG_ERR_SYSTEM_ERROR | 109, + GPG_ERR_EPROCLIM = GPG_ERR_SYSTEM_ERROR | 110, + GPG_ERR_EPROCUNAVAIL = GPG_ERR_SYSTEM_ERROR | 111, + GPG_ERR_EPROGMISMATCH = GPG_ERR_SYSTEM_ERROR | 112, + GPG_ERR_EPROGUNAVAIL = GPG_ERR_SYSTEM_ERROR | 113, + GPG_ERR_EPROTO = GPG_ERR_SYSTEM_ERROR | 114, + GPG_ERR_EPROTONOSUPPORT = GPG_ERR_SYSTEM_ERROR | 115, + GPG_ERR_EPROTOTYPE = GPG_ERR_SYSTEM_ERROR | 116, + GPG_ERR_ERANGE = GPG_ERR_SYSTEM_ERROR | 117, + GPG_ERR_EREMCHG = GPG_ERR_SYSTEM_ERROR | 118, + GPG_ERR_EREMOTE = GPG_ERR_SYSTEM_ERROR | 119, + GPG_ERR_EREMOTEIO = GPG_ERR_SYSTEM_ERROR | 120, + GPG_ERR_ERESTART = GPG_ERR_SYSTEM_ERROR | 121, + GPG_ERR_EROFS = GPG_ERR_SYSTEM_ERROR | 122, + GPG_ERR_ERPCMISMATCH = GPG_ERR_SYSTEM_ERROR | 123, + GPG_ERR_ESHUTDOWN = GPG_ERR_SYSTEM_ERROR | 124, + GPG_ERR_ESOCKTNOSUPPORT = GPG_ERR_SYSTEM_ERROR | 125, + GPG_ERR_ESPIPE = GPG_ERR_SYSTEM_ERROR | 126, + GPG_ERR_ESRCH = GPG_ERR_SYSTEM_ERROR | 127, + GPG_ERR_ESRMNT = GPG_ERR_SYSTEM_ERROR | 128, + GPG_ERR_ESTALE = GPG_ERR_SYSTEM_ERROR | 129, + GPG_ERR_ESTRPIPE = GPG_ERR_SYSTEM_ERROR | 130, + GPG_ERR_ETIME = GPG_ERR_SYSTEM_ERROR | 131, + GPG_ERR_ETIMEDOUT = GPG_ERR_SYSTEM_ERROR | 132, + GPG_ERR_ETOOMANYREFS = GPG_ERR_SYSTEM_ERROR | 133, + GPG_ERR_ETXTBSY = GPG_ERR_SYSTEM_ERROR | 134, + GPG_ERR_EUCLEAN = GPG_ERR_SYSTEM_ERROR | 135, + GPG_ERR_EUNATCH = GPG_ERR_SYSTEM_ERROR | 136, + GPG_ERR_EUSERS = GPG_ERR_SYSTEM_ERROR | 137, + GPG_ERR_EWOULDBLOCK = GPG_ERR_SYSTEM_ERROR | 138, + GPG_ERR_EXDEV = GPG_ERR_SYSTEM_ERROR | 139, + GPG_ERR_EXFULL = GPG_ERR_SYSTEM_ERROR | 140, + + /* This is one more than the largest allowed entry. */ + GPG_ERR_CODE_DIM = 65536 + } gpg_err_code_t; + + +/* The error value type gpg_error_t. */ + +/* We would really like to use bit-fields in a struct, but using + structs as return values can cause binary compatibility issues, in + particular if you want to do it effeciently (also see + -freg-struct-return option to GCC). */ +typedef unsigned int gpg_error_t; + +/* We use the lowest 16 bits of gpg_error_t for error codes. The 16th + bit indicates system errors. */ +#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1) + +/* Bits 17 to 24 are reserved. */ + +/* We use the upper 7 bits of gpg_error_t for error sources. */ +#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1) +#define GPG_ERR_SOURCE_SHIFT 24 + +/* The highest bit is reserved. It shouldn't be used to prevent + potential negative numbers when transmitting error values as + text. */ + + +/* GCC feature test. */ +#undef _GPG_ERR_HAVE_CONSTRUCTOR +#if __GNUC__ +#define _GPG_ERR_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _GPG_ERR_GCC_VERSION > 30100 +#define _GPG_ERR_CONSTRUCTOR __attribute__ ((__constructor__)) +#define _GPG_ERR_HAVE_CONSTRUCTOR +#endif +#endif + +#ifndef _GPG_ERR_CONSTRUCTOR +#define _GPG_ERR_CONSTRUCTOR +#endif + + +/* Initialization function. */ + +/* Initialize the library. This function should be run early. */ +gpg_error_t gpg_err_init (void) _GPG_ERR_CONSTRUCTOR; + +/* If this is defined, the library is already initialized by the + constructor and does not need to be initialized explicitely. */ +#undef GPG_ERR_INITIALIZED +#ifdef _GPG_ERR_HAVE_CONSTRUCTOR +#define GPG_ERR_INITIALIZED 1 +#endif + + +/* Constructor and accessor functions. */ + +/* Construct an error value from an error code and source. Within a + subsystem, use gpg_error. */ +static GPG_ERR_INLINE gpg_error_t +gpg_err_make (gpg_err_source_t source, gpg_err_code_t code) +{ + return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR + : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT) + | (code & GPG_ERR_CODE_MASK)); +} + + +/* The user should define GPG_ERR_SOURCE_DEFAULT before including this + file to specify a default source for gpg_error. */ +#ifndef GPG_ERR_SOURCE_DEFAULT +#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN +#endif + +static GPG_ERR_INLINE gpg_error_t +gpg_error (gpg_err_code_t code) +{ + return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code); +} + + +/* Retrieve the error code from an error value. */ +static GPG_ERR_INLINE gpg_err_code_t +gpg_err_code (gpg_error_t err) +{ + return (gpg_err_code_t) (err & GPG_ERR_CODE_MASK); +} + + +/* Retrieve the error source from an error value. */ +static GPG_ERR_INLINE gpg_err_source_t +gpg_err_source (gpg_error_t err) +{ + return (gpg_err_source_t) ((err >> GPG_ERR_SOURCE_SHIFT) + & GPG_ERR_SOURCE_MASK); +} + + +/* String functions. */ + +/* Return a pointer to a string containing a description of the error + code in the error value ERR. This function is not thread-safe. */ +const char *gpg_strerror (gpg_error_t err); + +/* Return the error string for ERR in the user-supplied buffer BUF of + size BUFLEN. This function is, in contrast to gpg_strerror, + thread-safe if a thread-safe strerror_r() function is provided by + the system. If the function succeeds, 0 is returned and BUF + contains the string describing the error. If the buffer was not + large enough, ERANGE is returned and BUF contains as much of the + beginning of the error string as fits into the buffer. */ +int gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen); + +/* Return a pointer to a string containing a description of the error + source in the error value ERR. */ +const char *gpg_strsource (gpg_error_t err); + + +/* Mapping of system errors (errno). */ + +/* Retrieve the error code for the system error ERR. This returns + GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report + this). */ +gpg_err_code_t gpg_err_code_from_errno (int err); + + +/* Retrieve the system error for the error code CODE. This returns 0 + if CODE is not a system error code. */ +int gpg_err_code_to_errno (gpg_err_code_t code); + + +/* Retrieve the error code directly from the ERRNO variable. This + returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped + (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */ +gpg_err_code_t gpg_err_code_from_syserror (void); + + +/* Set the ERRNO variable. This function is the preferred way to set + ERRNO due to peculiarities on WindowsCE. */ +void gpg_err_set_errno (int err); + +/* Decide whether to use the format_arg attribute. */ +#if _GPG_ERR_GCC_VERSION > 20800 +# define _GPG_ERR_ATTR_FORMAT_ARG(a) __attribute__ ((__format_arg__ (a))) +#else +# define _GPG_ERR_ATTR_FORMAT_ARG(a) +#endif + +/* A lean gettext implementation based on GNU style mo files which are + required to be encoded in UTF-8. There is a limit on 65534 entries + to save some RAM. Only Germanic plural rules are supported. */ +const char *_gpg_w32_bindtextdomain (const char *domainname, + const char *dirname); +const char *_gpg_w32_textdomain (const char *domainname); +const char *_gpg_w32_gettext (const char *msgid) + _GPG_ERR_ATTR_FORMAT_ARG (1); +const char *_gpg_w32_dgettext (const char *domainname, const char *msgid) + _GPG_ERR_ATTR_FORMAT_ARG (2); +const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1, + const char *msgid2, unsigned long int n) + _GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3); +const char *_gpg_w32_gettext_localename (void); +int _gpg_w32_gettext_use_utf8 (int value); + +#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS +# define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b)) +# define textdomain(a) _gpg_w32_textdomain ((a)) +# define gettext(a) _gpg_w32_gettext ((a)) +# define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) +# define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) +# define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) +# define gettext_localename() _gpg_w32_gettext_localename () +# define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) +#endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/ + + + +/* Self-documenting convenience functions. */ + +static GPG_ERR_INLINE gpg_error_t +gpg_err_make_from_errno (gpg_err_source_t source, int err) +{ + return gpg_err_make (source, gpg_err_code_from_errno (err)); +} + + +static GPG_ERR_INLINE gpg_error_t +gpg_error_from_errno (int err) +{ + return gpg_error (gpg_err_code_from_errno (err)); +} + +static GPG_ERR_INLINE gpg_error_t +gpg_error_from_syserror (void) +{ + return gpg_error (gpg_err_code_from_syserror ()); +} + +#ifdef __cplusplus +} +#endif + + +#endif /* GPG_ERROR_H */ @@ -0,0 +1,2101 @@ +/* gpgme.h - Public interface to GnuPG Made Easy. -*- c -*- + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2009 + 2010 g10 Code GmbH + + This file is part of GPGME. + + GPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + GPGME is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see <http://www.gnu.org/licenses/>. + + File: src/gpgme.h. Generated from gpgme.h.in by configure. */ + +#ifndef GPGME_H +#define GPGME_H + +#ifdef __GNUC__ +#define _GPGME_INLINE __inline__ +#elif __STDC_VERSION__ >= 199901L +#define _GPGME_INLINE inline +#else +#define _GPGME_INLINE +#endif + +/* Include stdio.h for the FILE type definition. */ +#include <stdio.h> + +#ifdef _MSC_VER + typedef long off_t; + typedef long ssize_t; +#else +# include <sys/types.h> +#endif + +#include <gpg-error.h> + +#ifdef __cplusplus +extern "C" { +#if 0 /* just to make Emacs auto-indent happy */ +} +#endif +#endif /* __cplusplus */ + + + +/* Check for compiler features. */ +#if __GNUC__ +#define _GPGME_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _GPGME_GCC_VERSION > 30100 +#define _GPGME_DEPRECATED __attribute__ ((__deprecated__)) +#endif +#endif + +#ifndef _GPGME_DEPRECATED +#define _GPGME_DEPRECATED +#endif + +/* The macro _GPGME_DEPRECATED_OUTSIDE_GPGME suppresses warnings for + fields we must access in GPGME for ABI compatibility. */ +#ifdef _GPGME_IN_GPGME +#define _GPGME_DEPRECATED_OUTSIDE_GPGME +#else +#define _GPGME_DEPRECATED_OUTSIDE_GPGME _GPGME_DEPRECATED +#endif + + +/* The version of this header should match the one of the library. Do + not use this symbol in your application, use gpgme_check_version + instead. The purpose of this macro is to let autoconf (using the + AM_PATH_GPGME macro) check that this header matches the installed + library. */ +#define GPGME_VERSION "1.3.0" + +/* Check for a matching _FILE_OFFSET_BITS definition. */ +#if 0 +#ifndef _FILE_OFFSET_BITS +#error GPGME was compiled with _FILE_OFFSET_BITS = 0, please see the section "Largefile support (LFS)" in the GPGME manual. +#else +#if (_FILE_OFFSET_BITS) != (0) +#error GPGME was compiled with a different value for _FILE_OFFSET_BITS, namely 0, please see the section "Largefile support (LFS)" in the GPGME manual. +#endif +#endif +#endif + + + +/* Some opaque data types used by GPGME. */ + +/* The context holds some global state and configration options, as + well as the results of a crypto operation. */ +struct gpgme_context; +typedef struct gpgme_context *gpgme_ctx_t; + +/* The data object is used by GPGME to exchange arbitrary data. */ +struct gpgme_data; +typedef struct gpgme_data *gpgme_data_t; + + +/* Wrappers for the libgpg-error library. */ + +typedef gpg_error_t gpgme_error_t; +typedef gpg_err_code_t gpgme_err_code_t; +typedef gpg_err_source_t gpgme_err_source_t; + + +static _GPGME_INLINE gpgme_error_t +gpgme_err_make (gpgme_err_source_t source, gpgme_err_code_t code) +{ + return gpg_err_make (source, code); +} + + +/* The user can define GPGME_ERR_SOURCE_DEFAULT before including this + file to specify a default source for gpgme_error. */ +#ifndef GPGME_ERR_SOURCE_DEFAULT +#define GPGME_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 +#endif + +static _GPGME_INLINE gpgme_error_t +gpgme_error (gpgme_err_code_t code) +{ + return gpgme_err_make (GPGME_ERR_SOURCE_DEFAULT, code); +} + + +static _GPGME_INLINE gpgme_err_code_t +gpgme_err_code (gpgme_error_t err) +{ + return gpg_err_code (err); +} + + +static _GPGME_INLINE gpgme_err_source_t +gpgme_err_source (gpgme_error_t err) +{ + return gpg_err_source (err); +} + + +/* Return a pointer to a string containing a description of the error + code in the error value ERR. This function is not thread safe. */ +const char *gpgme_strerror (gpgme_error_t err); + +/* Return the error string for ERR in the user-supplied buffer BUF of + size BUFLEN. This function is, in contrast to gpg_strerror, + thread-safe if a thread-safe strerror_r() function is provided by + the system. If the function succeeds, 0 is returned and BUF + contains the string describing the error. If the buffer was not + large enough, ERANGE is returned and BUF contains as much of the + beginning of the error string as fits into the buffer. */ +int gpgme_strerror_r (gpg_error_t err, char *buf, size_t buflen); + + +/* Return a pointer to a string containing a description of the error + source in the error value ERR. */ +const char *gpgme_strsource (gpgme_error_t err); + + +/* Retrieve the error code for the system error ERR. This returns + GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report + this). */ +gpgme_err_code_t gpgme_err_code_from_errno (int err); + + +/* Retrieve the system error for the error code CODE. This returns 0 + if CODE is not a system error code. */ +int gpgme_err_code_to_errno (gpgme_err_code_t code); + + +/* Return an error value with the error source SOURCE and the system + error ERR. */ +gpgme_error_t gpgme_err_make_from_errno (gpgme_err_source_t source, int err); + + +/* Return an error value with the system error ERR. */ +gpgme_err_code_t gpgme_error_from_errno (int err); + + +/* The possible encoding mode of gpgme_data_t objects. */ +typedef enum + { + GPGME_DATA_ENCODING_NONE = 0, /* Not specified. */ + GPGME_DATA_ENCODING_BINARY = 1, + GPGME_DATA_ENCODING_BASE64 = 2, + GPGME_DATA_ENCODING_ARMOR = 3, /* Either PEM or OpenPGP Armor. */ + GPGME_DATA_ENCODING_URL = 4, /* LF delimited URL list. */ + GPGME_DATA_ENCODING_URLESC = 5, /* Ditto, but percent escaped. */ + GPGME_DATA_ENCODING_URL0 = 6 /* Nul delimited URL list. */ + } +gpgme_data_encoding_t; + + +/* Public key algorithms from libgcrypt. */ +typedef enum + { + GPGME_PK_RSA = 1, + GPGME_PK_RSA_E = 2, + GPGME_PK_RSA_S = 3, + GPGME_PK_ELG_E = 16, + GPGME_PK_DSA = 17, + GPGME_PK_ELG = 20, + GPGME_PK_ECDSA = 301, + GPGME_PK_ECDH = 302 + } +gpgme_pubkey_algo_t; + + +/* Hash algorithms from libgcrypt. */ +typedef enum + { + GPGME_MD_NONE = 0, + GPGME_MD_MD5 = 1, + GPGME_MD_SHA1 = 2, + GPGME_MD_RMD160 = 3, + GPGME_MD_MD2 = 5, + GPGME_MD_TIGER = 6, /* TIGER/192. */ + GPGME_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */ + GPGME_MD_SHA256 = 8, + GPGME_MD_SHA384 = 9, + GPGME_MD_SHA512 = 10, + GPGME_MD_MD4 = 301, + GPGME_MD_CRC32 = 302, + GPGME_MD_CRC32_RFC1510 = 303, + GPGME_MD_CRC24_RFC2440 = 304 + } +gpgme_hash_algo_t; + + +/* The possible signature stati. Deprecated, use error value in sig + status. */ +typedef enum + { + GPGME_SIG_STAT_NONE = 0, + GPGME_SIG_STAT_GOOD = 1, + GPGME_SIG_STAT_BAD = 2, + GPGME_SIG_STAT_NOKEY = 3, + GPGME_SIG_STAT_NOSIG = 4, + GPGME_SIG_STAT_ERROR = 5, + GPGME_SIG_STAT_DIFF = 6, + GPGME_SIG_STAT_GOOD_EXP = 7, + GPGME_SIG_STAT_GOOD_EXPKEY = 8 + } +_gpgme_sig_stat_t; +typedef _gpgme_sig_stat_t gpgme_sig_stat_t _GPGME_DEPRECATED; + + +/* The available signature modes. */ +typedef enum + { + GPGME_SIG_MODE_NORMAL = 0, + GPGME_SIG_MODE_DETACH = 1, + GPGME_SIG_MODE_CLEAR = 2 + } +gpgme_sig_mode_t; + + +/* The available key and signature attributes. Deprecated, use the + individual result structures instead. */ +typedef enum + { + GPGME_ATTR_KEYID = 1, + GPGME_ATTR_FPR = 2, + GPGME_ATTR_ALGO = 3, + GPGME_ATTR_LEN = 4, + GPGME_ATTR_CREATED = 5, + GPGME_ATTR_EXPIRE = 6, + GPGME_ATTR_OTRUST = 7, + GPGME_ATTR_USERID = 8, + GPGME_ATTR_NAME = 9, + GPGME_ATTR_EMAIL = 10, + GPGME_ATTR_COMMENT = 11, + GPGME_ATTR_VALIDITY = 12, + GPGME_ATTR_LEVEL = 13, + GPGME_ATTR_TYPE = 14, + GPGME_ATTR_IS_SECRET = 15, + GPGME_ATTR_KEY_REVOKED = 16, + GPGME_ATTR_KEY_INVALID = 17, + GPGME_ATTR_UID_REVOKED = 18, + GPGME_ATTR_UID_INVALID = 19, + GPGME_ATTR_KEY_CAPS = 20, + GPGME_ATTR_CAN_ENCRYPT = 21, + GPGME_ATTR_CAN_SIGN = 22, + GPGME_ATTR_CAN_CERTIFY = 23, + GPGME_ATTR_KEY_EXPIRED = 24, + GPGME_ATTR_KEY_DISABLED = 25, + GPGME_ATTR_SERIAL = 26, + GPGME_ATTR_ISSUER = 27, + GPGME_ATTR_CHAINID = 28, + GPGME_ATTR_SIG_STATUS = 29, + GPGME_ATTR_ERRTOK = 30, + GPGME_ATTR_SIG_SUMMARY = 31, + GPGME_ATTR_SIG_CLASS = 32 + } +_gpgme_attr_t; +typedef _gpgme_attr_t gpgme_attr_t _GPGME_DEPRECATED; + + +/* The available validities for a trust item or key. */ +typedef enum + { + GPGME_VALIDITY_UNKNOWN = 0, + GPGME_VALIDITY_UNDEFINED = 1, + GPGME_VALIDITY_NEVER = 2, + GPGME_VALIDITY_MARGINAL = 3, + GPGME_VALIDITY_FULL = 4, + GPGME_VALIDITY_ULTIMATE = 5 + } +gpgme_validity_t; + + +/* The available protocols. */ +typedef enum + { + GPGME_PROTOCOL_OpenPGP = 0, /* The default mode. */ + GPGME_PROTOCOL_CMS = 1, + GPGME_PROTOCOL_GPGCONF = 2, /* Special code for gpgconf. */ + GPGME_PROTOCOL_ASSUAN = 3, /* Low-level access to an Assuan server. */ + GPGME_PROTOCOL_G13 = 4, + GPGME_PROTOCOL_UISERVER= 5, + GPGME_PROTOCOL_DEFAULT = 254, + GPGME_PROTOCOL_UNKNOWN = 255 + } +gpgme_protocol_t; + + +/* The available keylist mode flags. */ +#define GPGME_KEYLIST_MODE_LOCAL 1 +#define GPGME_KEYLIST_MODE_EXTERN 2 +#define GPGME_KEYLIST_MODE_SIGS 4 +#define GPGME_KEYLIST_MODE_SIG_NOTATIONS 8 +#define GPGME_KEYLIST_MODE_EPHEMERAL 128 +#define GPGME_KEYLIST_MODE_VALIDATE 256 + +typedef unsigned int gpgme_keylist_mode_t; + + +/* The available export mode flags. */ +#define GPGME_EXPORT_MODE_EXTERN 2 + +typedef unsigned int gpgme_export_mode_t; + + +/* Flags for the audit log functions. */ +#define GPGME_AUDITLOG_HTML 1 +#define GPGME_AUDITLOG_WITH_HELP 128 + + +/* Signature notations. */ + +/* The available signature notation flags. */ +#define GPGME_SIG_NOTATION_HUMAN_READABLE 1 +#define GPGME_SIG_NOTATION_CRITICAL 2 + +typedef unsigned int gpgme_sig_notation_flags_t; + +struct _gpgme_sig_notation +{ + struct _gpgme_sig_notation *next; + + /* If NAME is a null pointer, then VALUE contains a policy URL + rather than a notation. */ + char *name; + + /* The value of the notation data. */ + char *value; + + /* The length of the name of the notation data. */ + int name_len; + + /* The length of the value of the notation data. */ + int value_len; + + /* The accumulated flags. */ + gpgme_sig_notation_flags_t flags; + + /* Notation data is human-readable. */ + unsigned int human_readable : 1; + + /* Notation data is critical. */ + unsigned int critical : 1; + + /* Internal to GPGME, do not use. */ + int _unused : 30; +}; +typedef struct _gpgme_sig_notation *gpgme_sig_notation_t; + + +/* The possible stati for the edit operation. */ +typedef enum + { + GPGME_STATUS_EOF = 0, + /* mkstatus processing starts here */ + GPGME_STATUS_ENTER = 1, + GPGME_STATUS_LEAVE = 2, + GPGME_STATUS_ABORT = 3, + + GPGME_STATUS_GOODSIG = 4, + GPGME_STATUS_BADSIG = 5, + GPGME_STATUS_ERRSIG = 6, + + GPGME_STATUS_BADARMOR = 7, + + GPGME_STATUS_RSA_OR_IDEA = 8, + GPGME_STATUS_KEYEXPIRED = 9, + GPGME_STATUS_KEYREVOKED = 10, + + GPGME_STATUS_TRUST_UNDEFINED = 11, + GPGME_STATUS_TRUST_NEVER = 12, + GPGME_STATUS_TRUST_MARGINAL = 13, + GPGME_STATUS_TRUST_FULLY = 14, + GPGME_STATUS_TRUST_ULTIMATE = 15, + + GPGME_STATUS_SHM_INFO = 16, + GPGME_STATUS_SHM_GET = 17, + GPGME_STATUS_SHM_GET_BOOL = 18, + GPGME_STATUS_SHM_GET_HIDDEN = 19, + + GPGME_STATUS_NEED_PASSPHRASE = 20, + GPGME_STATUS_VALIDSIG = 21, + GPGME_STATUS_SIG_ID = 22, + GPGME_STATUS_ENC_TO = 23, + GPGME_STATUS_NODATA = 24, + GPGME_STATUS_BAD_PASSPHRASE = 25, + GPGME_STATUS_NO_PUBKEY = 26, + GPGME_STATUS_NO_SECKEY = 27, + GPGME_STATUS_NEED_PASSPHRASE_SYM = 28, + GPGME_STATUS_DECRYPTION_FAILED = 29, + GPGME_STATUS_DECRYPTION_OKAY = 30, + GPGME_STATUS_MISSING_PASSPHRASE = 31, + GPGME_STATUS_GOOD_PASSPHRASE = 32, + GPGME_STATUS_GOODMDC = 33, + GPGME_STATUS_BADMDC = 34, + GPGME_STATUS_ERRMDC = 35, + GPGME_STATUS_IMPORTED = 36, + GPGME_STATUS_IMPORT_OK = 37, + GPGME_STATUS_IMPORT_PROBLEM = 38, + GPGME_STATUS_IMPORT_RES = 39, + GPGME_STATUS_FILE_START = 40, + GPGME_STATUS_FILE_DONE = 41, + GPGME_STATUS_FILE_ERROR = 42, + + GPGME_STATUS_BEGIN_DECRYPTION = 43, + GPGME_STATUS_END_DECRYPTION = 44, + GPGME_STATUS_BEGIN_ENCRYPTION = 45, + GPGME_STATUS_END_ENCRYPTION = 46, + + GPGME_STATUS_DELETE_PROBLEM = 47, + GPGME_STATUS_GET_BOOL = 48, + GPGME_STATUS_GET_LINE = 49, + GPGME_STATUS_GET_HIDDEN = 50, + GPGME_STATUS_GOT_IT = 51, + GPGME_STATUS_PROGRESS = 52, + GPGME_STATUS_SIG_CREATED = 53, + GPGME_STATUS_SESSION_KEY = 54, + GPGME_STATUS_NOTATION_NAME = 55, + GPGME_STATUS_NOTATION_DATA = 56, + GPGME_STATUS_POLICY_URL = 57, + GPGME_STATUS_BEGIN_STREAM = 58, + GPGME_STATUS_END_STREAM = 59, + GPGME_STATUS_KEY_CREATED = 60, + GPGME_STATUS_USERID_HINT = 61, + GPGME_STATUS_UNEXPECTED = 62, + GPGME_STATUS_INV_RECP = 63, + GPGME_STATUS_NO_RECP = 64, + GPGME_STATUS_ALREADY_SIGNED = 65, + GPGME_STATUS_SIGEXPIRED = 66, + GPGME_STATUS_EXPSIG = 67, + GPGME_STATUS_EXPKEYSIG = 68, + GPGME_STATUS_TRUNCATED = 69, + GPGME_STATUS_ERROR = 70, + GPGME_STATUS_NEWSIG = 71, + GPGME_STATUS_REVKEYSIG = 72, + GPGME_STATUS_SIG_SUBPACKET = 73, + GPGME_STATUS_NEED_PASSPHRASE_PIN = 74, + GPGME_STATUS_SC_OP_FAILURE = 75, + GPGME_STATUS_SC_OP_SUCCESS = 76, + GPGME_STATUS_CARDCTRL = 77, + GPGME_STATUS_BACKUP_KEY_CREATED = 78, + GPGME_STATUS_PKA_TRUST_BAD = 79, + GPGME_STATUS_PKA_TRUST_GOOD = 80, + + GPGME_STATUS_PLAINTEXT = 81, + GPGME_STATUS_INV_SGNR = 82, + GPGME_STATUS_NO_SGNR = 83 + } +gpgme_status_code_t; + + +/* The engine information structure. */ +struct _gpgme_engine_info +{ + struct _gpgme_engine_info *next; + + /* The protocol ID. */ + gpgme_protocol_t protocol; + + /* The file name of the engine binary. */ + char *file_name; + + /* The version string of the installed engine. */ + char *version; + + /* The minimum version required for GPGME. */ + const char *req_version; + + /* The home directory used, or NULL if default. */ + char *home_dir; +}; +typedef struct _gpgme_engine_info *gpgme_engine_info_t; + + +/* A subkey from a key. */ +struct _gpgme_subkey +{ + struct _gpgme_subkey *next; + + /* True if subkey is revoked. */ + unsigned int revoked : 1; + + /* True if subkey is expired. */ + unsigned int expired : 1; + + /* True if subkey is disabled. */ + unsigned int disabled : 1; + + /* True if subkey is invalid. */ + unsigned int invalid : 1; + + /* True if subkey can be used for encryption. */ + unsigned int can_encrypt : 1; + + /* True if subkey can be used for signing. */ + unsigned int can_sign : 1; + + /* True if subkey can be used for certification. */ + unsigned int can_certify : 1; + + /* True if subkey is secret. */ + unsigned int secret : 1; + + /* True if subkey can be used for authentication. */ + unsigned int can_authenticate : 1; + + /* True if subkey is qualified for signatures according to German law. */ + unsigned int is_qualified : 1; + + /* True if the secret key is stored on a smart card. */ + unsigned int is_cardkey : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 21; + + /* Public key algorithm supported by this subkey. */ + gpgme_pubkey_algo_t pubkey_algo; + + /* Length of the subkey. */ + unsigned int length; + + /* The key ID of the subkey. */ + char *keyid; + + /* Internal to GPGME, do not use. */ + char _keyid[16 + 1]; + + /* The fingerprint of the subkey in hex digit form. */ + char *fpr; + + /* The creation timestamp, -1 if invalid, 0 if not available. */ + long int timestamp; + + /* The expiration timestamp, 0 if the subkey does not expire. */ + long int expires; + + /* The serial number of a smart card holding this key or NULL. */ + char *card_number; +}; +typedef struct _gpgme_subkey *gpgme_subkey_t; + + +/* A signature on a user ID. */ +struct _gpgme_key_sig +{ + struct _gpgme_key_sig *next; + + /* True if the signature is a revocation signature. */ + unsigned int revoked : 1; + + /* True if the signature is expired. */ + unsigned int expired : 1; + + /* True if the signature is invalid. */ + unsigned int invalid : 1; + + /* True if the signature should be exported. */ + unsigned int exportable : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 28; + + /* The public key algorithm used to create the signature. */ + gpgme_pubkey_algo_t pubkey_algo; + + /* The key ID of key used to create the signature. */ + char *keyid; + + /* Internal to GPGME, do not use. */ + char _keyid[16 + 1]; + + /* The creation timestamp, -1 if invalid, 0 if not available. */ + long int timestamp; + + /* The expiration timestamp, 0 if the subkey does not expire. */ + long int expires; + + /* Same as in gpgme_signature_t. */ + gpgme_error_t status; + +#ifdef __cplusplus + unsigned int _obsolete_class _GPGME_DEPRECATED; +#else + /* Must be set to SIG_CLASS below. */ + unsigned int class _GPGME_DEPRECATED_OUTSIDE_GPGME; +#endif + + /* The user ID string. */ + char *uid; + + /* The name part of the user ID. */ + char *name; + + /* The email part of the user ID. */ + char *email; + + /* The comment part of the user ID. */ + char *comment; + + /* Crypto backend specific signature class. */ + unsigned int sig_class; + + /* Notation data and policy URLs. */ + gpgme_sig_notation_t notations; + + /* Internal to GPGME, do not use. */ + gpgme_sig_notation_t _last_notation; +}; +typedef struct _gpgme_key_sig *gpgme_key_sig_t; + + +/* An user ID from a key. */ +struct _gpgme_user_id +{ + struct _gpgme_user_id *next; + + /* True if the user ID is revoked. */ + unsigned int revoked : 1; + + /* True if the user ID is invalid. */ + unsigned int invalid : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 30; + + /* The validity of the user ID. */ + gpgme_validity_t validity; + + /* The user ID string. */ + char *uid; + + /* The name part of the user ID. */ + char *name; + + /* The email part of the user ID. */ + char *email; + + /* The comment part of the user ID. */ + char *comment; + + /* The signatures of the user ID. */ + gpgme_key_sig_t signatures; + + /* Internal to GPGME, do not use. */ + gpgme_key_sig_t _last_keysig; +}; +typedef struct _gpgme_user_id *gpgme_user_id_t; + + +/* A key from the keyring. */ +struct _gpgme_key +{ + /* Internal to GPGME, do not use. */ + unsigned int _refs; + + /* True if key is revoked. */ + unsigned int revoked : 1; + + /* True if key is expired. */ + unsigned int expired : 1; + + /* True if key is disabled. */ + unsigned int disabled : 1; + + /* True if key is invalid. */ + unsigned int invalid : 1; + + /* True if key can be used for encryption. */ + unsigned int can_encrypt : 1; + + /* True if key can be used for signing. */ + unsigned int can_sign : 1; + + /* True if key can be used for certification. */ + unsigned int can_certify : 1; + + /* True if key is secret. */ + unsigned int secret : 1; + + /* True if key can be used for authentication. */ + unsigned int can_authenticate : 1; + + /* True if subkey is qualified for signatures according to German law. */ + unsigned int is_qualified : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 22; + + /* This is the protocol supported by this key. */ + gpgme_protocol_t protocol; + + /* If protocol is GPGME_PROTOCOL_CMS, this string contains the + issuer serial. */ + char *issuer_serial; + + /* If protocol is GPGME_PROTOCOL_CMS, this string contains the + issuer name. */ + char *issuer_name; + + /* If protocol is GPGME_PROTOCOL_CMS, this string contains the chain + ID. */ + char *chain_id; + + /* If protocol is GPGME_PROTOCOL_OpenPGP, this field contains the + owner trust. */ + gpgme_validity_t owner_trust; + + /* The subkeys of the key. */ + gpgme_subkey_t subkeys; + + /* The user IDs of the key. */ + gpgme_user_id_t uids; + + /* Internal to GPGME, do not use. */ + gpgme_subkey_t _last_subkey; + + /* Internal to GPGME, do not use. */ + gpgme_user_id_t _last_uid; + + /* The keylist mode that was active when listing the key. */ + gpgme_keylist_mode_t keylist_mode; +}; +typedef struct _gpgme_key *gpgme_key_t; + + + +/* Types for callback functions. */ + +/* Request a passphrase from the user. */ +typedef gpgme_error_t (*gpgme_passphrase_cb_t) (void *hook, + const char *uid_hint, + const char *passphrase_info, + int prev_was_bad, int fd); + +/* Inform the user about progress made. */ +typedef void (*gpgme_progress_cb_t) (void *opaque, const char *what, + int type, int current, int total); + +/* Interact with the user about an edit operation. */ +typedef gpgme_error_t (*gpgme_edit_cb_t) (void *opaque, + gpgme_status_code_t status, + const char *args, int fd); + + + + +/* Context management functions. */ + +/* Create a new context and return it in CTX. */ +gpgme_error_t gpgme_new (gpgme_ctx_t *ctx); + +/* Release the context CTX. */ +void gpgme_release (gpgme_ctx_t ctx); + +/* Set the protocol to be used by CTX to PROTO. */ +gpgme_error_t gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t proto); + +/* Get the protocol used with CTX */ +gpgme_protocol_t gpgme_get_protocol (gpgme_ctx_t ctx); + +/* Set the crypto protocol to be used by CTX to PROTO. + gpgme_set_protocol actually sets the backend engine. This sets the + crypto protocol used in engines that support more than one crypto + prococol (for example, an UISERVER can support OpenPGP and CMS). + This is reset to the default with gpgme_set_protocol. */ +gpgme_error_t gpgme_set_sub_protocol (gpgme_ctx_t ctx, + gpgme_protocol_t proto); + +/* Get the sub protocol. */ +gpgme_protocol_t gpgme_get_sub_protocol (gpgme_ctx_t ctx); + +/* Get the string describing protocol PROTO, or NULL if invalid. */ +const char *gpgme_get_protocol_name (gpgme_protocol_t proto); + +/* If YES is non-zero, enable armor mode in CTX, disable it otherwise. */ +void gpgme_set_armor (gpgme_ctx_t ctx, int yes); + +/* Return non-zero if armor mode is set in CTX. */ +int gpgme_get_armor (gpgme_ctx_t ctx); + +/* If YES is non-zero, enable text mode in CTX, disable it otherwise. */ +void gpgme_set_textmode (gpgme_ctx_t ctx, int yes); + +/* Return non-zero if text mode is set in CTX. */ +int gpgme_get_textmode (gpgme_ctx_t ctx); + +/* Use whatever the default of the backend crypto engine is. */ +#define GPGME_INCLUDE_CERTS_DEFAULT -256 + +/* Include up to NR_OF_CERTS certificates in an S/MIME message. */ +void gpgme_set_include_certs (gpgme_ctx_t ctx, int nr_of_certs); + +/* Return the number of certs to include in an S/MIME message. */ +int gpgme_get_include_certs (gpgme_ctx_t ctx); + +/* Set keylist mode in CTX to MODE. */ +gpgme_error_t gpgme_set_keylist_mode (gpgme_ctx_t ctx, + gpgme_keylist_mode_t mode); + +/* Get keylist mode in CTX. */ +gpgme_keylist_mode_t gpgme_get_keylist_mode (gpgme_ctx_t ctx); + +/* Set the passphrase callback function in CTX to CB. HOOK_VALUE is + passed as first argument to the passphrase callback function. */ +void gpgme_set_passphrase_cb (gpgme_ctx_t ctx, + gpgme_passphrase_cb_t cb, void *hook_value); + +/* Get the current passphrase callback function in *CB and the current + hook value in *HOOK_VALUE. */ +void gpgme_get_passphrase_cb (gpgme_ctx_t ctx, gpgme_passphrase_cb_t *cb, + void **hook_value); + +/* Set the progress callback function in CTX to CB. HOOK_VALUE is + passed as first argument to the progress callback function. */ +void gpgme_set_progress_cb (gpgme_ctx_t c, gpgme_progress_cb_t cb, + void *hook_value); + +/* Get the current progress callback function in *CB and the current + hook value in *HOOK_VALUE. */ +void gpgme_get_progress_cb (gpgme_ctx_t ctx, gpgme_progress_cb_t *cb, + void **hook_value); + +/* This function sets the locale for the context CTX, or the default + locale if CTX is a null pointer. */ +gpgme_error_t gpgme_set_locale (gpgme_ctx_t ctx, int category, + const char *value); + +/* Get the information about the configured engines. A pointer to the + first engine in the statically allocated linked list is returned. + The returned data is valid until the next gpgme_ctx_set_engine_info. */ +gpgme_engine_info_t gpgme_ctx_get_engine_info (gpgme_ctx_t ctx); + +/* Set the engine info for the context CTX, protocol PROTO, to the + file name FILE_NAME and the home directory HOME_DIR. */ +gpgme_error_t gpgme_ctx_set_engine_info (gpgme_ctx_t ctx, + gpgme_protocol_t proto, + const char *file_name, + const char *home_dir); + + +/* Return a statically allocated string with the name of the public + key algorithm ALGO, or NULL if that name is not known. */ +const char *gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo); + +/* Return a statically allocated string with the name of the hash + algorithm ALGO, or NULL if that name is not known. */ +const char *gpgme_hash_algo_name (gpgme_hash_algo_t algo); + + +/* Delete all signers from CTX. */ +void gpgme_signers_clear (gpgme_ctx_t ctx); + +/* Add KEY to list of signers in CTX. */ +gpgme_error_t gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key); + +/* Return the SEQth signer's key in CTX. */ +gpgme_key_t gpgme_signers_enum (const gpgme_ctx_t ctx, int seq); + +/* Retrieve the signature status of signature IDX in CTX after a + successful verify operation in R_STAT (if non-null). The creation + time stamp of the signature is returned in R_CREATED (if non-null). + The function returns a string containing the fingerprint. + Deprecated, use verify result directly. */ +const char *gpgme_get_sig_status (gpgme_ctx_t ctx, int idx, + _gpgme_sig_stat_t *r_stat, + time_t *r_created) _GPGME_DEPRECATED; + +/* Retrieve certain attributes of a signature. IDX is the index + number of the signature after a successful verify operation. WHAT + is an attribute where GPGME_ATTR_EXPIRE is probably the most useful + one. WHATIDX is to be passed as 0 for most attributes . */ +unsigned long gpgme_get_sig_ulong_attr (gpgme_ctx_t c, int idx, + _gpgme_attr_t what, int whatidx) + _GPGME_DEPRECATED; +const char *gpgme_get_sig_string_attr (gpgme_ctx_t c, int idx, + _gpgme_attr_t what, int whatidx) + _GPGME_DEPRECATED; + + +/* Get the key used to create signature IDX in CTX and return it in + R_KEY. */ +gpgme_error_t gpgme_get_sig_key (gpgme_ctx_t ctx, int idx, gpgme_key_t *r_key) + _GPGME_DEPRECATED; + + +/* Clear all notation data from the context. */ +void gpgme_sig_notation_clear (gpgme_ctx_t ctx); + +/* Add the human-readable notation data with name NAME and value VALUE + to the context CTX, using the flags FLAGS. If NAME is NULL, then + VALUE should be a policy URL. The flag + GPGME_SIG_NOTATION_HUMAN_READABLE is forced to be true for notation + data, and false for policy URLs. */ +gpgme_error_t gpgme_sig_notation_add (gpgme_ctx_t ctx, const char *name, + const char *value, + gpgme_sig_notation_flags_t flags); + +/* Get the sig notations for this context. */ +gpgme_sig_notation_t gpgme_sig_notation_get (gpgme_ctx_t ctx); + + +/* Run control. */ + +/* The type of an I/O callback function. */ +typedef gpgme_error_t (*gpgme_io_cb_t) (void *data, int fd); + +/* The type of a function that can register FNC as the I/O callback + function for the file descriptor FD with direction dir (0: for writing, + 1: for reading). FNC_DATA should be passed as DATA to FNC. The + function should return a TAG suitable for the corresponding + gpgme_remove_io_cb_t, and an error value. */ +typedef gpgme_error_t (*gpgme_register_io_cb_t) (void *data, int fd, int dir, + gpgme_io_cb_t fnc, + void *fnc_data, void **tag); + +/* The type of a function that can remove a previously registered I/O + callback function given TAG as returned by the register + function. */ +typedef void (*gpgme_remove_io_cb_t) (void *tag); + +typedef enum + { + GPGME_EVENT_START, + GPGME_EVENT_DONE, + GPGME_EVENT_NEXT_KEY, + GPGME_EVENT_NEXT_TRUSTITEM + } +gpgme_event_io_t; + +struct gpgme_io_event_done_data +{ + /* A fatal IPC error or an operational error in state-less + protocols. */ + gpgme_error_t err; + + /* An operational errors in session-based protocols. */ + gpgme_error_t op_err; +}; +typedef struct gpgme_io_event_done_data *gpgme_io_event_done_data_t; + +/* The type of a function that is called when a context finished an + operation. */ +typedef void (*gpgme_event_io_cb_t) (void *data, gpgme_event_io_t type, + void *type_data); + +struct gpgme_io_cbs +{ + gpgme_register_io_cb_t add; + void *add_priv; + gpgme_remove_io_cb_t remove; + gpgme_event_io_cb_t event; + void *event_priv; +}; +typedef struct gpgme_io_cbs *gpgme_io_cbs_t; + +/* Set the I/O callback functions in CTX to IO_CBS. */ +void gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs); + +/* Get the current I/O callback functions. */ +void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs); + +/* Wrappers around the internal I/O functions for use with + gpgme_passphrase_cb_t and gpgme_edit_cb_t. */ +ssize_t gpgme_io_read (int fd, void *buffer, size_t count); +ssize_t gpgme_io_write (int fd, const void *buffer, size_t count); + +/* Process the pending operation and, if HANG is non-zero, wait for + the pending operation to finish. */ +gpgme_ctx_t gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang); + +gpgme_ctx_t gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status, + gpgme_error_t *op_err, int hang); + + +/* Functions to handle data objects. */ + +/* Read up to SIZE bytes into buffer BUFFER from the data object with + the handle HANDLE. Return the number of characters read, 0 on EOF + and -1 on error. If an error occurs, errno is set. */ +typedef ssize_t (*gpgme_data_read_cb_t) (void *handle, void *buffer, + size_t size); + +/* Write up to SIZE bytes from buffer BUFFER to the data object with + the handle HANDLE. Return the number of characters written, or -1 + on error. If an error occurs, errno is set. */ +typedef ssize_t (*gpgme_data_write_cb_t) (void *handle, const void *buffer, + size_t size); + +/* Set the current position from where the next read or write starts + in the data object with the handle HANDLE to OFFSET, relativ to + WHENCE. */ +typedef off_t (*gpgme_data_seek_cb_t) (void *handle, off_t offset, int whence); + +/* Close the data object with the handle DL. */ +typedef void (*gpgme_data_release_cb_t) (void *handle); + +struct gpgme_data_cbs +{ + gpgme_data_read_cb_t read; + gpgme_data_write_cb_t write; + gpgme_data_seek_cb_t seek; + gpgme_data_release_cb_t release; +}; +typedef struct gpgme_data_cbs *gpgme_data_cbs_t; + +/* Read up to SIZE bytes into buffer BUFFER from the data object with + the handle DH. Return the number of characters read, 0 on EOF and + -1 on error. If an error occurs, errno is set. */ +ssize_t gpgme_data_read (gpgme_data_t dh, void *buffer, size_t size); + +/* Write up to SIZE bytes from buffer BUFFER to the data object with + the handle DH. Return the number of characters written, or -1 on + error. If an error occurs, errno is set. */ +ssize_t gpgme_data_write (gpgme_data_t dh, const void *buffer, size_t size); + +/* Set the current position from where the next read or write starts + in the data object with the handle DH to OFFSET, relativ to + WHENCE. */ +off_t gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence); + +/* Create a new data buffer and return it in R_DH. */ +gpgme_error_t gpgme_data_new (gpgme_data_t *r_dh); + +/* Destroy the data buffer DH. */ +void gpgme_data_release (gpgme_data_t dh); + +/* Create a new data buffer filled with SIZE bytes starting from + BUFFER. If COPY is zero, copying is delayed until necessary, and + the data is taken from the original location when needed. */ +gpgme_error_t gpgme_data_new_from_mem (gpgme_data_t *r_dh, + const char *buffer, size_t size, + int copy); + +/* Destroy the data buffer DH and return a pointer to its content. + The memory has be to released with gpgme_free() by the user. It's + size is returned in R_LEN. */ +char *gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len); + +/* Release the memory returned by gpgme_data_release_and_get_mem(). */ +void gpgme_free (void *buffer); + +gpgme_error_t gpgme_data_new_from_cbs (gpgme_data_t *dh, + gpgme_data_cbs_t cbs, + void *handle); + +gpgme_error_t gpgme_data_new_from_fd (gpgme_data_t *dh, int fd); + +gpgme_error_t gpgme_data_new_from_stream (gpgme_data_t *dh, FILE *stream); + +/* Return the encoding attribute of the data buffer DH */ +gpgme_data_encoding_t gpgme_data_get_encoding (gpgme_data_t dh); + +/* Set the encoding attribute of data buffer DH to ENC */ +gpgme_error_t gpgme_data_set_encoding (gpgme_data_t dh, + gpgme_data_encoding_t enc); + +/* Get the file name associated with the data object with handle DH, or + NULL if there is none. */ +char *gpgme_data_get_file_name (gpgme_data_t dh); + +/* Set the file name associated with the data object with handle DH to + FILE_NAME. */ +gpgme_error_t gpgme_data_set_file_name (gpgme_data_t dh, + const char *file_name); + + +/* Create a new data buffer which retrieves the data from the callback + function READ_CB. Deprecated, please use gpgme_data_new_from_cbs + instead. */ +gpgme_error_t gpgme_data_new_with_read_cb (gpgme_data_t *r_dh, + int (*read_cb) (void*,char *, + size_t,size_t*), + void *read_cb_value) + _GPGME_DEPRECATED; + +/* Create a new data buffer filled with the content of file FNAME. + COPY must be non-zero. For delayed read, please use + gpgme_data_new_from_fd or gpgme_data_new_from stream instead. */ +gpgme_error_t gpgme_data_new_from_file (gpgme_data_t *r_dh, + const char *fname, + int copy); + +/* Create a new data buffer filled with LENGTH bytes starting from + OFFSET within the file FNAME or stream FP (exactly one must be + non-zero). */ +gpgme_error_t gpgme_data_new_from_filepart (gpgme_data_t *r_dh, + const char *fname, FILE *fp, + off_t offset, size_t length); + +/* Reset the read pointer in DH. Deprecated, please use + gpgme_data_seek instead. */ +gpgme_error_t gpgme_data_rewind (gpgme_data_t dh) _GPGME_DEPRECATED; + + +/* Key and trust functions. */ + +/* Get the key with the fingerprint FPR from the crypto backend. If + SECRET is true, get the secret key. */ +gpgme_error_t gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, + gpgme_key_t *r_key, int secret); + +/* Acquire a reference to KEY. */ +void gpgme_key_ref (gpgme_key_t key); + +/* Release a reference to KEY. If this was the last one the key is + destroyed. */ +void gpgme_key_unref (gpgme_key_t key); +void gpgme_key_release (gpgme_key_t key); + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by a string. IDX specifies the sub key or user ID + for attributes related to sub keys or user IDs. Deprecated, use + key structure directly instead. */ +const char *gpgme_key_get_string_attr (gpgme_key_t key, _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by an unsigned integer. IDX specifies the sub key or + user ID for attributes related to sub keys or user IDs. + Deprecated, use key structure directly instead. */ +unsigned long gpgme_key_get_ulong_attr (gpgme_key_t key, _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + +/* Return the value of the attribute WHAT of a signature on user ID + UID_IDX in KEY, which has to be representable by a string. IDX + specifies the signature. Deprecated, use key structure directly + instead. */ +const char *gpgme_key_sig_get_string_attr (gpgme_key_t key, int uid_idx, + _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + +/* Return the value of the attribute WHAT of a signature on user ID + UID_IDX in KEY, which has to be representable by an unsigned + integer string. IDX specifies the signature. Deprecated, use key + structure directly instead. */ +unsigned long gpgme_key_sig_get_ulong_attr (gpgme_key_t key, int uid_idx, + _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + + +/* Crypto Operations. */ + +/* Cancel a pending asynchronous operation. */ +gpgme_error_t gpgme_cancel (gpgme_ctx_t ctx); + +/* Cancel a pending operation asynchronously. */ +gpgme_error_t gpgme_cancel_async (gpgme_ctx_t ctx); + + +struct _gpgme_invalid_key +{ + struct _gpgme_invalid_key *next; + char *fpr; + gpgme_error_t reason; +}; +typedef struct _gpgme_invalid_key *gpgme_invalid_key_t; + + +/* Encryption. */ +struct _gpgme_op_encrypt_result +{ + /* The list of invalid recipients. */ + gpgme_invalid_key_t invalid_recipients; +}; +typedef struct _gpgme_op_encrypt_result *gpgme_encrypt_result_t; + +/* Retrieve a pointer to the result of the encrypt operation. */ +gpgme_encrypt_result_t gpgme_op_encrypt_result (gpgme_ctx_t ctx); + +/* The valid encryption flags. */ +typedef enum + { + GPGME_ENCRYPT_ALWAYS_TRUST = 1, + GPGME_ENCRYPT_NO_ENCRYPT_TO = 2, + GPGME_ENCRYPT_PREPARE = 4, + GPGME_ENCRYPT_EXPECT_SIGN = 8 + } +gpgme_encrypt_flags_t; + +/* Encrypt plaintext PLAIN within CTX for the recipients RECP and + store the resulting ciphertext in CIPHER. */ +gpgme_error_t gpgme_op_encrypt_start (gpgme_ctx_t ctx, gpgme_key_t recp[], + gpgme_encrypt_flags_t flags, + gpgme_data_t plain, gpgme_data_t cipher); +gpgme_error_t gpgme_op_encrypt (gpgme_ctx_t ctx, gpgme_key_t recp[], + gpgme_encrypt_flags_t flags, + gpgme_data_t plain, gpgme_data_t cipher); + +/* Encrypt plaintext PLAIN within CTX for the recipients RECP and + store the resulting ciphertext in CIPHER. Also sign the ciphertext + with the signers in CTX. */ +gpgme_error_t gpgme_op_encrypt_sign_start (gpgme_ctx_t ctx, + gpgme_key_t recp[], + gpgme_encrypt_flags_t flags, + gpgme_data_t plain, + gpgme_data_t cipher); +gpgme_error_t gpgme_op_encrypt_sign (gpgme_ctx_t ctx, gpgme_key_t recp[], + gpgme_encrypt_flags_t flags, + gpgme_data_t plain, gpgme_data_t cipher); + + +/* Decryption. */ + +struct _gpgme_recipient +{ + struct _gpgme_recipient *next; + + /* The key ID of key for which the text was encrypted. */ + char *keyid; + + /* Internal to GPGME, do not use. */ + char _keyid[16 + 1]; + + /* The public key algorithm of the recipient key. */ + gpgme_pubkey_algo_t pubkey_algo; + + /* The status of the recipient. */ + gpgme_error_t status; +}; +typedef struct _gpgme_recipient *gpgme_recipient_t; + +struct _gpgme_op_decrypt_result +{ + char *unsupported_algorithm; + + /* Key should not have been used for encryption. */ + unsigned int wrong_key_usage : 1; + + /* Internal to GPGME, do not use. */ + int _unused : 31; + + gpgme_recipient_t recipients; + + /* The original file name of the plaintext message, if + available. */ + char *file_name; +}; +typedef struct _gpgme_op_decrypt_result *gpgme_decrypt_result_t; + +/* Retrieve a pointer to the result of the decrypt operation. */ +gpgme_decrypt_result_t gpgme_op_decrypt_result (gpgme_ctx_t ctx); + +/* Decrypt ciphertext CIPHER within CTX and store the resulting + plaintext in PLAIN. */ +gpgme_error_t gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher, + gpgme_data_t plain); +gpgme_error_t gpgme_op_decrypt (gpgme_ctx_t ctx, + gpgme_data_t cipher, gpgme_data_t plain); + +/* Decrypt ciphertext CIPHER and make a signature verification within + CTX and store the resulting plaintext in PLAIN. */ +gpgme_error_t gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, + gpgme_data_t cipher, + gpgme_data_t plain); +gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher, + gpgme_data_t plain); + + +/* Signing. */ +struct _gpgme_new_signature +{ + struct _gpgme_new_signature *next; + + /* The type of the signature. */ + gpgme_sig_mode_t type; + + /* The public key algorithm used to create the signature. */ + gpgme_pubkey_algo_t pubkey_algo; + + /* The hash algorithm used to create the signature. */ + gpgme_hash_algo_t hash_algo; + + /* Internal to GPGME, do not use. Must be set to the same value as + CLASS below. */ + unsigned long _obsolete_class; + + /* Signature creation time. */ + long int timestamp; + + /* The fingerprint of the signature. */ + char *fpr; + +#ifdef __cplusplus + unsigned int _obsolete_class_2; +#else + /* Must be set to SIG_CLASS below. */ + unsigned int class _GPGME_DEPRECATED_OUTSIDE_GPGME; +#endif + + /* Crypto backend specific signature class. */ + unsigned int sig_class; +}; +typedef struct _gpgme_new_signature *gpgme_new_signature_t; + +struct _gpgme_op_sign_result +{ + /* The list of invalid signers. */ + gpgme_invalid_key_t invalid_signers; + gpgme_new_signature_t signatures; +}; +typedef struct _gpgme_op_sign_result *gpgme_sign_result_t; + +/* Retrieve a pointer to the result of the signing operation. */ +gpgme_sign_result_t gpgme_op_sign_result (gpgme_ctx_t ctx); + +/* Sign the plaintext PLAIN and store the signature in SIG. */ +gpgme_error_t gpgme_op_sign_start (gpgme_ctx_t ctx, + gpgme_data_t plain, gpgme_data_t sig, + gpgme_sig_mode_t mode); +gpgme_error_t gpgme_op_sign (gpgme_ctx_t ctx, + gpgme_data_t plain, gpgme_data_t sig, + gpgme_sig_mode_t mode); + + +/* Verify. */ + +/* Flags used for the SUMMARY field in a gpgme_signature_t. */ +typedef enum + { + GPGME_SIGSUM_VALID = 0x0001, /* The signature is fully valid. */ + GPGME_SIGSUM_GREEN = 0x0002, /* The signature is good. */ + GPGME_SIGSUM_RED = 0x0004, /* The signature is bad. */ + GPGME_SIGSUM_KEY_REVOKED = 0x0010, /* One key has been revoked. */ + GPGME_SIGSUM_KEY_EXPIRED = 0x0020, /* One key has expired. */ + GPGME_SIGSUM_SIG_EXPIRED = 0x0040, /* The signature has expired. */ + GPGME_SIGSUM_KEY_MISSING = 0x0080, /* Can't verify: key missing. */ + GPGME_SIGSUM_CRL_MISSING = 0x0100, /* CRL not available. */ + GPGME_SIGSUM_CRL_TOO_OLD = 0x0200, /* Available CRL is too old. */ + GPGME_SIGSUM_BAD_POLICY = 0x0400, /* A policy was not met. */ + GPGME_SIGSUM_SYS_ERROR = 0x0800 /* A system error occured. */ + } +gpgme_sigsum_t; + +struct _gpgme_signature +{ + struct _gpgme_signature *next; + + /* A summary of the signature status. */ + gpgme_sigsum_t summary; + + /* The fingerprint or key ID of the signature. */ + char *fpr; + + /* The status of the signature. */ + gpgme_error_t status; + + /* Notation data and policy URLs. */ + gpgme_sig_notation_t notations; + + /* Signature creation time. */ + unsigned long timestamp; + + /* Signature exipration time or 0. */ + unsigned long exp_timestamp; + + /* Key should not have been used for signing. */ + unsigned int wrong_key_usage : 1; + + /* PKA status: 0 = not available, 1 = bad, 2 = okay, 3 = RFU. */ + unsigned int pka_trust : 2; + + /* Validity has been verified using the chain model. */ + unsigned int chain_model : 1; + + /* Internal to GPGME, do not use. */ + int _unused : 28; + + gpgme_validity_t validity; + gpgme_error_t validity_reason; + + /* The public key algorithm used to create the signature. */ + gpgme_pubkey_algo_t pubkey_algo; + + /* The hash algorithm used to create the signature. */ + gpgme_hash_algo_t hash_algo; + + /* The mailbox from the PKA information or NULL. */ + char *pka_address; +}; +typedef struct _gpgme_signature *gpgme_signature_t; + +struct _gpgme_op_verify_result +{ + gpgme_signature_t signatures; + + /* The original file name of the plaintext message, if + available. */ + char *file_name; +}; +typedef struct _gpgme_op_verify_result *gpgme_verify_result_t; + +/* Retrieve a pointer to the result of the verify operation. */ +gpgme_verify_result_t gpgme_op_verify_result (gpgme_ctx_t ctx); + +/* Verify within CTX that SIG is a valid signature for TEXT. */ +gpgme_error_t gpgme_op_verify_start (gpgme_ctx_t ctx, gpgme_data_t sig, + gpgme_data_t signed_text, + gpgme_data_t plaintext); +gpgme_error_t gpgme_op_verify (gpgme_ctx_t ctx, gpgme_data_t sig, + gpgme_data_t signed_text, + gpgme_data_t plaintext); + + +/* Import. */ + +/* The key was new. */ +#define GPGME_IMPORT_NEW 1 + +/* The key contained new user IDs. */ +#define GPGME_IMPORT_UID 2 + +/* The key contained new signatures. */ +#define GPGME_IMPORT_SIG 4 + +/* The key contained new sub keys. */ +#define GPGME_IMPORT_SUBKEY 8 + +/* The key contained a secret key. */ +#define GPGME_IMPORT_SECRET 16 + + +struct _gpgme_import_status +{ + struct _gpgme_import_status *next; + + /* Fingerprint. */ + char *fpr; + + /* If a problem occured, the reason why the key could not be + imported. Otherwise GPGME_No_Error. */ + gpgme_error_t result; + + /* The result of the import, the GPGME_IMPORT_* values bit-wise + ORed. 0 means the key was already known and no new components + have been added. */ + unsigned int status; +}; +typedef struct _gpgme_import_status *gpgme_import_status_t; + +/* Import. */ +struct _gpgme_op_import_result +{ + /* Number of considered keys. */ + int considered; + + /* Keys without user ID. */ + int no_user_id; + + /* Imported keys. */ + int imported; + + /* Imported RSA keys. */ + int imported_rsa; + + /* Unchanged keys. */ + int unchanged; + + /* Number of new user ids. */ + int new_user_ids; + + /* Number of new sub keys. */ + int new_sub_keys; + + /* Number of new signatures. */ + int new_signatures; + + /* Number of new revocations. */ + int new_revocations; + + /* Number of secret keys read. */ + int secret_read; + + /* Number of secret keys imported. */ + int secret_imported; + + /* Number of secret keys unchanged. */ + int secret_unchanged; + + /* Number of new keys skipped. */ + int skipped_new_keys; + + /* Number of keys not imported. */ + int not_imported; + + /* List of keys for which an import was attempted. */ + gpgme_import_status_t imports; +}; +typedef struct _gpgme_op_import_result *gpgme_import_result_t; + +/* Retrieve a pointer to the result of the import operation. */ +gpgme_import_result_t gpgme_op_import_result (gpgme_ctx_t ctx); + +/* Import the key in KEYDATA into the keyring. */ +gpgme_error_t gpgme_op_import_start (gpgme_ctx_t ctx, gpgme_data_t keydata); +gpgme_error_t gpgme_op_import (gpgme_ctx_t ctx, gpgme_data_t keydata); +gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t ctx, gpgme_data_t keydata, + int *nr) _GPGME_DEPRECATED; + +/* Import the keys from the array KEYS into the keyring. */ +gpgme_error_t gpgme_op_import_keys_start (gpgme_ctx_t ctx, gpgme_key_t keys[]); +gpgme_error_t gpgme_op_import_keys (gpgme_ctx_t ctx, gpgme_key_t keys[]); + + + +/* Export the keys found by PATTERN into KEYDATA. */ +gpgme_error_t gpgme_op_export_start (gpgme_ctx_t ctx, const char *pattern, + gpgme_export_mode_t mode, + gpgme_data_t keydata); +gpgme_error_t gpgme_op_export (gpgme_ctx_t ctx, const char *pattern, + gpgme_export_mode_t mode, + gpgme_data_t keydata); + +gpgme_error_t gpgme_op_export_ext_start (gpgme_ctx_t ctx, + const char *pattern[], + gpgme_export_mode_t mode, + gpgme_data_t keydata); +gpgme_error_t gpgme_op_export_ext (gpgme_ctx_t ctx, const char *pattern[], + gpgme_export_mode_t mode, + gpgme_data_t keydata); + +/* Export the keys from the array KEYS into KEYDATA. */ +gpgme_error_t gpgme_op_export_keys_start (gpgme_ctx_t ctx, + gpgme_key_t keys[], + gpgme_export_mode_t mode, + gpgme_data_t keydata); +gpgme_error_t gpgme_op_export_keys (gpgme_ctx_t ctx, + gpgme_key_t keys[], + gpgme_export_mode_t mode, + gpgme_data_t keydata); + + + +/* Key generation. */ +struct _gpgme_op_genkey_result +{ + /* A primary key was generated. */ + unsigned int primary : 1; + + /* A sub key was generated. */ + unsigned int sub : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 30; + + /* The fingerprint of the generated key. */ + char *fpr; +}; +typedef struct _gpgme_op_genkey_result *gpgme_genkey_result_t; + +/* Generate a new keypair and add it to the keyring. PUBKEY and + SECKEY should be null for now. PARMS specifies what keys should be + generated. */ +gpgme_error_t gpgme_op_genkey_start (gpgme_ctx_t ctx, const char *parms, + gpgme_data_t pubkey, gpgme_data_t seckey); +gpgme_error_t gpgme_op_genkey (gpgme_ctx_t ctx, const char *parms, + gpgme_data_t pubkey, gpgme_data_t seckey); + +/* Retrieve a pointer to the result of the genkey operation. */ +gpgme_genkey_result_t gpgme_op_genkey_result (gpgme_ctx_t ctx); + + +/* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret + keys are also deleted. */ +gpgme_error_t gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key, + int allow_secret); +gpgme_error_t gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key, + int allow_secret); + + +/* Edit the key KEY. Send status and command requests to FNC and + output of edit commands to OUT. */ +gpgme_error_t gpgme_op_edit_start (gpgme_ctx_t ctx, gpgme_key_t key, + gpgme_edit_cb_t fnc, void *fnc_value, + gpgme_data_t out); +gpgme_error_t gpgme_op_edit (gpgme_ctx_t ctx, gpgme_key_t key, + gpgme_edit_cb_t fnc, void *fnc_value, + gpgme_data_t out); + +/* Edit the card for the key KEY. Send status and command requests to + FNC and output of edit commands to OUT. */ +gpgme_error_t gpgme_op_card_edit_start (gpgme_ctx_t ctx, gpgme_key_t key, + gpgme_edit_cb_t fnc, void *fnc_value, + gpgme_data_t out); +gpgme_error_t gpgme_op_card_edit (gpgme_ctx_t ctx, gpgme_key_t key, + gpgme_edit_cb_t fnc, void *fnc_value, + gpgme_data_t out); + + +/* Key management functions. */ +struct _gpgme_op_keylist_result +{ + unsigned int truncated : 1; + + /* Internal to GPGME, do not use. */ + unsigned int _unused : 31; +}; +typedef struct _gpgme_op_keylist_result *gpgme_keylist_result_t; + +/* Retrieve a pointer to the result of the key listing operation. */ +gpgme_keylist_result_t gpgme_op_keylist_result (gpgme_ctx_t ctx); + +/* Start a keylist operation within CTX, searching for keys which + match PATTERN. If SECRET_ONLY is true, only secret keys are + returned. */ +gpgme_error_t gpgme_op_keylist_start (gpgme_ctx_t ctx, const char *pattern, + int secret_only); +gpgme_error_t gpgme_op_keylist_ext_start (gpgme_ctx_t ctx, + const char *pattern[], + int secret_only, int reserved); + +/* Return the next key from the keylist in R_KEY. */ +gpgme_error_t gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key); + +/* Terminate a pending keylist operation within CTX. */ +gpgme_error_t gpgme_op_keylist_end (gpgme_ctx_t ctx); + +/* Change the passphrase for KEY. FLAGS is reserved for future use + and must be passed as 0. */ +gpgme_error_t gpgme_op_passwd_start (gpgme_ctx_t ctx, gpgme_key_t key, + unsigned int flags); +gpgme_error_t gpgme_op_passwd (gpgme_ctx_t ctx, gpgme_key_t key, + unsigned int flags); + + + +/* Trust items and operations. */ + +struct _gpgme_trust_item +{ + /* Internal to GPGME, do not use. */ + unsigned int _refs; + + /* The key ID to which the trust item belongs. */ + char *keyid; + + /* Internal to GPGME, do not use. */ + char _keyid[16 + 1]; + + /* The type of the trust item, 1 refers to a key, 2 to a user ID. */ + int type; + + /* The trust level. */ + int level; + + /* The owner trust if TYPE is 1. */ + char *owner_trust; + + /* Internal to GPGME, do not use. */ + char _owner_trust[2]; + + /* The calculated validity. */ + char *validity; + + /* Internal to GPGME, do not use. */ + char _validity[2]; + + /* The user name if TYPE is 2. */ + char *name; +}; +typedef struct _gpgme_trust_item *gpgme_trust_item_t; + +/* Start a trustlist operation within CTX, searching for trust items + which match PATTERN. */ +gpgme_error_t gpgme_op_trustlist_start (gpgme_ctx_t ctx, + const char *pattern, int max_level); + +/* Return the next trust item from the trustlist in R_ITEM. */ +gpgme_error_t gpgme_op_trustlist_next (gpgme_ctx_t ctx, + gpgme_trust_item_t *r_item); + +/* Terminate a pending trustlist operation within CTX. */ +gpgme_error_t gpgme_op_trustlist_end (gpgme_ctx_t ctx); + +/* Acquire a reference to ITEM. */ +void gpgme_trust_item_ref (gpgme_trust_item_t item); + +/* Release a reference to ITEM. If this was the last one the trust + item is destroyed. */ +void gpgme_trust_item_unref (gpgme_trust_item_t item); + +/* Release the trust item ITEM. Deprecated, use + gpgme_trust_item_unref. */ +void gpgme_trust_item_release (gpgme_trust_item_t item) _GPGME_DEPRECATED; + +/* Return the value of the attribute WHAT of ITEM, which has to be + representable by a string. Deprecated, use trust item structure + directly. */ +const char *gpgme_trust_item_get_string_attr (gpgme_trust_item_t item, + _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + +/* Return the value of the attribute WHAT of KEY, which has to be + representable by an integer. IDX specifies a running index if the + attribute appears more than once in the key. Deprecated, use trust + item structure directly. */ +int gpgme_trust_item_get_int_attr (gpgme_trust_item_t item, _gpgme_attr_t what, + const void *reserved, int idx) + _GPGME_DEPRECATED; + + +/* Return the auditlog for the current session. This may be called + after a successful or failed operation. If no audit log is + available GPG_ERR_NO_DATA is returned. */ +gpgme_error_t gpgme_op_getauditlog_start (gpgme_ctx_t ctx, gpgme_data_t output, + unsigned int flags); +gpgme_error_t gpgme_op_getauditlog (gpgme_ctx_t ctx, gpgme_data_t output, + unsigned int flags); + + + +/* Low-level Assuan protocol access. */ +typedef gpgme_error_t (*gpgme_assuan_data_cb_t) + (void *opaque, const void *data, size_t datalen); + +typedef gpgme_error_t (*gpgme_assuan_inquire_cb_t) + (void *opaque, const char *name, const char *args, + gpgme_data_t *r_data); + +typedef gpgme_error_t (*gpgme_assuan_status_cb_t) + (void *opaque, const char *status, const char *args); + +/* Send the Assuan COMMAND and return results via the callbacks. + Asynchronous variant. */ +gpgme_error_t gpgme_op_assuan_transact_start (gpgme_ctx_t ctx, + const char *command, + gpgme_assuan_data_cb_t data_cb, + void *data_cb_value, + gpgme_assuan_inquire_cb_t inq_cb, + void *inq_cb_value, + gpgme_assuan_status_cb_t stat_cb, + void *stat_cb_value); + +/* Send the Assuan COMMAND and return results via the callbacks. + Synchronous variant. */ +gpgme_error_t gpgme_op_assuan_transact_ext (gpgme_ctx_t ctx, + const char *command, + gpgme_assuan_data_cb_t data_cb, + void *data_cb_value, + gpgme_assuan_inquire_cb_t inq_cb, + void *inq_cb_value, + gpgme_assuan_status_cb_t stat_cb, + void *stat_cb_value, + gpgme_error_t *op_err); + +/* Compat. */ +struct _gpgme_op_assuan_result +{ + /* Deprecated. Use the second value in a DONE event or the + synchronous variant gpgme_op_assuan_transact_ext. */ + gpgme_error_t err _GPGME_DEPRECATED_OUTSIDE_GPGME; +}; +typedef struct _gpgme_op_assuan_result *gpgme_assuan_result_t; + + +/* Return the result of the last Assuan command. */ +gpgme_assuan_result_t gpgme_op_assuan_result (gpgme_ctx_t ctx) + _GPGME_DEPRECATED; + +gpgme_error_t +gpgme_op_assuan_transact (gpgme_ctx_t ctx, + const char *command, + gpgme_assuan_data_cb_t data_cb, + void *data_cb_value, + gpgme_assuan_inquire_cb_t inq_cb, + void *inq_cb_value, + gpgme_assuan_status_cb_t status_cb, + void *status_cb_value) _GPGME_DEPRECATED; + + +/* Crypto container support. */ +struct _gpgme_op_vfs_mount_result +{ + char *mount_dir; +}; +typedef struct _gpgme_op_vfs_mount_result *gpgme_vfs_mount_result_t; + +gpgme_vfs_mount_result_t gpgme_op_vfs_mount_result (gpgme_ctx_t ctx); + +/* The container is automatically unmounted when the context is reset + or destroyed. Transmission errors are returned directly, + operational errors are returned in OP_ERR. */ +gpgme_error_t gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file, + const char *mount_dir, unsigned int flags, + gpgme_error_t *op_err); + +gpgme_error_t gpgme_op_vfs_create (gpgme_ctx_t ctx, gpgme_key_t recp[], + const char *container_file, + unsigned int flags, gpgme_error_t *op_err); + + +/* Interface to gpgconf(1). */ + +/* The expert level at which a configuration option or group of + options should be displayed. See the gpgconf(1) documentation for + more details. */ +typedef enum + { + GPGME_CONF_BASIC = 0, + GPGME_CONF_ADVANCED = 1, + GPGME_CONF_EXPERT = 2, + GPGME_CONF_INVISIBLE = 3, + GPGME_CONF_INTERNAL = 4 + } +gpgme_conf_level_t; + + +/* The data type of a configuration option argument. See the gpgconf(1) + documentation for more details. */ +typedef enum + { + /* Basic types. */ + GPGME_CONF_NONE = 0, + GPGME_CONF_STRING = 1, + GPGME_CONF_INT32 = 2, + GPGME_CONF_UINT32 = 3, + + /* Complex types. */ + GPGME_CONF_FILENAME = 32, + GPGME_CONF_LDAP_SERVER = 33, + GPGME_CONF_KEY_FPR = 34, + GPGME_CONF_PUB_KEY = 35, + GPGME_CONF_SEC_KEY = 36, + GPGME_CONF_ALIAS_LIST = 37 + } +gpgme_conf_type_t; + +/* For now, compatibility. */ +#define GPGME_CONF_PATHNAME GPGME_CONF_FILENAME + + +/* This represents a single argument for a configuration option. + Which of the members of value is used depends on the ALT_TYPE. */ +typedef struct gpgme_conf_arg +{ + struct gpgme_conf_arg *next; + /* True if the option appears without an (optional) argument. */ + unsigned int no_arg; + union + { + unsigned int count; + unsigned int uint32; + int int32; + char *string; + } value; +} *gpgme_conf_arg_t; + + +/* The flags of a configuration option. See the gpg-conf + documentation for details. */ +#define GPGME_CONF_GROUP (1 << 0) +#define GPGME_CONF_OPTIONAL (1 << 1) +#define GPGME_CONF_LIST (1 << 2) +#define GPGME_CONF_RUNTIME (1 << 3) +#define GPGME_CONF_DEFAULT (1 << 4) +#define GPGME_CONF_DEFAULT_DESC (1 << 5) +#define GPGME_CONF_NO_ARG_DESC (1 << 6) +#define GPGME_CONF_NO_CHANGE (1 << 7) + + +/* The representation of a single configuration option. See the + gpg-conf documentation for details. */ +typedef struct gpgme_conf_opt +{ + struct gpgme_conf_opt *next; + + /* The option name. */ + char *name; + + /* The flags for this option. */ + unsigned int flags; + + /* The level of this option. */ + gpgme_conf_level_t level; + + /* The localized description of this option. */ + char *description; + + /* The type and alternate type of this option. */ + gpgme_conf_type_t type; + gpgme_conf_type_t alt_type; + + /* The localized (short) name of the argument, if any. */ + char *argname; + + /* The default value. */ + gpgme_conf_arg_t default_value; + char *default_description; + + /* The default value if the option is not set. */ + gpgme_conf_arg_t no_arg_value; + char *no_arg_description; + + /* The current value if the option is set. */ + gpgme_conf_arg_t value; + + /* The new value, if any. NULL means reset to default. */ + int change_value; + gpgme_conf_arg_t new_value; + + /* Free for application use. */ + void *user_data; +} *gpgme_conf_opt_t; + + +/* The representation of a component that can be configured. See the + gpg-conf documentation for details. */ +typedef struct gpgme_conf_comp +{ + struct gpgme_conf_comp *next; + + /* Internal to GPGME, do not use! */ + gpgme_conf_opt_t *_last_opt_p; + + /* The component name. */ + char *name; + + /* A human-readable description for the component. */ + char *description; + + /* The program name (an absolute path to the program). */ + char *program_name; + + /* A linked list of options for this component. */ + struct gpgme_conf_opt *options; +} *gpgme_conf_comp_t; + + +/* Allocate a new gpgme_conf_arg_t. If VALUE is NULL, a "no arg + default" is prepared. If type is a string type, VALUE should point + to the string. Else, it should point to an unsigned or signed + integer respectively. */ +gpgme_error_t gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p, + gpgme_conf_type_t type, void *value); + +/* This also releases all chained argument structures! */ +void gpgme_conf_arg_release (gpgme_conf_arg_t arg, gpgme_conf_type_t type); + +/* Register a change for the value of OPT to ARG. If RESET is 1 (do + not use any values but 0 or 1), ARG is ignored and the option is + not changed (reverting a previous change). Otherwise, if ARG is + NULL, the option is cleared or reset to its default. */ +gpgme_error_t gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, + gpgme_conf_arg_t arg); + +/* Release a set of configurations. */ +void gpgme_conf_release (gpgme_conf_comp_t conf); + +/* Retrieve the current configurations. */ +gpgme_error_t gpgme_op_conf_load (gpgme_ctx_t ctx, gpgme_conf_comp_t *conf_p); + +/* Save the configuration of component comp. This function does not + follow chained components! */ +gpgme_error_t gpgme_op_conf_save (gpgme_ctx_t ctx, gpgme_conf_comp_t comp); + + +/* UIServer support. */ + +/* Create a dummy key to specify an email address. */ +gpgme_error_t gpgme_key_from_uid (gpgme_key_t *key, const char *name); + + + +/* Various functions. */ + +/* Check that the library fulfills the version requirement. Note: + This is here only for the case where a user takes a pointer from + the old version of this function. The new version and macro for + run-time checks are below. */ +const char *gpgme_check_version (const char *req_version); + +/* Check that the library fulfills the version requirement and check + for struct layout mismatch involving bitfields. */ +const char *gpgme_check_version_internal (const char *req_version, + size_t offset_sig_validity); + +#define gpgme_check_version(req_version) \ + gpgme_check_version_internal (req_version, \ + offsetof (struct _gpgme_signature, validity)) + +/* Get the information about the configured and installed engines. A + pointer to the first engine in the statically allocated linked list + is returned in *INFO. If an error occurs, it is returned. The + returned data is valid until the next gpgme_set_engine_info. */ +gpgme_error_t gpgme_get_engine_info (gpgme_engine_info_t *engine_info); + +/* Set the default engine info for the protocol PROTO to the file name + FILE_NAME and the home directory HOME_DIR. */ +gpgme_error_t gpgme_set_engine_info (gpgme_protocol_t proto, + const char *file_name, + const char *home_dir); + + +/* Engine support functions. */ + +/* Verify that the engine implementing PROTO is installed and + available. */ +gpgme_error_t gpgme_engine_check_version (gpgme_protocol_t proto); + + +void gpgme_result_ref (void *result); +void gpgme_result_unref (void *result); + + +/* Deprecated types. */ +typedef gpgme_ctx_t GpgmeCtx _GPGME_DEPRECATED; +typedef gpgme_data_t GpgmeData _GPGME_DEPRECATED; +typedef gpgme_error_t GpgmeError _GPGME_DEPRECATED; +typedef gpgme_data_encoding_t GpgmeDataEncoding _GPGME_DEPRECATED; +typedef gpgme_pubkey_algo_t GpgmePubKeyAlgo _GPGME_DEPRECATED; +typedef gpgme_hash_algo_t GpgmeHashAlgo _GPGME_DEPRECATED; +typedef gpgme_sig_stat_t GpgmeSigStat _GPGME_DEPRECATED; +typedef gpgme_sig_mode_t GpgmeSigMode _GPGME_DEPRECATED; +typedef gpgme_attr_t GpgmeAttr _GPGME_DEPRECATED; +typedef gpgme_validity_t GpgmeValidity _GPGME_DEPRECATED; +typedef gpgme_protocol_t GpgmeProtocol _GPGME_DEPRECATED; +typedef gpgme_engine_info_t GpgmeEngineInfo _GPGME_DEPRECATED; +typedef gpgme_subkey_t GpgmeSubkey _GPGME_DEPRECATED; +typedef gpgme_key_sig_t GpgmeKeySig _GPGME_DEPRECATED; +typedef gpgme_user_id_t GpgmeUserID _GPGME_DEPRECATED; +typedef gpgme_key_t GpgmeKey _GPGME_DEPRECATED; +typedef gpgme_passphrase_cb_t GpgmePassphraseCb _GPGME_DEPRECATED; +typedef gpgme_progress_cb_t GpgmeProgressCb _GPGME_DEPRECATED; +typedef gpgme_io_cb_t GpgmeIOCb _GPGME_DEPRECATED; +typedef gpgme_register_io_cb_t GpgmeRegisterIOCb _GPGME_DEPRECATED; +typedef gpgme_remove_io_cb_t GpgmeRemoveIOCb _GPGME_DEPRECATED; +typedef gpgme_event_io_t GpgmeEventIO _GPGME_DEPRECATED; +typedef gpgme_event_io_cb_t GpgmeEventIOCb _GPGME_DEPRECATED; +#define GpgmeIOCbs gpgme_io_cbs +typedef gpgme_data_read_cb_t GpgmeDataReadCb _GPGME_DEPRECATED; +typedef gpgme_data_write_cb_t GpgmeDataWriteCb _GPGME_DEPRECATED; +typedef gpgme_data_seek_cb_t GpgmeDataSeekCb _GPGME_DEPRECATED; +typedef gpgme_data_release_cb_t GpgmeDataReleaseCb _GPGME_DEPRECATED; +#define GpgmeDataCbs gpgme_data_cbs +typedef gpgme_encrypt_result_t GpgmeEncryptResult _GPGME_DEPRECATED; +typedef gpgme_sig_notation_t GpgmeSigNotation _GPGME_DEPRECATED; +typedef gpgme_signature_t GpgmeSignature _GPGME_DEPRECATED; +typedef gpgme_verify_result_t GpgmeVerifyResult _GPGME_DEPRECATED; +typedef gpgme_import_status_t GpgmeImportStatus _GPGME_DEPRECATED; +typedef gpgme_import_result_t GpgmeImportResult _GPGME_DEPRECATED; +typedef gpgme_genkey_result_t GpgmeGenKeyResult _GPGME_DEPRECATED; +typedef gpgme_trust_item_t GpgmeTrustItem _GPGME_DEPRECATED; +typedef gpgme_status_code_t GpgmeStatusCode _GPGME_DEPRECATED; + +#ifdef __cplusplus +} +#endif +#endif /* GPGME_H */ @@ -0,0 +1,526 @@ +/* ksba.h - X509 library for the Aegypten project + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 g10 Code GmbH + * + * This file is part of KSBA. + * + * KSBA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * KSBA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef KSBA_H +#define KSBA_H 1 + +#include <gpg-error.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#if 0 + } +#endif +#endif + + +/* Check for compiler features. */ +#ifdef __GNUC__ +#define _KSBA_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) +#if _KSBA_GCC_VERSION > 30100 +#define _KSBA_DEPRECATED __attribute__ ((__deprecated__)) +#endif +#endif /*__GNUC__*/ + +#ifndef _KSBA_DEPRECATED +#define _KSBA_DEPRECATED +#endif + + +typedef gpg_error_t KsbaError _KSBA_DEPRECATED; + +typedef enum + { + KSBA_CT_NONE = 0, + KSBA_CT_DATA = 1, + KSBA_CT_SIGNED_DATA = 2, + KSBA_CT_ENVELOPED_DATA = 3, + KSBA_CT_DIGESTED_DATA = 4, + KSBA_CT_ENCRYPTED_DATA = 5, + KSBA_CT_AUTH_DATA = 6, + KSBA_CT_PKCS12 = 7 + } +ksba_content_type_t; +typedef ksba_content_type_t KsbaContentType _KSBA_DEPRECATED; + + + +typedef enum + { + KSBA_SR_NONE = 0, /* Never seen by libksba user. */ + KSBA_SR_RUNNING = 1, /* Never seen by libksba user. */ + KSBA_SR_GOT_CONTENT = 2, + KSBA_SR_NEED_HASH = 3, + KSBA_SR_BEGIN_DATA = 4, + KSBA_SR_END_DATA = 5, + KSBA_SR_READY = 6, + KSBA_SR_NEED_SIG = 7, + KSBA_SR_DETACHED_DATA = 8, + KSBA_SR_BEGIN_ITEMS = 9, + KSBA_SR_GOT_ITEM = 10, + KSBA_SR_END_ITEMS = 11 + } +ksba_stop_reason_t; +typedef ksba_stop_reason_t KsbaStopReason _KSBA_DEPRECATED; + +typedef enum + { + KSBA_CRLREASON_UNSPECIFIED = 1, + KSBA_CRLREASON_KEY_COMPROMISE = 2, + KSBA_CRLREASON_CA_COMPROMISE = 4, + KSBA_CRLREASON_AFFILIATION_CHANGED = 8, + KSBA_CRLREASON_SUPERSEDED = 16, + KSBA_CRLREASON_CESSATION_OF_OPERATION = 32, + KSBA_CRLREASON_CERTIFICATE_HOLD = 64, + KSBA_CRLREASON_REMOVE_FROM_CRL = 256, + KSBA_CRLREASON_PRIVILEGE_WITHDRAWN = 512, + KSBA_CRLREASON_AA_COMPROMISE = 1024, + KSBA_CRLREASON_OTHER = 32768 + } +ksba_crl_reason_t; +typedef ksba_crl_reason_t KsbaCRLReason _KSBA_DEPRECATED; + +typedef enum + { + KSBA_OCSP_RSPSTATUS_SUCCESS = 0, + KSBA_OCSP_RSPSTATUS_MALFORMED = 1, + KSBA_OCSP_RSPSTATUS_INTERNAL = 2, + KSBA_OCSP_RSPSTATUS_TRYLATER = 3, + KSBA_OCSP_RSPSTATUS_SIGREQUIRED = 5, + KSBA_OCSP_RSPSTATUS_UNAUTHORIZED = 6, + KSBA_OCSP_RSPSTATUS_REPLAYED = 253, + KSBA_OCSP_RSPSTATUS_OTHER = 254, + KSBA_OCSP_RSPSTATUS_NONE = 255 + } +ksba_ocsp_response_status_t; + +typedef enum + { + KSBA_STATUS_NONE = 0, + KSBA_STATUS_UNKNOWN = 1, + KSBA_STATUS_GOOD = 2, + KSBA_STATUS_REVOKED = 4 + } +ksba_status_t; + + +typedef enum + { + KSBA_KEYUSAGE_DIGITAL_SIGNATURE = 1, + KSBA_KEYUSAGE_NON_REPUDIATION = 2, + KSBA_KEYUSAGE_KEY_ENCIPHERMENT = 4, + KSBA_KEYUSAGE_DATA_ENCIPHERMENT = 8, + KSBA_KEYUSAGE_KEY_AGREEMENT = 16, + KSBA_KEYUSAGE_KEY_CERT_SIGN = 32, + KSBA_KEYUSAGE_CRL_SIGN = 64, + KSBA_KEYUSAGE_ENCIPHER_ONLY = 128, + KSBA_KEYUSAGE_DECIPHER_ONLY = 256 + } +ksba_key_usage_t; +typedef ksba_key_usage_t KsbaKeyUsage _KSBA_DEPRECATED; + +/* ISO format, e.g. "19610711T172059", assumed to be UTC. */ +typedef char ksba_isotime_t[16]; + + +/* X.509 certificates are represented by this object. + ksba_cert_new() creates such an object */ +struct ksba_cert_s; +typedef struct ksba_cert_s *ksba_cert_t; +typedef struct ksba_cert_s *KsbaCert _KSBA_DEPRECATED; + +/* CMS objects are controlled by this object. + ksba_cms_new() creates it */ +struct ksba_cms_s; +typedef struct ksba_cms_s *ksba_cms_t; +typedef struct ksba_cms_s *KsbaCMS _KSBA_DEPRECATED; + +/* CRL objects are controlled by this object. + ksba_crl_new() creates it */ +struct ksba_crl_s; +typedef struct ksba_crl_s *ksba_crl_t; +typedef struct ksba_crl_s *KsbaCRL _KSBA_DEPRECATED; + +/* OCSP objects are controlled by this object. + ksba_ocsp_new() creates it. */ +struct ksba_ocsp_s; +typedef struct ksba_ocsp_s *ksba_ocsp_t; + +/* PKCS-10 creation is controlled by this object. + ksba_certreq_new() creates it */ +struct ksba_certreq_s; +typedef struct ksba_certreq_s *ksba_certreq_t; +typedef struct ksba_certreq_s *KsbaCertreq _KSBA_DEPRECATED; + +/* This is a reader object for various purposes + see ksba_reader_new et al. */ +struct ksba_reader_s; +typedef struct ksba_reader_s *ksba_reader_t; +typedef struct ksba_reader_s *KsbaReader _KSBA_DEPRECATED; + +/* This is a writer object for various purposes + see ksba_writer_new et al. */ +struct ksba_writer_s; +typedef struct ksba_writer_s *ksba_writer_t; +typedef struct ksba_writer_s *KsbaWriter _KSBA_DEPRECATED; + +/* This is an object to store an ASN.1 parse tree as + create by ksba_asn_parse_file() */ +struct ksba_asn_tree_s; +typedef struct ksba_asn_tree_s *ksba_asn_tree_t; +typedef struct ksba_asn_tree_s *KsbaAsnTree _KSBA_DEPRECATED; + +/* This is an object to reference a General Name. Such an object is + returned by several functions. */ +struct ksba_name_s; +typedef struct ksba_name_s *ksba_name_t; +typedef struct ksba_name_s *KsbaName _KSBA_DEPRECATED; + +/* KsbaSexp is just an unsigned char * which should be used for + documentation purpose. The S-expressions returned by libksba are + always in canonical representation with an extra 0 byte at the end, + so that one can print the values in the debugger and at least see + the first bytes */ +typedef unsigned char *ksba_sexp_t; +typedef unsigned char *KsbaSexp _KSBA_DEPRECATED; +typedef const unsigned char *ksba_const_sexp_t; +typedef const unsigned char *KsbaConstSexp _KSBA_DEPRECATED; + + +/*-- cert.c --*/ +gpg_error_t ksba_cert_new (ksba_cert_t *acert); +void ksba_cert_ref (ksba_cert_t cert); +void ksba_cert_release (ksba_cert_t cert); +gpg_error_t ksba_cert_set_user_data (ksba_cert_t cert, const char *key, + const void *data, size_t datalen); +gpg_error_t ksba_cert_get_user_data (ksba_cert_t cert, const char *key, + void *buffer, size_t bufferlen, + size_t *datalen); + +gpg_error_t ksba_cert_read_der (ksba_cert_t cert, ksba_reader_t reader); +gpg_error_t ksba_cert_init_from_mem (ksba_cert_t cert, + const void *buffer, size_t length); +const unsigned char *ksba_cert_get_image (ksba_cert_t cert, size_t *r_length); +gpg_error_t ksba_cert_hash (ksba_cert_t cert, + int what, + void (*hasher)(void *, + const void *, + size_t length), + void *hasher_arg); +const char *ksba_cert_get_digest_algo (ksba_cert_t cert); +ksba_sexp_t ksba_cert_get_serial (ksba_cert_t cert); +char *ksba_cert_get_issuer (ksba_cert_t cert, int idx); +gpg_error_t ksba_cert_get_validity (ksba_cert_t cert, int what, + ksba_isotime_t r_time); +char *ksba_cert_get_subject (ksba_cert_t cert, int idx); +ksba_sexp_t ksba_cert_get_public_key (ksba_cert_t cert); +ksba_sexp_t ksba_cert_get_sig_val (ksba_cert_t cert); + +gpg_error_t ksba_cert_get_extension (ksba_cert_t cert, int idx, + char const **r_oid, int *r_crit, + size_t *r_deroff, size_t *r_derlen); + +gpg_error_t ksba_cert_is_ca (ksba_cert_t cert, int *r_ca, int *r_pathlen); +gpg_error_t ksba_cert_get_key_usage (ksba_cert_t cert, unsigned int *r_flags); +gpg_error_t ksba_cert_get_cert_policies (ksba_cert_t cert, char **r_policies); +gpg_error_t ksba_cert_get_ext_key_usages (ksba_cert_t cert, char **result); +gpg_error_t ksba_cert_get_crl_dist_point (ksba_cert_t cert, int idx, + ksba_name_t *r_distpoint, + ksba_name_t *r_issuer, + ksba_crl_reason_t *r_reason); +gpg_error_t ksba_cert_get_auth_key_id (ksba_cert_t cert, + ksba_sexp_t *r_keyid, + ksba_name_t *r_name, + ksba_sexp_t *r_serial); +gpg_error_t ksba_cert_get_subj_key_id (ksba_cert_t cert, + int *r_crit, + ksba_sexp_t *r_keyid); +gpg_error_t ksba_cert_get_authority_info_access (ksba_cert_t cert, int idx, + char **r_method, + ksba_name_t *r_location); +gpg_error_t ksba_cert_get_subject_info_access (ksba_cert_t cert, int idx, + char **r_method, + ksba_name_t *r_location); + + +/*-- cms.c --*/ +ksba_content_type_t ksba_cms_identify (ksba_reader_t reader); + +gpg_error_t ksba_cms_new (ksba_cms_t *r_cms); +void ksba_cms_release (ksba_cms_t cms); +gpg_error_t ksba_cms_set_reader_writer (ksba_cms_t cms, + ksba_reader_t r, ksba_writer_t w); + +gpg_error_t ksba_cms_parse (ksba_cms_t cms, ksba_stop_reason_t *r_stopreason); +gpg_error_t ksba_cms_build (ksba_cms_t cms, ksba_stop_reason_t *r_stopreason); + +ksba_content_type_t ksba_cms_get_content_type (ksba_cms_t cms, int what); +const char *ksba_cms_get_content_oid (ksba_cms_t cms, int what); +gpg_error_t ksba_cms_get_content_enc_iv (ksba_cms_t cms, void *iv, + size_t maxivlen, size_t *ivlen); +const char *ksba_cms_get_digest_algo_list (ksba_cms_t cms, int idx); +gpg_error_t ksba_cms_get_issuer_serial (ksba_cms_t cms, int idx, + char **r_issuer, + ksba_sexp_t *r_serial); +const char *ksba_cms_get_digest_algo (ksba_cms_t cms, int idx); +ksba_cert_t ksba_cms_get_cert (ksba_cms_t cms, int idx); +gpg_error_t ksba_cms_get_message_digest (ksba_cms_t cms, int idx, + char **r_digest, size_t *r_digest_len); +gpg_error_t ksba_cms_get_signing_time (ksba_cms_t cms, int idx, + ksba_isotime_t r_sigtime); +gpg_error_t ksba_cms_get_sigattr_oids (ksba_cms_t cms, int idx, + const char *reqoid, char **r_value); +ksba_sexp_t ksba_cms_get_sig_val (ksba_cms_t cms, int idx); +ksba_sexp_t ksba_cms_get_enc_val (ksba_cms_t cms, int idx); + +void ksba_cms_set_hash_function (ksba_cms_t cms, + void (*hash_fnc)(void *, const void *, size_t), + void *hash_fnc_arg); + +gpg_error_t ksba_cms_hash_signed_attrs (ksba_cms_t cms, int idx); + + +gpg_error_t ksba_cms_set_content_type (ksba_cms_t cms, int what, + ksba_content_type_t type); +gpg_error_t ksba_cms_add_digest_algo (ksba_cms_t cms, const char *oid); +gpg_error_t ksba_cms_add_signer (ksba_cms_t cms, ksba_cert_t cert); +gpg_error_t ksba_cms_add_cert (ksba_cms_t cms, ksba_cert_t cert); +gpg_error_t ksba_cms_add_smime_capability (ksba_cms_t cms, const char *oid, + const unsigned char *der, + size_t derlen); +gpg_error_t ksba_cms_set_message_digest (ksba_cms_t cms, int idx, + const unsigned char *digest, + size_t digest_len); +gpg_error_t ksba_cms_set_signing_time (ksba_cms_t cms, int idx, + const ksba_isotime_t sigtime); +gpg_error_t ksba_cms_set_sig_val (ksba_cms_t cms, + int idx, ksba_const_sexp_t sigval); + +gpg_error_t ksba_cms_set_content_enc_algo (ksba_cms_t cms, + const char *oid, + const void *iv, + size_t ivlen); +gpg_error_t ksba_cms_add_recipient (ksba_cms_t cms, ksba_cert_t cert); +gpg_error_t ksba_cms_set_enc_val (ksba_cms_t cms, + int idx, ksba_const_sexp_t encval); + + +/*-- crl.c --*/ +gpg_error_t ksba_crl_new (ksba_crl_t *r_crl); +void ksba_crl_release (ksba_crl_t crl); +gpg_error_t ksba_crl_set_reader (ksba_crl_t crl, ksba_reader_t r); +void ksba_crl_set_hash_function (ksba_crl_t crl, + void (*hash_fnc)(void *, + const void *, size_t), + void *hash_fnc_arg); +const char *ksba_crl_get_digest_algo (ksba_crl_t crl); +gpg_error_t ksba_crl_get_issuer (ksba_crl_t crl, char **r_issuer); +gpg_error_t ksba_crl_get_extension (ksba_crl_t crl, int idx, + char const **oid, int *critical, + unsigned char const **der, size_t *derlen); +gpg_error_t ksba_crl_get_auth_key_id (ksba_crl_t crl, + ksba_sexp_t *r_keyid, + ksba_name_t *r_name, + ksba_sexp_t *r_serial); +gpg_error_t ksba_crl_get_crl_number (ksba_crl_t crl, ksba_sexp_t *number); +gpg_error_t ksba_crl_get_update_times (ksba_crl_t crl, + ksba_isotime_t this_update, + ksba_isotime_t next_update); +gpg_error_t ksba_crl_get_item (ksba_crl_t crl, + ksba_sexp_t *r_serial, + ksba_isotime_t r_revocation_date, + ksba_crl_reason_t *r_reason); +ksba_sexp_t ksba_crl_get_sig_val (ksba_crl_t crl); +gpg_error_t ksba_crl_parse (ksba_crl_t crl, ksba_stop_reason_t *r_stopreason); + + + +/*-- ocsp.c --*/ +gpg_error_t ksba_ocsp_new (ksba_ocsp_t *r_oscp); +void ksba_ocsp_release (ksba_ocsp_t ocsp); +gpg_error_t ksba_ocsp_set_digest_algo (ksba_ocsp_t ocsp, const char *oid); +gpg_error_t ksba_ocsp_set_requestor (ksba_ocsp_t ocsp, ksba_cert_t cert); +gpg_error_t ksba_ocsp_add_target (ksba_ocsp_t ocsp, + ksba_cert_t cert, ksba_cert_t issuer_cert); +size_t ksba_ocsp_set_nonce (ksba_ocsp_t ocsp, + unsigned char *nonce, size_t noncelen); + +gpg_error_t ksba_ocsp_prepare_request (ksba_ocsp_t ocsp); +gpg_error_t ksba_ocsp_hash_request (ksba_ocsp_t ocsp, + void (*hasher)(void *, const void *, + size_t length), + void *hasher_arg); +gpg_error_t ksba_ocsp_set_sig_val (ksba_ocsp_t ocsp, + ksba_const_sexp_t sigval); +gpg_error_t ksba_ocsp_add_cert (ksba_ocsp_t ocsp, ksba_cert_t cert); +gpg_error_t ksba_ocsp_build_request (ksba_ocsp_t ocsp, + unsigned char **r_buffer, + size_t *r_buflen); + +gpg_error_t ksba_ocsp_parse_response (ksba_ocsp_t ocsp, + const unsigned char *msg, size_t msglen, + ksba_ocsp_response_status_t *resp_status); + +const char *ksba_ocsp_get_digest_algo (ksba_ocsp_t ocsp); +gpg_error_t ksba_ocsp_hash_response (ksba_ocsp_t ocsp, + const unsigned char *msg, size_t msglen, + void (*hasher)(void *, const void *, + size_t length), + void *hasher_arg); +ksba_sexp_t ksba_ocsp_get_sig_val (ksba_ocsp_t ocsp, + ksba_isotime_t produced_at); +gpg_error_t ksba_ocsp_get_responder_id (ksba_ocsp_t ocsp, + char **r_name, + ksba_sexp_t *r_keyid); +ksba_cert_t ksba_ocsp_get_cert (ksba_ocsp_t ocsp, int idx); +gpg_error_t ksba_ocsp_get_status (ksba_ocsp_t ocsp, ksba_cert_t cert, + ksba_status_t *r_status, + ksba_isotime_t r_this_update, + ksba_isotime_t r_next_update, + ksba_isotime_t r_revocation_time, + ksba_crl_reason_t *r_reason); +gpg_error_t ksba_ocsp_get_extension (ksba_ocsp_t ocsp, ksba_cert_t cert, + int idx, + char const **r_oid, int *r_crit, + unsigned char const **r_der, + size_t *r_derlen); + + +/*-- certreq.c --*/ +gpg_error_t ksba_certreq_new (ksba_certreq_t *r_cr); +void ksba_certreq_release (ksba_certreq_t cr); +gpg_error_t ksba_certreq_set_writer (ksba_certreq_t cr, ksba_writer_t w); +void ksba_certreq_set_hash_function ( + ksba_certreq_t cr, + void (*hash_fnc)(void *, const void *, size_t), + void *hash_fnc_arg); +gpg_error_t ksba_certreq_add_subject (ksba_certreq_t cr, const char *name); +gpg_error_t ksba_certreq_set_public_key (ksba_certreq_t cr, + ksba_const_sexp_t key); +gpg_error_t ksba_certreq_add_extension (ksba_certreq_t cr, + const char *oid, int is_crit, + const void *der, + size_t derlen); +gpg_error_t ksba_certreq_set_sig_val (ksba_certreq_t cr, + ksba_const_sexp_t sigval); +gpg_error_t ksba_certreq_build (ksba_certreq_t cr, + ksba_stop_reason_t *r_stopreason); + + +/*-- reader.c --*/ +gpg_error_t ksba_reader_new (ksba_reader_t *r_r); +void ksba_reader_release (ksba_reader_t r); +gpg_error_t ksba_reader_clear (ksba_reader_t r, + unsigned char **buffer, size_t *buflen); +gpg_error_t ksba_reader_error (ksba_reader_t r); + +gpg_error_t ksba_reader_set_mem (ksba_reader_t r, + const void *buffer, size_t length); +gpg_error_t ksba_reader_set_fd (ksba_reader_t r, int fd); +gpg_error_t ksba_reader_set_file (ksba_reader_t r, FILE *fp); +gpg_error_t ksba_reader_set_cb (ksba_reader_t r, + int (*cb)(void*,char *,size_t,size_t*), + void *cb_value ); + +gpg_error_t ksba_reader_read (ksba_reader_t r, + char *buffer, size_t length, size_t *nread); +gpg_error_t ksba_reader_unread (ksba_reader_t r, const void *buffer, size_t count); +unsigned long ksba_reader_tell (ksba_reader_t r); + +/*-- writer.c --*/ +gpg_error_t ksba_writer_new (ksba_writer_t *r_w); +void ksba_writer_release (ksba_writer_t w); +int ksba_writer_error (ksba_writer_t w); +unsigned long ksba_writer_tell (ksba_writer_t w); +gpg_error_t ksba_writer_set_fd (ksba_writer_t w, int fd); +gpg_error_t ksba_writer_set_file (ksba_writer_t w, FILE *fp); +gpg_error_t ksba_writer_set_cb (ksba_writer_t w, + int (*cb)(void*,const void *,size_t), + void *cb_value); +gpg_error_t ksba_writer_set_mem (ksba_writer_t w, size_t initial_size); +const void *ksba_writer_get_mem (ksba_writer_t w, size_t *nbytes); +void * ksba_writer_snatch_mem (ksba_writer_t w, size_t *nbytes); +gpg_error_t ksba_writer_set_filter (ksba_writer_t w, + gpg_error_t (*filter)(void*, + const void *,size_t, size_t *, + void *, size_t, size_t *), + void *filter_arg); + +gpg_error_t ksba_writer_write (ksba_writer_t w, const void *buffer, size_t length); +gpg_error_t ksba_writer_write_octet_string (ksba_writer_t w, + const void *buffer, size_t length, + int flush); + +/*-- asn1-parse.y --*/ +int ksba_asn_parse_file (const char *filename, ksba_asn_tree_t *result, + int debug); +void ksba_asn_tree_release (ksba_asn_tree_t tree); + +/*-- asn1-func.c --*/ +void ksba_asn_tree_dump (ksba_asn_tree_t tree, const char *name, FILE *fp); +gpg_error_t ksba_asn_create_tree (const char *mod_name, ksba_asn_tree_t *result); + +/*-- oid.c --*/ +char *ksba_oid_to_str (const char *buffer, size_t length); +gpg_error_t ksba_oid_from_str (const char *string, + unsigned char **rbuf, size_t *rlength); + +/*-- dn.c --*/ +gpg_error_t ksba_dn_der2str (const void *der, size_t derlen, char **r_string); +gpg_error_t ksba_dn_str2der (const char *string, + unsigned char **rder, size_t *rderlen); +gpg_error_t ksba_dn_teststr (const char *string, int seq, + size_t *rerroff, size_t *rerrlen); + + +/*-- name.c --*/ +gpg_error_t ksba_name_new (ksba_name_t *r_name); +void ksba_name_ref (ksba_name_t name); +void ksba_name_release (ksba_name_t name); +const char *ksba_name_enum (ksba_name_t name, int idx); +char *ksba_name_get_uri (ksba_name_t name, int idx); + + +/*-- util.c --*/ +void ksba_set_malloc_hooks ( void *(*new_alloc_func)(size_t n), + void *(*new_realloc_func)(void *p, size_t n), + void (*new_free_func)(void*) ); +void ksba_set_hash_buffer_function ( gpg_error_t (*fnc) + (void *arg, const char *oid, + const void *buffer, size_t length, + size_t resultsize, + unsigned char *result, + size_t *resultlen), + void *fnc_arg); +void *ksba_malloc (size_t n ); +void *ksba_calloc (size_t n, size_t m ); +void *ksba_realloc (void *p, size_t n); +char *ksba_strdup (const char *p); +void ksba_free ( void *a ); + +/*--version.c --*/ +const char *ksba_check_version (const char *req_version); + +#ifdef __cplusplus +} +#endif +#endif /*KSBA_H*/ |