changeset 4:81aaf4ba1eaa

Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
author Ivo Smits <Ivo@UCIS.nl>
date Fri, 18 Mar 2011 16:58:48 +0100
parents c0f3bf4aac47
children df71d49a6f98
files nacl.c php_nacl.h
diffstat 2 files changed, 46 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/nacl.c	Mon Feb 28 22:47:56 2011 +0100
+++ b/nacl.c	Fri Mar 18 16:58:48 2011 +0100
@@ -35,13 +35,16 @@
 #include "php_nacl.h"
 
 static function_entry nacl_functions[] = {
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305, NULL)
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open, NULL)
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_getpublickey, NULL)
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_beforenm, NULL)
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_afternm, NULL)
-    PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open_afternm, NULL)
-    {NULL, NULL, NULL}
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305, NULL)
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open, NULL)
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_getpublickey, NULL)
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_beforenm, NULL)
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_afternm, NULL)
+	PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open_afternm, NULL)
+	PHP_FE(nacl_crypto_sign_edwards25519sha512batch, NULL)
+	PHP_FE(nacl_crypto_sign_edwards25519sha512batch_open, NULL)
+//	PHP_FE(nacl_crypto_sign_edwards25519sha512batch_keypair, NULL)
+	{NULL, NULL, NULL}
 };
 
 zend_module_entry nacl_module_entry = {
@@ -72,6 +75,9 @@
 	REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_NONCEBYTES", crypto_box_curve25519xsalsa20poly1305_NONCEBYTES, CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_ZEROBYTES", crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_BOXZEROBYTES", crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_BYTES", crypto_sign_edwards25519sha512batch_BYTES, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_PUBLICKEYBYTES", crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_SECRETKEYBYTES", crypto_sign_edwards25519sha512batch_SECRETKEYBYTES, CONST_CS | CONST_PERSISTENT);
 }
 
 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305) { //(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *)
@@ -176,3 +182,34 @@
 	crypto_scalarmult_curve25519(pk, sk, base);
 	RETURN_STRINGL(pk, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, 0);
 }
+PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch) { //(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
+	char *m, *sk;
+	int lm, lsk;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &m, &lm, &sk, &lsk) == FAILURE) RETURN_NULL();
+	if (lsk != crypto_sign_edwards25519sha512batch_SECRETKEYBYTES) RETURN_FALSE;
+	int smlen = lm + crypto_sign_edwards25519sha512batch_BYTES;
+	char* smb = emalloc(smlen);
+	int ret = crypto_sign_edwards25519sha512batch(smb, &smlen, m, lm, sk);
+	char* sm = emalloc(smlen);
+	memcpy(sm, smb, smlen);
+	efree(smb);
+	if (ret == 0) RETURN_STRINGL(sm, smlen, 0);
+	efree(sm);
+	RETURN_FALSE;
+}
+PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_open) { //(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
+	char *sm, *pk;
+	int lsm, lpk;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &sm, &lsm, &pk, &lpk) == FAILURE) RETURN_NULL();
+	if (lpk != crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES) RETURN_FALSE;
+	int mlen = lsm;
+	char* mb = emalloc(mlen);
+	int ret = crypto_sign_edwards25519sha512batch_open(mb, &mlen, sm, lsm, pk);
+	char* m = emalloc(mlen);
+	memcpy(m, mb, mlen);
+	efree(mb);
+	if (ret == 0) RETURN_STRINGL(m, mlen, 0);
+	efree(m);
+	RETURN_FALSE;
+}
+//extern int crypto_sign_edwards25519sha512batch_ref_keypair(unsigned char *,unsigned char *);
--- a/php_nacl.h	Mon Feb 28 22:47:56 2011 +0100
+++ b/php_nacl.h	Fri Mar 18 16:58:48 2011 +0100
@@ -15,6 +15,8 @@
 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_beforenm);
 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_afternm);
 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_open_afternm);
+PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch)
+PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_open)
 
 extern zend_module_entry nacl_module_entry;
 #define phpext_module_ptr &nacl_module_entry