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',
'crypto_sign_ed25519_ref10_ge_scalarmult_base',
'sph_sha512_init',
'malloc'
'malloc',
'free'
]
}
},

View file

@ -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"));