Rebuild curve25519 for free

Add free to the list of exposed functions so that it can be called,
then `grunt compile concat:curve25519`
This commit is contained in:
lilia 2015-02-11 02:55:42 -08:00
parent 69ce5917f6
commit c230b47ef2
2 changed files with 22 additions and 2 deletions

View file

@ -114,7 +114,8 @@ module.exports = function(grunt) {
'curve25519_verify', 'curve25519_verify',
'crypto_sign_ed25519_ref10_ge_scalarmult_base', 'crypto_sign_ed25519_ref10_ge_scalarmult_base',
'sph_sha512_init', 'sph_sha512_init',
'malloc' 'malloc',
'free'
] ]
} }
}, },

View file

@ -918,6 +918,7 @@ function copyTempDouble(ptr) {
Module["_malloc"] = _malloc; Module["_malloc"] = _malloc;
function _free() { function _free() {
} }
Module["_free"] = _free;
Module["_strlen"] = _strlen; Module["_strlen"] = _strlen;
var Browser={mainLoop:{scheduler:null,shouldPause:false,paused:false,queue:[],pause:function () { var Browser={mainLoop:{scheduler:null,shouldPause:false,paused:false,queue:[],pause:function () {
Browser.mainLoop.shouldPause = true; Browser.mainLoop.shouldPause = true;
@ -2942,6 +2943,10 @@ run();
var res = new Uint8Array(32); var res = new Uint8Array(32);
_readBytes(publicKey_ptr, 32, res); _readBytes(publicKey_ptr, 32, res);
Module._free(publicKey_ptr);
Module._free(privateKey_ptr);
Module._free(basepoint_ptr);
return Promise.resolve({ pubKey: res.buffer, privKey: privKey }); return Promise.resolve({ pubKey: res.buffer, privKey: privKey });
}, },
sharedSecret: function(pubKey, privKey) { sharedSecret: function(pubKey, privKey) {
@ -2962,11 +2967,16 @@ run();
var res = new Uint8Array(32); var res = new Uint8Array(32);
_readBytes(sharedKey_ptr, 32, res); _readBytes(sharedKey_ptr, 32, res);
Module._free(sharedKey_ptr);
Module._free(privateKey_ptr);
Module._free(basepoint_ptr);
return Promise.resolve(res.buffer); return Promise.resolve(res.buffer);
}, },
sign: function(privKey, message) { sign: function(privKey, message) {
// Where to store the result // Where to store the result
var signature_ptr = Module._malloc(32); var signature_ptr = Module._malloc(64);
// Get a pointer to our private key // Get a pointer to our private key
var privateKey_ptr = _allocate(new Uint8Array(privKey)); var privateKey_ptr = _allocate(new Uint8Array(privKey));
@ -2981,6 +2991,11 @@ run();
var res = new Uint8Array(64); var res = new Uint8Array(64);
_readBytes(signature_ptr, 64, res); _readBytes(signature_ptr, 64, res);
Module._free(signature_ptr);
Module._free(privateKey_ptr);
Module._free(message_ptr);
return Promise.resolve(res.buffer); return Promise.resolve(res.buffer);
}, },
verify: function(pubKey, message, sig) { verify: function(pubKey, message, sig) {
@ -2998,6 +3013,10 @@ run();
message_ptr, message_ptr,
message.byteLength); message.byteLength);
Module._free(publicKey_ptr);
Module._free(signature_ptr);
Module._free(message_ptr);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
if (res !== 0) { if (res !== 0) {
reject(new Error("Invalid signature")); reject(new Error("Invalid signature"));