[Asterisk-cvs] asterisk/res res_crypto.c,1.11,1.12

markster at lists.digium.com markster at lists.digium.com
Sat Aug 14 16:33:30 CDT 2004


Update of /usr/cvsroot/asterisk/res
In directory localhost.localdomain:/tmp/cvs-serv14256/res

Modified Files:
	res_crypto.c 
Log Message:
Create binary versions of signature functions


Index: res_crypto.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_crypto.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- res_crypto.c	14 Jul 2004 13:57:15 -0000	1.11
+++ res_crypto.c	14 Aug 2004 20:19:38 -0000	1.12
@@ -296,10 +296,9 @@
 
 #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 @@
 		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 @@
 		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 @@
 	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;




More information about the svn-commits mailing list