Thu Apr 28 2011 17:13:33

Asterisk developer's documentation


crypto.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Provide cryptographic signature routines
00021  */
00022 
00023 #ifndef _ASTERISK_CRYPTO_H
00024 #define _ASTERISK_CRYPTO_H
00025 
00026 #if defined(__cplusplus) || defined(c_plusplus)
00027 extern "C" {
00028 #endif
00029 
00030 #define AST_KEY_PUBLIC  (1 << 0)
00031 #define AST_KEY_PRIVATE (1 << 1)
00032 
00033 struct ast_key;
00034 
00035 /*! 
00036  * \brief Retrieve a key
00037  * \param name of the key we are retrieving
00038  * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE)
00039  *
00040  * \retval the key on success.
00041  * \retval NULL on failure.
00042  */
00043 extern struct ast_key *(*ast_key_get)(const char *key, int type);
00044 
00045 /*! 
00046  * \brief Check the authenticity of a message signature using a given public key
00047  * \param key a public key to use to verify
00048  * \param msg the message that has been signed
00049  * \param sig the proposed valid signature in mime64-like encoding
00050  *
00051  * \retval 0 if the signature is valid.
00052  * \retval -1 otherwise.
00053  *
00054  */
00055 extern int (*ast_check_signature)(struct ast_key *key, const char *msg, const char *sig);
00056 
00057 /*! 
00058  * \brief Check the authenticity of a message signature using a given public key
00059  * \param key a public key to use to verify
00060  * \param msg the message that has been signed
00061  * \param sig the proposed valid signature in raw binary representation
00062  *
00063  * \retval 0 if the signature is valid.
00064  * \retval -1 otherwise.
00065  *
00066  */
00067 extern int (*ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *sig);
00068 
00069 /*!
00070  * \brief Sign a message signature using a given private key
00071  * \param key a private key to use to create the signature
00072  * \param msg the message to sign
00073  * \param sig a pointer to a buffer of at least 256 bytes in which the
00074  * mime64-like encoded signature will be stored
00075  *
00076  * \retval 0 on success.
00077  * \retval -1 on failure.
00078  *
00079  */
00080 extern int (*ast_sign)(struct ast_key *key, char *msg, char *sig);
00081 
00082 /*!
00083  * \brief Sign a message signature using a given private key
00084  * \param key a private key to use to create the signature
00085  * \param msg the message to sign
00086  * \param sig a pointer to a buffer of at least 128 bytes in which the
00087  * raw encoded signature will be stored
00088  *
00089  * \retval 0 on success.
00090  * \retval -1 on failure.
00091  *
00092  */
00093 extern int (*ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *sig);
00094 
00095 /*!
00096  * \brief Encrypt a message using a given private key
00097  * \param key a private key to use to encrypt
00098  * \param src the message to encrypt
00099  * \param srclen the length of the message to encrypt
00100  * \param dst a pointer to a buffer of at least srclen * 1.5 bytes in which the encrypted
00101  * answer will be stored
00102  *
00103  * \retval length of encrypted data on success.
00104  * \retval -1 on failure.
00105  *
00106  */
00107 extern int (*ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
00108 
00109 /*!
00110  * \brief Decrypt a message using a given private key
00111  * \param key a private key to use to decrypt
00112  * \param src the message to decrypt
00113  * \param srclen the length of the message to decrypt
00114  * \param dst a pointer to a buffer of at least srclen bytes in which the decrypted
00115  * answer will be stored
00116  *
00117  * \retval length of dencrypted data on success.
00118  * \retval -1 on failure.
00119  *
00120  */
00121 extern int (*ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
00122 #if defined(__cplusplus) || defined(c_plusplus)
00123 }
00124 #endif
00125 
00126 #endif /* _ASTERISK_CRYPTO_H */