Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Sep 2, 2014
1 parent 4b75b3e commit fd784e2
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -5,8 +5,8 @@
[2]: https://coveralls.io/r/litejs/crypto-lite
[4]: http://nodejs.org/api/crypto.html

@version 0.0.4
@date 2014-04-21
@version 0.0.5
@date 2014-09-02

Standard cryptographic algorithms – [![Build][]][1] [![Coverage][]][2]
=================================
Expand Down Expand Up @@ -41,7 +41,9 @@ var crypto = require("crypto-lite").crypto
External links
--------------

- [npmjs.org/package/crypto-lite](https://npmjs.org/package/crypto-lite)
- [Source-code on Github](https://github.com/litejs/crypto-lite)
- [Package on npm](https://npmjs.org/package/crypto-lite)


### Licence

Expand Down
5 changes: 0 additions & 5 deletions build/crypto-lite-min.js

This file was deleted.

2 changes: 0 additions & 2 deletions build/sha1.js

This file was deleted.

3 changes: 0 additions & 3 deletions build/sha256.js

This file was deleted.

8 changes: 8 additions & 0 deletions dist/crypto-lite-min.js

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

67 changes: 45 additions & 22 deletions build/sha1-src.js → dist/sha1-src.js
@@ -1,32 +1,52 @@



/*
* @version 0.0.4
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
/**
* @version 0.0.5
* @date 2014-09-02
* @stability 1 - Experimental
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/



!function(root, nuls) {
var crypto = root.crypto || (root.crypto = {})

!function(exports) {
var crypto = exports.crypto || (exports.crypto = {})

/**
* Convert array of integers to a hex string.
*
* @param {number[]} array of integers
*
* @return {string} HEX string
*/

function i2s(a) { // integer array to hex string
for (var i = a.length; i--;) a[i] = ("0000000"+(a[i]>>>0).toString(16)).slice(-8)
return a.join("")
}

/**
* Convert string to an array of integers.
*
* @param {string}
*
* @return {number[]} array of integers
*/

function s2i(s) { // string to integer array
s = unescape(encodeURIComponent(s))
var len = s.length
, i = 0
, bin = []

while (i < len) {
bin[i>>2] = s.charCodeAt(i)<<24|s.charCodeAt(i+1)<<16|s.charCodeAt(i+2)<<8|s.charCodeAt(i+3)
i+=4
bin[i>>2] = s.charCodeAt(i++)<<24 |
s.charCodeAt(i++)<<16 |
s.charCodeAt(i++)<<8 |
s.charCodeAt(i++)
}
bin.len = len
return bin
Expand All @@ -40,7 +60,7 @@
, ipad = []
, opad = []
key = (key.length > 64) ? hasher(key, true) : s2i(key)
key = (key.length > 64) ? hasher(key, 1) : s2i(key)
while (i < 16) {
ipad[i] = key[i]^0x36363636
Expand Down Expand Up @@ -79,6 +99,7 @@
/*** PBKDF2
// pbkdf2(sha256, this, salt, count, length || 32)
// crypto.pbkdf2('secret', 'salt', 4096, 512, 'sha256', function(err, key) {
// $PBKDF2$HMACSHA1:1000:akrvug==$Zi+c82tnjpcrRmUAHRd8h4ZRR5M=
crypto.pbkdf2 = crypto.pbkdf2Sync = pbkdf2
Expand Down Expand Up @@ -115,14 +136,16 @@
//*/


function sha_init(bin, len) {
function shaInit(bin, len) {
if (typeof bin == "string") {
bin = s2i(bin)
len = bin.len
} else len = len || bin.length<<2

bin[len>>2] |= 0x80 << (24 - (31 & len<<3))
return bin.concat(nuls.slice( bin.length & 15 ), [0, len<<3])
bin[len>>2] |= 0x80 << (24 - (31 & (len<<=3)))
bin[((len + 64 >> 9) << 4) + 15] = len

return bin
}

//** sha1
Expand All @@ -139,7 +162,7 @@
, C = 0x98badcfe
, D = 0x10325476
, E = 0xc3d2e1f0
, bin = sha_init(data, _len)
, bin = shaInit(data, _len)
, len = bin.length

while (i < len) {
Expand All @@ -152,7 +175,7 @@
e = E
j = 0
while (j<80) {
t = (j<20 ? ((b&c)|(~b&d))+0x5A827999 : j<40 ? (b^c^d)+0x6ED9EBA1 : j<60 ? ((b&c)|(b&d)|(c&d))+0x8F1BBCDC : (b^c^d)+0xCA62C1D6)+l(a,5)+e+w[j++]
t = (j<20 ? ((b&c)|(~b&d))+0x5A827999 : j<40 ? (b^c^d)+0x6ED9EBA1 : j<60 ? ((b&c)|(b&d)|(c&d))+0x8F1BBCDC : (b^c^d)+0xCA62C1D6)+l(a,5)+e+(w[j++]|0)
e = d
d = c
c = l(b,30)
Expand Down Expand Up @@ -183,7 +206,7 @@
/*** sha256
var initial_map = [], constants_map = []
function build_maps() {
function buildMaps() {
// getFractionalBits
function a(e) {
return (e - (e>>>0)) * 0x100000000 | 0
Expand All @@ -198,12 +221,11 @@
}
function sha256(data, raw, _len) {
initial_map[0] || build_maps()
initial_map[0] || buildMaps()
var a, b, c, d, e, f, g, h, t1, t2, j
, i = 0
, w = []
, bin = sha_init(data, _len)
, A = initial_map[0]
, B = initial_map[1]
, C = initial_map[2]
Expand All @@ -212,6 +234,7 @@
, F = initial_map[5]
, G = initial_map[6]
, H = initial_map[7]
, bin = shaInit(data, _len)
, len = bin.length
, K = constants_map
Expand All @@ -232,10 +255,10 @@
else {
t1 = w[j-2]
t2 = w[j-15]
w[j] = (t1>>>17^t1<<15^t1>>>19^t1<<13^t1>>>10) + w[j-7] + (t2>>>7^t2<<25^t2>>>18^t2<<14^t2>>>3) + w[j-16]
w[j] = (t1>>>17^t1<<15^t1>>>19^t1<<13^t1>>>10) + (w[j-7]|0) + (t2>>>7^t2<<25^t2>>>18^t2<<14^t2>>>3) + (w[j-16]|0)
}
t1 = w[j] + h + (e>>>6^e<<26^e>>>11^e<<21^e>>>25^e<<7) + ((e&f)^((~e)&g)) + K[j]
t1 = (w[j]|0) + h + (e>>>6^e<<26^e>>>11^e<<21^e>>>25^e<<7) + ((e&f)^((~e)&g)) + K[j]
t2 = (a>>>2^a<<30^a>>>13^a<<19^a>>>22^a<<10) + ((a&b)^(a&c)^(b&c))
h = g
Expand All @@ -256,7 +279,7 @@
F += f
G += g
H += h
i+=16
i += 16
}
t = [A, B, C, D, E, F, G, H]
return raw ? t : i2s(t)
Expand All @@ -273,6 +296,6 @@
}
//*/

}(this, [0,0,0,0,0,0,0,0,0,0,0,0,0,0])
}(this)


5 changes: 5 additions & 0 deletions dist/sha1.js

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

0 comments on commit fd784e2

Please sign in to comment.