Mercurial > hg > php_nacl
annotate nacl.c @ 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 |
rev | line source |
---|---|
0 | 1 /* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved. |
2 Redistribution and use in source and binary forms, with or without modification, are | |
3 permitted provided that the following conditions are met: | |
4 | |
5 1. Redistributions of source code must retain the above copyright notice, this list of | |
6 conditions and the following disclaimer. | |
7 | |
8 2. Redistributions in binary form must reproduce the above copyright notice, this list | |
9 of conditions and the following disclaimer in the documentation and/or other materials | |
10 provided with the distribution. | |
11 | |
12 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
13 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
14 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR | |
15 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
16 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
17 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
18 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
19 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
20 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
21 | |
22 The views and conclusions contained in the software and documentation are those of the | |
23 authors and should not be interpreted as representing official policies, either expressed | |
24 or implied, of Ivo Smits.*/ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include "config.h" | |
28 #endif | |
2
04384d01b1d7
Added build script, changed header location
Ivo Smits <Ivo@UCIS.nl>
parents:
1
diff
changeset
|
29 |
04384d01b1d7
Added build script, changed header location
Ivo Smits <Ivo@UCIS.nl>
parents:
1
diff
changeset
|
30 #include "nacl/crypto_box_curve25519xsalsa20poly1305.h" |
04384d01b1d7
Added build script, changed header location
Ivo Smits <Ivo@UCIS.nl>
parents:
1
diff
changeset
|
31 #include "nacl/crypto_scalarmult_curve25519.h" |
5
df71d49a6f98
Fixes to support crypto_sign_edwards25519sha512batch
Ivo Smits <Ivo@UCIS.nl>
parents:
4
diff
changeset
|
32 #include "nacl/crypto_sign_edwards25519sha512batch.h" |
0 | 33 |
34 #include "php.h" | |
35 #include "php_ini.h" | |
36 #include "php_nacl.h" | |
37 | |
38 static function_entry nacl_functions[] = { | |
4
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
39 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
40 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
41 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_getpublickey, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
42 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_beforenm, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
43 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_afternm, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
44 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_open_afternm, NULL) |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
45 PHP_FE(nacl_crypto_box_curve25519xsalsa20poly1305_keypair, NULL) |
4
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
46 PHP_FE(nacl_crypto_sign_edwards25519sha512batch, NULL) |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
47 PHP_FE(nacl_crypto_sign_edwards25519sha512batch_open, NULL) |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
48 PHP_FE(nacl_crypto_sign_edwards25519sha512batch_keypair, NULL) |
4
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
49 {NULL, NULL, NULL} |
0 | 50 }; |
51 | |
52 zend_module_entry nacl_module_entry = { | |
53 #if ZEND_MODULE_API_NO >= 20010901 | |
54 STANDARD_MODULE_HEADER, | |
55 #endif | |
56 PHP_NACL_EXTNAME, | |
57 nacl_functions, | |
58 PHP_MINIT(nacl), | |
59 NULL, | |
60 NULL, | |
61 NULL, | |
62 NULL, | |
63 #if ZEND_MODULE_API_NO >= 20010901 | |
64 PHP_NACL_VERSION, | |
65 #endif | |
66 STANDARD_MODULE_PROPERTIES | |
67 }; | |
68 | |
69 #ifdef COMPILE_DL_NACL | |
70 ZEND_GET_MODULE(nacl) | |
71 #endif | |
72 | |
73 PHP_MINIT_FUNCTION(nacl) { | |
74 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_PUBLICKEYBYTES", crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, CONST_CS | CONST_PERSISTENT); | |
75 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_SECRETKEYBYTES", crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES, CONST_CS | CONST_PERSISTENT); | |
76 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_BEFORENMBYTES", crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES, CONST_CS | CONST_PERSISTENT); | |
77 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_NONCEBYTES", crypto_box_curve25519xsalsa20poly1305_NONCEBYTES, CONST_CS | CONST_PERSISTENT); | |
78 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_ZEROBYTES", crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, CONST_CS | CONST_PERSISTENT); | |
79 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_BOXZEROBYTES", crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, CONST_CS | CONST_PERSISTENT); | |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
80 REGISTER_LONG_CONSTANT("NACL_CRYPTO_BOX_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES", crypto_box_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES, CONST_CS | CONST_PERSISTENT); |
4
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
81 REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_BYTES", crypto_sign_edwards25519sha512batch_BYTES, CONST_CS | CONST_PERSISTENT); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
82 REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_PUBLICKEYBYTES", crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES, CONST_CS | CONST_PERSISTENT); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
83 REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_SECRETKEYBYTES", crypto_sign_edwards25519sha512batch_SECRETKEYBYTES, CONST_CS | CONST_PERSISTENT); |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
84 REGISTER_LONG_CONSTANT("NACL_CRYPTO_SIGN_edwards25519sha512batch_KEYPAIRRANDOMBYTES", crypto_sign_edwards25519sha512batch_KEYPAIRRANDOMBYTES, CONST_CS | CONST_PERSISTENT); |
0 | 85 } |
86 | |
87 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305) { //(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *) | |
88 char *m, *n, *pk, *sk; | |
89 int lm, ln, lpk, lsk; | |
1
84e0f7ead583
Changed the order of function arguments to match those of the original code
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
90 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &m, &lm, &n, &ln, &pk, &lpk, &sk, &lsk) == FAILURE) RETURN_NULL(); |
0 | 91 if (ln != crypto_box_curve25519xsalsa20poly1305_NONCEBYTES) RETURN_FALSE; |
92 if (lpk != crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) RETURN_FALSE; | |
93 if (lsk != crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) RETURN_FALSE; | |
94 int mlen = lm + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; | |
95 char* mb = ecalloc(mlen, 1); | |
96 char* cb = ecalloc(mlen, 1); | |
97 memcpy(mb + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, m, lm); | |
98 int ret = crypto_box_curve25519xsalsa20poly1305(cb, mb, mlen, n, pk, sk); | |
99 int clen = mlen - crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | |
100 char* c = emalloc(clen); | |
101 memcpy(c, cb + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, clen); | |
102 efree(mb); | |
103 efree(cb); | |
104 if (ret == 0) RETURN_STRINGL(c, clen, 0); | |
105 efree(c); | |
106 RETURN_FALSE; | |
107 } | |
108 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_open) { //(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *) | |
109 char *c, *n, *pk, *sk; | |
110 int lc, ln, lpk, lsk; | |
1
84e0f7ead583
Changed the order of function arguments to match those of the original code
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
111 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &c, &lc, &n, &ln, &pk, &lpk, &sk, &lsk) == FAILURE) RETURN_NULL(); |
0 | 112 if (ln != crypto_box_curve25519xsalsa20poly1305_NONCEBYTES) RETURN_FALSE; |
113 if (lpk != crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) RETURN_FALSE; | |
114 if (lsk != crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) RETURN_FALSE; | |
115 int clen = lc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | |
116 char* mb = ecalloc(clen, 1); | |
117 char* cb = ecalloc(clen, 1); | |
118 memcpy(cb + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, c, lc); | |
119 int ret = crypto_box_curve25519xsalsa20poly1305_open(mb, cb, clen, n, pk, sk); | |
120 int mlen = clen - crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; | |
121 char* m = emalloc(mlen); | |
122 memcpy(m, mb + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, mlen); | |
123 efree(mb); | |
124 efree(cb); | |
125 if (ret == 0) RETURN_STRINGL(m, mlen, 0); | |
126 efree(m); | |
127 RETURN_FALSE; | |
128 } | |
129 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_beforenm) { //(unsigned char *,const unsigned char *,const unsigned char *) | |
130 char *pk, *sk; | |
131 int lpk, lsk; | |
132 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &pk, &lpk, &sk, &lsk) == FAILURE) RETURN_NULL(); | |
133 if (lpk != crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) RETURN_FALSE; | |
134 if (lsk != crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) RETURN_FALSE; | |
135 char* k = emalloc(crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES); | |
136 crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk); | |
137 RETURN_STRINGL(k, crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES, 0); | |
138 } | |
139 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_afternm) { //(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *) | |
140 char *m, *n, *k; | |
141 int lm, ln, lk; | |
1
84e0f7ead583
Changed the order of function arguments to match those of the original code
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
142 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &m, &lm, &n, &ln, &k, &lk) == FAILURE) RETURN_NULL(); |
0 | 143 if (ln != crypto_box_curve25519xsalsa20poly1305_NONCEBYTES) RETURN_FALSE; |
144 if (lk != crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES) RETURN_FALSE; | |
145 int mlen = lm + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; | |
146 char* mb = ecalloc(mlen, 1); | |
147 char* cb = ecalloc(mlen, 1); | |
148 memcpy(mb + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, m, lm); | |
149 int ret = crypto_box_curve25519xsalsa20poly1305_afternm(cb, mb, mlen, n, k); | |
150 int clen = mlen - crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | |
151 char* c = emalloc(clen); | |
152 memcpy(c, cb + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, clen); | |
153 efree(mb); | |
154 efree(cb); | |
155 if (ret == 0) RETURN_STRINGL(c, clen, 0); | |
156 efree(c); | |
157 RETURN_FALSE; | |
158 } | |
159 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_open_afternm) { //(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *) | |
160 char *c, *n, *k; | |
161 int lc, ln, lk; | |
1
84e0f7ead583
Changed the order of function arguments to match those of the original code
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
162 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &c, &lc, &n, &ln, &k, &lk) == FAILURE) RETURN_NULL(); |
0 | 163 if (ln != crypto_box_curve25519xsalsa20poly1305_NONCEBYTES) RETURN_FALSE; |
164 if (lk != crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES) RETURN_FALSE; | |
165 int clen = lc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; | |
166 char* mb = ecalloc(clen, 1); | |
167 char* cb = ecalloc(clen, 1); | |
168 memcpy(cb + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES, c, lc); | |
169 int ret = crypto_box_curve25519xsalsa20poly1305_open_afternm(mb, cb, clen, n, k); | |
170 int mlen = clen - crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; | |
171 char* m = emalloc(mlen); | |
172 memcpy(m, mb + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, mlen); | |
173 efree(mb); | |
174 efree(cb); | |
175 if (ret == 0) RETURN_STRINGL(m, mlen, 0); | |
176 efree(m); | |
177 RETURN_FALSE; | |
178 } | |
179 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_getpublickey) { | |
180 char base[32] = {9}; | |
181 char *sk; | |
182 int lsk; | |
183 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &sk, &lsk) == FAILURE) RETURN_NULL(); | |
184 if (lsk != crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) RETURN_FALSE; | |
185 char* pk = emalloc(crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); | |
186 crypto_scalarmult_curve25519(pk, sk, base); | |
187 RETURN_STRINGL(pk, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, 0); | |
188 } | |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
189 PHP_FUNCTION(nacl_crypto_box_curve25519xsalsa20poly1305_keypair) { |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
190 char *rb; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
191 int lrb; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
192 zval *zsk; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
193 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zsk, &rb, &lrb) == FAILURE) RETURN_NULL(); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
194 if (!zsk) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
195 if (lrb != crypto_box_curve25519xsalsa20poly1305_KEYPAIRRANDOMBYTES) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
196 char *spk = emalloc(crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
197 char *ssk = emalloc(crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
198 int ret = crypto_box_curve25519xsalsa20poly1305_keypair(spk, ssk, rb); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
199 if (ret) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
200 zval_dtor(zsk); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
201 ZVAL_STRINGL(zsk, ssk, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES, 0); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
202 RETURN_STRINGL(spk, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, 0); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
203 } |
4
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
204 PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch) { //(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
205 char *m, *sk; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
206 int lm, lsk; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
207 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &m, &lm, &sk, &lsk) == FAILURE) RETURN_NULL(); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
208 if (lsk != crypto_sign_edwards25519sha512batch_SECRETKEYBYTES) RETURN_FALSE; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
209 int smlen = lm + crypto_sign_edwards25519sha512batch_BYTES; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
210 char* smb = emalloc(smlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
211 int ret = crypto_sign_edwards25519sha512batch(smb, &smlen, m, lm, sk); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
212 char* sm = emalloc(smlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
213 memcpy(sm, smb, smlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
214 efree(smb); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
215 if (ret == 0) RETURN_STRINGL(sm, smlen, 0); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
216 efree(sm); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
217 RETURN_FALSE; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
218 } |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
219 PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_open) { //(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
220 char *sm, *pk; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
221 int lsm, lpk; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
222 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &sm, &lsm, &pk, &lpk) == FAILURE) RETURN_NULL(); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
223 if (lpk != crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES) RETURN_FALSE; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
224 int mlen = lsm; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
225 char* mb = emalloc(mlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
226 int ret = crypto_sign_edwards25519sha512batch_open(mb, &mlen, sm, lsm, pk); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
227 char* m = emalloc(mlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
228 memcpy(m, mb, mlen); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
229 efree(mb); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
230 if (ret == 0) RETURN_STRINGL(m, mlen, 0); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
231 efree(m); |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
232 RETURN_FALSE; |
81aaf4ba1eaa
Added partial untested support for sign_edwards25519sha512batch, replaced some whitespaces with tabs
Ivo Smits <Ivo@UCIS.nl>
parents:
2
diff
changeset
|
233 } |
6
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
234 PHP_FUNCTION(nacl_crypto_sign_edwards25519sha512batch_keypair) { //(unsigned char *,unsigned char *); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
235 char *rb; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
236 int lrb; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
237 zval *zsk; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
238 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zsk, &rb, &lrb) == FAILURE) RETURN_NULL(); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
239 if (lrb != crypto_sign_edwards25519sha512batch_KEYPAIRRANDOMBYTES) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
240 if (!zsk) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
241 char *spk = emalloc(crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
242 char *ssk = emalloc(crypto_sign_edwards25519sha512batch_SECRETKEYBYTES); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
243 int ret = crypto_sign_edwards25519sha512batch_keypair(spk, ssk, rb); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
244 if (ret) RETURN_FALSE; |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
245 zval_dtor(zsk); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
246 ZVAL_STRINGL(zsk, ssk, crypto_sign_edwards25519sha512batch_SECRETKEYBYTES, 0); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
247 RETURN_STRINGL(spk, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES, 0); |
ded86f4d6275
Added keypair generation functions (with random data input)
Ivo Smits <Ivo@UCIS.nl>
parents:
5
diff
changeset
|
248 } |