Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beginning to build out sendMsg in AKE #6

Closed
wants to merge 2 commits into from
Closed
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
40 changes: 35 additions & 5 deletions otr.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
var TWO = BigInt.str2bigInt('2', 10)
var N_MINUS_2 = BigInt.sub(N, TWO)

// otr message wrapper begin and end
var WRAPPER_BEGIN = "?OTR:"
var WRAPPER_END = "."

// some helpers
function checkGroup(g) {
return HLP.GTOE(g, TWO) && HLP.GTOE(N_MINUS_2, g)
Expand All @@ -67,7 +71,9 @@
, CryptoJS.enc.Latin1.parse(c)
, opts
)
return aesctr.toString()

var aesctr_decoded = CryptoJS.enc.Base64.parse(aesctr.toString())
return CryptoJS.enc.Latin1.stringify(aesctr_decoded)
}

function decryptAes(msg, c, iv) {
Expand Down Expand Up @@ -310,6 +316,30 @@
return send
},

sendMsg: function(msg){
var bm = msg.version + msg.type
switch(msg.type){
// d-h commit message
case '\x02':
bm += msg.encrypted
bm += msg.hashed
break
// d-h key message
case '\x0a':
bm += msg.gy
// reveal sig message
case '\x11':
bm += msg.r
bm += msg.aesctr
bm += msg.mac
// sig message
case '\x12':
bm += msg.aesctr
bm += msg.mac
}
return WRAPPER_BEGIN + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Latin1.parse(bm)) + WRAPPER_END
},

initiateAKE: function () {
// d-h commit message
var send = {
Expand All @@ -321,12 +351,12 @@

this.r = HLP.randomValue()
var key = CryptoJS.enc.Hex.parse(BigInt.bigInt2str(this.r, 16))
send.encrypted = makeAes(CryptoJS.enc.Latin1.parse(gxmpi), key, 0)
send.encrypted = HLP.packData(makeAes(gxmpi, key, 0))

var hash = CryptoJS.SHA256(gxmpi)
send.hashed = hash.toString(CryptoJS.enc.Latin1)
send.hashed = HLP.packData(hash.toString(CryptoJS.enc.Latin1))

this.sendMsg(send)
return this.sendMsg(send)
}

}
Expand Down Expand Up @@ -475,4 +505,4 @@

}

}).call(this)
}).call(this)
2 changes: 1 addition & 1 deletion vendor/cryptojs/cryptojs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var CryptoJS = require('./lib/core.js');

require('./lib/enc-base64.js')(CryptoJS);
require('./lib/cipher-core.js')(CryptoJS);
require('./lib/aes.js')(CryptoJS);
require('./lib/sha1.js')(CryptoJS);
require('./lib/sha256.js')(CryptoJS);
require('./lib/hmac.js')(CryptoJS);
require('./lib/pad-nopadding.js')(CryptoJS);
require('./lib/mode-ctr.js')(CryptoJS);
require('./lib/enc-base64.js')(CryptoJS);

module.exports = CryptoJS