Mercurial > hg > php_nacl
changeset 6:ded86f4d6275
Added keypair generation functions (with random data input)
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 12 Jul 2011 20:51:44 +0000 |
parents | df71d49a6f98 |
children | a139bed53614 |
files | nacl.c php_nacl.h |
diffstat | 2 files changed, 36 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nacl.c Fri Mar 18 17:41:40 2011 +0100 +++ b/nacl.c Tue Jul 12 20:51:44 2011 +0000 @@ -42,9 +42,10 @@ 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_box_curve25519xsalsa20poly1305_keypair, NULL) PHP_FE(nacl_crypto_sign_edwards25519sha512batch, NULL) PHP_FE(nacl_crypto_sign_edwards25519sha512batch_open, NULL) -// PHP_FE(nacl_crypto_sign_edwards25519sha512batch_keypair, NULL) + PHP_FE(nacl_crypto_sign_edwards25519sha512batch_keypair, NULL) {NULL, NULL, NULL} }; @@ -76,9 +77,11 @@ 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_BOX_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES", crypto_box_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES, 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); + REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_KEYPAIRRANDOMBYTES", crypto_sign_edwards25519sha512batch_KEYPAIRRANDOMBYTES, 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 *) @@ -183,6 +186,21 @@ crypto_scalarmult_curve25519(pk, sk, base); RETURN_STRINGL(pk, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, 0); } +PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_keypair) { + char *rb; + int lrb; + zval *zsk; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zsk, &rb, &lrb) == FAILURE) RETURN_NULL(); + if (!zsk) RETURN_FALSE; + if (lrb != crypto_box_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES) RETURN_FALSE; + char *spk = emalloc(crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); + char *ssk = emalloc(crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); + int ret = crypto_box_curve25519xsalsa20poly1305_keypair(spk, ssk, rb); + if (ret) RETURN_FALSE; + zval_dtor(zsk); + ZVAL_STRINGL(zsk, ssk, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES, 0); + RETURN_STRINGL(spk, 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; @@ -213,4 +231,18 @@ efree(m); RETURN_FALSE; } -//extern int crypto_sign_edwards25519sha512batch_ref_keypair(unsigned char *,unsigned char *); +PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_keypair) { //(unsigned char *,unsigned char *); + char *rb; + int lrb; + zval *zsk; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zsk, &rb, &lrb) == FAILURE) RETURN_NULL(); + if (lrb != crypto_sign_edwards25519sha512batch_KEYPAIRRANDOMBYTES) RETURN_FALSE; + if (!zsk) RETURN_FALSE; + char *spk = emalloc(crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES); + char *ssk = emalloc(crypto_sign_edwards25519sha512batch_SECRETKEYBYTES); + int ret = crypto_sign_edwards25519sha512batch_keypair(spk, ssk, rb); + if (ret) RETURN_FALSE; + zval_dtor(zsk); + ZVAL_STRINGL(zsk, ssk, crypto_sign_edwards25519sha512batch_SECRETKEYBYTES, 0); + RETURN_STRINGL(spk, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES, 0); +}
--- a/php_nacl.h Fri Mar 18 17:41:40 2011 +0100 +++ b/php_nacl.h Tue Jul 12 20:51:44 2011 +0000 @@ -15,8 +15,10 @@ 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_box_curve25519xsalsa20poly1305_keypair); PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch); PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_open); +PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_keypair); extern zend_module_entry nacl_module_entry; #define phpext_module_ptr &nacl_module_entry