2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * Provide cryptographic signature routines
23 #ifndef _ASTERISK_CRYPTO_H
24 #define _ASTERISK_CRYPTO_H
26 #include "asterisk/channel.h"
27 #include "asterisk/file.h"
29 #if defined(__cplusplus) || defined(c_plusplus)
33 #define AST_KEY_PUBLIC (1 << 0)
34 #define AST_KEY_PRIVATE (1 << 1)
40 * \param name of the key we are retrieving
41 * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE)
43 * Returns the key on success or NULL on failure
45 extern struct ast_key *ast_key_get(char *key, int type);
47 /*! Initialize keys (that is, retrieve pass codes for all private keys) */
49 * \param fd a file descriptor for I/O for passwords
52 extern int ast_key_init(int fd);
54 /*! Check the authenticity of a message signature using a given public key */
56 * \param key a public key to use to verify
57 * \param msg the message that has been signed
58 * \param sig the proposed valid signature in mime64-like encoding
60 * Returns 0 if the signature is valid, or -1 otherwise
63 extern int ast_check_signature(struct ast_key *key, char *msg, char *sig);
65 /*! Check the authenticity of a message signature using a given public key */
67 * \param key a public key to use to verify
68 * \param msg the message that has been signed
69 * \param sig the proposed valid signature in raw binary representation
71 * Returns 0 if the signature is valid, or -1 otherwise
74 extern int ast_check_signature_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig);
77 * \param key a private key to use to create the signature
78 * \param msg the message to sign
79 * \param sig a pointer to a buffer of at least 256 bytes in which the
80 * mime64-like encoded signature will be stored
82 * Returns 0 on success or -1 on failure.
85 extern int ast_sign(struct ast_key *key, char *msg, char *sig);
87 * \param key a private key to use to create the signature
88 * \param msg the message to sign
89 * \param sig a pointer to a buffer of at least 128 bytes in which the
90 * raw encoded signature will be stored
92 * Returns 0 on success or -1 on failure.
95 extern int ast_sign_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig);
98 * \param key a private key to use to encrypt
99 * \param src the message to encrypt
100 * \param srclen the length of the message to encrypt
101 * \param dst a pointer to a buffer of at least srclen * 1.5 bytes in which the encrypted
102 * answer will be stored
104 * Returns length of encrypted data on success or -1 on failure.
107 extern int ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
110 * \param key a private key to use to decrypt
111 * \param src the message to decrypt
112 * \param srclen the length of the message to decrypt
113 * \param dst a pointer to a buffer of at least srclen bytes in which the decrypted
114 * answer will be stored
116 * Returns length of decrypted data on success or -1 on failure.
119 extern int ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
120 #if defined(__cplusplus) || defined(c_plusplus)
124 #endif /* _ASTERISK_CRYPTO_H */