00001 /* 00002 * Asterisk -- A telephony toolkit for Linux. 00003 * 00004 * Provide cryptographic signature routines 00005 * 00006 * Copyright (C) 1999, Mark Spencer 00007 * 00008 * Mark Spencer <markster@linux-support.net> 00009 * 00010 * This program is free software, distributed under the terms of 00011 * the GNU General Public License 00012 */ 00013 00014 #ifndef _ASTERISK_CRYPTO_H 00015 #define _ASTERISK_CRYPTO_H 00016 00017 #include <asterisk/channel.h> 00018 #include <asterisk/file.h> 00019 00020 #if defined(__cplusplus) || defined(c_plusplus) 00021 extern "C" { 00022 #endif 00023 00024 #define AST_KEY_PUBLIC (1 << 0) 00025 #define AST_KEY_PRIVATE (1 << 1) 00026 00027 struct ast_key; 00028 00029 //! Retrieve a key 00030 /*! 00031 * \param name of the key we are retrieving 00032 * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE) 00033 * 00034 * Returns the key on success or NULL on failure 00035 */ 00036 extern struct ast_key *ast_key_get(char *key, int type); 00037 00038 //! Initialize keys (that is, retrieve pass codes for all private keys) 00039 /*! 00040 * \param fd a file descriptor for I/O for passwords 00041 * 00042 */ 00043 extern int ast_key_init(int fd); 00044 00045 //! Check the authenticity of a message signature using a given public key 00046 /*! 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 * Returns 0 if the signature is valid, or -1 otherwise 00052 * 00053 */ 00054 extern int ast_check_signature(struct ast_key *key, char *msg, char *sig); 00055 00056 //! Check the authenticity of a message signature using a given public key 00057 /*! 00058 * \param key a public key to use to verify 00059 * \param msg the message that has been signed 00060 * \param sig the proposed valid signature in raw binary representation 00061 * 00062 * Returns 0 if the signature is valid, or -1 otherwise 00063 * 00064 */ 00065 extern int ast_check_signature_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig); 00066 00067 /*! 00068 * \param key a private key to use to create the signature 00069 * \param msg the message to sign 00070 * \param sig a pointer to a buffer of at least 256 bytes in which the 00071 * mime64-like encoded signature will be stored 00072 * 00073 * Returns 0 on success or -1 on failure. 00074 * 00075 */ 00076 extern int ast_sign(struct ast_key *key, char *msg, char *sig); 00077 /*! 00078 * \param key a private key to use to create the signature 00079 * \param msg the message to sign 00080 * \param sig a pointer to a buffer of at least 128 bytes in which the 00081 * raw encoded signature will be stored 00082 * 00083 * Returns 0 on success or -1 on failure. 00084 * 00085 */ 00086 extern int ast_sign_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig); 00087 00088 /*! 00089 * \param key a private key to use to encrypt 00090 * \param src the message to encrypt 00091 * \param srclen the length of the message to encrypt 00092 * \param dst a pointer to a buffer of at least srclen * 1.5 bytes in which the encrypted 00093 * answer will be stored 00094 * 00095 * Returns length of encrypted data on success or -1 on failure. 00096 * 00097 */ 00098 extern int ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key); 00099 00100 /*! 00101 * \param key a private key to use to decrypt 00102 * \param src the message to decrypt 00103 * \param srclen the length of the message to decrypt 00104 * \param dst a pointer to a buffer of at least srclen bytes in which the decrypted 00105 * answer will be stored 00106 * 00107 * Returns length of decrypted data on success or -1 on failure. 00108 * 00109 */ 00110 extern int ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key); 00111 #if defined(__cplusplus) || defined(c_plusplus) 00112 } 00113 #endif 00114 00115 #endif