Compare commits

..

No commits in common. 'master' and 'v0.3.0' have entirely different histories.

@ -1,2 +1,2 @@
/node_modules/
/tests/
node_modules/

4
.gitignore vendored

@ -1,2 +1,2 @@
/node_modules/
/covreporter/
covreporter
node_modules

@ -1,8 +1,10 @@
language: node_js
node_js:
- "0.12.15"
- "4.5"
- "6.5.0"
- "4.1"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
before_install:
- npm install coveralls
- npm install mocha-lcov-reporter

@ -1,31 +1,18 @@
# Change Log
# v0.3.0 / 2015-12-28
## v0.3.2 / 2017-01-24
### Added
- missing arrayBuffer method.
* Added support for update hash.
* Added support for bytes array output.
* Added support for ArrayBuffer output.
## v0.3.1 / 2017-01-23
### Fixed
- ArrayBuffer dosen't work in Webpack.
# v0.2.0 / 2015-12-01
### Deprecated
- `buffer` maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
* Added support for bytes.
* Added support for AMD.
## v0.3.0 / 2015-12-28
### Added
- support for update hash.
- support for bytes array output.
- support for ArrayBuffer output.
# v0.1.1 / 2015-03-01
## v0.2.0 / 2015-12-01
### Added
- support for bytes.
- support for AMD.
Improve performance.
## v0.1.1 / 2015-03-01
### Improved
- performance.
# v0.1.0 / 2015-03-01
## v0.1.0 / 2015-03-01
### Added
- initial release.
Initial release

@ -1,4 +1,4 @@
Copyright 2015-2017 Yi-Cyuan Chen
Copyright 2015 Yi-Cyuan Chen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

