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 * \brief Provide cryptographic signature routines
23 #ifndef _ASTERISK_CRYPTO_H
24 #define _ASTERISK_CRYPTO_H
26 #if defined(__cplusplus) || defined(c_plusplus)
30 #define AST_KEY_PUBLIC (1 << 0)
31 #define AST_KEY_PRIVATE (1 << 1)
35 /*! \brief Retrieve a key
36 * \param name of the key we are retrieving
37 * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE)
39 * Returns the key on success or NULL on failure
41 struct ast_key
*(*ast_key_get
)(const char *key
, int type
);
43 /*! \brief Check the authenticity of a message signature using a given public key
44 * \param key a public key to use to verify
45 * \param msg the message that has been signed
46 * \param sig the proposed valid signature in mime64-like encoding
48 * Returns 0 if the signature is valid, or -1 otherwise
51 int (*ast_check_signature
)(struct ast_key
*key
, const char *msg
, const char *sig
);
53 /*! \brief Check the authenticity of a message signature using a given public key
54 * \param key a public key to use to verify
55 * \param msg the message that has been signed
56 * \param sig the proposed valid signature in raw binary representation
58 * Returns 0 if the signature is valid, or -1 otherwise
61 int (*ast_check_signature_bin
)(struct ast_key
*key
, const char *msg
, int msglen
, const unsigned char *sig
);
64 * \param key a private key to use to create the signature
65 * \param msg the message to sign
66 * \param sig a pointer to a buffer of at least 256 bytes in which the
67 * mime64-like encoded signature will be stored
69 * Returns 0 on success or -1 on failure.
72 int (*ast_sign
)(struct ast_key
*key
, char *msg
, char *sig
);
75 * \param key a private key to use to create the signature
76 * \param msg the message to sign
77 * \param sig a pointer to a buffer of at least 128 bytes in which the
78 * raw encoded signature will be stored
80 * Returns 0 on success or -1 on failure.
83 int (*ast_sign_bin
)(struct ast_key
*key
, const char *msg
, int msglen
, unsigned char *sig
);
86 * \param key a private key to use to encrypt
87 * \param src the message to encrypt
88 * \param srclen the length of the message to encrypt
89 * \param dst a pointer to a buffer of at least srclen * 1.5 bytes in which the encrypted
90 * answer will be stored
92 * Returns length of encrypted data on success or -1 on failure.
95 int (*ast_encrypt_bin
)(unsigned char *dst
, const unsigned char *src
, int srclen
, struct ast_key
*key
);
98 * \param key a private key to use to decrypt
99 * \param src the message to decrypt
100 * \param srclen the length of the message to decrypt
101 * \param dst a pointer to a buffer of at least srclen bytes in which the decrypted
102 * answer will be stored
104 * Returns length of decrypted data on success or -1 on failure.
107 int (*ast_decrypt_bin
)(unsigned char *dst
, const unsigned char *src
, int srclen
, struct ast_key
*key
);
108 #if defined(__cplusplus) || defined(c_plusplus)
112 #endif /* _ASTERISK_CRYPTO_H */