└── nd1309_practice_block
├── package.json
├── README.md
├── package-lock.json
├── crypto-js
├── enc-hex.js
├── enc-latin1.js
├── enc-utf8.js
├── pad-pkcs7.js
├── format-openssl.js
├── hmac-md5.js
├── hmac-sha1.js
├── hmac-sha256.js
├── hmac-ripemd160.js
├── hmac-sha3.js
├── hmac-sha224.js
├── hmac-sha512.js
├── hmac-sha384.js
├── pad-nopadding.js
├── bower.json
├── mode-ecb.js
├── pad-iso97971.js
├── LICENSE
├── pad-iso10126.js
├── pad-zeropadding.js
├── pad-ansix923.js
├── mode-ofb.js
├── index.js
├── mode-ctr.js
├── package.json
├── format-hex.js
├── sha224.js
├── mode-cfb.js
├── lib-typedarrays.js
├── sha384.js
├── mode-ctr-gladman.js
├── rc4.js
├── evpkdf.js
├── hmac.js
├── enc-base64.js
├── sha1.js
├── enc-utf16.js
├── pbkdf2.js
├── sha256.js
├── README.md
├── rabbit.js
├── rabbit-legacy.js
├── aes.js
├── x64-core.js
├── ripemd160.js
├── md5.js
├── sha3.js
├── sha512.js
├── docs
│ └── QuickStartGuide.wiki
└── core.js
├── app.js
├── block.js
└── .gitignore
/nd1309_practice_block/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "block_data",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "app.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "crypto-js": "^3.1.9-1"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/nd1309_practice_block/README.md:
--------------------------------------------------------------------------------
1 | # Practice Block Data Exercise
2 |
3 |
4 | To use this boilerplate code locally follow this steps:
5 |
6 | 1. Clone or download the project.
7 | 2. Open your project with your favorite IDE.
8 | 3. Run `npm install` to install the dependencies.
9 | 4. Implement your code.
10 | 5. Use `node app.js` to run the application.
11 |
--------------------------------------------------------------------------------
/nd1309_practice_block/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "block_data",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "crypto-js": {
8 | "version": "3.1.9-1",
9 | "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz",
10 | "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg="
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/enc-hex.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.enc.Hex;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/enc-latin1.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.enc.Latin1;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/enc-utf8.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.enc.Utf8;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-pkcs7.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.pad.Pkcs7;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/format-openssl.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.format.OpenSSL;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-md5.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./md5"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./md5", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacMD5;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha1.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha1", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA1;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha256.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha256", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA256;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-ripemd160.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./ripemd160"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./ripemd160", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacRIPEMD160;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha3.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha3"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core", "./sha3", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA3;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha224.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha256"), require("./sha224"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha256", "./sha224", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA224;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha512.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core", "./sha512", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA512;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac-sha384.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"), require("./sha384"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core", "./sha512", "./sha384", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS.HmacSHA384;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Importing the Block class
3 | */
4 | //
5 | const BlockClass = require('./block.js');
6 |
7 | /**
8 | * Creating a block object
9 | */
10 | const block = new BlockClass.Block("Test Block");
11 |
12 | // Generating the block hash
13 | block.generateHash().then((result) => {
14 | console.log(`Block Hash: ${result.hash}`);
15 | console.log(`Block: ${JSON.stringify(result)}`);
16 | }).catch((error) => {console.log(error)});
17 |
18 | /**
19 | * Step 3: Run the application in node.js
20 | *
21 | */
22 |
23 | // From the terminal: cd into Project folder
24 | // From the terminal: Run node app.js to run the code
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-nopadding.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * A noop padding strategy.
18 | */
19 | CryptoJS.pad.NoPadding = {
20 | pad: function () {
21 | },
22 |
23 | unpad: function () {
24 | }
25 | };
26 |
27 |
28 | return CryptoJS.pad.NoPadding;
29 |
30 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crypto-js",
3 | "version": "4.0.0",
4 | "description": "JavaScript library of crypto standards.",
5 | "license": "MIT",
6 | "homepage": "http://github.com/brix/crypto-js",
7 | "repository": {
8 | "type": "git",
9 | "url": "http://github.com/brix/crypto-js.git"
10 | },
11 | "keywords": [
12 | "security",
13 | "crypto",
14 | "Hash",
15 | "MD5",
16 | "SHA1",
17 | "SHA-1",
18 | "SHA256",
19 | "SHA-256",
20 | "RC4",
21 | "Rabbit",
22 | "AES",
23 | "DES",
24 | "PBKDF2",
25 | "HMAC",
26 | "OFB",
27 | "CFB",
28 | "CTR",
29 | "CBC",
30 | "Base64"
31 | ],
32 | "main": "index.js",
33 | "dependencies": {},
34 | "ignore": []
35 | }
36 |
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/mode-ecb.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * Electronic Codebook block mode.
18 | */
19 | CryptoJS.mode.ECB = (function () {
20 | var ECB = CryptoJS.lib.BlockCipherMode.extend();
21 |
22 | ECB.Encryptor = ECB.extend({
23 | processBlock: function (words, offset) {
24 | this._cipher.encryptBlock(words, offset);
25 | }
26 | });
27 |
28 | ECB.Decryptor = ECB.extend({
29 | processBlock: function (words, offset) {
30 | this._cipher.decryptBlock(words, offset);
31 | }
32 | });
33 |
34 | return ECB;
35 | }());
36 |
37 |
38 | return CryptoJS.mode.ECB;
39 |
40 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-iso97971.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * ISO/IEC 9797-1 Padding Method 2.
18 | */
19 | CryptoJS.pad.Iso97971 = {
20 | pad: function (data, blockSize) {
21 | // Add 0x80 byte
22 | data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
23 |
24 | // Zero pad the rest
25 | CryptoJS.pad.ZeroPadding.pad(data, blockSize);
26 | },
27 |
28 | unpad: function (data) {
29 | // Remove zero padding
30 | CryptoJS.pad.ZeroPadding.unpad(data);
31 |
32 | // Remove one more byte -- the 0x80 byte
33 | data.sigBytes--;
34 | }
35 | };
36 |
37 |
38 | return CryptoJS.pad.Iso97971;
39 |
40 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/LICENSE:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | [The MIT License (MIT)](http://opensource.org/licenses/MIT)
4 |
5 | Copyright (c) 2009-2013 Jeff Mott
6 | Copyright (c) 2013-2016 Evan Vosberg
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
--------------------------------------------------------------------------------
/nd1309_practice_block/block.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Import crypto-js/SHA256 library
3 | */
4 | const SHA256 = require('crypto-js/sha256');
5 |
6 | /**
7 | * Class with a constructor for block
8 | */
9 | class Block {
10 |
11 | constructor(data){
12 | this.id = 0;
13 | this.nonce = 144444;
14 | this.body = data;
15 | this.hash = "";
16 | }
17 |
18 | /**
19 | * Step 1. Implement `generateHash()`
20 | * method that return the `self` block with the hash.
21 | *
22 | * Create a Promise that resolve with `self` after you create
23 | * the hash of the object and assigned to the hash property `self.hash = ...`
24 | */
25 | //
26 | generateHash() {
27 | // Use this to create a temporary reference of the class object
28 | let self = this;
29 | var promise=new Promise(function(resolve,reject){
30 | let hash=SHA256(JSON.stringify(self)).toString();
31 | if(hash!=null){
32 | self.hash=hash;
33 | resolve(self);
34 | }
35 | else{
36 | reject("Not Worked");
37 | }
38 | });
39 | //Implement your code here
40 | return promise;
41 | }
42 | }
43 |
44 | // Exporting the class Block to be reuse in other files
45 | module.exports.Block = Block;
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-iso10126.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * ISO 10126 padding strategy.
18 | */
19 | CryptoJS.pad.Iso10126 = {
20 | pad: function (data, blockSize) {
21 | // Shortcut
22 | var blockSizeBytes = blockSize * 4;
23 |
24 | // Count padding bytes
25 | var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
26 |
27 | // Pad
28 | data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
29 | concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
30 | },
31 |
32 | unpad: function (data) {
33 | // Get number of padding bytes from last byte
34 | var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
35 |
36 | // Remove padding
37 | data.sigBytes -= nPaddingBytes;
38 | }
39 | };
40 |
41 |
42 | return CryptoJS.pad.Iso10126;
43 |
44 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-zeropadding.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * Zero padding strategy.
18 | */
19 | CryptoJS.pad.ZeroPadding = {
20 | pad: function (data, blockSize) {
21 | // Shortcut
22 | var blockSizeBytes = blockSize * 4;
23 |
24 | // Pad
25 | data.clamp();
26 | data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
27 | },
28 |
29 | unpad: function (data) {
30 | // Shortcut
31 | var dataWords = data.words;
32 |
33 | // Unpad
34 | var i = data.sigBytes - 1;
35 | for (var i = data.sigBytes - 1; i >= 0; i--) {
36 | if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
37 | data.sigBytes = i + 1;
38 | break;
39 | }
40 | }
41 | }
42 | };
43 |
44 |
45 | return CryptoJS.pad.ZeroPadding;
46 |
47 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pad-ansix923.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * ANSI X.923 padding strategy.
18 | */
19 | CryptoJS.pad.AnsiX923 = {
20 | pad: function (data, blockSize) {
21 | // Shortcuts
22 | var dataSigBytes = data.sigBytes;
23 | var blockSizeBytes = blockSize * 4;
24 |
25 | // Count padding bytes
26 | var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
27 |
28 | // Compute last byte position
29 | var lastBytePos = dataSigBytes + nPaddingBytes - 1;
30 |
31 | // Pad
32 | data.clamp();
33 | data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
34 | data.sigBytes += nPaddingBytes;
35 | },
36 |
37 | unpad: function (data) {
38 | // Get number of padding bytes from last byte
39 | var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
40 |
41 | // Remove padding
42 | data.sigBytes -= nPaddingBytes;
43 | }
44 | };
45 |
46 |
47 | return CryptoJS.pad.Ansix923;
48 |
49 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/mode-ofb.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * Output Feedback block mode.
18 | */
19 | CryptoJS.mode.OFB = (function () {
20 | var OFB = CryptoJS.lib.BlockCipherMode.extend();
21 |
22 | var Encryptor = OFB.Encryptor = OFB.extend({
23 | processBlock: function (words, offset) {
24 | // Shortcuts
25 | var cipher = this._cipher
26 | var blockSize = cipher.blockSize;
27 | var iv = this._iv;
28 | var keystream = this._keystream;
29 |
30 | // Generate keystream
31 | if (iv) {
32 | keystream = this._keystream = iv.slice(0);
33 |
34 | // Remove IV for subsequent blocks
35 | this._iv = undefined;
36 | }
37 | cipher.encryptBlock(keystream, 0);
38 |
39 | // Encrypt
40 | for (var i = 0; i < blockSize; i++) {
41 | words[offset + i] ^= keystream[i];
42 | }
43 | }
44 | });
45 |
46 | OFB.Decryptor = Encryptor;
47 |
48 | return OFB;
49 | }());
50 |
51 |
52 | return CryptoJS.mode.OFB;
53 |
54 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/.gitignore:
--------------------------------------------------------------------------------
1 | # Visual Studeio Code Editor
2 | /.vscode/*
3 | !/.vscode/settings.json
4 | !/.vscode/tasks.json
5 | !/.vscode/launch.json
6 | !/.vscode/extensions.json
7 | # Build directories
8 | /build/*
9 | # OSX
10 | /.DS_Store
11 | # Logs
12 | logs
13 | *.log
14 | npm-debug.log*
15 | yarn-debug.log*
16 | yarn-error.log*
17 |
18 | # Runtime data
19 | pids
20 | *.pid
21 | *.seed
22 | *.pid.lock
23 |
24 | # Directory for instrumented libs generated by jscoverage/JSCover
25 | lib-cov
26 |
27 | # Coverage directory used by tools like istanbul
28 | coverage
29 |
30 | # nyc test coverage
31 | .nyc_output
32 |
33 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
34 | .grunt
35 |
36 | # Bower dependency directory (https://bower.io/)
37 | bower_components
38 |
39 | # node-waf configuration
40 | .lock-wscript
41 |
42 | # Compiled binary addons (https://nodejs.org/api/addons.html)
43 | build/Release
44 |
45 | # Dependency directories
46 | node_modules/
47 | jspm_packages/
48 |
49 | # TypeScript v1 declaration files
50 | typings/
51 |
52 | # Optional npm cache directory
53 | .npm
54 |
55 | # Optional eslint cache
56 | .eslintcache
57 |
58 | # Optional REPL history
59 | .node_repl_history
60 |
61 | # Output of 'npm pack'
62 | *.tgz
63 |
64 | # Yarn Integrity file
65 | .yarn-integrity
66 |
67 | # dotenv environment variables file
68 | .env
69 |
70 | # parcel-bundler cache (https://parceljs.org/)
71 | .cache
72 |
73 | # next.js build output
74 | .next
75 |
76 | # nuxt.js build output
77 | .nuxt
78 |
79 | # vuepress build output
80 | .vuepress/dist
81 |
82 | # Serverless directories
83 | .serverless
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/index.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"), require("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | root.CryptoJS = factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | return CryptoJS;
17 |
18 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/mode-ctr.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * Counter block mode.
18 | */
19 | CryptoJS.mode.CTR = (function () {
20 | var CTR = CryptoJS.lib.BlockCipherMode.extend();
21 |
22 | var Encryptor = CTR.Encryptor = CTR.extend({
23 | processBlock: function (words, offset) {
24 | // Shortcuts
25 | var cipher = this._cipher
26 | var blockSize = cipher.blockSize;
27 | var iv = this._iv;
28 | var counter = this._counter;
29 |
30 | // Generate keystream
31 | if (iv) {
32 | counter = this._counter = iv.slice(0);
33 |
34 | // Remove IV for subsequent blocks
35 | this._iv = undefined;
36 | }
37 | var keystream = counter.slice(0);
38 | cipher.encryptBlock(keystream, 0);
39 |
40 | // Increment counter
41 | counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
42 |
43 | // Encrypt
44 | for (var i = 0; i < blockSize; i++) {
45 | words[offset + i] ^= keystream[i];
46 | }
47 | }
48 | });
49 |
50 | CTR.Decryptor = Encryptor;
51 |
52 | return CTR;
53 | }());
54 |
55 |
56 | return CryptoJS.mode.CTR;
57 |
58 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "_from": "crypto-js",
3 | "_id": "crypto-js@4.0.0",
4 | "_inBundle": false,
5 | "_integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==",
6 | "_location": "/crypto-js",
7 | "_phantomChildren": {},
8 | "_requested": {
9 | "type": "tag",
10 | "registry": true,
11 | "raw": "crypto-js",
12 | "name": "crypto-js",
13 | "escapedName": "crypto-js",
14 | "rawSpec": "",
15 | "saveSpec": null,
16 | "fetchSpec": "latest"
17 | },
18 | "_requiredBy": [
19 | "#USER",
20 | "/"
21 | ],
22 | "_resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
23 | "_shasum": "2904ab2677a9d042856a2ea2ef80de92e4a36dcc",
24 | "_spec": "crypto-js",
25 | "_where": "C:\\Users\\ASUS\\Desktop\\Block Chain Nano Degree",
26 | "author": {
27 | "name": "Evan Vosberg",
28 | "url": "http://github.com/evanvosberg"
29 | },
30 | "bugs": {
31 | "url": "https://github.com/brix/crypto-js/issues"
32 | },
33 | "bundleDependencies": false,
34 | "dependencies": {},
35 | "deprecated": false,
36 | "description": "JavaScript library of crypto standards.",
37 | "homepage": "http://github.com/brix/crypto-js",
38 | "keywords": [
39 | "security",
40 | "crypto",
41 | "Hash",
42 | "MD5",
43 | "SHA1",
44 | "SHA-1",
45 | "SHA256",
46 | "SHA-256",
47 | "RC4",
48 | "Rabbit",
49 | "AES",
50 | "DES",
51 | "PBKDF2",
52 | "HMAC",
53 | "OFB",
54 | "CFB",
55 | "CTR",
56 | "CBC",
57 | "Base64"
58 | ],
59 | "license": "MIT",
60 | "main": "index.js",
61 | "name": "crypto-js",
62 | "repository": {
63 | "type": "git",
64 | "url": "git+ssh://git@github.com/brix/crypto-js.git"
65 | },
66 | "version": "4.0.0"
67 | }
68 |
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/format-hex.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function (undefined) {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var CipherParams = C_lib.CipherParams;
21 | var C_enc = C.enc;
22 | var Hex = C_enc.Hex;
23 | var C_format = C.format;
24 |
25 | var HexFormatter = C_format.Hex = {
26 | /**
27 | * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
28 | *
29 | * @param {CipherParams} cipherParams The cipher params object.
30 | *
31 | * @return {string} The hexadecimally encoded string.
32 | *
33 | * @static
34 | *
35 | * @example
36 | *
37 | * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
38 | */
39 | stringify: function (cipherParams) {
40 | return cipherParams.ciphertext.toString(Hex);
41 | },
42 |
43 | /**
44 | * Converts a hexadecimally encoded ciphertext string to a cipher params object.
45 | *
46 | * @param {string} input The hexadecimally encoded string.
47 | *
48 | * @return {CipherParams} The cipher params object.
49 | *
50 | * @static
51 | *
52 | * @example
53 | *
54 | * var cipherParams = CryptoJS.format.Hex.parse(hexString);
55 | */
56 | parse: function (input) {
57 | var ciphertext = Hex.parse(input);
58 | return CipherParams.create({ ciphertext: ciphertext });
59 | }
60 | };
61 | }());
62 |
63 |
64 | return CryptoJS.format.Hex;
65 |
66 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha224.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha256"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha256"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var C_algo = C.algo;
22 | var SHA256 = C_algo.SHA256;
23 |
24 | /**
25 | * SHA-224 hash algorithm.
26 | */
27 | var SHA224 = C_algo.SHA224 = SHA256.extend({
28 | _doReset: function () {
29 | this._hash = new WordArray.init([
30 | 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
31 | 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
32 | ]);
33 | },
34 |
35 | _doFinalize: function () {
36 | var hash = SHA256._doFinalize.call(this);
37 |
38 | hash.sigBytes -= 4;
39 |
40 | return hash;
41 | }
42 | });
43 |
44 | /**
45 | * Shortcut function to the hasher's object interface.
46 | *
47 | * @param {WordArray|string} message The message to hash.
48 | *
49 | * @return {WordArray} The hash.
50 | *
51 | * @static
52 | *
53 | * @example
54 | *
55 | * var hash = CryptoJS.SHA224('message');
56 | * var hash = CryptoJS.SHA224(wordArray);
57 | */
58 | C.SHA224 = SHA256._createHelper(SHA224);
59 |
60 | /**
61 | * Shortcut function to the HMAC's object interface.
62 | *
63 | * @param {WordArray|string} message The message to hash.
64 | * @param {WordArray|string} key The secret key.
65 | *
66 | * @return {WordArray} The HMAC.
67 | *
68 | * @static
69 | *
70 | * @example
71 | *
72 | * var hmac = CryptoJS.HmacSHA224(message, key);
73 | */
74 | C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
75 | }());
76 |
77 |
78 | return CryptoJS.SHA224;
79 |
80 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/mode-cfb.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /**
17 | * Cipher Feedback block mode.
18 | */
19 | CryptoJS.mode.CFB = (function () {
20 | var CFB = CryptoJS.lib.BlockCipherMode.extend();
21 |
22 | CFB.Encryptor = CFB.extend({
23 | processBlock: function (words, offset) {
24 | // Shortcuts
25 | var cipher = this._cipher;
26 | var blockSize = cipher.blockSize;
27 |
28 | generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
29 |
30 | // Remember this block to use with next block
31 | this._prevBlock = words.slice(offset, offset + blockSize);
32 | }
33 | });
34 |
35 | CFB.Decryptor = CFB.extend({
36 | processBlock: function (words, offset) {
37 | // Shortcuts
38 | var cipher = this._cipher;
39 | var blockSize = cipher.blockSize;
40 |
41 | // Remember this block to use with next block
42 | var thisBlock = words.slice(offset, offset + blockSize);
43 |
44 | generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
45 |
46 | // This block becomes the previous block
47 | this._prevBlock = thisBlock;
48 | }
49 | });
50 |
51 | function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
52 | var keystream;
53 |
54 | // Shortcut
55 | var iv = this._iv;
56 |
57 | // Generate keystream
58 | if (iv) {
59 | keystream = iv.slice(0);
60 |
61 | // Remove IV for subsequent blocks
62 | this._iv = undefined;
63 | } else {
64 | keystream = this._prevBlock;
65 | }
66 | cipher.encryptBlock(keystream, 0);
67 |
68 | // Encrypt
69 | for (var i = 0; i < blockSize; i++) {
70 | words[offset + i] ^= keystream[i];
71 | }
72 | }
73 |
74 | return CFB;
75 | }());
76 |
77 |
78 | return CryptoJS.mode.CFB;
79 |
80 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/lib-typedarrays.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Check if typed arrays are supported
18 | if (typeof ArrayBuffer != 'function') {
19 | return;
20 | }
21 |
22 | // Shortcuts
23 | var C = CryptoJS;
24 | var C_lib = C.lib;
25 | var WordArray = C_lib.WordArray;
26 |
27 | // Reference original init
28 | var superInit = WordArray.init;
29 |
30 | // Augment WordArray.init to handle typed arrays
31 | var subInit = WordArray.init = function (typedArray) {
32 | // Convert buffers to uint8
33 | if (typedArray instanceof ArrayBuffer) {
34 | typedArray = new Uint8Array(typedArray);
35 | }
36 |
37 | // Convert other array views to uint8
38 | if (
39 | typedArray instanceof Int8Array ||
40 | (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
41 | typedArray instanceof Int16Array ||
42 | typedArray instanceof Uint16Array ||
43 | typedArray instanceof Int32Array ||
44 | typedArray instanceof Uint32Array ||
45 | typedArray instanceof Float32Array ||
46 | typedArray instanceof Float64Array
47 | ) {
48 | typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
49 | }
50 |
51 | // Handle Uint8Array
52 | if (typedArray instanceof Uint8Array) {
53 | // Shortcut
54 | var typedArrayByteLength = typedArray.byteLength;
55 |
56 | // Extract bytes
57 | var words = [];
58 | for (var i = 0; i < typedArrayByteLength; i++) {
59 | words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
60 | }
61 |
62 | // Initialize this word array
63 | superInit.call(this, words, typedArrayByteLength);
64 | } else {
65 | // Else call normal init
66 | superInit.apply(this, arguments);
67 | }
68 | };
69 |
70 | subInit.prototype = WordArray;
71 | }());
72 |
73 |
74 | return CryptoJS.lib.WordArray;
75 |
76 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha384.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core", "./sha512"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_x64 = C.x64;
20 | var X64Word = C_x64.Word;
21 | var X64WordArray = C_x64.WordArray;
22 | var C_algo = C.algo;
23 | var SHA512 = C_algo.SHA512;
24 |
25 | /**
26 | * SHA-384 hash algorithm.
27 | */
28 | var SHA384 = C_algo.SHA384 = SHA512.extend({
29 | _doReset: function () {
30 | this._hash = new X64WordArray.init([
31 | new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
32 | new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
33 | new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
34 | new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
35 | ]);
36 | },
37 |
38 | _doFinalize: function () {
39 | var hash = SHA512._doFinalize.call(this);
40 |
41 | hash.sigBytes -= 16;
42 |
43 | return hash;
44 | }
45 | });
46 |
47 | /**
48 | * Shortcut function to the hasher's object interface.
49 | *
50 | * @param {WordArray|string} message The message to hash.
51 | *
52 | * @return {WordArray} The hash.
53 | *
54 | * @static
55 | *
56 | * @example
57 | *
58 | * var hash = CryptoJS.SHA384('message');
59 | * var hash = CryptoJS.SHA384(wordArray);
60 | */
61 | C.SHA384 = SHA512._createHelper(SHA384);
62 |
63 | /**
64 | * Shortcut function to the HMAC's object interface.
65 | *
66 | * @param {WordArray|string} message The message to hash.
67 | * @param {WordArray|string} key The secret key.
68 | *
69 | * @return {WordArray} The HMAC.
70 | *
71 | * @static
72 | *
73 | * @example
74 | *
75 | * var hmac = CryptoJS.HmacSHA384(message, key);
76 | */
77 | C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
78 | }());
79 |
80 |
81 | return CryptoJS.SHA384;
82 |
83 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/mode-ctr-gladman.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /** @preserve
17 | * Counter block mode compatible with Dr Brian Gladman fileenc.c
18 | * derived from CryptoJS.mode.CTR
19 | * Jan Hruby jhruby.web@gmail.com
20 | */
21 | CryptoJS.mode.CTRGladman = (function () {
22 | var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
23 |
24 | function incWord(word)
25 | {
26 | if (((word >> 24) & 0xff) === 0xff) { //overflow
27 | var b1 = (word >> 16)&0xff;
28 | var b2 = (word >> 8)&0xff;
29 | var b3 = word & 0xff;
30 |
31 | if (b1 === 0xff) // overflow b1
32 | {
33 | b1 = 0;
34 | if (b2 === 0xff)
35 | {
36 | b2 = 0;
37 | if (b3 === 0xff)
38 | {
39 | b3 = 0;
40 | }
41 | else
42 | {
43 | ++b3;
44 | }
45 | }
46 | else
47 | {
48 | ++b2;
49 | }
50 | }
51 | else
52 | {
53 | ++b1;
54 | }
55 |
56 | word = 0;
57 | word += (b1 << 16);
58 | word += (b2 << 8);
59 | word += b3;
60 | }
61 | else
62 | {
63 | word += (0x01 << 24);
64 | }
65 | return word;
66 | }
67 |
68 | function incCounter(counter)
69 | {
70 | if ((counter[0] = incWord(counter[0])) === 0)
71 | {
72 | // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
73 | counter[1] = incWord(counter[1]);
74 | }
75 | return counter;
76 | }
77 |
78 | var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
79 | processBlock: function (words, offset) {
80 | // Shortcuts
81 | var cipher = this._cipher
82 | var blockSize = cipher.blockSize;
83 | var iv = this._iv;
84 | var counter = this._counter;
85 |
86 | // Generate keystream
87 | if (iv) {
88 | counter = this._counter = iv.slice(0);
89 |
90 | // Remove IV for subsequent blocks
91 | this._iv = undefined;
92 | }
93 |
94 | incCounter(counter);
95 |
96 | var keystream = counter.slice(0);
97 | cipher.encryptBlock(keystream, 0);
98 |
99 | // Encrypt
100 | for (var i = 0; i < blockSize; i++) {
101 | words[offset + i] ^= keystream[i];
102 | }
103 | }
104 | });
105 |
106 | CTRGladman.Decryptor = Encryptor;
107 |
108 | return CTRGladman;
109 | }());
110 |
111 |
112 |
113 |
114 | return CryptoJS.mode.CTRGladman;
115 |
116 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/rc4.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var StreamCipher = C_lib.StreamCipher;
21 | var C_algo = C.algo;
22 |
23 | /**
24 | * RC4 stream cipher algorithm.
25 | */
26 | var RC4 = C_algo.RC4 = StreamCipher.extend({
27 | _doReset: function () {
28 | // Shortcuts
29 | var key = this._key;
30 | var keyWords = key.words;
31 | var keySigBytes = key.sigBytes;
32 |
33 | // Init sbox
34 | var S = this._S = [];
35 | for (var i = 0; i < 256; i++) {
36 | S[i] = i;
37 | }
38 |
39 | // Key setup
40 | for (var i = 0, j = 0; i < 256; i++) {
41 | var keyByteIndex = i % keySigBytes;
42 | var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
43 |
44 | j = (j + S[i] + keyByte) % 256;
45 |
46 | // Swap
47 | var t = S[i];
48 | S[i] = S[j];
49 | S[j] = t;
50 | }
51 |
52 | // Counters
53 | this._i = this._j = 0;
54 | },
55 |
56 | _doProcessBlock: function (M, offset) {
57 | M[offset] ^= generateKeystreamWord.call(this);
58 | },
59 |
60 | keySize: 256/32,
61 |
62 | ivSize: 0
63 | });
64 |
65 | function generateKeystreamWord() {
66 | // Shortcuts
67 | var S = this._S;
68 | var i = this._i;
69 | var j = this._j;
70 |
71 | // Generate keystream word
72 | var keystreamWord = 0;
73 | for (var n = 0; n < 4; n++) {
74 | i = (i + 1) % 256;
75 | j = (j + S[i]) % 256;
76 |
77 | // Swap
78 | var t = S[i];
79 | S[i] = S[j];
80 | S[j] = t;
81 |
82 | keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
83 | }
84 |
85 | // Update counters
86 | this._i = i;
87 | this._j = j;
88 |
89 | return keystreamWord;
90 | }
91 |
92 | /**
93 | * Shortcut functions to the cipher's object interface.
94 | *
95 | * @example
96 | *
97 | * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
98 | * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
99 | */
100 | C.RC4 = StreamCipher._createHelper(RC4);
101 |
102 | /**
103 | * Modified RC4 stream cipher algorithm.
104 | */
105 | var RC4Drop = C_algo.RC4Drop = RC4.extend({
106 | /**
107 | * Configuration options.
108 | *
109 | * @property {number} drop The number of keystream words to drop. Default 192
110 | */
111 | cfg: RC4.cfg.extend({
112 | drop: 192
113 | }),
114 |
115 | _doReset: function () {
116 | RC4._doReset.call(this);
117 |
118 | // Drop
119 | for (var i = this.cfg.drop; i > 0; i--) {
120 | generateKeystreamWord.call(this);
121 | }
122 | }
123 | });
124 |
125 | /**
126 | * Shortcut functions to the cipher's object interface.
127 | *
128 | * @example
129 | *
130 | * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
131 | * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
132 | */
133 | C.RC4Drop = StreamCipher._createHelper(RC4Drop);
134 | }());
135 |
136 |
137 | return CryptoJS.RC4;
138 |
139 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/evpkdf.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha1", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var Base = C_lib.Base;
21 | var WordArray = C_lib.WordArray;
22 | var C_algo = C.algo;
23 | var MD5 = C_algo.MD5;
24 |
25 | /**
26 | * This key derivation function is meant to conform with EVP_BytesToKey.
27 | * www.openssl.org/docs/crypto/EVP_BytesToKey.html
28 | */
29 | var EvpKDF = C_algo.EvpKDF = Base.extend({
30 | /**
31 | * Configuration options.
32 | *
33 | * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
34 | * @property {Hasher} hasher The hash algorithm to use. Default: MD5
35 | * @property {number} iterations The number of iterations to perform. Default: 1
36 | */
37 | cfg: Base.extend({
38 | keySize: 128/32,
39 | hasher: MD5,
40 | iterations: 1
41 | }),
42 |
43 | /**
44 | * Initializes a newly created key derivation function.
45 | *
46 | * @param {Object} cfg (Optional) The configuration options to use for the derivation.
47 | *
48 | * @example
49 | *
50 | * var kdf = CryptoJS.algo.EvpKDF.create();
51 | * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
52 | * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
53 | */
54 | init: function (cfg) {
55 | this.cfg = this.cfg.extend(cfg);
56 | },
57 |
58 | /**
59 | * Derives a key from a password.
60 | *
61 | * @param {WordArray|string} password The password.
62 | * @param {WordArray|string} salt A salt.
63 | *
64 | * @return {WordArray} The derived key.
65 | *
66 | * @example
67 | *
68 | * var key = kdf.compute(password, salt);
69 | */
70 | compute: function (password, salt) {
71 | var block;
72 |
73 | // Shortcut
74 | var cfg = this.cfg;
75 |
76 | // Init hasher
77 | var hasher = cfg.hasher.create();
78 |
79 | // Initial values
80 | var derivedKey = WordArray.create();
81 |
82 | // Shortcuts
83 | var derivedKeyWords = derivedKey.words;
84 | var keySize = cfg.keySize;
85 | var iterations = cfg.iterations;
86 |
87 | // Generate key
88 | while (derivedKeyWords.length < keySize) {
89 | if (block) {
90 | hasher.update(block);
91 | }
92 | block = hasher.update(password).finalize(salt);
93 | hasher.reset();
94 |
95 | // Iterations
96 | for (var i = 1; i < iterations; i++) {
97 | block = hasher.finalize(block);
98 | hasher.reset();
99 | }
100 |
101 | derivedKey.concat(block);
102 | }
103 | derivedKey.sigBytes = keySize * 4;
104 |
105 | return derivedKey;
106 | }
107 | });
108 |
109 | /**
110 | * Derives a key from a password.
111 | *
112 | * @param {WordArray|string} password The password.
113 | * @param {WordArray|string} salt A salt.
114 | * @param {Object} cfg (Optional) The configuration options to use for this computation.
115 | *
116 | * @return {WordArray} The derived key.
117 | *
118 | * @static
119 | *
120 | * @example
121 | *
122 | * var key = CryptoJS.EvpKDF(password, salt);
123 | * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
124 | * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
125 | */
126 | C.EvpKDF = function (password, salt, cfg) {
127 | return EvpKDF.create(cfg).compute(password, salt);
128 | };
129 | }());
130 |
131 |
132 | return CryptoJS.EvpKDF;
133 |
134 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/hmac.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var Base = C_lib.Base;
21 | var C_enc = C.enc;
22 | var Utf8 = C_enc.Utf8;
23 | var C_algo = C.algo;
24 |
25 | /**
26 | * HMAC algorithm.
27 | */
28 | var HMAC = C_algo.HMAC = Base.extend({
29 | /**
30 | * Initializes a newly created HMAC.
31 | *
32 | * @param {Hasher} hasher The hash algorithm to use.
33 | * @param {WordArray|string} key The secret key.
34 | *
35 | * @example
36 | *
37 | * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
38 | */
39 | init: function (hasher, key) {
40 | // Init hasher
41 | hasher = this._hasher = new hasher.init();
42 |
43 | // Convert string to WordArray, else assume WordArray already
44 | if (typeof key == 'string') {
45 | key = Utf8.parse(key);
46 | }
47 |
48 | // Shortcuts
49 | var hasherBlockSize = hasher.blockSize;
50 | var hasherBlockSizeBytes = hasherBlockSize * 4;
51 |
52 | // Allow arbitrary length keys
53 | if (key.sigBytes > hasherBlockSizeBytes) {
54 | key = hasher.finalize(key);
55 | }
56 |
57 | // Clamp excess bits
58 | key.clamp();
59 |
60 | // Clone key for inner and outer pads
61 | var oKey = this._oKey = key.clone();
62 | var iKey = this._iKey = key.clone();
63 |
64 | // Shortcuts
65 | var oKeyWords = oKey.words;
66 | var iKeyWords = iKey.words;
67 |
68 | // XOR keys with pad constants
69 | for (var i = 0; i < hasherBlockSize; i++) {
70 | oKeyWords[i] ^= 0x5c5c5c5c;
71 | iKeyWords[i] ^= 0x36363636;
72 | }
73 | oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
74 |
75 | // Set initial values
76 | this.reset();
77 | },
78 |
79 | /**
80 | * Resets this HMAC to its initial state.
81 | *
82 | * @example
83 | *
84 | * hmacHasher.reset();
85 | */
86 | reset: function () {
87 | // Shortcut
88 | var hasher = this._hasher;
89 |
90 | // Reset
91 | hasher.reset();
92 | hasher.update(this._iKey);
93 | },
94 |
95 | /**
96 | * Updates this HMAC with a message.
97 | *
98 | * @param {WordArray|string} messageUpdate The message to append.
99 | *
100 | * @return {HMAC} This HMAC instance.
101 | *
102 | * @example
103 | *
104 | * hmacHasher.update('message');
105 | * hmacHasher.update(wordArray);
106 | */
107 | update: function (messageUpdate) {
108 | this._hasher.update(messageUpdate);
109 |
110 | // Chainable
111 | return this;
112 | },
113 |
114 | /**
115 | * Finalizes the HMAC computation.
116 | * Note that the finalize operation is effectively a destructive, read-once operation.
117 | *
118 | * @param {WordArray|string} messageUpdate (Optional) A final message update.
119 | *
120 | * @return {WordArray} The HMAC.
121 | *
122 | * @example
123 | *
124 | * var hmac = hmacHasher.finalize();
125 | * var hmac = hmacHasher.finalize('message');
126 | * var hmac = hmacHasher.finalize(wordArray);
127 | */
128 | finalize: function (messageUpdate) {
129 | // Shortcut
130 | var hasher = this._hasher;
131 |
132 | // Compute HMAC
133 | var innerHash = hasher.finalize(messageUpdate);
134 | hasher.reset();
135 | var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
136 |
137 | return hmac;
138 | }
139 | });
140 | }());
141 |
142 |
143 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/enc-base64.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var C_enc = C.enc;
22 |
23 | /**
24 | * Base64 encoding strategy.
25 | */
26 | var Base64 = C_enc.Base64 = {
27 | /**
28 | * Converts a word array to a Base64 string.
29 | *
30 | * @param {WordArray} wordArray The word array.
31 | *
32 | * @return {string} The Base64 string.
33 | *
34 | * @static
35 | *
36 | * @example
37 | *
38 | * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
39 | */
40 | stringify: function (wordArray) {
41 | // Shortcuts
42 | var words = wordArray.words;
43 | var sigBytes = wordArray.sigBytes;
44 | var map = this._map;
45 |
46 | // Clamp excess bits
47 | wordArray.clamp();
48 |
49 | // Convert
50 | var base64Chars = [];
51 | for (var i = 0; i < sigBytes; i += 3) {
52 | var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
53 | var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
54 | var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
55 |
56 | var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
57 |
58 | for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
59 | base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
60 | }
61 | }
62 |
63 | // Add padding
64 | var paddingChar = map.charAt(64);
65 | if (paddingChar) {
66 | while (base64Chars.length % 4) {
67 | base64Chars.push(paddingChar);
68 | }
69 | }
70 |
71 | return base64Chars.join('');
72 | },
73 |
74 | /**
75 | * Converts a Base64 string to a word array.
76 | *
77 | * @param {string} base64Str The Base64 string.
78 | *
79 | * @return {WordArray} The word array.
80 | *
81 | * @static
82 | *
83 | * @example
84 | *
85 | * var wordArray = CryptoJS.enc.Base64.parse(base64String);
86 | */
87 | parse: function (base64Str) {
88 | // Shortcuts
89 | var base64StrLength = base64Str.length;
90 | var map = this._map;
91 | var reverseMap = this._reverseMap;
92 |
93 | if (!reverseMap) {
94 | reverseMap = this._reverseMap = [];
95 | for (var j = 0; j < map.length; j++) {
96 | reverseMap[map.charCodeAt(j)] = j;
97 | }
98 | }
99 |
100 | // Ignore padding
101 | var paddingChar = map.charAt(64);
102 | if (paddingChar) {
103 | var paddingIndex = base64Str.indexOf(paddingChar);
104 | if (paddingIndex !== -1) {
105 | base64StrLength = paddingIndex;
106 | }
107 | }
108 |
109 | // Convert
110 | return parseLoop(base64Str, base64StrLength, reverseMap);
111 |
112 | },
113 |
114 | _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
115 | };
116 |
117 | function parseLoop(base64Str, base64StrLength, reverseMap) {
118 | var words = [];
119 | var nBytes = 0;
120 | for (var i = 0; i < base64StrLength; i++) {
121 | if (i % 4) {
122 | var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
123 | var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
124 | var bitsCombined = bits1 | bits2;
125 | words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
126 | nBytes++;
127 | }
128 | }
129 | return WordArray.create(words, nBytes);
130 | }
131 | }());
132 |
133 |
134 | return CryptoJS.enc.Base64;
135 |
136 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha1.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var Hasher = C_lib.Hasher;
22 | var C_algo = C.algo;
23 |
24 | // Reusable object
25 | var W = [];
26 |
27 | /**
28 | * SHA-1 hash algorithm.
29 | */
30 | var SHA1 = C_algo.SHA1 = Hasher.extend({
31 | _doReset: function () {
32 | this._hash = new WordArray.init([
33 | 0x67452301, 0xefcdab89,
34 | 0x98badcfe, 0x10325476,
35 | 0xc3d2e1f0
36 | ]);
37 | },
38 |
39 | _doProcessBlock: function (M, offset) {
40 | // Shortcut
41 | var H = this._hash.words;
42 |
43 | // Working variables
44 | var a = H[0];
45 | var b = H[1];
46 | var c = H[2];
47 | var d = H[3];
48 | var e = H[4];
49 |
50 | // Computation
51 | for (var i = 0; i < 80; i++) {
52 | if (i < 16) {
53 | W[i] = M[offset + i] | 0;
54 | } else {
55 | var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
56 | W[i] = (n << 1) | (n >>> 31);
57 | }
58 |
59 | var t = ((a << 5) | (a >>> 27)) + e + W[i];
60 | if (i < 20) {
61 | t += ((b & c) | (~b & d)) + 0x5a827999;
62 | } else if (i < 40) {
63 | t += (b ^ c ^ d) + 0x6ed9eba1;
64 | } else if (i < 60) {
65 | t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
66 | } else /* if (i < 80) */ {
67 | t += (b ^ c ^ d) - 0x359d3e2a;
68 | }
69 |
70 | e = d;
71 | d = c;
72 | c = (b << 30) | (b >>> 2);
73 | b = a;
74 | a = t;
75 | }
76 |
77 | // Intermediate hash value
78 | H[0] = (H[0] + a) | 0;
79 | H[1] = (H[1] + b) | 0;
80 | H[2] = (H[2] + c) | 0;
81 | H[3] = (H[3] + d) | 0;
82 | H[4] = (H[4] + e) | 0;
83 | },
84 |
85 | _doFinalize: function () {
86 | // Shortcuts
87 | var data = this._data;
88 | var dataWords = data.words;
89 |
90 | var nBitsTotal = this._nDataBytes * 8;
91 | var nBitsLeft = data.sigBytes * 8;
92 |
93 | // Add padding
94 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
95 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
96 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
97 | data.sigBytes = dataWords.length * 4;
98 |
99 | // Hash final blocks
100 | this._process();
101 |
102 | // Return final computed hash
103 | return this._hash;
104 | },
105 |
106 | clone: function () {
107 | var clone = Hasher.clone.call(this);
108 | clone._hash = this._hash.clone();
109 |
110 | return clone;
111 | }
112 | });
113 |
114 | /**
115 | * Shortcut function to the hasher's object interface.
116 | *
117 | * @param {WordArray|string} message The message to hash.
118 | *
119 | * @return {WordArray} The hash.
120 | *
121 | * @static
122 | *
123 | * @example
124 | *
125 | * var hash = CryptoJS.SHA1('message');
126 | * var hash = CryptoJS.SHA1(wordArray);
127 | */
128 | C.SHA1 = Hasher._createHelper(SHA1);
129 |
130 | /**
131 | * Shortcut function to the HMAC's object interface.
132 | *
133 | * @param {WordArray|string} message The message to hash.
134 | * @param {WordArray|string} key The secret key.
135 | *
136 | * @return {WordArray} The HMAC.
137 | *
138 | * @static
139 | *
140 | * @example
141 | *
142 | * var hmac = CryptoJS.HmacSHA1(message, key);
143 | */
144 | C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
145 | }());
146 |
147 |
148 | return CryptoJS.SHA1;
149 |
150 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/enc-utf16.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var C_enc = C.enc;
22 |
23 | /**
24 | * UTF-16 BE encoding strategy.
25 | */
26 | var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
27 | /**
28 | * Converts a word array to a UTF-16 BE string.
29 | *
30 | * @param {WordArray} wordArray The word array.
31 | *
32 | * @return {string} The UTF-16 BE string.
33 | *
34 | * @static
35 | *
36 | * @example
37 | *
38 | * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
39 | */
40 | stringify: function (wordArray) {
41 | // Shortcuts
42 | var words = wordArray.words;
43 | var sigBytes = wordArray.sigBytes;
44 |
45 | // Convert
46 | var utf16Chars = [];
47 | for (var i = 0; i < sigBytes; i += 2) {
48 | var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
49 | utf16Chars.push(String.fromCharCode(codePoint));
50 | }
51 |
52 | return utf16Chars.join('');
53 | },
54 |
55 | /**
56 | * Converts a UTF-16 BE string to a word array.
57 | *
58 | * @param {string} utf16Str The UTF-16 BE string.
59 | *
60 | * @return {WordArray} The word array.
61 | *
62 | * @static
63 | *
64 | * @example
65 | *
66 | * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
67 | */
68 | parse: function (utf16Str) {
69 | // Shortcut
70 | var utf16StrLength = utf16Str.length;
71 |
72 | // Convert
73 | var words = [];
74 | for (var i = 0; i < utf16StrLength; i++) {
75 | words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
76 | }
77 |
78 | return WordArray.create(words, utf16StrLength * 2);
79 | }
80 | };
81 |
82 | /**
83 | * UTF-16 LE encoding strategy.
84 | */
85 | C_enc.Utf16LE = {
86 | /**
87 | * Converts a word array to a UTF-16 LE string.
88 | *
89 | * @param {WordArray} wordArray The word array.
90 | *
91 | * @return {string} The UTF-16 LE string.
92 | *
93 | * @static
94 | *
95 | * @example
96 | *
97 | * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
98 | */
99 | stringify: function (wordArray) {
100 | // Shortcuts
101 | var words = wordArray.words;
102 | var sigBytes = wordArray.sigBytes;
103 |
104 | // Convert
105 | var utf16Chars = [];
106 | for (var i = 0; i < sigBytes; i += 2) {
107 | var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
108 | utf16Chars.push(String.fromCharCode(codePoint));
109 | }
110 |
111 | return utf16Chars.join('');
112 | },
113 |
114 | /**
115 | * Converts a UTF-16 LE string to a word array.
116 | *
117 | * @param {string} utf16Str The UTF-16 LE string.
118 | *
119 | * @return {WordArray} The word array.
120 | *
121 | * @static
122 | *
123 | * @example
124 | *
125 | * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
126 | */
127 | parse: function (utf16Str) {
128 | // Shortcut
129 | var utf16StrLength = utf16Str.length;
130 |
131 | // Convert
132 | var words = [];
133 | for (var i = 0; i < utf16StrLength; i++) {
134 | words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
135 | }
136 |
137 | return WordArray.create(words, utf16StrLength * 2);
138 | }
139 | };
140 |
141 | function swapEndian(word) {
142 | return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
143 | }
144 | }());
145 |
146 |
147 | return CryptoJS.enc.Utf16;
148 |
149 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/pbkdf2.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./sha1", "./hmac"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var Base = C_lib.Base;
21 | var WordArray = C_lib.WordArray;
22 | var C_algo = C.algo;
23 | var SHA1 = C_algo.SHA1;
24 | var HMAC = C_algo.HMAC;
25 |
26 | /**
27 | * Password-Based Key Derivation Function 2 algorithm.
28 | */
29 | var PBKDF2 = C_algo.PBKDF2 = Base.extend({
30 | /**
31 | * Configuration options.
32 | *
33 | * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
34 | * @property {Hasher} hasher The hasher to use. Default: SHA1
35 | * @property {number} iterations The number of iterations to perform. Default: 1
36 | */
37 | cfg: Base.extend({
38 | keySize: 128/32,
39 | hasher: SHA1,
40 | iterations: 1
41 | }),
42 |
43 | /**
44 | * Initializes a newly created key derivation function.
45 | *
46 | * @param {Object} cfg (Optional) The configuration options to use for the derivation.
47 | *
48 | * @example
49 | *
50 | * var kdf = CryptoJS.algo.PBKDF2.create();
51 | * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
52 | * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
53 | */
54 | init: function (cfg) {
55 | this.cfg = this.cfg.extend(cfg);
56 | },
57 |
58 | /**
59 | * Computes the Password-Based Key Derivation Function 2.
60 | *
61 | * @param {WordArray|string} password The password.
62 | * @param {WordArray|string} salt A salt.
63 | *
64 | * @return {WordArray} The derived key.
65 | *
66 | * @example
67 | *
68 | * var key = kdf.compute(password, salt);
69 | */
70 | compute: function (password, salt) {
71 | // Shortcut
72 | var cfg = this.cfg;
73 |
74 | // Init HMAC
75 | var hmac = HMAC.create(cfg.hasher, password);
76 |
77 | // Initial values
78 | var derivedKey = WordArray.create();
79 | var blockIndex = WordArray.create([0x00000001]);
80 |
81 | // Shortcuts
82 | var derivedKeyWords = derivedKey.words;
83 | var blockIndexWords = blockIndex.words;
84 | var keySize = cfg.keySize;
85 | var iterations = cfg.iterations;
86 |
87 | // Generate key
88 | while (derivedKeyWords.length < keySize) {
89 | var block = hmac.update(salt).finalize(blockIndex);
90 | hmac.reset();
91 |
92 | // Shortcuts
93 | var blockWords = block.words;
94 | var blockWordsLength = blockWords.length;
95 |
96 | // Iterations
97 | var intermediate = block;
98 | for (var i = 1; i < iterations; i++) {
99 | intermediate = hmac.finalize(intermediate);
100 | hmac.reset();
101 |
102 | // Shortcut
103 | var intermediateWords = intermediate.words;
104 |
105 | // XOR intermediate with block
106 | for (var j = 0; j < blockWordsLength; j++) {
107 | blockWords[j] ^= intermediateWords[j];
108 | }
109 | }
110 |
111 | derivedKey.concat(block);
112 | blockIndexWords[0]++;
113 | }
114 | derivedKey.sigBytes = keySize * 4;
115 |
116 | return derivedKey;
117 | }
118 | });
119 |
120 | /**
121 | * Computes the Password-Based Key Derivation Function 2.
122 | *
123 | * @param {WordArray|string} password The password.
124 | * @param {WordArray|string} salt A salt.
125 | * @param {Object} cfg (Optional) The configuration options to use for this computation.
126 | *
127 | * @return {WordArray} The derived key.
128 | *
129 | * @static
130 | *
131 | * @example
132 | *
133 | * var key = CryptoJS.PBKDF2(password, salt);
134 | * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
135 | * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
136 | */
137 | C.PBKDF2 = function (password, salt, cfg) {
138 | return PBKDF2.create(cfg).compute(password, salt);
139 | };
140 | }());
141 |
142 |
143 | return CryptoJS.PBKDF2;
144 |
145 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha256.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function (Math) {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var Hasher = C_lib.Hasher;
22 | var C_algo = C.algo;
23 |
24 | // Initialization and round constants tables
25 | var H = [];
26 | var K = [];
27 |
28 | // Compute constants
29 | (function () {
30 | function isPrime(n) {
31 | var sqrtN = Math.sqrt(n);
32 | for (var factor = 2; factor <= sqrtN; factor++) {
33 | if (!(n % factor)) {
34 | return false;
35 | }
36 | }
37 |
38 | return true;
39 | }
40 |
41 | function getFractionalBits(n) {
42 | return ((n - (n | 0)) * 0x100000000) | 0;
43 | }
44 |
45 | var n = 2;
46 | var nPrime = 0;
47 | while (nPrime < 64) {
48 | if (isPrime(n)) {
49 | if (nPrime < 8) {
50 | H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
51 | }
52 | K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
53 |
54 | nPrime++;
55 | }
56 |
57 | n++;
58 | }
59 | }());
60 |
61 | // Reusable object
62 | var W = [];
63 |
64 | /**
65 | * SHA-256 hash algorithm.
66 | */
67 | var SHA256 = C_algo.SHA256 = Hasher.extend({
68 | _doReset: function () {
69 | this._hash = new WordArray.init(H.slice(0));
70 | },
71 |
72 | _doProcessBlock: function (M, offset) {
73 | // Shortcut
74 | var H = this._hash.words;
75 |
76 | // Working variables
77 | var a = H[0];
78 | var b = H[1];
79 | var c = H[2];
80 | var d = H[3];
81 | var e = H[4];
82 | var f = H[5];
83 | var g = H[6];
84 | var h = H[7];
85 |
86 | // Computation
87 | for (var i = 0; i < 64; i++) {
88 | if (i < 16) {
89 | W[i] = M[offset + i] | 0;
90 | } else {
91 | var gamma0x = W[i - 15];
92 | var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
93 | ((gamma0x << 14) | (gamma0x >>> 18)) ^
94 | (gamma0x >>> 3);
95 |
96 | var gamma1x = W[i - 2];
97 | var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
98 | ((gamma1x << 13) | (gamma1x >>> 19)) ^
99 | (gamma1x >>> 10);
100 |
101 | W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
102 | }
103 |
104 | var ch = (e & f) ^ (~e & g);
105 | var maj = (a & b) ^ (a & c) ^ (b & c);
106 |
107 | var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
108 | var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
109 |
110 | var t1 = h + sigma1 + ch + K[i] + W[i];
111 | var t2 = sigma0 + maj;
112 |
113 | h = g;
114 | g = f;
115 | f = e;
116 | e = (d + t1) | 0;
117 | d = c;
118 | c = b;
119 | b = a;
120 | a = (t1 + t2) | 0;
121 | }
122 |
123 | // Intermediate hash value
124 | H[0] = (H[0] + a) | 0;
125 | H[1] = (H[1] + b) | 0;
126 | H[2] = (H[2] + c) | 0;
127 | H[3] = (H[3] + d) | 0;
128 | H[4] = (H[4] + e) | 0;
129 | H[5] = (H[5] + f) | 0;
130 | H[6] = (H[6] + g) | 0;
131 | H[7] = (H[7] + h) | 0;
132 | },
133 |
134 | _doFinalize: function () {
135 | // Shortcuts
136 | var data = this._data;
137 | var dataWords = data.words;
138 |
139 | var nBitsTotal = this._nDataBytes * 8;
140 | var nBitsLeft = data.sigBytes * 8;
141 |
142 | // Add padding
143 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
144 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
145 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
146 | data.sigBytes = dataWords.length * 4;
147 |
148 | // Hash final blocks
149 | this._process();
150 |
151 | // Return final computed hash
152 | return this._hash;
153 | },
154 |
155 | clone: function () {
156 | var clone = Hasher.clone.call(this);
157 | clone._hash = this._hash.clone();
158 |
159 | return clone;
160 | }
161 | });
162 |
163 | /**
164 | * Shortcut function to the hasher's object interface.
165 | *
166 | * @param {WordArray|string} message The message to hash.
167 | *
168 | * @return {WordArray} The hash.
169 | *
170 | * @static
171 | *
172 | * @example
173 | *
174 | * var hash = CryptoJS.SHA256('message');
175 | * var hash = CryptoJS.SHA256(wordArray);
176 | */
177 | C.SHA256 = Hasher._createHelper(SHA256);
178 |
179 | /**
180 | * Shortcut function to the HMAC's object interface.
181 | *
182 | * @param {WordArray|string} message The message to hash.
183 | * @param {WordArray|string} key The secret key.
184 | *
185 | * @return {WordArray} The HMAC.
186 | *
187 | * @static
188 | *
189 | * @example
190 | *
191 | * var hmac = CryptoJS.HmacSHA256(message, key);
192 | */
193 | C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
194 | }(Math));
195 |
196 |
197 | return CryptoJS.SHA256;
198 |
199 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/README.md:
--------------------------------------------------------------------------------
1 | # crypto-js [](https://travis-ci.org/brix/crypto-js)
2 |
3 | JavaScript library of crypto standards.
4 |
5 | ## Node.js (Install)
6 |
7 | Requirements:
8 |
9 | - Node.js
10 | - npm (Node.js package manager)
11 |
12 | ```bash
13 | npm install crypto-js
14 | ```
15 |
16 | ### Usage
17 |
18 | ES6 import for typical API call signing use case:
19 |
20 | ```javascript
21 | import sha256 from 'crypto-js/sha256';
22 | import hmacSHA512 from 'crypto-js/hmac-sha512';
23 | import Base64 from 'crypto-js/enc-base64';
24 |
25 | const message, nonce, path, privateKey; // ...
26 | const hashDigest = sha256(nonce + message);
27 | const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));
28 | ```
29 |
30 | Modular include:
31 |
32 | ```javascript
33 | var AES = require("crypto-js/aes");
34 | var SHA256 = require("crypto-js/sha256");
35 | ...
36 | console.log(SHA256("Message"));
37 | ```
38 |
39 | Including all libraries, for access to extra methods:
40 |
41 | ```javascript
42 | var CryptoJS = require("crypto-js");
43 | console.log(CryptoJS.HmacSHA1("Message", "Key"));
44 | ```
45 |
46 | ## Client (browser)
47 |
48 | Requirements:
49 |
50 | - Node.js
51 | - Bower (package manager for frontend)
52 |
53 | ```bash
54 | bower install crypto-js
55 | ```
56 |
57 | ### Usage
58 |
59 | Modular include:
60 |
61 | ```javascript
62 | require.config({
63 | packages: [
64 | {
65 | name: 'crypto-js',
66 | location: 'path-to/bower_components/crypto-js',
67 | main: 'index'
68 | }
69 | ]
70 | });
71 |
72 | require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
73 | console.log(SHA256("Message"));
74 | });
75 | ```
76 |
77 | Including all libraries, for access to extra methods:
78 |
79 | ```javascript
80 | // Above-mentioned will work or use this simple form
81 | require.config({
82 | paths: {
83 | 'crypto-js': 'path-to/bower_components/crypto-js/crypto-js'
84 | }
85 | });
86 |
87 | require(["crypto-js"], function (CryptoJS) {
88 | console.log(CryptoJS.HmacSHA1("Message", "Key"));
89 | });
90 | ```
91 |
92 | ### Usage without RequireJS
93 |
94 | ```html
95 |
96 |
100 | ```
101 |
102 | ## API
103 |
104 | See: https://cryptojs.gitbook.io/docs/
105 |
106 | ### AES Encryption
107 |
108 | #### Plain text encryption
109 |
110 | ```javascript
111 | var CryptoJS = require("crypto-js");
112 |
113 | // Encrypt
114 | var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();
115 |
116 | // Decrypt
117 | var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
118 | var originalText = bytes.toString(CryptoJS.enc.Utf8);
119 |
120 | console.log(originalText); // 'my message'
121 | ```
122 |
123 | #### Object encryption
124 |
125 | ```javascript
126 | var CryptoJS = require("crypto-js");
127 |
128 | var data = [{id: 1}, {id: 2}]
129 |
130 | // Encrypt
131 | var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();
132 |
133 | // Decrypt
134 | var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
135 | var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
136 |
137 | console.log(decryptedData); // [{id: 1}, {id: 2}]
138 | ```
139 |
140 | ### List of modules
141 |
142 |
143 | - ```crypto-js/core```
144 | - ```crypto-js/x64-core```
145 | - ```crypto-js/lib-typedarrays```
146 |
147 | ---
148 |
149 | - ```crypto-js/md5```
150 | - ```crypto-js/sha1```
151 | - ```crypto-js/sha256```
152 | - ```crypto-js/sha224```
153 | - ```crypto-js/sha512```
154 | - ```crypto-js/sha384```
155 | - ```crypto-js/sha3```
156 | - ```crypto-js/ripemd160```
157 |
158 | ---
159 |
160 | - ```crypto-js/hmac-md5```
161 | - ```crypto-js/hmac-sha1```
162 | - ```crypto-js/hmac-sha256```
163 | - ```crypto-js/hmac-sha224```
164 | - ```crypto-js/hmac-sha512```
165 | - ```crypto-js/hmac-sha384```
166 | - ```crypto-js/hmac-sha3```
167 | - ```crypto-js/hmac-ripemd160```
168 |
169 | ---
170 |
171 | - ```crypto-js/pbkdf2```
172 |
173 | ---
174 |
175 | - ```crypto-js/aes```
176 | - ```crypto-js/tripledes```
177 | - ```crypto-js/rc4```
178 | - ```crypto-js/rabbit```
179 | - ```crypto-js/rabbit-legacy```
180 | - ```crypto-js/evpkdf```
181 |
182 | ---
183 |
184 | - ```crypto-js/format-openssl```
185 | - ```crypto-js/format-hex```
186 |
187 | ---
188 |
189 | - ```crypto-js/enc-latin1```
190 | - ```crypto-js/enc-utf8```
191 | - ```crypto-js/enc-hex```
192 | - ```crypto-js/enc-utf16```
193 | - ```crypto-js/enc-base64```
194 |
195 | ---
196 |
197 | - ```crypto-js/mode-cfb```
198 | - ```crypto-js/mode-ctr```
199 | - ```crypto-js/mode-ctr-gladman```
200 | - ```crypto-js/mode-ofb```
201 | - ```crypto-js/mode-ecb```
202 |
203 | ---
204 |
205 | - ```crypto-js/pad-pkcs7```
206 | - ```crypto-js/pad-ansix923```
207 | - ```crypto-js/pad-iso10126```
208 | - ```crypto-js/pad-iso97971```
209 | - ```crypto-js/pad-zeropadding```
210 | - ```crypto-js/pad-nopadding```
211 |
212 |
213 | ## Release notes
214 |
215 | ### 4.0.0
216 |
217 | This is an update including breaking changes for some environments.
218 |
219 | In this version `Math.random()` has been replaced by the random methods of the native crypto module.
220 |
221 | For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before or React Native.
222 |
223 | ### 3.3.0
224 |
225 | Rollback, `3.3.0` is the same as `3.1.9-1`.
226 |
227 | The move of using native secure crypto module will be shifted to a new `4.x.x` version. As it is a breaking change the impact is too big for a minor release.
228 |
229 | ### 3.2.1
230 |
231 | The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.
232 |
233 | ### 3.2.0
234 |
235 | In this version `Math.random()` has been replaced by the random methods of the native crypto module.
236 |
237 | For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before.
238 |
239 | If it's absolute required to run CryptoJS in such an environment, stay with `3.1.x` version. Encrypting and decrypting stays compatible. But keep in mind `3.1.x` versions still use `Math.random()` which is cryptographically not secure, as it's not random enough.
240 |
241 | This version came along with `CRITICAL` `BUG`.
242 |
243 | DO NOT USE THIS VERSION! Please, go for a newer version!
244 |
245 | ### 3.1.x
246 |
247 | The `3.1.x` are based on the original CryptoJS, wrapped in CommonJS modules.
248 |
249 |
250 |
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/rabbit.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var StreamCipher = C_lib.StreamCipher;
21 | var C_algo = C.algo;
22 |
23 | // Reusable objects
24 | var S = [];
25 | var C_ = [];
26 | var G = [];
27 |
28 | /**
29 | * Rabbit stream cipher algorithm
30 | */
31 | var Rabbit = C_algo.Rabbit = StreamCipher.extend({
32 | _doReset: function () {
33 | // Shortcuts
34 | var K = this._key.words;
35 | var iv = this.cfg.iv;
36 |
37 | // Swap endian
38 | for (var i = 0; i < 4; i++) {
39 | K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
40 | (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
41 | }
42 |
43 | // Generate initial state values
44 | var X = this._X = [
45 | K[0], (K[3] << 16) | (K[2] >>> 16),
46 | K[1], (K[0] << 16) | (K[3] >>> 16),
47 | K[2], (K[1] << 16) | (K[0] >>> 16),
48 | K[3], (K[2] << 16) | (K[1] >>> 16)
49 | ];
50 |
51 | // Generate initial counter values
52 | var C = this._C = [
53 | (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
54 | (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
55 | (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
56 | (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
57 | ];
58 |
59 | // Carry bit
60 | this._b = 0;
61 |
62 | // Iterate the system four times
63 | for (var i = 0; i < 4; i++) {
64 | nextState.call(this);
65 | }
66 |
67 | // Modify the counters
68 | for (var i = 0; i < 8; i++) {
69 | C[i] ^= X[(i + 4) & 7];
70 | }
71 |
72 | // IV setup
73 | if (iv) {
74 | // Shortcuts
75 | var IV = iv.words;
76 | var IV_0 = IV[0];
77 | var IV_1 = IV[1];
78 |
79 | // Generate four subvectors
80 | var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
81 | var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
82 | var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
83 | var i3 = (i2 << 16) | (i0 & 0x0000ffff);
84 |
85 | // Modify counter values
86 | C[0] ^= i0;
87 | C[1] ^= i1;
88 | C[2] ^= i2;
89 | C[3] ^= i3;
90 | C[4] ^= i0;
91 | C[5] ^= i1;
92 | C[6] ^= i2;
93 | C[7] ^= i3;
94 |
95 | // Iterate the system four times
96 | for (var i = 0; i < 4; i++) {
97 | nextState.call(this);
98 | }
99 | }
100 | },
101 |
102 | _doProcessBlock: function (M, offset) {
103 | // Shortcut
104 | var X = this._X;
105 |
106 | // Iterate the system
107 | nextState.call(this);
108 |
109 | // Generate four keystream words
110 | S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
111 | S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
112 | S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
113 | S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
114 |
115 | for (var i = 0; i < 4; i++) {
116 | // Swap endian
117 | S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
118 | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
119 |
120 | // Encrypt
121 | M[offset + i] ^= S[i];
122 | }
123 | },
124 |
125 | blockSize: 128/32,
126 |
127 | ivSize: 64/32
128 | });
129 |
130 | function nextState() {
131 | // Shortcuts
132 | var X = this._X;
133 | var C = this._C;
134 |
135 | // Save old counter values
136 | for (var i = 0; i < 8; i++) {
137 | C_[i] = C[i];
138 | }
139 |
140 | // Calculate new counter values
141 | C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
142 | C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
143 | C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
144 | C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
145 | C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
146 | C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
147 | C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
148 | C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
149 | this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
150 |
151 | // Calculate the g-values
152 | for (var i = 0; i < 8; i++) {
153 | var gx = X[i] + C[i];
154 |
155 | // Construct high and low argument for squaring
156 | var ga = gx & 0xffff;
157 | var gb = gx >>> 16;
158 |
159 | // Calculate high and low result of squaring
160 | var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
161 | var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
162 |
163 | // High XOR low
164 | G[i] = gh ^ gl;
165 | }
166 |
167 | // Calculate new state values
168 | X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
169 | X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
170 | X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
171 | X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
172 | X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
173 | X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
174 | X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
175 | X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
176 | }
177 |
178 | /**
179 | * Shortcut functions to the cipher's object interface.
180 | *
181 | * @example
182 | *
183 | * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
184 | * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
185 | */
186 | C.Rabbit = StreamCipher._createHelper(Rabbit);
187 | }());
188 |
189 |
190 | return CryptoJS.Rabbit;
191 |
192 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/rabbit-legacy.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var StreamCipher = C_lib.StreamCipher;
21 | var C_algo = C.algo;
22 |
23 | // Reusable objects
24 | var S = [];
25 | var C_ = [];
26 | var G = [];
27 |
28 | /**
29 | * Rabbit stream cipher algorithm.
30 | *
31 | * This is a legacy version that neglected to convert the key to little-endian.
32 | * This error doesn't affect the cipher's security,
33 | * but it does affect its compatibility with other implementations.
34 | */
35 | var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
36 | _doReset: function () {
37 | // Shortcuts
38 | var K = this._key.words;
39 | var iv = this.cfg.iv;
40 |
41 | // Generate initial state values
42 | var X = this._X = [
43 | K[0], (K[3] << 16) | (K[2] >>> 16),
44 | K[1], (K[0] << 16) | (K[3] >>> 16),
45 | K[2], (K[1] << 16) | (K[0] >>> 16),
46 | K[3], (K[2] << 16) | (K[1] >>> 16)
47 | ];
48 |
49 | // Generate initial counter values
50 | var C = this._C = [
51 | (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
52 | (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
53 | (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
54 | (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
55 | ];
56 |
57 | // Carry bit
58 | this._b = 0;
59 |
60 | // Iterate the system four times
61 | for (var i = 0; i < 4; i++) {
62 | nextState.call(this);
63 | }
64 |
65 | // Modify the counters
66 | for (var i = 0; i < 8; i++) {
67 | C[i] ^= X[(i + 4) & 7];
68 | }
69 |
70 | // IV setup
71 | if (iv) {
72 | // Shortcuts
73 | var IV = iv.words;
74 | var IV_0 = IV[0];
75 | var IV_1 = IV[1];
76 |
77 | // Generate four subvectors
78 | var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
79 | var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
80 | var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
81 | var i3 = (i2 << 16) | (i0 & 0x0000ffff);
82 |
83 | // Modify counter values
84 | C[0] ^= i0;
85 | C[1] ^= i1;
86 | C[2] ^= i2;
87 | C[3] ^= i3;
88 | C[4] ^= i0;
89 | C[5] ^= i1;
90 | C[6] ^= i2;
91 | C[7] ^= i3;
92 |
93 | // Iterate the system four times
94 | for (var i = 0; i < 4; i++) {
95 | nextState.call(this);
96 | }
97 | }
98 | },
99 |
100 | _doProcessBlock: function (M, offset) {
101 | // Shortcut
102 | var X = this._X;
103 |
104 | // Iterate the system
105 | nextState.call(this);
106 |
107 | // Generate four keystream words
108 | S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
109 | S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
110 | S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
111 | S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
112 |
113 | for (var i = 0; i < 4; i++) {
114 | // Swap endian
115 | S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
116 | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
117 |
118 | // Encrypt
119 | M[offset + i] ^= S[i];
120 | }
121 | },
122 |
123 | blockSize: 128/32,
124 |
125 | ivSize: 64/32
126 | });
127 |
128 | function nextState() {
129 | // Shortcuts
130 | var X = this._X;
131 | var C = this._C;
132 |
133 | // Save old counter values
134 | for (var i = 0; i < 8; i++) {
135 | C_[i] = C[i];
136 | }
137 |
138 | // Calculate new counter values
139 | C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
140 | C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
141 | C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
142 | C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
143 | C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
144 | C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
145 | C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
146 | C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
147 | this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
148 |
149 | // Calculate the g-values
150 | for (var i = 0; i < 8; i++) {
151 | var gx = X[i] + C[i];
152 |
153 | // Construct high and low argument for squaring
154 | var ga = gx & 0xffff;
155 | var gb = gx >>> 16;
156 |
157 | // Calculate high and low result of squaring
158 | var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
159 | var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
160 |
161 | // High XOR low
162 | G[i] = gh ^ gl;
163 | }
164 |
165 | // Calculate new state values
166 | X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
167 | X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
168 | X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
169 | X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
170 | X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
171 | X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
172 | X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
173 | X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
174 | }
175 |
176 | /**
177 | * Shortcut functions to the cipher's object interface.
178 | *
179 | * @example
180 | *
181 | * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
182 | * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
183 | */
184 | C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
185 | }());
186 |
187 |
188 | return CryptoJS.RabbitLegacy;
189 |
190 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/aes.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var BlockCipher = C_lib.BlockCipher;
21 | var C_algo = C.algo;
22 |
23 | // Lookup tables
24 | var SBOX = [];
25 | var INV_SBOX = [];
26 | var SUB_MIX_0 = [];
27 | var SUB_MIX_1 = [];
28 | var SUB_MIX_2 = [];
29 | var SUB_MIX_3 = [];
30 | var INV_SUB_MIX_0 = [];
31 | var INV_SUB_MIX_1 = [];
32 | var INV_SUB_MIX_2 = [];
33 | var INV_SUB_MIX_3 = [];
34 |
35 | // Compute lookup tables
36 | (function () {
37 | // Compute double table
38 | var d = [];
39 | for (var i = 0; i < 256; i++) {
40 | if (i < 128) {
41 | d[i] = i << 1;
42 | } else {
43 | d[i] = (i << 1) ^ 0x11b;
44 | }
45 | }
46 |
47 | // Walk GF(2^8)
48 | var x = 0;
49 | var xi = 0;
50 | for (var i = 0; i < 256; i++) {
51 | // Compute sbox
52 | var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
53 | sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
54 | SBOX[x] = sx;
55 | INV_SBOX[sx] = x;
56 |
57 | // Compute multiplication
58 | var x2 = d[x];
59 | var x4 = d[x2];
60 | var x8 = d[x4];
61 |
62 | // Compute sub bytes, mix columns tables
63 | var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
64 | SUB_MIX_0[x] = (t << 24) | (t >>> 8);
65 | SUB_MIX_1[x] = (t << 16) | (t >>> 16);
66 | SUB_MIX_2[x] = (t << 8) | (t >>> 24);
67 | SUB_MIX_3[x] = t;
68 |
69 | // Compute inv sub bytes, inv mix columns tables
70 | var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
71 | INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
72 | INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
73 | INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
74 | INV_SUB_MIX_3[sx] = t;
75 |
76 | // Compute next counter
77 | if (!x) {
78 | x = xi = 1;
79 | } else {
80 | x = x2 ^ d[d[d[x8 ^ x2]]];
81 | xi ^= d[d[xi]];
82 | }
83 | }
84 | }());
85 |
86 | // Precomputed Rcon lookup
87 | var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
88 |
89 | /**
90 | * AES block cipher algorithm.
91 | */
92 | var AES = C_algo.AES = BlockCipher.extend({
93 | _doReset: function () {
94 | var t;
95 |
96 | // Skip reset of nRounds has been set before and key did not change
97 | if (this._nRounds && this._keyPriorReset === this._key) {
98 | return;
99 | }
100 |
101 | // Shortcuts
102 | var key = this._keyPriorReset = this._key;
103 | var keyWords = key.words;
104 | var keySize = key.sigBytes / 4;
105 |
106 | // Compute number of rounds
107 | var nRounds = this._nRounds = keySize + 6;
108 |
109 | // Compute number of key schedule rows
110 | var ksRows = (nRounds + 1) * 4;
111 |
112 | // Compute key schedule
113 | var keySchedule = this._keySchedule = [];
114 | for (var ksRow = 0; ksRow < ksRows; ksRow++) {
115 | if (ksRow < keySize) {
116 | keySchedule[ksRow] = keyWords[ksRow];
117 | } else {
118 | t = keySchedule[ksRow - 1];
119 |
120 | if (!(ksRow % keySize)) {
121 | // Rot word
122 | t = (t << 8) | (t >>> 24);
123 |
124 | // Sub word
125 | t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
126 |
127 | // Mix Rcon
128 | t ^= RCON[(ksRow / keySize) | 0] << 24;
129 | } else if (keySize > 6 && ksRow % keySize == 4) {
130 | // Sub word
131 | t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
132 | }
133 |
134 | keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
135 | }
136 | }
137 |
138 | // Compute inv key schedule
139 | var invKeySchedule = this._invKeySchedule = [];
140 | for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
141 | var ksRow = ksRows - invKsRow;
142 |
143 | if (invKsRow % 4) {
144 | var t = keySchedule[ksRow];
145 | } else {
146 | var t = keySchedule[ksRow - 4];
147 | }
148 |
149 | if (invKsRow < 4 || ksRow <= 4) {
150 | invKeySchedule[invKsRow] = t;
151 | } else {
152 | invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
153 | INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
154 | }
155 | }
156 | },
157 |
158 | encryptBlock: function (M, offset) {
159 | this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
160 | },
161 |
162 | decryptBlock: function (M, offset) {
163 | // Swap 2nd and 4th rows
164 | var t = M[offset + 1];
165 | M[offset + 1] = M[offset + 3];
166 | M[offset + 3] = t;
167 |
168 | this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
169 |
170 | // Inv swap 2nd and 4th rows
171 | var t = M[offset + 1];
172 | M[offset + 1] = M[offset + 3];
173 | M[offset + 3] = t;
174 | },
175 |
176 | _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
177 | // Shortcut
178 | var nRounds = this._nRounds;
179 |
180 | // Get input, add round key
181 | var s0 = M[offset] ^ keySchedule[0];
182 | var s1 = M[offset + 1] ^ keySchedule[1];
183 | var s2 = M[offset + 2] ^ keySchedule[2];
184 | var s3 = M[offset + 3] ^ keySchedule[3];
185 |
186 | // Key schedule row counter
187 | var ksRow = 4;
188 |
189 | // Rounds
190 | for (var round = 1; round < nRounds; round++) {
191 | // Shift rows, sub bytes, mix columns, add round key
192 | var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
193 | var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
194 | var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
195 | var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
196 |
197 | // Update state
198 | s0 = t0;
199 | s1 = t1;
200 | s2 = t2;
201 | s3 = t3;
202 | }
203 |
204 | // Shift rows, sub bytes, add round key
205 | var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
206 | var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
207 | var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
208 | var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
209 |
210 | // Set output
211 | M[offset] = t0;
212 | M[offset + 1] = t1;
213 | M[offset + 2] = t2;
214 | M[offset + 3] = t3;
215 | },
216 |
217 | keySize: 256/32
218 | });
219 |
220 | /**
221 | * Shortcut functions to the cipher's object interface.
222 | *
223 | * @example
224 | *
225 | * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
226 | * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
227 | */
228 | C.AES = BlockCipher._createHelper(AES);
229 | }());
230 |
231 |
232 | return CryptoJS.AES;
233 |
234 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/x64-core.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function (undefined) {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var Base = C_lib.Base;
21 | var X32WordArray = C_lib.WordArray;
22 |
23 | /**
24 | * x64 namespace.
25 | */
26 | var C_x64 = C.x64 = {};
27 |
28 | /**
29 | * A 64-bit word.
30 | */
31 | var X64Word = C_x64.Word = Base.extend({
32 | /**
33 | * Initializes a newly created 64-bit word.
34 | *
35 | * @param {number} high The high 32 bits.
36 | * @param {number} low The low 32 bits.
37 | *
38 | * @example
39 | *
40 | * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
41 | */
42 | init: function (high, low) {
43 | this.high = high;
44 | this.low = low;
45 | }
46 |
47 | /**
48 | * Bitwise NOTs this word.
49 | *
50 | * @return {X64Word} A new x64-Word object after negating.
51 | *
52 | * @example
53 | *
54 | * var negated = x64Word.not();
55 | */
56 | // not: function () {
57 | // var high = ~this.high;
58 | // var low = ~this.low;
59 |
60 | // return X64Word.create(high, low);
61 | // },
62 |
63 | /**
64 | * Bitwise ANDs this word with the passed word.
65 | *
66 | * @param {X64Word} word The x64-Word to AND with this word.
67 | *
68 | * @return {X64Word} A new x64-Word object after ANDing.
69 | *
70 | * @example
71 | *
72 | * var anded = x64Word.and(anotherX64Word);
73 | */
74 | // and: function (word) {
75 | // var high = this.high & word.high;
76 | // var low = this.low & word.low;
77 |
78 | // return X64Word.create(high, low);
79 | // },
80 |
81 | /**
82 | * Bitwise ORs this word with the passed word.
83 | *
84 | * @param {X64Word} word The x64-Word to OR with this word.
85 | *
86 | * @return {X64Word} A new x64-Word object after ORing.
87 | *
88 | * @example
89 | *
90 | * var ored = x64Word.or(anotherX64Word);
91 | */
92 | // or: function (word) {
93 | // var high = this.high | word.high;
94 | // var low = this.low | word.low;
95 |
96 | // return X64Word.create(high, low);
97 | // },
98 |
99 | /**
100 | * Bitwise XORs this word with the passed word.
101 | *
102 | * @param {X64Word} word The x64-Word to XOR with this word.
103 | *
104 | * @return {X64Word} A new x64-Word object after XORing.
105 | *
106 | * @example
107 | *
108 | * var xored = x64Word.xor(anotherX64Word);
109 | */
110 | // xor: function (word) {
111 | // var high = this.high ^ word.high;
112 | // var low = this.low ^ word.low;
113 |
114 | // return X64Word.create(high, low);
115 | // },
116 |
117 | /**
118 | * Shifts this word n bits to the left.
119 | *
120 | * @param {number} n The number of bits to shift.
121 | *
122 | * @return {X64Word} A new x64-Word object after shifting.
123 | *
124 | * @example
125 | *
126 | * var shifted = x64Word.shiftL(25);
127 | */
128 | // shiftL: function (n) {
129 | // if (n < 32) {
130 | // var high = (this.high << n) | (this.low >>> (32 - n));
131 | // var low = this.low << n;
132 | // } else {
133 | // var high = this.low << (n - 32);
134 | // var low = 0;
135 | // }
136 |
137 | // return X64Word.create(high, low);
138 | // },
139 |
140 | /**
141 | * Shifts this word n bits to the right.
142 | *
143 | * @param {number} n The number of bits to shift.
144 | *
145 | * @return {X64Word} A new x64-Word object after shifting.
146 | *
147 | * @example
148 | *
149 | * var shifted = x64Word.shiftR(7);
150 | */
151 | // shiftR: function (n) {
152 | // if (n < 32) {
153 | // var low = (this.low >>> n) | (this.high << (32 - n));
154 | // var high = this.high >>> n;
155 | // } else {
156 | // var low = this.high >>> (n - 32);
157 | // var high = 0;
158 | // }
159 |
160 | // return X64Word.create(high, low);
161 | // },
162 |
163 | /**
164 | * Rotates this word n bits to the left.
165 | *
166 | * @param {number} n The number of bits to rotate.
167 | *
168 | * @return {X64Word} A new x64-Word object after rotating.
169 | *
170 | * @example
171 | *
172 | * var rotated = x64Word.rotL(25);
173 | */
174 | // rotL: function (n) {
175 | // return this.shiftL(n).or(this.shiftR(64 - n));
176 | // },
177 |
178 | /**
179 | * Rotates this word n bits to the right.
180 | *
181 | * @param {number} n The number of bits to rotate.
182 | *
183 | * @return {X64Word} A new x64-Word object after rotating.
184 | *
185 | * @example
186 | *
187 | * var rotated = x64Word.rotR(7);
188 | */
189 | // rotR: function (n) {
190 | // return this.shiftR(n).or(this.shiftL(64 - n));
191 | // },
192 |
193 | /**
194 | * Adds this word with the passed word.
195 | *
196 | * @param {X64Word} word The x64-Word to add with this word.
197 | *
198 | * @return {X64Word} A new x64-Word object after adding.
199 | *
200 | * @example
201 | *
202 | * var added = x64Word.add(anotherX64Word);
203 | */
204 | // add: function (word) {
205 | // var low = (this.low + word.low) | 0;
206 | // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
207 | // var high = (this.high + word.high + carry) | 0;
208 |
209 | // return X64Word.create(high, low);
210 | // }
211 | });
212 |
213 | /**
214 | * An array of 64-bit words.
215 | *
216 | * @property {Array} words The array of CryptoJS.x64.Word objects.
217 | * @property {number} sigBytes The number of significant bytes in this word array.
218 | */
219 | var X64WordArray = C_x64.WordArray = Base.extend({
220 | /**
221 | * Initializes a newly created word array.
222 | *
223 | * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
224 | * @param {number} sigBytes (Optional) The number of significant bytes in the words.
225 | *
226 | * @example
227 | *
228 | * var wordArray = CryptoJS.x64.WordArray.create();
229 | *
230 | * var wordArray = CryptoJS.x64.WordArray.create([
231 | * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
232 | * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
233 | * ]);
234 | *
235 | * var wordArray = CryptoJS.x64.WordArray.create([
236 | * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
237 | * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
238 | * ], 10);
239 | */
240 | init: function (words, sigBytes) {
241 | words = this.words = words || [];
242 |
243 | if (sigBytes != undefined) {
244 | this.sigBytes = sigBytes;
245 | } else {
246 | this.sigBytes = words.length * 8;
247 | }
248 | },
249 |
250 | /**
251 | * Converts this 64-bit word array to a 32-bit word array.
252 | *
253 | * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
254 | *
255 | * @example
256 | *
257 | * var x32WordArray = x64WordArray.toX32();
258 | */
259 | toX32: function () {
260 | // Shortcuts
261 | var x64Words = this.words;
262 | var x64WordsLength = x64Words.length;
263 |
264 | // Convert
265 | var x32Words = [];
266 | for (var i = 0; i < x64WordsLength; i++) {
267 | var x64Word = x64Words[i];
268 | x32Words.push(x64Word.high);
269 | x32Words.push(x64Word.low);
270 | }
271 |
272 | return X32WordArray.create(x32Words, this.sigBytes);
273 | },
274 |
275 | /**
276 | * Creates a copy of this word array.
277 | *
278 | * @return {X64WordArray} The clone.
279 | *
280 | * @example
281 | *
282 | * var clone = x64WordArray.clone();
283 | */
284 | clone: function () {
285 | var clone = Base.clone.call(this);
286 |
287 | // Clone "words" array
288 | var words = clone.words = this.words.slice(0);
289 |
290 | // Clone each X64Word object
291 | var wordsLength = words.length;
292 | for (var i = 0; i < wordsLength; i++) {
293 | words[i] = words[i].clone();
294 | }
295 |
296 | return clone;
297 | }
298 | });
299 | }());
300 |
301 |
302 | return CryptoJS;
303 |
304 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/ripemd160.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | /** @preserve
17 | (c) 2012 by Cédric Mesnil. All rights reserved.
18 |
19 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
20 |
21 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
23 |
24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | (function (Math) {
28 | // Shortcuts
29 | var C = CryptoJS;
30 | var C_lib = C.lib;
31 | var WordArray = C_lib.WordArray;
32 | var Hasher = C_lib.Hasher;
33 | var C_algo = C.algo;
34 |
35 | // Constants table
36 | var _zl = WordArray.create([
37 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
38 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
39 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
40 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
41 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
42 | var _zr = WordArray.create([
43 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
44 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
45 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
46 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
47 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
48 | var _sl = WordArray.create([
49 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
50 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
51 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
52 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
53 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
54 | var _sr = WordArray.create([
55 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
56 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
57 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
58 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
59 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
60 |
61 | var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
62 | var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
63 |
64 | /**
65 | * RIPEMD160 hash algorithm.
66 | */
67 | var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
68 | _doReset: function () {
69 | this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
70 | },
71 |
72 | _doProcessBlock: function (M, offset) {
73 |
74 | // Swap endian
75 | for (var i = 0; i < 16; i++) {
76 | // Shortcuts
77 | var offset_i = offset + i;
78 | var M_offset_i = M[offset_i];
79 |
80 | // Swap
81 | M[offset_i] = (
82 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
83 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
84 | );
85 | }
86 | // Shortcut
87 | var H = this._hash.words;
88 | var hl = _hl.words;
89 | var hr = _hr.words;
90 | var zl = _zl.words;
91 | var zr = _zr.words;
92 | var sl = _sl.words;
93 | var sr = _sr.words;
94 |
95 | // Working variables
96 | var al, bl, cl, dl, el;
97 | var ar, br, cr, dr, er;
98 |
99 | ar = al = H[0];
100 | br = bl = H[1];
101 | cr = cl = H[2];
102 | dr = dl = H[3];
103 | er = el = H[4];
104 | // Computation
105 | var t;
106 | for (var i = 0; i < 80; i += 1) {
107 | t = (al + M[offset+zl[i]])|0;
108 | if (i<16){
109 | t += f1(bl,cl,dl) + hl[0];
110 | } else if (i<32) {
111 | t += f2(bl,cl,dl) + hl[1];
112 | } else if (i<48) {
113 | t += f3(bl,cl,dl) + hl[2];
114 | } else if (i<64) {
115 | t += f4(bl,cl,dl) + hl[3];
116 | } else {// if (i<80) {
117 | t += f5(bl,cl,dl) + hl[4];
118 | }
119 | t = t|0;
120 | t = rotl(t,sl[i]);
121 | t = (t+el)|0;
122 | al = el;
123 | el = dl;
124 | dl = rotl(cl, 10);
125 | cl = bl;
126 | bl = t;
127 |
128 | t = (ar + M[offset+zr[i]])|0;
129 | if (i<16){
130 | t += f5(br,cr,dr) + hr[0];
131 | } else if (i<32) {
132 | t += f4(br,cr,dr) + hr[1];
133 | } else if (i<48) {
134 | t += f3(br,cr,dr) + hr[2];
135 | } else if (i<64) {
136 | t += f2(br,cr,dr) + hr[3];
137 | } else {// if (i<80) {
138 | t += f1(br,cr,dr) + hr[4];
139 | }
140 | t = t|0;
141 | t = rotl(t,sr[i]) ;
142 | t = (t+er)|0;
143 | ar = er;
144 | er = dr;
145 | dr = rotl(cr, 10);
146 | cr = br;
147 | br = t;
148 | }
149 | // Intermediate hash value
150 | t = (H[1] + cl + dr)|0;
151 | H[1] = (H[2] + dl + er)|0;
152 | H[2] = (H[3] + el + ar)|0;
153 | H[3] = (H[4] + al + br)|0;
154 | H[4] = (H[0] + bl + cr)|0;
155 | H[0] = t;
156 | },
157 |
158 | _doFinalize: function () {
159 | // Shortcuts
160 | var data = this._data;
161 | var dataWords = data.words;
162 |
163 | var nBitsTotal = this._nDataBytes * 8;
164 | var nBitsLeft = data.sigBytes * 8;
165 |
166 | // Add padding
167 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
168 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
169 | (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
170 | (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
171 | );
172 | data.sigBytes = (dataWords.length + 1) * 4;
173 |
174 | // Hash final blocks
175 | this._process();
176 |
177 | // Shortcuts
178 | var hash = this._hash;
179 | var H = hash.words;
180 |
181 | // Swap endian
182 | for (var i = 0; i < 5; i++) {
183 | // Shortcut
184 | var H_i = H[i];
185 |
186 | // Swap
187 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
188 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
189 | }
190 |
191 | // Return final computed hash
192 | return hash;
193 | },
194 |
195 | clone: function () {
196 | var clone = Hasher.clone.call(this);
197 | clone._hash = this._hash.clone();
198 |
199 | return clone;
200 | }
201 | });
202 |
203 |
204 | function f1(x, y, z) {
205 | return ((x) ^ (y) ^ (z));
206 |
207 | }
208 |
209 | function f2(x, y, z) {
210 | return (((x)&(y)) | ((~x)&(z)));
211 | }
212 |
213 | function f3(x, y, z) {
214 | return (((x) | (~(y))) ^ (z));
215 | }
216 |
217 | function f4(x, y, z) {
218 | return (((x) & (z)) | ((y)&(~(z))));
219 | }
220 |
221 | function f5(x, y, z) {
222 | return ((x) ^ ((y) |(~(z))));
223 |
224 | }
225 |
226 | function rotl(x,n) {
227 | return (x<>>(32-n));
228 | }
229 |
230 |
231 | /**
232 | * Shortcut function to the hasher's object interface.
233 | *
234 | * @param {WordArray|string} message The message to hash.
235 | *
236 | * @return {WordArray} The hash.
237 | *
238 | * @static
239 | *
240 | * @example
241 | *
242 | * var hash = CryptoJS.RIPEMD160('message');
243 | * var hash = CryptoJS.RIPEMD160(wordArray);
244 | */
245 | C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
246 |
247 | /**
248 | * Shortcut function to the HMAC's object interface.
249 | *
250 | * @param {WordArray|string} message The message to hash.
251 | * @param {WordArray|string} key The secret key.
252 | *
253 | * @return {WordArray} The HMAC.
254 | *
255 | * @static
256 | *
257 | * @example
258 | *
259 | * var hmac = CryptoJS.HmacRIPEMD160(message, key);
260 | */
261 | C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
262 | }(Math));
263 |
264 |
265 | return CryptoJS.RIPEMD160;
266 |
267 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/md5.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function (Math) {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var Hasher = C_lib.Hasher;
22 | var C_algo = C.algo;
23 |
24 | // Constants table
25 | var T = [];
26 |
27 | // Compute constants
28 | (function () {
29 | for (var i = 0; i < 64; i++) {
30 | T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
31 | }
32 | }());
33 |
34 | /**
35 | * MD5 hash algorithm.
36 | */
37 | var MD5 = C_algo.MD5 = Hasher.extend({
38 | _doReset: function () {
39 | this._hash = new WordArray.init([
40 | 0x67452301, 0xefcdab89,
41 | 0x98badcfe, 0x10325476
42 | ]);
43 | },
44 |
45 | _doProcessBlock: function (M, offset) {
46 | // Swap endian
47 | for (var i = 0; i < 16; i++) {
48 | // Shortcuts
49 | var offset_i = offset + i;
50 | var M_offset_i = M[offset_i];
51 |
52 | M[offset_i] = (
53 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
54 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
55 | );
56 | }
57 |
58 | // Shortcuts
59 | var H = this._hash.words;
60 |
61 | var M_offset_0 = M[offset + 0];
62 | var M_offset_1 = M[offset + 1];
63 | var M_offset_2 = M[offset + 2];
64 | var M_offset_3 = M[offset + 3];
65 | var M_offset_4 = M[offset + 4];
66 | var M_offset_5 = M[offset + 5];
67 | var M_offset_6 = M[offset + 6];
68 | var M_offset_7 = M[offset + 7];
69 | var M_offset_8 = M[offset + 8];
70 | var M_offset_9 = M[offset + 9];
71 | var M_offset_10 = M[offset + 10];
72 | var M_offset_11 = M[offset + 11];
73 | var M_offset_12 = M[offset + 12];
74 | var M_offset_13 = M[offset + 13];
75 | var M_offset_14 = M[offset + 14];
76 | var M_offset_15 = M[offset + 15];
77 |
78 | // Working varialbes
79 | var a = H[0];
80 | var b = H[1];
81 | var c = H[2];
82 | var d = H[3];
83 |
84 | // Computation
85 | a = FF(a, b, c, d, M_offset_0, 7, T[0]);
86 | d = FF(d, a, b, c, M_offset_1, 12, T[1]);
87 | c = FF(c, d, a, b, M_offset_2, 17, T[2]);
88 | b = FF(b, c, d, a, M_offset_3, 22, T[3]);
89 | a = FF(a, b, c, d, M_offset_4, 7, T[4]);
90 | d = FF(d, a, b, c, M_offset_5, 12, T[5]);
91 | c = FF(c, d, a, b, M_offset_6, 17, T[6]);
92 | b = FF(b, c, d, a, M_offset_7, 22, T[7]);
93 | a = FF(a, b, c, d, M_offset_8, 7, T[8]);
94 | d = FF(d, a, b, c, M_offset_9, 12, T[9]);
95 | c = FF(c, d, a, b, M_offset_10, 17, T[10]);
96 | b = FF(b, c, d, a, M_offset_11, 22, T[11]);
97 | a = FF(a, b, c, d, M_offset_12, 7, T[12]);
98 | d = FF(d, a, b, c, M_offset_13, 12, T[13]);
99 | c = FF(c, d, a, b, M_offset_14, 17, T[14]);
100 | b = FF(b, c, d, a, M_offset_15, 22, T[15]);
101 |
102 | a = GG(a, b, c, d, M_offset_1, 5, T[16]);
103 | d = GG(d, a, b, c, M_offset_6, 9, T[17]);
104 | c = GG(c, d, a, b, M_offset_11, 14, T[18]);
105 | b = GG(b, c, d, a, M_offset_0, 20, T[19]);
106 | a = GG(a, b, c, d, M_offset_5, 5, T[20]);
107 | d = GG(d, a, b, c, M_offset_10, 9, T[21]);
108 | c = GG(c, d, a, b, M_offset_15, 14, T[22]);
109 | b = GG(b, c, d, a, M_offset_4, 20, T[23]);
110 | a = GG(a, b, c, d, M_offset_9, 5, T[24]);
111 | d = GG(d, a, b, c, M_offset_14, 9, T[25]);
112 | c = GG(c, d, a, b, M_offset_3, 14, T[26]);
113 | b = GG(b, c, d, a, M_offset_8, 20, T[27]);
114 | a = GG(a, b, c, d, M_offset_13, 5, T[28]);
115 | d = GG(d, a, b, c, M_offset_2, 9, T[29]);
116 | c = GG(c, d, a, b, M_offset_7, 14, T[30]);
117 | b = GG(b, c, d, a, M_offset_12, 20, T[31]);
118 |
119 | a = HH(a, b, c, d, M_offset_5, 4, T[32]);
120 | d = HH(d, a, b, c, M_offset_8, 11, T[33]);
121 | c = HH(c, d, a, b, M_offset_11, 16, T[34]);
122 | b = HH(b, c, d, a, M_offset_14, 23, T[35]);
123 | a = HH(a, b, c, d, M_offset_1, 4, T[36]);
124 | d = HH(d, a, b, c, M_offset_4, 11, T[37]);
125 | c = HH(c, d, a, b, M_offset_7, 16, T[38]);
126 | b = HH(b, c, d, a, M_offset_10, 23, T[39]);
127 | a = HH(a, b, c, d, M_offset_13, 4, T[40]);
128 | d = HH(d, a, b, c, M_offset_0, 11, T[41]);
129 | c = HH(c, d, a, b, M_offset_3, 16, T[42]);
130 | b = HH(b, c, d, a, M_offset_6, 23, T[43]);
131 | a = HH(a, b, c, d, M_offset_9, 4, T[44]);
132 | d = HH(d, a, b, c, M_offset_12, 11, T[45]);
133 | c = HH(c, d, a, b, M_offset_15, 16, T[46]);
134 | b = HH(b, c, d, a, M_offset_2, 23, T[47]);
135 |
136 | a = II(a, b, c, d, M_offset_0, 6, T[48]);
137 | d = II(d, a, b, c, M_offset_7, 10, T[49]);
138 | c = II(c, d, a, b, M_offset_14, 15, T[50]);
139 | b = II(b, c, d, a, M_offset_5, 21, T[51]);
140 | a = II(a, b, c, d, M_offset_12, 6, T[52]);
141 | d = II(d, a, b, c, M_offset_3, 10, T[53]);
142 | c = II(c, d, a, b, M_offset_10, 15, T[54]);
143 | b = II(b, c, d, a, M_offset_1, 21, T[55]);
144 | a = II(a, b, c, d, M_offset_8, 6, T[56]);
145 | d = II(d, a, b, c, M_offset_15, 10, T[57]);
146 | c = II(c, d, a, b, M_offset_6, 15, T[58]);
147 | b = II(b, c, d, a, M_offset_13, 21, T[59]);
148 | a = II(a, b, c, d, M_offset_4, 6, T[60]);
149 | d = II(d, a, b, c, M_offset_11, 10, T[61]);
150 | c = II(c, d, a, b, M_offset_2, 15, T[62]);
151 | b = II(b, c, d, a, M_offset_9, 21, T[63]);
152 |
153 | // Intermediate hash value
154 | H[0] = (H[0] + a) | 0;
155 | H[1] = (H[1] + b) | 0;
156 | H[2] = (H[2] + c) | 0;
157 | H[3] = (H[3] + d) | 0;
158 | },
159 |
160 | _doFinalize: function () {
161 | // Shortcuts
162 | var data = this._data;
163 | var dataWords = data.words;
164 |
165 | var nBitsTotal = this._nDataBytes * 8;
166 | var nBitsLeft = data.sigBytes * 8;
167 |
168 | // Add padding
169 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
170 |
171 | var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
172 | var nBitsTotalL = nBitsTotal;
173 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
174 | (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
175 | (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
176 | );
177 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
178 | (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
179 | (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
180 | );
181 |
182 | data.sigBytes = (dataWords.length + 1) * 4;
183 |
184 | // Hash final blocks
185 | this._process();
186 |
187 | // Shortcuts
188 | var hash = this._hash;
189 | var H = hash.words;
190 |
191 | // Swap endian
192 | for (var i = 0; i < 4; i++) {
193 | // Shortcut
194 | var H_i = H[i];
195 |
196 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
197 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
198 | }
199 |
200 | // Return final computed hash
201 | return hash;
202 | },
203 |
204 | clone: function () {
205 | var clone = Hasher.clone.call(this);
206 | clone._hash = this._hash.clone();
207 |
208 | return clone;
209 | }
210 | });
211 |
212 | function FF(a, b, c, d, x, s, t) {
213 | var n = a + ((b & c) | (~b & d)) + x + t;
214 | return ((n << s) | (n >>> (32 - s))) + b;
215 | }
216 |
217 | function GG(a, b, c, d, x, s, t) {
218 | var n = a + ((b & d) | (c & ~d)) + x + t;
219 | return ((n << s) | (n >>> (32 - s))) + b;
220 | }
221 |
222 | function HH(a, b, c, d, x, s, t) {
223 | var n = a + (b ^ c ^ d) + x + t;
224 | return ((n << s) | (n >>> (32 - s))) + b;
225 | }
226 |
227 | function II(a, b, c, d, x, s, t) {
228 | var n = a + (c ^ (b | ~d)) + x + t;
229 | return ((n << s) | (n >>> (32 - s))) + b;
230 | }
231 |
232 | /**
233 | * Shortcut function to the hasher's object interface.
234 | *
235 | * @param {WordArray|string} message The message to hash.
236 | *
237 | * @return {WordArray} The hash.
238 | *
239 | * @static
240 | *
241 | * @example
242 | *
243 | * var hash = CryptoJS.MD5('message');
244 | * var hash = CryptoJS.MD5(wordArray);
245 | */
246 | C.MD5 = Hasher._createHelper(MD5);
247 |
248 | /**
249 | * Shortcut function to the HMAC's object interface.
250 | *
251 | * @param {WordArray|string} message The message to hash.
252 | * @param {WordArray|string} key The secret key.
253 | *
254 | * @return {WordArray} The HMAC.
255 | *
256 | * @static
257 | *
258 | * @example
259 | *
260 | * var hmac = CryptoJS.HmacMD5(message, key);
261 | */
262 | C.HmacMD5 = Hasher._createHmacHelper(MD5);
263 | }(Math));
264 |
265 |
266 | return CryptoJS.MD5;
267 |
268 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha3.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function (Math) {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var WordArray = C_lib.WordArray;
21 | var Hasher = C_lib.Hasher;
22 | var C_x64 = C.x64;
23 | var X64Word = C_x64.Word;
24 | var C_algo = C.algo;
25 |
26 | // Constants tables
27 | var RHO_OFFSETS = [];
28 | var PI_INDEXES = [];
29 | var ROUND_CONSTANTS = [];
30 |
31 | // Compute Constants
32 | (function () {
33 | // Compute rho offset constants
34 | var x = 1, y = 0;
35 | for (var t = 0; t < 24; t++) {
36 | RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
37 |
38 | var newX = y % 5;
39 | var newY = (2 * x + 3 * y) % 5;
40 | x = newX;
41 | y = newY;
42 | }
43 |
44 | // Compute pi index constants
45 | for (var x = 0; x < 5; x++) {
46 | for (var y = 0; y < 5; y++) {
47 | PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
48 | }
49 | }
50 |
51 | // Compute round constants
52 | var LFSR = 0x01;
53 | for (var i = 0; i < 24; i++) {
54 | var roundConstantMsw = 0;
55 | var roundConstantLsw = 0;
56 |
57 | for (var j = 0; j < 7; j++) {
58 | if (LFSR & 0x01) {
59 | var bitPosition = (1 << j) - 1;
60 | if (bitPosition < 32) {
61 | roundConstantLsw ^= 1 << bitPosition;
62 | } else /* if (bitPosition >= 32) */ {
63 | roundConstantMsw ^= 1 << (bitPosition - 32);
64 | }
65 | }
66 |
67 | // Compute next LFSR
68 | if (LFSR & 0x80) {
69 | // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
70 | LFSR = (LFSR << 1) ^ 0x71;
71 | } else {
72 | LFSR <<= 1;
73 | }
74 | }
75 |
76 | ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
77 | }
78 | }());
79 |
80 | // Reusable objects for temporary values
81 | var T = [];
82 | (function () {
83 | for (var i = 0; i < 25; i++) {
84 | T[i] = X64Word.create();
85 | }
86 | }());
87 |
88 | /**
89 | * SHA-3 hash algorithm.
90 | */
91 | var SHA3 = C_algo.SHA3 = Hasher.extend({
92 | /**
93 | * Configuration options.
94 | *
95 | * @property {number} outputLength
96 | * The desired number of bits in the output hash.
97 | * Only values permitted are: 224, 256, 384, 512.
98 | * Default: 512
99 | */
100 | cfg: Hasher.cfg.extend({
101 | outputLength: 512
102 | }),
103 |
104 | _doReset: function () {
105 | var state = this._state = []
106 | for (var i = 0; i < 25; i++) {
107 | state[i] = new X64Word.init();
108 | }
109 |
110 | this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
111 | },
112 |
113 | _doProcessBlock: function (M, offset) {
114 | // Shortcuts
115 | var state = this._state;
116 | var nBlockSizeLanes = this.blockSize / 2;
117 |
118 | // Absorb
119 | for (var i = 0; i < nBlockSizeLanes; i++) {
120 | // Shortcuts
121 | var M2i = M[offset + 2 * i];
122 | var M2i1 = M[offset + 2 * i + 1];
123 |
124 | // Swap endian
125 | M2i = (
126 | (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
127 | (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
128 | );
129 | M2i1 = (
130 | (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
131 | (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
132 | );
133 |
134 | // Absorb message into state
135 | var lane = state[i];
136 | lane.high ^= M2i1;
137 | lane.low ^= M2i;
138 | }
139 |
140 | // Rounds
141 | for (var round = 0; round < 24; round++) {
142 | // Theta
143 | for (var x = 0; x < 5; x++) {
144 | // Mix column lanes
145 | var tMsw = 0, tLsw = 0;
146 | for (var y = 0; y < 5; y++) {
147 | var lane = state[x + 5 * y];
148 | tMsw ^= lane.high;
149 | tLsw ^= lane.low;
150 | }
151 |
152 | // Temporary values
153 | var Tx = T[x];
154 | Tx.high = tMsw;
155 | Tx.low = tLsw;
156 | }
157 | for (var x = 0; x < 5; x++) {
158 | // Shortcuts
159 | var Tx4 = T[(x + 4) % 5];
160 | var Tx1 = T[(x + 1) % 5];
161 | var Tx1Msw = Tx1.high;
162 | var Tx1Lsw = Tx1.low;
163 |
164 | // Mix surrounding columns
165 | var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
166 | var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
167 | for (var y = 0; y < 5; y++) {
168 | var lane = state[x + 5 * y];
169 | lane.high ^= tMsw;
170 | lane.low ^= tLsw;
171 | }
172 | }
173 |
174 | // Rho Pi
175 | for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
176 | var tMsw;
177 | var tLsw;
178 |
179 | // Shortcuts
180 | var lane = state[laneIndex];
181 | var laneMsw = lane.high;
182 | var laneLsw = lane.low;
183 | var rhoOffset = RHO_OFFSETS[laneIndex];
184 |
185 | // Rotate lanes
186 | if (rhoOffset < 32) {
187 | tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
188 | tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
189 | } else /* if (rhoOffset >= 32) */ {
190 | tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
191 | tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
192 | }
193 |
194 | // Transpose lanes
195 | var TPiLane = T[PI_INDEXES[laneIndex]];
196 | TPiLane.high = tMsw;
197 | TPiLane.low = tLsw;
198 | }
199 |
200 | // Rho pi at x = y = 0
201 | var T0 = T[0];
202 | var state0 = state[0];
203 | T0.high = state0.high;
204 | T0.low = state0.low;
205 |
206 | // Chi
207 | for (var x = 0; x < 5; x++) {
208 | for (var y = 0; y < 5; y++) {
209 | // Shortcuts
210 | var laneIndex = x + 5 * y;
211 | var lane = state[laneIndex];
212 | var TLane = T[laneIndex];
213 | var Tx1Lane = T[((x + 1) % 5) + 5 * y];
214 | var Tx2Lane = T[((x + 2) % 5) + 5 * y];
215 |
216 | // Mix rows
217 | lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
218 | lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
219 | }
220 | }
221 |
222 | // Iota
223 | var lane = state[0];
224 | var roundConstant = ROUND_CONSTANTS[round];
225 | lane.high ^= roundConstant.high;
226 | lane.low ^= roundConstant.low;
227 | }
228 | },
229 |
230 | _doFinalize: function () {
231 | // Shortcuts
232 | var data = this._data;
233 | var dataWords = data.words;
234 | var nBitsTotal = this._nDataBytes * 8;
235 | var nBitsLeft = data.sigBytes * 8;
236 | var blockSizeBits = this.blockSize * 32;
237 |
238 | // Add padding
239 | dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
240 | dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
241 | data.sigBytes = dataWords.length * 4;
242 |
243 | // Hash final blocks
244 | this._process();
245 |
246 | // Shortcuts
247 | var state = this._state;
248 | var outputLengthBytes = this.cfg.outputLength / 8;
249 | var outputLengthLanes = outputLengthBytes / 8;
250 |
251 | // Squeeze
252 | var hashWords = [];
253 | for (var i = 0; i < outputLengthLanes; i++) {
254 | // Shortcuts
255 | var lane = state[i];
256 | var laneMsw = lane.high;
257 | var laneLsw = lane.low;
258 |
259 | // Swap endian
260 | laneMsw = (
261 | (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
262 | (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
263 | );
264 | laneLsw = (
265 | (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
266 | (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
267 | );
268 |
269 | // Squeeze state to retrieve hash
270 | hashWords.push(laneLsw);
271 | hashWords.push(laneMsw);
272 | }
273 |
274 | // Return final computed hash
275 | return new WordArray.init(hashWords, outputLengthBytes);
276 | },
277 |
278 | clone: function () {
279 | var clone = Hasher.clone.call(this);
280 |
281 | var state = clone._state = this._state.slice(0);
282 | for (var i = 0; i < 25; i++) {
283 | state[i] = state[i].clone();
284 | }
285 |
286 | return clone;
287 | }
288 | });
289 |
290 | /**
291 | * Shortcut function to the hasher's object interface.
292 | *
293 | * @param {WordArray|string} message The message to hash.
294 | *
295 | * @return {WordArray} The hash.
296 | *
297 | * @static
298 | *
299 | * @example
300 | *
301 | * var hash = CryptoJS.SHA3('message');
302 | * var hash = CryptoJS.SHA3(wordArray);
303 | */
304 | C.SHA3 = Hasher._createHelper(SHA3);
305 |
306 | /**
307 | * Shortcut function to the HMAC's object interface.
308 | *
309 | * @param {WordArray|string} message The message to hash.
310 | * @param {WordArray|string} key The secret key.
311 | *
312 | * @return {WordArray} The HMAC.
313 | *
314 | * @static
315 | *
316 | * @example
317 | *
318 | * var hmac = CryptoJS.HmacSHA3(message, key);
319 | */
320 | C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
321 | }(Math));
322 |
323 |
324 | return CryptoJS.SHA3;
325 |
326 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/sha512.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory, undef) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory(require("./core"), require("./x64-core"));
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define(["./core", "./x64-core"], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | factory(root.CryptoJS);
13 | }
14 | }(this, function (CryptoJS) {
15 |
16 | (function () {
17 | // Shortcuts
18 | var C = CryptoJS;
19 | var C_lib = C.lib;
20 | var Hasher = C_lib.Hasher;
21 | var C_x64 = C.x64;
22 | var X64Word = C_x64.Word;
23 | var X64WordArray = C_x64.WordArray;
24 | var C_algo = C.algo;
25 |
26 | function X64Word_create() {
27 | return X64Word.create.apply(X64Word, arguments);
28 | }
29 |
30 | // Constants
31 | var K = [
32 | X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
33 | X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
34 | X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
35 | X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
36 | X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
37 | X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
38 | X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
39 | X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
40 | X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
41 | X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
42 | X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
43 | X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
44 | X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
45 | X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
46 | X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
47 | X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
48 | X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
49 | X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
50 | X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
51 | X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
52 | X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
53 | X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
54 | X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
55 | X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
56 | X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
57 | X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
58 | X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
59 | X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
60 | X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
61 | X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
62 | X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
63 | X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
64 | X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
65 | X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
66 | X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
67 | X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
68 | X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
69 | X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
70 | X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
71 | X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
72 | ];
73 |
74 | // Reusable objects
75 | var W = [];
76 | (function () {
77 | for (var i = 0; i < 80; i++) {
78 | W[i] = X64Word_create();
79 | }
80 | }());
81 |
82 | /**
83 | * SHA-512 hash algorithm.
84 | */
85 | var SHA512 = C_algo.SHA512 = Hasher.extend({
86 | _doReset: function () {
87 | this._hash = new X64WordArray.init([
88 | new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
89 | new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
90 | new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
91 | new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
92 | ]);
93 | },
94 |
95 | _doProcessBlock: function (M, offset) {
96 | // Shortcuts
97 | var H = this._hash.words;
98 |
99 | var H0 = H[0];
100 | var H1 = H[1];
101 | var H2 = H[2];
102 | var H3 = H[3];
103 | var H4 = H[4];
104 | var H5 = H[5];
105 | var H6 = H[6];
106 | var H7 = H[7];
107 |
108 | var H0h = H0.high;
109 | var H0l = H0.low;
110 | var H1h = H1.high;
111 | var H1l = H1.low;
112 | var H2h = H2.high;
113 | var H2l = H2.low;
114 | var H3h = H3.high;
115 | var H3l = H3.low;
116 | var H4h = H4.high;
117 | var H4l = H4.low;
118 | var H5h = H5.high;
119 | var H5l = H5.low;
120 | var H6h = H6.high;
121 | var H6l = H6.low;
122 | var H7h = H7.high;
123 | var H7l = H7.low;
124 |
125 | // Working variables
126 | var ah = H0h;
127 | var al = H0l;
128 | var bh = H1h;
129 | var bl = H1l;
130 | var ch = H2h;
131 | var cl = H2l;
132 | var dh = H3h;
133 | var dl = H3l;
134 | var eh = H4h;
135 | var el = H4l;
136 | var fh = H5h;
137 | var fl = H5l;
138 | var gh = H6h;
139 | var gl = H6l;
140 | var hh = H7h;
141 | var hl = H7l;
142 |
143 | // Rounds
144 | for (var i = 0; i < 80; i++) {
145 | var Wil;
146 | var Wih;
147 |
148 | // Shortcut
149 | var Wi = W[i];
150 |
151 | // Extend message
152 | if (i < 16) {
153 | Wih = Wi.high = M[offset + i * 2] | 0;
154 | Wil = Wi.low = M[offset + i * 2 + 1] | 0;
155 | } else {
156 | // Gamma0
157 | var gamma0x = W[i - 15];
158 | var gamma0xh = gamma0x.high;
159 | var gamma0xl = gamma0x.low;
160 | var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
161 | var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
162 |
163 | // Gamma1
164 | var gamma1x = W[i - 2];
165 | var gamma1xh = gamma1x.high;
166 | var gamma1xl = gamma1x.low;
167 | var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
168 | var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
169 |
170 | // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
171 | var Wi7 = W[i - 7];
172 | var Wi7h = Wi7.high;
173 | var Wi7l = Wi7.low;
174 |
175 | var Wi16 = W[i - 16];
176 | var Wi16h = Wi16.high;
177 | var Wi16l = Wi16.low;
178 |
179 | Wil = gamma0l + Wi7l;
180 | Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
181 | Wil = Wil + gamma1l;
182 | Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
183 | Wil = Wil + Wi16l;
184 | Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
185 |
186 | Wi.high = Wih;
187 | Wi.low = Wil;
188 | }
189 |
190 | var chh = (eh & fh) ^ (~eh & gh);
191 | var chl = (el & fl) ^ (~el & gl);
192 | var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
193 | var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
194 |
195 | var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
196 | var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
197 | var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
198 | var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
199 |
200 | // t1 = h + sigma1 + ch + K[i] + W[i]
201 | var Ki = K[i];
202 | var Kih = Ki.high;
203 | var Kil = Ki.low;
204 |
205 | var t1l = hl + sigma1l;
206 | var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
207 | var t1l = t1l + chl;
208 | var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
209 | var t1l = t1l + Kil;
210 | var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
211 | var t1l = t1l + Wil;
212 | var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
213 |
214 | // t2 = sigma0 + maj
215 | var t2l = sigma0l + majl;
216 | var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
217 |
218 | // Update working variables
219 | hh = gh;
220 | hl = gl;
221 | gh = fh;
222 | gl = fl;
223 | fh = eh;
224 | fl = el;
225 | el = (dl + t1l) | 0;
226 | eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
227 | dh = ch;
228 | dl = cl;
229 | ch = bh;
230 | cl = bl;
231 | bh = ah;
232 | bl = al;
233 | al = (t1l + t2l) | 0;
234 | ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
235 | }
236 |
237 | // Intermediate hash value
238 | H0l = H0.low = (H0l + al);
239 | H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
240 | H1l = H1.low = (H1l + bl);
241 | H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
242 | H2l = H2.low = (H2l + cl);
243 | H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
244 | H3l = H3.low = (H3l + dl);
245 | H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
246 | H4l = H4.low = (H4l + el);
247 | H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
248 | H5l = H5.low = (H5l + fl);
249 | H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
250 | H6l = H6.low = (H6l + gl);
251 | H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
252 | H7l = H7.low = (H7l + hl);
253 | H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
254 | },
255 |
256 | _doFinalize: function () {
257 | // Shortcuts
258 | var data = this._data;
259 | var dataWords = data.words;
260 |
261 | var nBitsTotal = this._nDataBytes * 8;
262 | var nBitsLeft = data.sigBytes * 8;
263 |
264 | // Add padding
265 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
266 | dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
267 | dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
268 | data.sigBytes = dataWords.length * 4;
269 |
270 | // Hash final blocks
271 | this._process();
272 |
273 | // Convert hash to 32-bit word array before returning
274 | var hash = this._hash.toX32();
275 |
276 | // Return final computed hash
277 | return hash;
278 | },
279 |
280 | clone: function () {
281 | var clone = Hasher.clone.call(this);
282 | clone._hash = this._hash.clone();
283 |
284 | return clone;
285 | },
286 |
287 | blockSize: 1024/32
288 | });
289 |
290 | /**
291 | * Shortcut function to the hasher's object interface.
292 | *
293 | * @param {WordArray|string} message The message to hash.
294 | *
295 | * @return {WordArray} The hash.
296 | *
297 | * @static
298 | *
299 | * @example
300 | *
301 | * var hash = CryptoJS.SHA512('message');
302 | * var hash = CryptoJS.SHA512(wordArray);
303 | */
304 | C.SHA512 = Hasher._createHelper(SHA512);
305 |
306 | /**
307 | * Shortcut function to the HMAC's object interface.
308 | *
309 | * @param {WordArray|string} message The message to hash.
310 | * @param {WordArray|string} key The secret key.
311 | *
312 | * @return {WordArray} The HMAC.
313 | *
314 | * @static
315 | *
316 | * @example
317 | *
318 | * var hmac = CryptoJS.HmacSHA512(message, key);
319 | */
320 | C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
321 | }());
322 |
323 |
324 | return CryptoJS.SHA512;
325 |
326 | }));
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/docs/QuickStartGuide.wiki:
--------------------------------------------------------------------------------
1 |
2 |
3 | ----
4 |
5 | = Quick-start Guide =
6 |
7 | == Hashers ==
8 |
9 | === The Hasher Algorithms ===
10 |
11 | ==== MD5 ====
12 |
13 | MD5 is a widely used hash function. It's been used in a variety of security applications and is also commonly used to check the integrity of files. Though, MD5 is not collision resistant, and it isn't suitable for applications like SSL certificates or digital signatures that rely on this property.
14 |
15 | {{{
16 |
17 |
20 | }}}
21 |
22 | ==== SHA-1 ====
23 |
24 | The SHA hash functions were designed by the National Security Agency (NSA). SHA-1 is the most established of the existing SHA hash functions, and it's used in a variety of security applications and protocols. Though, SHA-1's collision resistance has been weakening as new attacks are discovered or improved.
25 |
26 | {{{
27 |
28 |
31 | }}}
32 |
33 | ==== SHA-2 ====
34 |
35 | SHA-256 is one of the four variants in the SHA-2 set. It isn't as widely used as SHA-1, though it appears to provide much better security.
36 |
37 | {{{
38 |
39 |
42 | }}}
43 |
44 | SHA-512 is largely identical to SHA-256 but operates on 64-bit words rather than 32.
45 |
46 | {{{
47 |
48 |
51 | }}}
52 |
53 | CryptoJS also supports SHA-224 and SHA-384, which are largely identical but truncated versions of SHA-256 and SHA-512 respectively.
54 |
55 | ==== SHA-3 ====
56 |
57 | SHA-3 is the winner of a five-year competition to select a new cryptographic hash algorithm where 64 competing designs were evaluated.
58 |
59 | {{{
60 |
61 |
64 | }}}
65 |
66 | SHA-3 can be configured to output hash lengths of one of 224, 256, 384, or 512 bits. The default is 512 bits.
67 |
68 | {{{
69 |
70 |
76 | }}}
77 |
78 | ==== RIPEMD-160 ====
79 |
80 | {{{
81 |
82 |
85 | }}}
86 |
87 | === The Hasher Input ===
88 |
89 | The hash algorithms accept either strings or instances of CryptoJS.lib.WordArray. A WordArray object represents an array of 32-bit words. When you pass a string, it's automatically converted to a WordArray encoded as UTF-8.
90 |
91 | === The Hasher Output ===
92 |
93 | The hash you get back isn't a string yet. It's a WordArray object. When you use a WordArray object in a string context, it's automatically converted to a hex string.
94 |
95 | {{{
96 |
97 |
104 | }}}
105 |
106 | You can convert a WordArray object to other formats by explicitly calling the toString method and passing an encoder.
107 |
108 | {{{
109 |
110 |
111 |
120 | }}}
121 |
122 | === Progressive Hashing ===
123 |
124 | {{{
125 |
126 |
135 | }}}
136 |
137 | == HMAC ==
138 |
139 | Keyed-hash message authentication codes (HMAC) is a mechanism for message authentication using cryptographic hash functions.
140 |
141 | HMAC can be used in combination with any iterated cryptographic hash function.
142 |
143 | {{{
144 |
145 |
146 |
147 |
148 |
154 | }}}
155 |
156 | === Progressive HMAC Hashing ===
157 |
158 | {{{
159 |
160 |
169 | }}}
170 |
171 | == PBKDF2 ==
172 |
173 | PBKDF2 is a password-based key derivation function. In many applications of cryptography, user security is ultimately dependent on a password, and because a password usually can't be used directly as a cryptographic key, some processing is required.
174 |
175 | A salt provides a large set of keys for any given password, and an iteration count increases the cost of producing keys from a password, thereby also increasing the difficulty of attack.
176 |
177 | {{{
178 |
179 |
188 | }}}
189 |
190 | == Ciphers ==
191 |
192 | === The Cipher Algorithms ===
193 |
194 | ==== AES ====
195 |
196 | The Advanced Encryption Standard (AES) is a U.S. Federal Information Processing Standard (FIPS). It was selected after a 5-year process where 15 competing designs were evaluated.
197 |
198 | {{{
199 |
200 |
205 | }}}
206 |
207 | CryptoJS supports AES-128, AES-192, and AES-256. It will pick the variant by the size of the key you pass in. If you use a passphrase, then it will generate a 256-bit key.
208 |
209 | ==== DES, Triple DES ====
210 |
211 | DES is a previously dominant algorithm for encryption, and was published as an official Federal Information Processing Standard (FIPS). DES is now considered to be insecure due to the small key size.
212 |
213 | {{{
214 |
215 |
220 | }}}
221 |
222 | Triple DES applies DES three times to each block to increase the key size. The algorithm is believed to be secure in this form.
223 |
224 | {{{
225 |
226 |
231 | }}}
232 |
233 | ==== Rabbit ====
234 |
235 | Rabbit is a high-performance stream cipher and a finalist in the eSTREAM Portfolio. It is one of the four designs selected after a 3 1/2-year process where 22 designs were evaluated.
236 |
237 | {{{
238 |
239 |
244 | }}}
245 |
246 | ==== RC4, RC4Drop ====
247 |
248 | RC4 is a widely-used stream cipher. It's used in popular protocols such as SSL and WEP. Although remarkable for its simplicity and speed, the algorithm's history doesn't inspire confidence in its security.
249 |
250 | {{{
251 |
252 |
257 | }}}
258 |
259 | It was discovered that the first few bytes of keystream are strongly non-random and leak information about the key. We can defend against this attack by discarding the initial portion of the keystream. This modified algorithm is traditionally called RC4-drop.
260 |
261 | By default, 192 words (768 bytes) are dropped, but you can configure the algorithm to drop any number of words.
262 |
263 | {{{
264 |
265 |
272 | }}}
273 |
274 | === Custom Key and IV ===
275 |
276 | {{{
277 |
278 |
284 | }}}
285 |
286 | === Block Modes and Padding ===
287 |
288 | {{{
289 |
290 |
291 |
292 |
295 | }}}
296 |
297 | CryptoJS supports the following modes:
298 |
299 | * CBC (the default)
300 | * CFB
301 | * CTR
302 | * OFB
303 | * ECB
304 |
305 | And CryptoJS supports the following padding schemes:
306 |
307 | * Pkcs7 (the default)
308 | * Iso97971
309 | * AnsiX923
310 | * Iso10126
311 | * ZeroPadding
312 | * NoPadding
313 |
314 | === The Cipher Input ===
315 |
316 | For the plaintext message, the cipher algorithms accept either strings or instances of CryptoJS.lib.WordArray.
317 |
318 | For the key, when you pass a string, it's treated as a passphrase and used to derive an actual key and IV. Or you can pass a WordArray that represents the actual key. If you pass the actual key, you must also pass the actual IV.
319 |
320 | For the ciphertext, the cipher algorithms accept either strings or instances of CryptoJS.lib.CipherParams. A CipherParams object represents a collection of parameters such as the IV, a salt, and the raw ciphertext itself. When you pass a string, it's automatically converted to a CipherParams object according to a configurable format strategy.
321 |
322 | === The Cipher Output ===
323 |
324 | The plaintext you get back after decryption is a WordArray object. See Hashers' Output for more detail.
325 |
326 | The ciphertext you get back after encryption isn't a string yet. It's a CipherParams object. A CipherParams object gives you access to all the parameters used during encryption. When you use a CipherParams object in a string context, it's automatically converted to a string according to a format strategy. The default is an OpenSSL-compatible format.
327 |
328 | {{{
329 |
330 |
340 | }}}
341 |
342 | You can define your own formats in order to be compatible with other crypto implementations. A format is an object with two methods—stringify and parse—that converts between CipherParams objects and ciphertext strings.
343 |
344 | Here's how you might write a JSON formatter:
345 |
346 | {{{
347 |
348 |
397 | }}}
398 |
399 | === Progressive Ciphering ===
400 |
401 | {{{
402 |
403 |
422 | }}}
423 |
424 | === Interoperability ===
425 |
426 | ==== With OpenSSL ====
427 |
428 | Encrypt with OpenSSL:
429 |
430 | {{{
431 | openssl enc -aes-256-cbc -in infile -out outfile -pass pass:"Secret Passphrase" -e -base64
432 | }}}
433 |
434 | Decrypt with CryptoJS:
435 |
436 | {{{
437 |
438 |
441 | }}}
442 |
443 | == Encoders ==
444 |
445 | CryptoJS can convert from encoding formats such as Base64, Latin1 or Hex to WordArray objects and vica versa.
446 |
447 | {{{
448 |
449 |
450 |
451 |
470 | }}}
--------------------------------------------------------------------------------
/nd1309_practice_block/crypto-js/core.js:
--------------------------------------------------------------------------------
1 | ;(function (root, factory) {
2 | if (typeof exports === "object") {
3 | // CommonJS
4 | module.exports = exports = factory();
5 | }
6 | else if (typeof define === "function" && define.amd) {
7 | // AMD
8 | define([], factory);
9 | }
10 | else {
11 | // Global (browser)
12 | root.CryptoJS = factory();
13 | }
14 | }(this, function () {
15 |
16 | /*globals window, global, require*/
17 |
18 | /**
19 | * CryptoJS core components.
20 | */
21 | var CryptoJS = CryptoJS || (function (Math, undefined) {
22 |
23 | var crypto;
24 |
25 | // Native crypto from window (Browser)
26 | if (typeof window !== 'undefined' && window.crypto) {
27 | crypto = window.crypto;
28 | }
29 |
30 | // Native (experimental IE 11) crypto from window (Browser)
31 | if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
32 | crypto = window.msCrypto;
33 | }
34 |
35 | // Native crypto from global (NodeJS)
36 | if (!crypto && typeof global !== 'undefined' && global.crypto) {
37 | crypto = global.crypto;
38 | }
39 |
40 | // Native crypto import via require (NodeJS)
41 | if (!crypto && typeof require === 'function') {
42 | try {
43 | crypto = require('crypto');
44 | } catch (err) {}
45 | }
46 |
47 | /*
48 | * Cryptographically secure pseudorandom number generator
49 | *
50 | * As Math.random() is cryptographically not safe to use
51 | */
52 | var cryptoSecureRandomInt = function () {
53 | if (crypto) {
54 | // Use getRandomValues method (Browser)
55 | if (typeof crypto.getRandomValues === 'function') {
56 | try {
57 | return crypto.getRandomValues(new Uint32Array(1))[0];
58 | } catch (err) {}
59 | }
60 |
61 | // Use randomBytes method (NodeJS)
62 | if (typeof crypto.randomBytes === 'function') {
63 | try {
64 | return crypto.randomBytes(4).readInt32LE();
65 | } catch (err) {}
66 | }
67 | }
68 |
69 | throw new Error('Native crypto module could not be used to get secure random number.');
70 | };
71 |
72 | /*
73 | * Local polyfill of Object.create
74 |
75 | */
76 | var create = Object.create || (function () {
77 | function F() {}
78 |
79 | return function (obj) {
80 | var subtype;
81 |
82 | F.prototype = obj;
83 |
84 | subtype = new F();
85 |
86 | F.prototype = null;
87 |
88 | return subtype;
89 | };
90 | }())
91 |
92 | /**
93 | * CryptoJS namespace.
94 | */
95 | var C = {};
96 |
97 | /**
98 | * Library namespace.
99 | */
100 | var C_lib = C.lib = {};
101 |
102 | /**
103 | * Base object for prototypal inheritance.
104 | */
105 | var Base = C_lib.Base = (function () {
106 |
107 |
108 | return {
109 | /**
110 | * Creates a new object that inherits from this object.
111 | *
112 | * @param {Object} overrides Properties to copy into the new object.
113 | *
114 | * @return {Object} The new object.
115 | *
116 | * @static
117 | *
118 | * @example
119 | *
120 | * var MyType = CryptoJS.lib.Base.extend({
121 | * field: 'value',
122 | *
123 | * method: function () {
124 | * }
125 | * });
126 | */
127 | extend: function (overrides) {
128 | // Spawn
129 | var subtype = create(this);
130 |
131 | // Augment
132 | if (overrides) {
133 | subtype.mixIn(overrides);
134 | }
135 |
136 | // Create default initializer
137 | if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
138 | subtype.init = function () {
139 | subtype.$super.init.apply(this, arguments);
140 | };
141 | }
142 |
143 | // Initializer's prototype is the subtype object
144 | subtype.init.prototype = subtype;
145 |
146 | // Reference supertype
147 | subtype.$super = this;
148 |
149 | return subtype;
150 | },
151 |
152 | /**
153 | * Extends this object and runs the init method.
154 | * Arguments to create() will be passed to init().
155 | *
156 | * @return {Object} The new object.
157 | *
158 | * @static
159 | *
160 | * @example
161 | *
162 | * var instance = MyType.create();
163 | */
164 | create: function () {
165 | var instance = this.extend();
166 | instance.init.apply(instance, arguments);
167 |
168 | return instance;
169 | },
170 |
171 | /**
172 | * Initializes a newly created object.
173 | * Override this method to add some logic when your objects are created.
174 | *
175 | * @example
176 | *
177 | * var MyType = CryptoJS.lib.Base.extend({
178 | * init: function () {
179 | * // ...
180 | * }
181 | * });
182 | */
183 | init: function () {
184 | },
185 |
186 | /**
187 | * Copies properties into this object.
188 | *
189 | * @param {Object} properties The properties to mix in.
190 | *
191 | * @example
192 | *
193 | * MyType.mixIn({
194 | * field: 'value'
195 | * });
196 | */
197 | mixIn: function (properties) {
198 | for (var propertyName in properties) {
199 | if (properties.hasOwnProperty(propertyName)) {
200 | this[propertyName] = properties[propertyName];
201 | }
202 | }
203 |
204 | // IE won't copy toString using the loop above
205 | if (properties.hasOwnProperty('toString')) {
206 | this.toString = properties.toString;
207 | }
208 | },
209 |
210 | /**
211 | * Creates a copy of this object.
212 | *
213 | * @return {Object} The clone.
214 | *
215 | * @example
216 | *
217 | * var clone = instance.clone();
218 | */
219 | clone: function () {
220 | return this.init.prototype.extend(this);
221 | }
222 | };
223 | }());
224 |
225 | /**
226 | * An array of 32-bit words.
227 | *
228 | * @property {Array} words The array of 32-bit words.
229 | * @property {number} sigBytes The number of significant bytes in this word array.
230 | */
231 | var WordArray = C_lib.WordArray = Base.extend({
232 | /**
233 | * Initializes a newly created word array.
234 | *
235 | * @param {Array} words (Optional) An array of 32-bit words.
236 | * @param {number} sigBytes (Optional) The number of significant bytes in the words.
237 | *
238 | * @example
239 | *
240 | * var wordArray = CryptoJS.lib.WordArray.create();
241 | * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
242 | * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
243 | */
244 | init: function (words, sigBytes) {
245 | words = this.words = words || [];
246 |
247 | if (sigBytes != undefined) {
248 | this.sigBytes = sigBytes;
249 | } else {
250 | this.sigBytes = words.length * 4;
251 | }
252 | },
253 |
254 | /**
255 | * Converts this word array to a string.
256 | *
257 | * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
258 | *
259 | * @return {string} The stringified word array.
260 | *
261 | * @example
262 | *
263 | * var string = wordArray + '';
264 | * var string = wordArray.toString();
265 | * var string = wordArray.toString(CryptoJS.enc.Utf8);
266 | */
267 | toString: function (encoder) {
268 | return (encoder || Hex).stringify(this);
269 | },
270 |
271 | /**
272 | * Concatenates a word array to this word array.
273 | *
274 | * @param {WordArray} wordArray The word array to append.
275 | *
276 | * @return {WordArray} This word array.
277 | *
278 | * @example
279 | *
280 | * wordArray1.concat(wordArray2);
281 | */
282 | concat: function (wordArray) {
283 | // Shortcuts
284 | var thisWords = this.words;
285 | var thatWords = wordArray.words;
286 | var thisSigBytes = this.sigBytes;
287 | var thatSigBytes = wordArray.sigBytes;
288 |
289 | // Clamp excess bits
290 | this.clamp();
291 |
292 | // Concat
293 | if (thisSigBytes % 4) {
294 | // Copy one byte at a time
295 | for (var i = 0; i < thatSigBytes; i++) {
296 | var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
297 | thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
298 | }
299 | } else {
300 | // Copy one word at a time
301 | for (var i = 0; i < thatSigBytes; i += 4) {
302 | thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
303 | }
304 | }
305 | this.sigBytes += thatSigBytes;
306 |
307 | // Chainable
308 | return this;
309 | },
310 |
311 | /**
312 | * Removes insignificant bits.
313 | *
314 | * @example
315 | *
316 | * wordArray.clamp();
317 | */
318 | clamp: function () {
319 | // Shortcuts
320 | var words = this.words;
321 | var sigBytes = this.sigBytes;
322 |
323 | // Clamp
324 | words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
325 | words.length = Math.ceil(sigBytes / 4);
326 | },
327 |
328 | /**
329 | * Creates a copy of this word array.
330 | *
331 | * @return {WordArray} The clone.
332 | *
333 | * @example
334 | *
335 | * var clone = wordArray.clone();
336 | */
337 | clone: function () {
338 | var clone = Base.clone.call(this);
339 | clone.words = this.words.slice(0);
340 |
341 | return clone;
342 | },
343 |
344 | /**
345 | * Creates a word array filled with random bytes.
346 | *
347 | * @param {number} nBytes The number of random bytes to generate.
348 | *
349 | * @return {WordArray} The random word array.
350 | *
351 | * @static
352 | *
353 | * @example
354 | *
355 | * var wordArray = CryptoJS.lib.WordArray.random(16);
356 | */
357 | random: function (nBytes) {
358 | var words = [];
359 |
360 | for (var i = 0; i < nBytes; i += 4) {
361 | words.push(cryptoSecureRandomInt());
362 | }
363 |
364 | return new WordArray.init(words, nBytes);
365 | }
366 | });
367 |
368 | /**
369 | * Encoder namespace.
370 | */
371 | var C_enc = C.enc = {};
372 |
373 | /**
374 | * Hex encoding strategy.
375 | */
376 | var Hex = C_enc.Hex = {
377 | /**
378 | * Converts a word array to a hex string.
379 | *
380 | * @param {WordArray} wordArray The word array.
381 | *
382 | * @return {string} The hex string.
383 | *
384 | * @static
385 | *
386 | * @example
387 | *
388 | * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
389 | */
390 | stringify: function (wordArray) {
391 | // Shortcuts
392 | var words = wordArray.words;
393 | var sigBytes = wordArray.sigBytes;
394 |
395 | // Convert
396 | var hexChars = [];
397 | for (var i = 0; i < sigBytes; i++) {
398 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
399 | hexChars.push((bite >>> 4).toString(16));
400 | hexChars.push((bite & 0x0f).toString(16));
401 | }
402 |
403 | return hexChars.join('');
404 | },
405 |
406 | /**
407 | * Converts a hex string to a word array.
408 | *
409 | * @param {string} hexStr The hex string.
410 | *
411 | * @return {WordArray} The word array.
412 | *
413 | * @static
414 | *
415 | * @example
416 | *
417 | * var wordArray = CryptoJS.enc.Hex.parse(hexString);
418 | */
419 | parse: function (hexStr) {
420 | // Shortcut
421 | var hexStrLength = hexStr.length;
422 |
423 | // Convert
424 | var words = [];
425 | for (var i = 0; i < hexStrLength; i += 2) {
426 | words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
427 | }
428 |
429 | return new WordArray.init(words, hexStrLength / 2);
430 | }
431 | };
432 |
433 | /**
434 | * Latin1 encoding strategy.
435 | */
436 | var Latin1 = C_enc.Latin1 = {
437 | /**
438 | * Converts a word array to a Latin1 string.
439 | *
440 | * @param {WordArray} wordArray The word array.
441 | *
442 | * @return {string} The Latin1 string.
443 | *
444 | * @static
445 | *
446 | * @example
447 | *
448 | * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
449 | */
450 | stringify: function (wordArray) {
451 | // Shortcuts
452 | var words = wordArray.words;
453 | var sigBytes = wordArray.sigBytes;
454 |
455 | // Convert
456 | var latin1Chars = [];
457 | for (var i = 0; i < sigBytes; i++) {
458 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
459 | latin1Chars.push(String.fromCharCode(bite));
460 | }
461 |
462 | return latin1Chars.join('');
463 | },
464 |
465 | /**
466 | * Converts a Latin1 string to a word array.
467 | *
468 | * @param {string} latin1Str The Latin1 string.
469 | *
470 | * @return {WordArray} The word array.
471 | *
472 | * @static
473 | *
474 | * @example
475 | *
476 | * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
477 | */
478 | parse: function (latin1Str) {
479 | // Shortcut
480 | var latin1StrLength = latin1Str.length;
481 |
482 | // Convert
483 | var words = [];
484 | for (var i = 0; i < latin1StrLength; i++) {
485 | words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
486 | }
487 |
488 | return new WordArray.init(words, latin1StrLength);
489 | }
490 | };
491 |
492 | /**
493 | * UTF-8 encoding strategy.
494 | */
495 | var Utf8 = C_enc.Utf8 = {
496 | /**
497 | * Converts a word array to a UTF-8 string.
498 | *
499 | * @param {WordArray} wordArray The word array.
500 | *
501 | * @return {string} The UTF-8 string.
502 | *
503 | * @static
504 | *
505 | * @example
506 | *
507 | * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
508 | */
509 | stringify: function (wordArray) {
510 | try {
511 | return decodeURIComponent(escape(Latin1.stringify(wordArray)));
512 | } catch (e) {
513 | throw new Error('Malformed UTF-8 data');
514 | }
515 | },
516 |
517 | /**
518 | * Converts a UTF-8 string to a word array.
519 | *
520 | * @param {string} utf8Str The UTF-8 string.
521 | *
522 | * @return {WordArray} The word array.
523 | *
524 | * @static
525 | *
526 | * @example
527 | *
528 | * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
529 | */
530 | parse: function (utf8Str) {
531 | return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
532 | }
533 | };
534 |
535 | /**
536 | * Abstract buffered block algorithm template.
537 | *
538 | * The property blockSize must be implemented in a concrete subtype.
539 | *
540 | * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
541 | */
542 | var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
543 | /**
544 | * Resets this block algorithm's data buffer to its initial state.
545 | *
546 | * @example
547 | *
548 | * bufferedBlockAlgorithm.reset();
549 | */
550 | reset: function () {
551 | // Initial values
552 | this._data = new WordArray.init();
553 | this._nDataBytes = 0;
554 | },
555 |
556 | /**
557 | * Adds new data to this block algorithm's buffer.
558 | *
559 | * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
560 | *
561 | * @example
562 | *
563 | * bufferedBlockAlgorithm._append('data');
564 | * bufferedBlockAlgorithm._append(wordArray);
565 | */
566 | _append: function (data) {
567 | // Convert string to WordArray, else assume WordArray already
568 | if (typeof data == 'string') {
569 | data = Utf8.parse(data);
570 | }
571 |
572 | // Append
573 | this._data.concat(data);
574 | this._nDataBytes += data.sigBytes;
575 | },
576 |
577 | /**
578 | * Processes available data blocks.
579 | *
580 | * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
581 | *
582 | * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
583 | *
584 | * @return {WordArray} The processed data.
585 | *
586 | * @example
587 | *
588 | * var processedData = bufferedBlockAlgorithm._process();
589 | * var processedData = bufferedBlockAlgorithm._process(!!'flush');
590 | */
591 | _process: function (doFlush) {
592 | var processedWords;
593 |
594 | // Shortcuts
595 | var data = this._data;
596 | var dataWords = data.words;
597 | var dataSigBytes = data.sigBytes;
598 | var blockSize = this.blockSize;
599 | var blockSizeBytes = blockSize * 4;
600 |
601 | // Count blocks ready
602 | var nBlocksReady = dataSigBytes / blockSizeBytes;
603 | if (doFlush) {
604 | // Round up to include partial blocks
605 | nBlocksReady = Math.ceil(nBlocksReady);
606 | } else {
607 | // Round down to include only full blocks,
608 | // less the number of blocks that must remain in the buffer
609 | nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
610 | }
611 |
612 | // Count words ready
613 | var nWordsReady = nBlocksReady * blockSize;
614 |
615 | // Count bytes ready
616 | var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
617 |
618 | // Process blocks
619 | if (nWordsReady) {
620 | for (var offset = 0; offset < nWordsReady; offset += blockSize) {
621 | // Perform concrete-algorithm logic
622 | this._doProcessBlock(dataWords, offset);
623 | }
624 |
625 | // Remove processed words
626 | processedWords = dataWords.splice(0, nWordsReady);
627 | data.sigBytes -= nBytesReady;
628 | }
629 |
630 | // Return processed words
631 | return new WordArray.init(processedWords, nBytesReady);
632 | },
633 |
634 | /**
635 | * Creates a copy of this object.
636 | *
637 | * @return {Object} The clone.
638 | *
639 | * @example
640 | *
641 | * var clone = bufferedBlockAlgorithm.clone();
642 | */
643 | clone: function () {
644 | var clone = Base.clone.call(this);
645 | clone._data = this._data.clone();
646 |
647 | return clone;
648 | },
649 |
650 | _minBufferSize: 0
651 | });
652 |
653 | /**
654 | * Abstract hasher template.
655 | *
656 | * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
657 | */
658 | var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
659 | /**
660 | * Configuration options.
661 | */
662 | cfg: Base.extend(),
663 |
664 | /**
665 | * Initializes a newly created hasher.
666 | *
667 | * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
668 | *
669 | * @example
670 | *
671 | * var hasher = CryptoJS.algo.SHA256.create();
672 | */
673 | init: function (cfg) {
674 | // Apply config defaults
675 | this.cfg = this.cfg.extend(cfg);
676 |
677 | // Set initial values
678 | this.reset();
679 | },
680 |
681 | /**
682 | * Resets this hasher to its initial state.
683 | *
684 | * @example
685 | *
686 | * hasher.reset();
687 | */
688 | reset: function () {
689 | // Reset data buffer
690 | BufferedBlockAlgorithm.reset.call(this);
691 |
692 | // Perform concrete-hasher logic
693 | this._doReset();
694 | },
695 |
696 | /**
697 | * Updates this hasher with a message.
698 | *
699 | * @param {WordArray|string} messageUpdate The message to append.
700 | *
701 | * @return {Hasher} This hasher.
702 | *
703 | * @example
704 | *
705 | * hasher.update('message');
706 | * hasher.update(wordArray);
707 | */
708 | update: function (messageUpdate) {
709 | // Append
710 | this._append(messageUpdate);
711 |
712 | // Update the hash
713 | this._process();
714 |
715 | // Chainable
716 | return this;
717 | },
718 |
719 | /**
720 | * Finalizes the hash computation.
721 | * Note that the finalize operation is effectively a destructive, read-once operation.
722 | *
723 | * @param {WordArray|string} messageUpdate (Optional) A final message update.
724 | *
725 | * @return {WordArray} The hash.
726 | *
727 | * @example
728 | *
729 | * var hash = hasher.finalize();
730 | * var hash = hasher.finalize('message');
731 | * var hash = hasher.finalize(wordArray);
732 | */
733 | finalize: function (messageUpdate) {
734 | // Final message update
735 | if (messageUpdate) {
736 | this._append(messageUpdate);
737 | }
738 |
739 | // Perform concrete-hasher logic
740 | var hash = this._doFinalize();
741 |
742 | return hash;
743 | },
744 |
745 | blockSize: 512/32,
746 |
747 | /**
748 | * Creates a shortcut function to a hasher's object interface.
749 | *
750 | * @param {Hasher} hasher The hasher to create a helper for.
751 | *
752 | * @return {Function} The shortcut function.
753 | *
754 | * @static
755 | *
756 | * @example
757 | *
758 | * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
759 | */
760 | _createHelper: function (hasher) {
761 | return function (message, cfg) {
762 | return new hasher.init(cfg).finalize(message);
763 | };
764 | },
765 |
766 | /**
767 | * Creates a shortcut function to the HMAC's object interface.
768 | *
769 | * @param {Hasher} hasher The hasher to use in this HMAC helper.
770 | *
771 | * @return {Function} The shortcut function.
772 | *
773 | * @static
774 | *
775 | * @example
776 | *
777 | * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
778 | */
779 | _createHmacHelper: function (hasher) {
780 | return function (message, key) {
781 | return new C_algo.HMAC.init(hasher, key).finalize(message);
782 | };
783 | }
784 | });
785 |
786 | /**
787 | * Algorithm namespace.
788 | */
789 | var C_algo = C.algo = {};
790 |
791 | return C;
792 | }(Math));
793 |
794 |
795 | return CryptoJS;
796 |
797 | }));
--------------------------------------------------------------------------------