@ -20,29 +20,21 @@ For node.js, you can use this command to install:
npm install js-md4
## Notice
`buffer` method is deprecated. This maybe confuse with Buffer in node.js. Please use `arrayBuffer` instead.
## Usage
You could use like this:
```JavaScript
md4('Message to hash');
var hash = md4.create();
hash.update('Message to hash');
hash.hex();
var hash2 = md4.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();
```
If you use node.js, you should require the module first:
```JavaScript
var md4 = require('js-md4');
md4 = require('js-md4');
```
It supports AMD:
```JavaScript
require(['your/path/md4.js'], function (md4) {
require(['your/path/md4.js'], function(md4) {
// ...
});
```
@ -66,7 +58,7 @@ md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.hex(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.array(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.digest(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.arrayBuffer(''); // ArrayBuffer
md4.buffer(''); // ArrayBuffer
```
## License
@ -74,4 +66,4 @@ The project is released under the [MIT license](http://www.opensource.org/licens
## Contact
The project's website is located at https://github.com/emn178/js-md4
Author: Chen, Yi-Cyuan (emn178@gmail.com)
Author: Yi-Cyuan Chen

@ -1,6 +1,6 @@
{
"name": "js-md4",
"version": "0.3.2",
"version": "0.3.0",
"main": ["src/md4.js"],
"ignore": [
"samples",

6
build/md4.min.js vendored

File diff suppressed because one or more lines are too long

@ -91,7 +91,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line132">line 132</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line113">line 113</a>
</li></ul></dd>
@ -198,7 +198,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line498">line 498</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line479">line 479</a>
</li></ul></dd>
@ -263,122 +263,6 @@
<h4 class="name" id="arrayBuffer"><span class="type-signature"></span>arrayBuffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
<div class="description">
Output hash as ArrayBuffer
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line510">line 510</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>md4.arrayBuffer</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
ArrayBuffer
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ArrayBuffer</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>hash.arrayBuffer();</code></pre>
<h4 class="name" id="buffer"><span class="type-signature"></span>buffer<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
@ -418,8 +302,6 @@
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.</li></ul></dd>
@ -432,7 +314,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line532">line 532</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line491">line 491</a>
</li></ul></dd>
@ -548,7 +430,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line476">line 476</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line457">line 457</a>
</li></ul></dd>
@ -664,7 +546,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line431">line 431</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line412">line 412</a>
</li></ul></dd>
@ -780,7 +662,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line464">line 464</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line445">line 445</a>
</li></ul></dd>
@ -954,7 +836,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line160">line 160</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line141">line 141</a>
</li></ul></dd>
@ -1031,7 +913,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -210,7 +210,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line550">line 550</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line518">line 518</a>
</li></ul></dd>
@ -285,7 +285,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -49,19 +49,13 @@
<h2>Download</h2><p><a href="https://raw.github.com/emn178/js-md4/master/build/md4.min.js">Compress</a><br><a href="https://raw.github.com/emn178/js-md4/master/src/md4.js">Uncompress</a></p>
<h2>Installation</h2><p>You can also install js-md4 by using Bower.</p>
<pre class="prettyprint source"><code>bower install js-md4</code></pre><p>For node.js, you can use this command to install:</p>
<pre class="prettyprint source"><code>npm install js-md4</code></pre><h2>Notice</h2><p><code>buffer</code> method is deprecated. This maybe confuse with Buffer in node.js. Please use <code>arrayBuffer</code> instead.</p>
<h2>Usage</h2><p>You could use like this:</p>
<pre class="prettyprint source"><code>npm install js-md4</code></pre><h2>Usage</h2><p>You could use like this:</p>
<pre class="prettyprint source lang-JavaScript"><code>md4('Message to hash');
var hash = md4.create();
hash.update('Message to hash');
hash.hex();
var hash2 = md4.update('Message to hash');
hash2.update('Message2 to hash');
hash2.array();</code></pre><p>If you use node.js, you should require the module first:</p>
<pre class="prettyprint source lang-JavaScript"><code>var md4 = require('js-md4');</code></pre><p>It supports AMD:</p>
<pre class="prettyprint source lang-JavaScript"><code>require(['your/path/md4.js'], function (md4) {
hash.hex();</code></pre><p>If you use node.js, you should require the module first:</p>
<pre class="prettyprint source lang-JavaScript"><code>md4 = require('js-md4');</code></pre><p>It supports AMD:</p>
<pre class="prettyprint source lang-JavaScript"><code>require(['your/path/md4.js'], function(md4) {
// ...
});</code></pre><p><a href="https://emn178.github.com/js-md4/doc/">See document</a></p>
<h2>Example</h2><pre class="prettyprint source lang-JavaScript"><code>md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
@ -80,8 +74,8 @@ md4(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.hex(''); // 31d6cfe0d16ae931b73c59d7e0c089c0
md4.array(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.digest(''); // [49, 214, 207, 224, 209, 106, 233, 49, 183, 60, 89, 215, 224, 192, 137, 192]
md4.arrayBuffer(''); // ArrayBuffer</code></pre><h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md4<br>Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
md4.buffer(''); // ArrayBuffer</code></pre><h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md4<br>Author: Yi-Cyuan Chen</p></article>
</section>
@ -98,7 +92,7 @@ md4.arrayBuffer(''); // ArrayBuffer</code></pre><h2>License</h2><p>The project i
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -47,7 +47,7 @@
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.3.2</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.3.0</li></ul></dd>
@ -75,7 +75,7 @@
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Yi-Cyuan Chen 2015-2027</li></ul></dd>
<dd class="tag-copyright"><ul class="dummy"><li>Yi-Cyuan Chen 2015</li></ul></dd>
@ -233,7 +233,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line54">line 54</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line53">line 53</a>
</li></ul></dd>
@ -400,7 +400,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line63">line 63</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line62">line 62</a>
</li></ul></dd>
@ -509,7 +509,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line78">line 78</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line77">line 77</a>
</li></ul></dd>
@ -676,7 +676,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line45">line 45</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line44">line 44</a>
</li></ul></dd>
@ -843,7 +843,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line34">line 34</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line33">line 33</a>
</li></ul></dd>
@ -1010,7 +1010,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line86">line 86</a>
<a href="md4.js.html">md4.js</a>, <a href="md4.js.html#line85">line 85</a>
</li></ul></dd>
@ -1085,7 +1085,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -30,27 +30,26 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.2
* @version 0.3.0
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015-2027
* @copyright Yi-Cyuan Chen 2015
* @license MIT
*/
/*jslint bitwise: true */
(function () {
(function (root) {
'use strict';
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_MD4_NO_NODE_JS &amp;&amp; typeof process === 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
var NODE_JS = typeof process == 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD4_NO_COMMON_JS &amp;&amp; typeof module === 'object' &amp;&amp; module.exports;
var AMD = typeof define === 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD4_NO_ARRAY_BUFFER &amp;&amp; typeof ArrayBuffer !== 'undefined';
var COMMON_JS = !root.JS_MD4_TEST &amp;&amp; typeof module == 'object' &amp;&amp; module.exports;
var AMD = typeof define == 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD4_TEST &amp;&amp; typeof ArrayBuffer != 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@ -125,37 +124,19 @@
*/
var createMethod = function () {
var method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Md4();
};
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0; i &lt; OUTPUT_TYPES.length; ++i) {
for (var i = 0;i &lt; OUTPUT_TYPES.length;++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type);
}
return method;
};
var nodeWrap = function (method) {
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md4').update(message, 'utf8').digest('hex');
} else if (ARRAY_BUFFER &amp;&amp; message instanceof ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
}
return crypto.createHash('md4').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
/**
* Md4 class
@ -198,8 +179,8 @@
if (this.finalized) {
return;
}
var notString = typeof message !== 'string';
if (notString &amp;&amp; ARRAY_BUFFER &amp;&amp; message instanceof ArrayBuffer) {
var notString = typeof(message) != 'string';
if(notString &amp;&amp; message.constructor == root.ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
@ -217,17 +198,17 @@
if (notString) {
if (ARRAY_BUFFER) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
blocks[i >> 2] |= message[index] &lt;&lt; SHIFT[i++ &amp; 3];
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
buffer8[i++] = code;
@ -247,7 +228,7 @@
}
}
} else {
for (i = this.start; index &lt; length &amp;&amp; i &lt; 64; ++index) {
for (i = this.start;index &lt; length &amp;&amp; i &lt; 64; ++index) {
code = message.charCodeAt(index);
if (code &lt; 0x80) {
blocks[i >> 2] |= code &lt;&lt; SHIFT[i++ &amp; 3];
@ -472,21 +453,21 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return HEX_CHARS[(h0 >> 4) &amp; 0x0F] + HEX_CHARS[h0 &amp; 0x0F] +
HEX_CHARS[(h0 >> 12) &amp; 0x0F] + HEX_CHARS[(h0 >> 8) &amp; 0x0F] +
HEX_CHARS[(h0 >> 20) &amp; 0x0F] + HEX_CHARS[(h0 >> 16) &amp; 0x0F] +
HEX_CHARS[(h0 >> 28) &amp; 0x0F] + HEX_CHARS[(h0 >> 24) &amp; 0x0F] +
HEX_CHARS[(h1 >> 4) &amp; 0x0F] + HEX_CHARS[h1 &amp; 0x0F] +
HEX_CHARS[(h1 >> 12) &amp; 0x0F] + HEX_CHARS[(h1 >> 8) &amp; 0x0F] +
HEX_CHARS[(h1 >> 20) &amp; 0x0F] + HEX_CHARS[(h1 >> 16) &amp; 0x0F] +
HEX_CHARS[(h1 >> 28) &amp; 0x0F] + HEX_CHARS[(h1 >> 24) &amp; 0x0F] +
HEX_CHARS[(h2 >> 4) &amp; 0x0F] + HEX_CHARS[h2 &amp; 0x0F] +
HEX_CHARS[(h2 >> 12) &amp; 0x0F] + HEX_CHARS[(h2 >> 8) &amp; 0x0F] +
HEX_CHARS[(h2 >> 20) &amp; 0x0F] + HEX_CHARS[(h2 >> 16) &amp; 0x0F] +
HEX_CHARS[(h2 >> 28) &amp; 0x0F] + HEX_CHARS[(h2 >> 24) &amp; 0x0F] +
HEX_CHARS[(h3 >> 4) &amp; 0x0F] + HEX_CHARS[h3 &amp; 0x0F] +
HEX_CHARS[(h3 >> 12) &amp; 0x0F] + HEX_CHARS[(h3 >> 8) &amp; 0x0F] +
HEX_CHARS[(h3 >> 20) &amp; 0x0F] + HEX_CHARS[(h3 >> 16) &amp; 0x0F] +
HEX_CHARS[(h3 >> 28) &amp; 0x0F] + HEX_CHARS[(h3 >> 24) &amp; 0x0F];
HEX_CHARS[(h0 >> 12) &amp; 0x0F] + HEX_CHARS[(h0 >> 8) &amp; 0x0F] +
HEX_CHARS[(h0 >> 20) &amp; 0x0F] + HEX_CHARS[(h0 >> 16) &amp; 0x0F] +
HEX_CHARS[(h0 >> 28) &amp; 0x0F] + HEX_CHARS[(h0 >> 24) &amp; 0x0F] +
HEX_CHARS[(h1 >> 4) &amp; 0x0F] + HEX_CHARS[h1 &amp; 0x0F] +
HEX_CHARS[(h1 >> 12) &amp; 0x0F] + HEX_CHARS[(h1 >> 8) &amp; 0x0F] +
HEX_CHARS[(h1 >> 20) &amp; 0x0F] + HEX_CHARS[(h1 >> 16) &amp; 0x0F] +
HEX_CHARS[(h1 >> 28) &amp; 0x0F] + HEX_CHARS[(h1 >> 24) &amp; 0x0F] +
HEX_CHARS[(h2 >> 4) &amp; 0x0F] + HEX_CHARS[h2 &amp; 0x0F] +
HEX_CHARS[(h2 >> 12) &amp; 0x0F] + HEX_CHARS[(h2 >> 8) &amp; 0x0F] +
HEX_CHARS[(h2 >> 20) &amp; 0x0F] + HEX_CHARS[(h2 >> 16) &amp; 0x0F] +
HEX_CHARS[(h2 >> 28) &amp; 0x0F] + HEX_CHARS[(h2 >> 24) &amp; 0x0F] +
HEX_CHARS[(h3 >> 4) &amp; 0x0F] + HEX_CHARS[h3 &amp; 0x0F] +
HEX_CHARS[(h3 >> 12) &amp; 0x0F] + HEX_CHARS[(h3 >> 8) &amp; 0x0F] +
HEX_CHARS[(h3 >> 20) &amp; 0x0F] + HEX_CHARS[(h3 >> 16) &amp; 0x0F] +
HEX_CHARS[(h3 >> 28) &amp; 0x0F] + HEX_CHARS[(h3 >> 24) &amp; 0x0F];
};
/**
@ -536,16 +517,16 @@
Md4.prototype.array = Md4.prototype.digest;
/**
* @method arrayBuffer
* @method buffer
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.arrayBuffer}
* @see {@link md4.buffer}
* @example
* hash.arrayBuffer();
* hash.buffer();
*/
Md4.prototype.arrayBuffer = function() {
Md4.prototype.buffer = function() {
this.finalize();
var buffer = new ArrayBuffer(16);
@ -557,19 +538,6 @@
return buffer;
};
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @example
* hash.buffer();
*/
Md4.prototype.buffer = Md4.prototype.arrayBuffer;
var exports = createMethod();
if (COMMON_JS) {
@ -599,7 +567,7 @@
});
}
}
})();
}(this));
</code></pre>
</article>
</section>
@ -616,7 +584,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jan 24 2017 15:15:12 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Dec 28 2015 11:56:02 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>

@ -153,7 +153,7 @@ h1
margin: 12px 24px 20px;
}
h2, h3.subsection-title
h2, h3
{
font-size: 30px;
font-weight: 700;
@ -161,13 +161,6 @@ h2, h3.subsection-title
margin-bottom: 12px;
}
h3
{
font-size: 24px;
letter-spacing: -0.5px;
margin-bottom: 12px;
}
h4
{
font-size: 18px;
@ -192,32 +185,6 @@ h6
font-style: italic;
}
table
{
border-spacing: 0;
border: 0;
border-collapse: collapse;
}
td, th
{
border: 1px solid #ddd;
margin: 0px;
text-align: left;
vertical-align: top;
padding: 4px 6px;
display: table-cell;
}
thead tr
{
background-color: #ddd;
font-weight: bold;
}
th { border-right: 1px solid #aaa; }
tr > th:last-child { border-right: 1px solid #ddd; }
.ancestors { color: #999; }
.ancestors a
{
@ -329,12 +296,44 @@ tr > th:last-child { border-right: 1px solid #ddd; }
user-select: text;
}
.params, .props
{
border-spacing: 0;
border: 0;
border-collapse: collapse;
}
.params .name, .props .name, .name code {
color: #4D4E53;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
font-size: 100%;
}
.params td, .params th, .props td, .props th
{
border: 1px solid #ddd;
margin: 0px;
text-align: left;
vertical-align: top;
padding: 4px 6px;
display: table-cell;
}
.params thead tr, .props thead tr
{
background-color: #ddd;
font-weight: bold;
}
.params .params thead tr, .props .props thead tr
{
background-color: #fff;
font-weight: bold;
}
.params th, .props th { border-right: 1px solid #aaa; }
.params thead .last, .props thead .last { border-right: 1px solid #ddd; }
.params td.description > p:first-child,
.props td.description > p:first-child
{

@ -1,6 +1,6 @@
{
"name": "js-md4",
"version": "0.3.2",
"version": "0.3.0",
"description": "A simple MD4 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md4.js",
"devDependencies": {
@ -30,7 +30,7 @@
"HMAC"
],
"license": "MIT",
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
"author": "emn178 <emn178@gmail.com>",
"homepage": "https://github.com/emn178/js-md4",
"bugs": {
"url": "https://github.com/emn178/js-md4/issues"

@ -2,27 +2,26 @@
* [js-md4]{@link https://github.com/emn178/js-md4}
*
* @namespace md4
* @version 0.3.2
* @version 0.3.0
* @author Yi-Cyuan Chen [emn178@gmail.com]
* @copyright Yi-Cyuan Chen 2015-2027
* @copyright Yi-Cyuan Chen 2015
* @license MIT
*/
/*jslint bitwise: true */
(function () {
(function (root) {
'use strict';
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_MD4_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD4_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD4_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var COMMON_JS = !root.JS_MD4_TEST && typeof module == 'object' && module.exports;
var AMD = typeof define == 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD4_TEST && typeof ArrayBuffer != 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer'];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer'];
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
@ -97,37 +96,19 @@
*/
var createMethod = function () {
var method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Md4();
};
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
for (var i = 0;i < OUTPUT_TYPES.length;++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type);
}
return method;
};
var nodeWrap = function (method) {
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md4').update(message, 'utf8').digest('hex');
} else if (ARRAY_BUFFER && message instanceof ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
}
return crypto.createHash('md4').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
/**
* Md4 class
@ -170,8 +151,8 @@
if (this.finalized) {
return;
}
var notString = typeof message !== 'string';
if (notString && ARRAY_BUFFER && message instanceof ArrayBuffer) {
var notString = typeof(message) != 'string';
if(notString && message.constructor == root.ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
@ -189,17 +170,17 @@
if (notString) {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
for (i = this.start;index < length && i < 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
for (i = this.start;index < length && i < 64; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
for (i = this.start;index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
buffer8[i++] = code;
@ -219,7 +200,7 @@
}
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
for (i = this.start;index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
@ -444,21 +425,21 @@
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F];
};
/**
@ -508,16 +489,16 @@
Md4.prototype.array = Md4.prototype.digest;
/**
* @method arrayBuffer
* @method buffer
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.arrayBuffer}
* @see {@link md4.buffer}
* @example
* hash.arrayBuffer();
* hash.buffer();
*/
Md4.prototype.arrayBuffer = function() {
Md4.prototype.buffer = function() {
this.finalize();
var buffer = new ArrayBuffer(16);
@ -529,19 +510,6 @@
return buffer;
};
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof Md4
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md4.buffer}
* @example
* hash.buffer();
*/
Md4.prototype.buffer = Md4.prototype.arrayBuffer;
var exports = createMethod();
if (COMMON_JS) {
@ -571,4 +539,4 @@
});
}
}
})();
}(this));

@ -1,38 +1,12 @@
// Node.js env
expect = require('expect.js');
md4 = require('../src/md4.js');
expect = require('expect.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')]
delete require.cache[require.resolve('./test.js')]
md4 = null
// Webpack browser env
JS_MD4_NO_NODE_JS = true;
window = global;
md4 = require('../src/md4.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
// browser env
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
window = global;
require('../src/md4.js');
require('./test.js');
delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
// browser env and no array buffer
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
JS_MD4_NO_ARRAY_BUFFER = true;
window = global;
JS_MD4_TEST = true;
require('../src/md4.js');
require('./test.js');
@ -40,12 +14,7 @@ delete require.cache[require.resolve('../src/md4.js')];
delete require.cache[require.resolve('./test.js')];
md4 = null;
// browser AMD
JS_MD4_NO_NODE_JS = true;
JS_MD4_NO_COMMON_JS = true;
JS_MD4_NO_ARRAY_BUFFER = undefined;
window = global;
define = function (func) {
define = function(func) {
md4 = func();
require('./test.js');
};

@ -2,9 +2,9 @@
Array.prototype.toHexString = ArrayBuffer.prototype.toHexString = function () {
var array = new Uint8Array(this);
var hex = '';
for (var i = 0; i < array.length; ++i) {
for (var i = 0;i < array.length;++i) {
var c = array[i].toString('16');
hex += c.length === 1 ? '0' + c : c;
hex += c.length == 1 ? '0' + c : c;
}
return hex;
};
@ -53,6 +53,7 @@
'47c61a0fa8738ba77308a8a600f88e4b': new ArrayBuffer(1)
},
'Object': {
'31d6cfe0d16ae931b73c59d7e0c089c0': {},
'31d6cfe0d16ae931b73c59d7e0c089c0': {what: 'ever'}
}
};
@ -118,9 +119,9 @@
}
},
{
name: 'arrayBuffer',
name: 'buffer',
call: function (message) {
return md4.update(message).arrayBuffer().toHexString();
return md4.update(message).buffer().toHexString();
}
},
{
@ -134,41 +135,34 @@
}
];
if (typeof JS_MD4_NO_ARRAY_BUFFER !== 'undefined') {
classMethods = classMethods.filter(function (method) {
return method.name != 'arrayBuffer';
});
delete testCases['ArrayBuffer'];
}
describe('Md4', function () {
methods.forEach(function (method) {
describe('#' + method.name, function() {
for (var testCaseName in testCases) {
(function (testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function (message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
methods.forEach(function (method) {
describe('#' + method.name, function() {
for(var testCaseName in testCases) {
(function(testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function(message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});
})(testCase[hash], hash);
}
});
})(testCaseName);
}
});
});
describe('Md4', function() {
classMethods.forEach(function (method) {
describe('#' + method.name, function() {
for (var testCaseName in testCases) {
(function (testCaseName) {
for(var testCaseName in testCases) {
(function(testCaseName) {
var testCase = testCases[testCaseName];
context('when ' + testCaseName, function() {
for(var hash in testCase) {
(function (message, hash) {
(function(message, hash) {
it('should be equal', function() {
expect(method.call(message)).to.be(hash);
});

Loading…
Cancel
Save