summaryrefslogtreecommitdiff
path: root/res/res_crypto.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2004-08-14 20:19:38 +0000
committerMark Spencer <markster@digium.com>2004-08-14 20:19:38 +0000
commit3ff53cd50b0a0758bf20bc364c31d45e20ecbc86 (patch)
treecdad27b4b0d247b7189c65c7863f13dfce778291 /res/res_crypto.c
parent94f18868f1818dc40f8812a4bfb9e172de81f095 (diff)
Create binary versions of signature functions
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3607 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_crypto.c')
-rwxr-xr-xres/res_crypto.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/res/res_crypto.c b/res/res_crypto.c
index 706171590..87339f292 100755
--- a/res/res_crypto.c
+++ b/res/res_crypto.c
@@ -296,10 +296,9 @@ static char *binary(int y, int len)
#endif
-int ast_sign(struct ast_key *key, char *msg, char *sig)
+int ast_sign_bin(struct ast_key *key, char *msg, unsigned char *dsig)
{
unsigned char digest[20];
- unsigned char dsig[128];
int siglen = sizeof(dsig);
int res;
@@ -324,16 +323,26 @@ int ast_sign(struct ast_key *key, char *msg, char *sig)
return -1;
}
- /* Success -- encode (256 bytes max as documented) */
- ast_base64encode(sig, dsig, siglen, 256);
return 0;
}
-int ast_check_signature(struct ast_key *key, char *msg, char *sig)
+int ast_sign(struct ast_key *key, char *msg, char *sig)
{
- unsigned char digest[20];
unsigned char dsig[128];
+ int siglen = sizeof(dsig);
+ int res;
+ res = ast_sign_bin(key, msg, dsig);
+ if (!res)
+ /* Success -- encode (256 bytes max as documented) */
+ ast_base64encode(sig, dsig, siglen, 256);
+ return res;
+
+}
+
+int ast_check_signature_bin(struct ast_key *key, char *msg, unsigned char *dsig)
+{
+ unsigned char digest[20];
int res;
if (key->ktype != AST_KEY_PUBLIC) {
@@ -343,13 +352,6 @@ int ast_check_signature(struct ast_key *key, char *msg, char *sig)
return -1;
}
- /* Decode signature */
- res = ast_base64decode(dsig, sig, sizeof(dsig));
- if (res != sizeof(dsig)) {
- ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res);
- return -1;
- }
-
/* Calculate digest of message */
SHA1((unsigned char *)msg, strlen(msg), digest);
@@ -364,6 +366,21 @@ int ast_check_signature(struct ast_key *key, char *msg, char *sig)
return 0;
}
+int ast_check_signature(struct ast_key *key, char *msg, char *sig)
+{
+ unsigned char dsig[128];
+ int res;
+
+ /* Decode signature */
+ res = ast_base64decode(dsig, sig, sizeof(dsig));
+ if (res != sizeof(dsig)) {
+ ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res);
+ return -1;
+ }
+ res = ast_check_signature_bin(key, msg, dsig);
+ return res;
+}
+
static void crypto_load(int ifd, int ofd)
{
struct ast_key *key, *nkey, *last;