From c230b47ef2b44143654ec5b5b5e6e9148d4d06fa Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 11 Feb 2015 02:55:42 -0800 Subject: [PATCH] Rebuild curve25519 for free Add free to the list of exposed functions so that it can be called, then `grunt compile concat:curve25519` --- Gruntfile.js | 3 ++- libtextsecure/curve25519_concat.js | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 22907259..485477b3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -114,7 +114,8 @@ module.exports = function(grunt) { 'curve25519_verify', 'crypto_sign_ed25519_ref10_ge_scalarmult_base', 'sph_sha512_init', - 'malloc' + 'malloc', + 'free' ] } }, diff --git a/libtextsecure/curve25519_concat.js b/libtextsecure/curve25519_concat.js index 16fd258e..8e35e9f5 100644 --- a/libtextsecure/curve25519_concat.js +++ b/libtextsecure/curve25519_concat.js @@ -918,6 +918,7 @@ function copyTempDouble(ptr) { Module["_malloc"] = _malloc; function _free() { } + Module["_free"] = _free; Module["_strlen"] = _strlen; var Browser={mainLoop:{scheduler:null,shouldPause:false,paused:false,queue:[],pause:function () { Browser.mainLoop.shouldPause = true; @@ -2942,6 +2943,10 @@ run(); var res = new Uint8Array(32); _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 }); }, sharedSecret: function(pubKey, privKey) { @@ -2962,11 +2967,16 @@ run(); var res = new Uint8Array(32); _readBytes(sharedKey_ptr, 32, res); + + Module._free(sharedKey_ptr); + Module._free(privateKey_ptr); + Module._free(basepoint_ptr); + return Promise.resolve(res.buffer); }, sign: function(privKey, message) { // Where to store the result - var signature_ptr = Module._malloc(32); + var signature_ptr = Module._malloc(64); // Get a pointer to our private key var privateKey_ptr = _allocate(new Uint8Array(privKey)); @@ -2981,6 +2991,11 @@ run(); var res = new Uint8Array(64); _readBytes(signature_ptr, 64, res); + + Module._free(signature_ptr); + Module._free(privateKey_ptr); + Module._free(message_ptr); + return Promise.resolve(res.buffer); }, verify: function(pubKey, message, sig) { @@ -2998,6 +3013,10 @@ run(); message_ptr, message.byteLength); + Module._free(publicKey_ptr); + Module._free(signature_ptr); + Module._free(message_ptr); + return new Promise(function(resolve, reject) { if (res !== 0) { reject(new Error("Invalid signature"));