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
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ <h4 class="modal-title" id="modal-title">Modal title</h4>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/aes.js"></script>
<script src="js/sha256.js"></script>
<script src="js/hmac-sha256.js"></script>
<script src="js/jsbn.js"></script>
<script src="js/jsbn2.js"></script>
<script src="js/base58.js"></script>
Expand Down
30 changes: 28 additions & 2 deletions js/hardbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,38 @@
* make sure to also load jquery + aes.js
*/

function constant_time_compare(a, b) {
if (typeof a !== 'string') {
throw "String expected, got " + (typeof a);
}
if (typeof b !== 'string') {
throw "String expected, got " + (typeof b);
}
if (a.length !== b.length) {
return false;
}
var d = 0;
var i = 0;
for (i = 0; i < a.length; i++) {
d |= a.charCodeAt(i) ^ b.charCodeAt(i);
}
return d === 0;
}

function encrypt(data, key) {
return CryptoJS.AES.encrypt(data, key).toString();
var unauthed = CryptoJS.AES.encrypt(data, key);
var mac = CryptoJS.HmacSHA256(unauthed, key);
return mac.toString() + unauthed.toString();
}

function decrypt(data, key) {
return CryptoJS.AES.decrypt(data, key).toString(CryptoJS.enc.Utf8);
var mac = data.substring(0, 32);
var message = data.substring(32);
var calc = CryptoJS.HmacSHA256(message, key).toString();
if (!constant_time_compare(calc, mac)) {
throw "Invalid message authentication code!";
}
return CryptoJS.AES.decrypt(message, key).toString(CryptoJS.enc.Utf8);
}

function generate_key() {
Expand Down
18 changes: 18 additions & 0 deletions js/hmac-sha256.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions js/sha256.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.