Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/node/algorithms/shared/AES.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
var sjcl = require("sjcl");
var sjcl = require("sjcl"),
crypto = require("crypto");

function AES_generateKey(noop){
return;
function AES_generateKey(algorithm){
return raw_import(crypto.randomBytes(algorithm.length / 8));
}

function raw_import(buf){
return new sjcl.cipher.aes(sjcl.codec.hex.toBits(buf.toString("hex")));
var key = new sjcl.cipher.aes(sjcl.codec.hex.toBits(buf.toString("hex")));
key._raw = buf;
return key;
}

function raw_export(key){
return key;
return key._raw;
}

function AES(Algorithm){
Algorithm.formats.raw.import = raw_import;
Algorithm.formats.raw.export = raw_export;
Algorithm.generate = AES_generateKey;
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/node/generateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ function generateKey(algorithm, exportable, usages, nonce){

//construct the return object from the scaffold
Object.keys(_scaf).forEach(function(type){
_res[_alg.types[type].returnLabel] = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce);
if (_alg.types[type].returnLabel) {
_res[_alg.types[type].returnLabel] = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce);
}
else {
_res = new CryptoKey(_key, type, _scaf[type]._exp, _scaf[type]._uses, nonce);
}
})

//special case... ECDH public keys don't have they're own usage, but are still needed as params in deriveKey/Bits
Expand Down