Merge branch 'feature/java-api' into 'master'
Feature/java api See merge request !13
Showing
51 changed files
with
4588 additions
and
14 deletions
Too many changes to show.
To preserve performance only 51 of 51+ files are displayed.
@@ -7,6 +7,7 @@ import mta from './vendors/mta_analysis'; | @@ -7,6 +7,7 @@ import mta from './vendors/mta_analysis'; | ||
7 | import {Event} from '/login/utils/index.js'; | 7 | import {Event} from '/login/utils/index.js'; |
8 | import {wxLogin} from '/login/utils/login/login'; | 8 | import {wxLogin} from '/login/utils/login/login'; |
9 | import appReport from './libs/appReport'; | 9 | import appReport from './libs/appReport'; |
10 | +import iconfSwitch from './libs/switch'; | ||
10 | import {isStringEmpty, getYHStorageSync} from './utils/util'; | 11 | import {isStringEmpty, getYHStorageSync} from './utils/util'; |
11 | import regeneratorRuntime from '/login/libs/regenerator-runtime/index'; | 12 | import regeneratorRuntime from '/login/libs/regenerator-runtime/index'; |
12 | 13 | ||
@@ -115,6 +116,15 @@ App({ | @@ -115,6 +116,15 @@ App({ | ||
115 | 116 | ||
116 | //当应用程序进入前台显示状态时触发 | 117 | //当应用程序进入前台显示状态时触发 |
117 | onShow(options) { | 118 | onShow(options) { |
119 | + iconfSwitch(this).then(data => { | ||
120 | + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> app onshow switch'); | ||
121 | + this.globalData.hasSetSwitch = true; | ||
122 | + if (data['javaapi'] && '0' === data['javaapi']) { | ||
123 | + this.globalData.switch_javaApiEnable = false; | ||
124 | + } | ||
125 | + }, () => { | ||
126 | + this.globalData.hasSetSwitch = true; | ||
127 | + }); | ||
118 | let that = this | 128 | let that = this |
119 | let params = {}; | 129 | let params = {}; |
120 | yasReport(YB_ENTER_FOREGROUND, params, that) | 130 | yasReport(YB_ENTER_FOREGROUND, params, that) |
@@ -313,6 +323,8 @@ App({ | @@ -313,6 +323,8 @@ App({ | ||
313 | }, | 323 | }, |
314 | 324 | ||
315 | globalData: { | 325 | globalData: { |
326 | + hasSetSwitch: false, | ||
327 | + switch_javaApiEnable: true, | ||
316 | selectedChannel: 'boy', | 328 | selectedChannel: 'boy', |
317 | userInfo: {}, | 329 | userInfo: {}, |
318 | systemInfo: null, | 330 | systemInfo: null, |
@@ -4,14 +4,15 @@ export const SERVICE_HOST = 'https://api.yoho.cn'; | @@ -4,14 +4,15 @@ export const SERVICE_HOST = 'https://api.yoho.cn'; | ||
4 | export const ACTIVITY_HOST = 'https://action.yoho.cn'; | 4 | export const ACTIVITY_HOST = 'https://action.yoho.cn'; |
5 | export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3'; | 5 | export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3'; |
6 | export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; | 6 | export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; |
7 | +export const ICONFIG_HOST = 'https://iconfig.yoho.cn/miniapp/v1/'; | ||
7 | 8 | ||
8 | // 测试环境 | 9 | // 测试环境 |
9 | // export const API_HOST = 'http://api-test3.dev.yohocorp.com'; | 10 | // export const API_HOST = 'http://api-test3.dev.yohocorp.com'; |
10 | // export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com'; | 11 | // export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com'; |
11 | // export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com'; | 12 | // export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com'; |
12 | -// export const ACTIVITY_HOST = 'http://limit-yoho-activity-platform.test3.ingress.dev.yohocorp.com'; | ||
13 | // export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3'; | 13 | // export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3'; |
14 | // export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; | 14 | // export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; |
15 | +// export const ICONFIG_HOST = 'http://iconfig.yoho.cn/miniapp/v1/'; | ||
15 | 16 | ||
16 | export const MINI_APP_TYPE = 29; | 17 | export const MINI_APP_TYPE = 29; |
17 | export const MINI_QR_TYPE = 16; | 18 | export const MINI_QR_TYPE = 16; |
@@ -61,6 +61,7 @@ function getPrivateKey(){ | @@ -61,6 +61,7 @@ function getPrivateKey(){ | ||
61 | } | 61 | } |
62 | function request(method = 'GET') { | 62 | function request(method = 'GET') { |
63 | return function(url, params = {}) { | 63 | return function(url, params = {}) { |
64 | + params = Object.assign({}, params); | ||
64 | return getPrivateKey() | 65 | return getPrivateKey() |
65 | .then(key => { | 66 | .then(key => { |
66 | return new Promise(function (resolve, reject) { | 67 | return new Promise(function (resolve, reject) { |
libs/switch.js
0 → 100644
1 | +import Promise from '../vendors/es6-promise'; | ||
2 | +import {APP_VERSION, ICONFIG_HOST} from '../libs/config'; | ||
3 | +import {encrypt, decrypt} from '../utils/icfg-aes'; | ||
4 | +import {stringify} from '../vendors/query-string'; | ||
5 | + | ||
6 | +let iconfSwitch = function (app) { | ||
7 | + app = app || getApp(); | ||
8 | + let data = {}; | ||
9 | + let device = app.globalData.systemInfo; | ||
10 | + | ||
11 | + data.app_ver = APP_VERSION; | ||
12 | + data.uid = app.getUid() || ''; | ||
13 | + data.os = device.platform.indexOf('ios') > -1 ? 0 : 1; | ||
14 | + data.osv = device.osv || device.version; | ||
15 | + data.model = device.model; | ||
16 | + data.udid = app.globalData.udid ? app.globalData.udid : ''; | ||
17 | + data.patchv = ''; | ||
18 | + data.ci = (app.getUnion_type() ? app.getUnion_type() : app.globalData.ch) || ''; | ||
19 | + | ||
20 | + return new Promise(function (resolve, reject) { | ||
21 | + wx.request({ | ||
22 | + url: `${ICONFIG_HOST}?${encrypt(stringify(data))}`, | ||
23 | + success({data} = {}) { | ||
24 | + resolve(JSON.parse(decrypt(data))); | ||
25 | + }, | ||
26 | + fail(err) { | ||
27 | + reject(err); | ||
28 | + } | ||
29 | + }); | ||
30 | + }) | ||
31 | + | ||
32 | +}; | ||
33 | + | ||
34 | +export default iconfSwitch; |
@@ -103,6 +103,11 @@ Component({ | @@ -103,6 +103,11 @@ Component({ | ||
103 | }); | 103 | }); |
104 | }, | 104 | }, |
105 | 105 | ||
106 | + hadJoinToShare() { | ||
107 | + this.goShare(); | ||
108 | + this.triggerEvent('getcode'); | ||
109 | + }, | ||
110 | + | ||
106 | goMyList() { | 111 | goMyList() { |
107 | wx.reLaunch({ | 112 | wx.reLaunch({ |
108 | url: '/pages/zeroSell/index?tabIndex=3&reload=0', | 113 | url: '/pages/zeroSell/index?tabIndex=3&reload=0', |
@@ -61,7 +61,7 @@ | @@ -61,7 +61,7 @@ | ||
61 | <view class="code">{{code}}</view> | 61 | <view class="code">{{code}}</view> |
62 | </view> | 62 | </view> |
63 | <form bindsubmit='submitFormId' report-submit='true'> | 63 | <form bindsubmit='submitFormId' report-submit='true'> |
64 | - <button class="share" form-type="submit" bindtap="goShare">分享一下,中奖概率立马double</button> | 64 | + <button class="share" form-type="submit" bindtap="hadJoinToShare">分享一下,中奖概率立马double</button> |
65 | </form> | 65 | </form> |
66 | <view class="share-desc">1个好友参加=1个抽奖码=中奖几率UP!</view> | 66 | <view class="share-desc">1个好友参加=1个抽奖码=中奖几率UP!</view> |
67 | </view> | 67 | </view> |
@@ -185,8 +185,10 @@ Page(Object.assign({ | @@ -185,8 +185,10 @@ Page(Object.assign({ | ||
185 | this.setData({ | 185 | this.setData({ |
186 | footText: '内容加载中...' | 186 | footText: '内容加载中...' |
187 | }) | 187 | }) |
188 | + setTimeout(() => { | ||
188 | this._getProceedingData(); | 189 | this._getProceedingData(); |
189 | this._getReleaseData(1); | 190 | this._getReleaseData(1); |
191 | + }, 1200); | ||
190 | return this._getPage(page).then(list => { | 192 | return this._getPage(page).then(list => { |
191 | if (list.length === 0) { | 193 | if (list.length === 0) { |
192 | this.setData({ | 194 | this.setData({ |
@@ -267,7 +269,7 @@ Page(Object.assign({ | @@ -267,7 +269,7 @@ Page(Object.assign({ | ||
267 | this.service.getMyList({type, page, limit}).then(res => { | 269 | this.service.getMyList({type, page, limit}).then(res => { |
268 | let data = [] | 270 | let data = [] |
269 | if (res && res.code === 200) { | 271 | if (res && res.code === 200) { |
270 | - data = res.data; | 272 | + data = res.data.list ? res.data.list : res.data; |
271 | } | 273 | } |
272 | this.setData({ | 274 | this.setData({ |
273 | [key]: data | 275 | [key]: data |
@@ -281,14 +283,14 @@ Page(Object.assign({ | @@ -281,14 +283,14 @@ Page(Object.assign({ | ||
281 | } | 283 | } |
282 | let type = 1; | 284 | let type = 1; |
283 | let my_zero_list = this.data.my_zero_list; | 285 | let my_zero_list = this.data.my_zero_list; |
284 | - let page = my_zero_list[type].page; | 286 | + let page = 1; |
285 | let oldData = my_zero_list[type].data; | 287 | let oldData = my_zero_list[type].data; |
286 | let key = `my_zero_list[${type}].data`; | 288 | let key = `my_zero_list[${type}].data`; |
287 | let keyPage = `my_zero_list[${type}].page`; | 289 | let keyPage = `my_zero_list[${type}].page`; |
288 | this.service.getMyList({type, page}).then(res => { | 290 | this.service.getMyList({type, page}).then(res => { |
289 | let data = [] | 291 | let data = [] |
290 | if (res && res.code === 200) { | 292 | if (res && res.code === 200) { |
291 | - data = res.data; | 293 | + data = res.data.list ? res.data.list : res.data; |
292 | } | 294 | } |
293 | this.setData({ | 295 | this.setData({ |
294 | [key]: data, | 296 | [key]: data, |
@@ -316,7 +318,7 @@ Page(Object.assign({ | @@ -316,7 +318,7 @@ Page(Object.assign({ | ||
316 | this.service.getMyList({type, page}).then(res => { | 318 | this.service.getMyList({type, page}).then(res => { |
317 | let data = [] | 319 | let data = [] |
318 | if (res && res.code === 200) { | 320 | if (res && res.code === 200) { |
319 | - data = res.data; | 321 | + data = res.data.list ? res.data.list : res.data; |
320 | } | 322 | } |
321 | this.setData({ | 323 | this.setData({ |
322 | [key]: oldData.concat(data), | 324 | [key]: oldData.concat(data), |
pages/zeroSell/service/humps.js
0 → 100644
1 | +// ========= | ||
2 | +// = humps = | ||
3 | +// ========= | ||
4 | +// Underscore-to-camelCase converter (and vice versa) | ||
5 | +// for strings and object keys | ||
6 | + | ||
7 | +// humps is copyright © 2012+ Dom Christie | ||
8 | +// Released under the MIT license. | ||
9 | + | ||
10 | + | ||
11 | +(function(global) { | ||
12 | + | ||
13 | + var _processKeys = function(convert, obj, options) { | ||
14 | + if(!_isObject(obj) || _isDate(obj) || _isRegExp(obj) || _isBoolean(obj) || _isFunction(obj)) { | ||
15 | + return obj; | ||
16 | + } | ||
17 | + | ||
18 | + var output, | ||
19 | + i = 0, | ||
20 | + l = 0; | ||
21 | + | ||
22 | + if(_isArray(obj)) { | ||
23 | + output = []; | ||
24 | + for(l=obj.length; i<l; i++) { | ||
25 | + output.push(_processKeys(convert, obj[i], options)); | ||
26 | + } | ||
27 | + } | ||
28 | + else { | ||
29 | + output = {}; | ||
30 | + for(var key in obj) { | ||
31 | + if(Object.prototype.hasOwnProperty.call(obj, key)) { | ||
32 | + output[convert(key, options)] = _processKeys(convert, obj[key], options); | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | + return output; | ||
37 | + }; | ||
38 | + | ||
39 | + // String conversion methods | ||
40 | + | ||
41 | + var separateWords = function(string, options) { | ||
42 | + options = options || {}; | ||
43 | + var separator = options.separator || '_'; | ||
44 | + var split = options.split || /(?=[A-Z])/; | ||
45 | + | ||
46 | + return string.split(split).join(separator); | ||
47 | + }; | ||
48 | + | ||
49 | + var camelize = function(string) { | ||
50 | + if (_isNumerical(string)) { | ||
51 | + return string; | ||
52 | + } | ||
53 | + string = string.replace(/[\-_\s]+(.)?/g, function(match, chr) { | ||
54 | + return chr ? chr.toUpperCase() : ''; | ||
55 | + }); | ||
56 | + // Ensure 1st char is always lowercase | ||
57 | + return string.substr(0, 1).toLowerCase() + string.substr(1); | ||
58 | + }; | ||
59 | + | ||
60 | + var pascalize = function(string) { | ||
61 | + var camelized = camelize(string); | ||
62 | + // Ensure 1st char is always uppercase | ||
63 | + return camelized.substr(0, 1).toUpperCase() + camelized.substr(1); | ||
64 | + }; | ||
65 | + | ||
66 | + var decamelize = function(string, options) { | ||
67 | + return separateWords(string, options).toLowerCase(); | ||
68 | + }; | ||
69 | + | ||
70 | + // Utilities | ||
71 | + // Taken from Underscore.js | ||
72 | + | ||
73 | + var toString = Object.prototype.toString; | ||
74 | + | ||
75 | + var _isFunction = function(obj) { | ||
76 | + return typeof(obj) === 'function'; | ||
77 | + }; | ||
78 | + var _isObject = function(obj) { | ||
79 | + return obj === Object(obj); | ||
80 | + }; | ||
81 | + var _isArray = function(obj) { | ||
82 | + return toString.call(obj) == '[object Array]'; | ||
83 | + }; | ||
84 | + var _isDate = function(obj) { | ||
85 | + return toString.call(obj) == '[object Date]'; | ||
86 | + }; | ||
87 | + var _isRegExp = function(obj) { | ||
88 | + return toString.call(obj) == '[object RegExp]'; | ||
89 | + }; | ||
90 | + var _isBoolean = function(obj) { | ||
91 | + return toString.call(obj) == '[object Boolean]'; | ||
92 | + }; | ||
93 | + | ||
94 | + // Performant way to determine if obj coerces to a number | ||
95 | + var _isNumerical = function(obj) { | ||
96 | + obj = obj - 0; | ||
97 | + return obj === obj; | ||
98 | + }; | ||
99 | + | ||
100 | + // Sets up function which handles processing keys | ||
101 | + // allowing the convert function to be modified by a callback | ||
102 | + var _processor = function(convert, options) { | ||
103 | + var callback = options && 'process' in options ? options.process : options; | ||
104 | + | ||
105 | + if(typeof(callback) !== 'function') { | ||
106 | + return convert; | ||
107 | + } | ||
108 | + | ||
109 | + return function(string, options) { | ||
110 | + return callback(string, convert, options); | ||
111 | + } | ||
112 | + }; | ||
113 | + | ||
114 | + var humps = { | ||
115 | + camelize: camelize, | ||
116 | + decamelize: decamelize, | ||
117 | + pascalize: pascalize, | ||
118 | + depascalize: decamelize, | ||
119 | + camelizeKeys: function(object, options) { | ||
120 | + return _processKeys(_processor(camelize, options), object); | ||
121 | + }, | ||
122 | + decamelizeKeys: function(object, options) { | ||
123 | + return _processKeys(_processor(decamelize, options), object, options); | ||
124 | + }, | ||
125 | + pascalizeKeys: function(object, options) { | ||
126 | + return _processKeys(_processor(pascalize, options), object); | ||
127 | + }, | ||
128 | + depascalizeKeys: function () { | ||
129 | + return this.decamelizeKeys.apply(this, arguments); | ||
130 | + } | ||
131 | + }; | ||
132 | + | ||
133 | + if (typeof define === 'function' && define.amd) { | ||
134 | + define(humps); | ||
135 | + } else if (typeof module !== 'undefined' && module.exports) { | ||
136 | + module.exports = humps; | ||
137 | + } else { | ||
138 | + global.humps = humps; | ||
139 | + } | ||
140 | + | ||
141 | +})(this); |
1 | 1 | ||
2 | import { GET, POST } from '../../../libs/request'; | 2 | import { GET, POST } from '../../../libs/request'; |
3 | -import { API_HOST} from '../../../libs/config'; | 3 | +import { API_HOST } from '../../../libs/config'; |
4 | +import Humps from './humps.js'; | ||
5 | +import iconfSwitch from '../../../libs/switch'; | ||
6 | +import md5 from '../../../vendors/md5'; | ||
7 | + | ||
8 | +//注:g_sourceApiArry与g_toJavaApiArry的length要相等,且一一对应 | ||
9 | +const g_sourceApiArry = [ '/list', '/content', '/list/recommend', '/code/recent', '/list/mine', '/code/gain', '/code/mine' ]; | ||
10 | +const g_toJavaApiArry = [ 'app.yoluck.activityList', 'app.yoluck.getContent', 'app.yoluck.recommendList', 'app.yoluck.recent', 'app.yoluck.participationList', 'app.yoluck.getCode', 'app.yoluck.userCode' ]; | ||
11 | + | ||
12 | + | ||
13 | +const app = getApp(); | ||
4 | 14 | ||
5 | class Service { | 15 | class Service { |
6 | constructor(url = '') { | 16 | constructor(url = '') { |
@@ -9,24 +19,53 @@ class Service { | @@ -9,24 +19,53 @@ class Service { | ||
9 | 19 | ||
10 | _get(path, data) { | 20 | _get(path, data) { |
11 | let method = path ? this.url + path : API_HOST; | 21 | let method = path ? this.url + path : API_HOST; |
22 | + let pathIndex = g_sourceApiArry.indexOf(path); | ||
23 | + | ||
24 | + let executeReq = () => { | ||
25 | + //适配服务器更换Java接口,开关控制是否切换 | ||
26 | + if (app.globalData.switch_javaApiEnable && pathIndex >= 0 && pathIndex < g_toJavaApiArry.length) { | ||
27 | + method = API_HOST; | ||
28 | + data.method = g_toJavaApiArry[pathIndex]; | ||
29 | + } | ||
12 | 30 | ||
13 | return GET(method, data).then(result => { | 31 | return GET(method, data).then(result => { |
14 | 32 | ||
15 | - if (result.code !== 200) { | 33 | + //适配服务器更换Java接口,开关控制是否切换 |
34 | + if (app.globalData.switch_javaApiEnable && pathIndex >= 0) { | ||
35 | + if (result.data.list) { | ||
36 | + let newList = Humps.decamelizeKeys(Object.values(result.data.list)); | ||
37 | + result.data.list = newList; | ||
16 | } else { | 38 | } else { |
39 | + let newData = Humps.decamelizeKeys(result.data); | ||
40 | + result.data = newData; | ||
41 | + } | ||
17 | } | 42 | } |
18 | return result | 43 | return result |
19 | }); | 44 | }); |
45 | + }; | ||
46 | + | ||
47 | + let needSwitch = g_sourceApiArry.indexOf(path) > -1; | ||
48 | + | ||
49 | + if (!app.globalData.hasSetSwitch && needSwitch) { | ||
50 | + return iconfSwitch().then(data => { | ||
51 | + app.globalData.hasSetSwitch = true; | ||
52 | + if (data['javaapi'] && '0' === data['javaapi']) { | ||
53 | + app.globalData.switch_javaApiEnable = false; | ||
54 | + } | ||
55 | + return executeReq(); | ||
56 | + }, () => { | ||
57 | + app.globalData.hasSetSwitch = true; | ||
58 | + return executeReq(); | ||
59 | + }); | ||
60 | + } else { | ||
61 | + return executeReq(); | ||
62 | + } | ||
20 | } | 63 | } |
21 | 64 | ||
22 | _post(path, data) { | 65 | _post(path, data) { |
23 | let method = path ? this.url + path : API_HOST; | 66 | let method = path ? this.url + path : API_HOST; |
24 | 67 | ||
25 | return POST(method, data).then(result => { | 68 | return POST(method, data).then(result => { |
26 | - | ||
27 | - if (result.code !== 200) { | ||
28 | - } else { | ||
29 | - } | ||
30 | return result; | 69 | return result; |
31 | }); | 70 | }); |
32 | } | 71 | } |
@@ -21,7 +21,7 @@ class ZeroSellService extends Service { | @@ -21,7 +21,7 @@ class ZeroSellService extends Service { | ||
21 | data.channel = 0 | 21 | data.channel = 0 |
22 | return this._get('/list', data).then(result => { | 22 | return this._get('/list', data).then(result => { |
23 | if (result.code === 200) { | 23 | if (result.code === 200) { |
24 | - const products = result.data; | 24 | + const products = result.data.list ? result.data.list : result.data; |
25 | const newProducts = products.map(productTime) | 25 | const newProducts = products.map(productTime) |
26 | 26 | ||
27 | result.data = newProducts; | 27 | result.data = newProducts; |
@@ -35,6 +35,11 @@ class ZeroSellService extends Service { | @@ -35,6 +35,11 @@ class ZeroSellService extends Service { | ||
35 | getDetail(data) { | 35 | getDetail(data) { |
36 | return this._get('/content', data).then(result => { | 36 | return this._get('/content', data).then(result => { |
37 | if (result.code === 200) { | 37 | if (result.code === 200) { |
38 | + Object.keys(result.data).forEach(item => { | ||
39 | + if (item === 'my_code_num') { | ||
40 | + result.data['myCodeNum'] = result.data[item]; | ||
41 | + } | ||
42 | + }) | ||
38 | productTime(result.data) | 43 | productTime(result.data) |
39 | 44 | ||
40 | return result; | 45 | return result; |
utils/icfg-aes.js
0 → 100644
1 | +const CryptoJS = require('../vendors/crypto-js/index'); | ||
2 | +const key = CryptoJS.enc.Utf8.parse('yoho9646YOHO9646'); | ||
3 | +const iv = CryptoJS.enc.Utf8.parse('YOHO9646yoho9646'); | ||
4 | + | ||
5 | +//加密方法 | ||
6 | +function encrypt(word) { | ||
7 | + word = CryptoJS.enc.Utf8.parse(word); | ||
8 | + let encrypted = CryptoJS.AES.encrypt(word, key, {iv}); | ||
9 | + return CryptoJS.enc.Base64.stringify(encrypted.ciphertext); | ||
10 | +} | ||
11 | + | ||
12 | +//解密方法 | ||
13 | +function decrypt(word) { | ||
14 | + let decrypted = CryptoJS.AES.decrypt(word, key, {iv}); | ||
15 | + return CryptoJS.enc.Utf8.stringify(decrypted); | ||
16 | +} | ||
17 | + | ||
18 | +export { | ||
19 | + encrypt, | ||
20 | + decrypt | ||
21 | +}; |
vendors/crypto-js/aes.js
0 → 100644
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 | + // Skip reset of nRounds has been set before and key did not change | ||
95 | + if (this._nRounds && this._keyPriorReset === this._key) { | ||
96 | + return; | ||
97 | + } | ||
98 | + | ||
99 | + // Shortcuts | ||
100 | + var key = this._keyPriorReset = this._key; | ||
101 | + var keyWords = key.words; | ||
102 | + var keySize = key.sigBytes / 4; | ||
103 | + | ||
104 | + // Compute number of rounds | ||
105 | + var nRounds = this._nRounds = keySize + 6; | ||
106 | + | ||
107 | + // Compute number of key schedule rows | ||
108 | + var ksRows = (nRounds + 1) * 4; | ||
109 | + | ||
110 | + // Compute key schedule | ||
111 | + var keySchedule = this._keySchedule = []; | ||
112 | + for (var ksRow = 0; ksRow < ksRows; ksRow++) { | ||
113 | + if (ksRow < keySize) { | ||
114 | + keySchedule[ksRow] = keyWords[ksRow]; | ||
115 | + } else { | ||
116 | + var t = keySchedule[ksRow - 1]; | ||
117 | + | ||
118 | + if (!(ksRow % keySize)) { | ||
119 | + // Rot word | ||
120 | + t = (t << 8) | (t >>> 24); | ||
121 | + | ||
122 | + // Sub word | ||
123 | + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; | ||
124 | + | ||
125 | + // Mix Rcon | ||
126 | + t ^= RCON[(ksRow / keySize) | 0] << 24; | ||
127 | + } else if (keySize > 6 && ksRow % keySize == 4) { | ||
128 | + // Sub word | ||
129 | + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; | ||
130 | + } | ||
131 | + | ||
132 | + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + // Compute inv key schedule | ||
137 | + var invKeySchedule = this._invKeySchedule = []; | ||
138 | + for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { | ||
139 | + var ksRow = ksRows - invKsRow; | ||
140 | + | ||
141 | + if (invKsRow % 4) { | ||
142 | + var t = keySchedule[ksRow]; | ||
143 | + } else { | ||
144 | + var t = keySchedule[ksRow - 4]; | ||
145 | + } | ||
146 | + | ||
147 | + if (invKsRow < 4 || ksRow <= 4) { | ||
148 | + invKeySchedule[invKsRow] = t; | ||
149 | + } else { | ||
150 | + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ | ||
151 | + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; | ||
152 | + } | ||
153 | + } | ||
154 | + }, | ||
155 | + | ||
156 | + encryptBlock: function (M, offset) { | ||
157 | + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); | ||
158 | + }, | ||
159 | + | ||
160 | + decryptBlock: function (M, offset) { | ||
161 | + // Swap 2nd and 4th rows | ||
162 | + var t = M[offset + 1]; | ||
163 | + M[offset + 1] = M[offset + 3]; | ||
164 | + M[offset + 3] = t; | ||
165 | + | ||
166 | + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); | ||
167 | + | ||
168 | + // Inv swap 2nd and 4th rows | ||
169 | + var t = M[offset + 1]; | ||
170 | + M[offset + 1] = M[offset + 3]; | ||
171 | + M[offset + 3] = t; | ||
172 | + }, | ||
173 | + | ||
174 | + _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { | ||
175 | + // Shortcut | ||
176 | + var nRounds = this._nRounds; | ||
177 | + | ||
178 | + // Get input, add round key | ||
179 | + var s0 = M[offset] ^ keySchedule[0]; | ||
180 | + var s1 = M[offset + 1] ^ keySchedule[1]; | ||
181 | + var s2 = M[offset + 2] ^ keySchedule[2]; | ||
182 | + var s3 = M[offset + 3] ^ keySchedule[3]; | ||
183 | + | ||
184 | + // Key schedule row counter | ||
185 | + var ksRow = 4; | ||
186 | + | ||
187 | + // Rounds | ||
188 | + for (var round = 1; round < nRounds; round++) { | ||
189 | + // Shift rows, sub bytes, mix columns, add round key | ||
190 | + 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++]; | ||
191 | + 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++]; | ||
192 | + 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++]; | ||
193 | + 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++]; | ||
194 | + | ||
195 | + // Update state | ||
196 | + s0 = t0; | ||
197 | + s1 = t1; | ||
198 | + s2 = t2; | ||
199 | + s3 = t3; | ||
200 | + } | ||
201 | + | ||
202 | + // Shift rows, sub bytes, add round key | ||
203 | + var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; | ||
204 | + var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; | ||
205 | + var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; | ||
206 | + var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; | ||
207 | + | ||
208 | + // Set output | ||
209 | + M[offset] = t0; | ||
210 | + M[offset + 1] = t1; | ||
211 | + M[offset + 2] = t2; | ||
212 | + M[offset + 3] = t3; | ||
213 | + }, | ||
214 | + | ||
215 | + keySize: 256/32 | ||
216 | + }); | ||
217 | + | ||
218 | + /** | ||
219 | + * Shortcut functions to the cipher's object interface. | ||
220 | + * | ||
221 | + * @example | ||
222 | + * | ||
223 | + * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); | ||
224 | + * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); | ||
225 | + */ | ||
226 | + C.AES = BlockCipher._createHelper(AES); | ||
227 | + }()); | ||
228 | + | ||
229 | + | ||
230 | + return CryptoJS.AES; | ||
231 | + | ||
232 | +})); |
vendors/crypto-js/cipher-core.js
0 → 100644
1 | +;(function (root, factory, undef) { | ||
2 | + if (typeof exports === "object") { | ||
3 | + // CommonJS | ||
4 | + module.exports = exports = factory(require("./core"), require("./evpkdf")); | ||
5 | + } | ||
6 | + else if (typeof define === "function" && define.amd) { | ||
7 | + // AMD | ||
8 | + define(["./core", "./evpkdf"], factory); | ||
9 | + } | ||
10 | + else { | ||
11 | + // Global (browser) | ||
12 | + factory(root.CryptoJS); | ||
13 | + } | ||
14 | +}(this, function (CryptoJS) { | ||
15 | + | ||
16 | + /** | ||
17 | + * Cipher core components. | ||
18 | + */ | ||
19 | + CryptoJS.lib.Cipher || (function (undefined) { | ||
20 | + // Shortcuts | ||
21 | + var C = CryptoJS; | ||
22 | + var C_lib = C.lib; | ||
23 | + var Base = C_lib.Base; | ||
24 | + var WordArray = C_lib.WordArray; | ||
25 | + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; | ||
26 | + var C_enc = C.enc; | ||
27 | + var Utf8 = C_enc.Utf8; | ||
28 | + var Base64 = C_enc.Base64; | ||
29 | + var C_algo = C.algo; | ||
30 | + var EvpKDF = C_algo.EvpKDF; | ||
31 | + | ||
32 | + /** | ||
33 | + * Abstract base cipher template. | ||
34 | + * | ||
35 | + * @property {number} keySize This cipher's key size. Default: 4 (128 bits) | ||
36 | + * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) | ||
37 | + * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. | ||
38 | + * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. | ||
39 | + */ | ||
40 | + var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ | ||
41 | + /** | ||
42 | + * Configuration options. | ||
43 | + * | ||
44 | + * @property {WordArray} iv The IV to use for this operation. | ||
45 | + */ | ||
46 | + cfg: Base.extend(), | ||
47 | + | ||
48 | + /** | ||
49 | + * Creates this cipher in encryption mode. | ||
50 | + * | ||
51 | + * @param {WordArray} key The key. | ||
52 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
53 | + * | ||
54 | + * @return {Cipher} A cipher instance. | ||
55 | + * | ||
56 | + * @static | ||
57 | + * | ||
58 | + * @example | ||
59 | + * | ||
60 | + * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); | ||
61 | + */ | ||
62 | + createEncryptor: function (key, cfg) { | ||
63 | + return this.create(this._ENC_XFORM_MODE, key, cfg); | ||
64 | + }, | ||
65 | + | ||
66 | + /** | ||
67 | + * Creates this cipher in decryption mode. | ||
68 | + * | ||
69 | + * @param {WordArray} key The key. | ||
70 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
71 | + * | ||
72 | + * @return {Cipher} A cipher instance. | ||
73 | + * | ||
74 | + * @static | ||
75 | + * | ||
76 | + * @example | ||
77 | + * | ||
78 | + * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); | ||
79 | + */ | ||
80 | + createDecryptor: function (key, cfg) { | ||
81 | + return this.create(this._DEC_XFORM_MODE, key, cfg); | ||
82 | + }, | ||
83 | + | ||
84 | + /** | ||
85 | + * Initializes a newly created cipher. | ||
86 | + * | ||
87 | + * @param {number} xformMode Either the encryption or decryption transormation mode constant. | ||
88 | + * @param {WordArray} key The key. | ||
89 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
90 | + * | ||
91 | + * @example | ||
92 | + * | ||
93 | + * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); | ||
94 | + */ | ||
95 | + init: function (xformMode, key, cfg) { | ||
96 | + // Apply config defaults | ||
97 | + this.cfg = this.cfg.extend(cfg); | ||
98 | + | ||
99 | + // Store transform mode and key | ||
100 | + this._xformMode = xformMode; | ||
101 | + this._key = key; | ||
102 | + | ||
103 | + // Set initial values | ||
104 | + this.reset(); | ||
105 | + }, | ||
106 | + | ||
107 | + /** | ||
108 | + * Resets this cipher to its initial state. | ||
109 | + * | ||
110 | + * @example | ||
111 | + * | ||
112 | + * cipher.reset(); | ||
113 | + */ | ||
114 | + reset: function () { | ||
115 | + // Reset data buffer | ||
116 | + BufferedBlockAlgorithm.reset.call(this); | ||
117 | + | ||
118 | + // Perform concrete-cipher logic | ||
119 | + this._doReset(); | ||
120 | + }, | ||
121 | + | ||
122 | + /** | ||
123 | + * Adds data to be encrypted or decrypted. | ||
124 | + * | ||
125 | + * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. | ||
126 | + * | ||
127 | + * @return {WordArray} The data after processing. | ||
128 | + * | ||
129 | + * @example | ||
130 | + * | ||
131 | + * var encrypted = cipher.process('data'); | ||
132 | + * var encrypted = cipher.process(wordArray); | ||
133 | + */ | ||
134 | + process: function (dataUpdate) { | ||
135 | + // Append | ||
136 | + this._append(dataUpdate); | ||
137 | + | ||
138 | + // Process available blocks | ||
139 | + return this._process(); | ||
140 | + }, | ||
141 | + | ||
142 | + /** | ||
143 | + * Finalizes the encryption or decryption process. | ||
144 | + * Note that the finalize operation is effectively a destructive, read-once operation. | ||
145 | + * | ||
146 | + * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. | ||
147 | + * | ||
148 | + * @return {WordArray} The data after final processing. | ||
149 | + * | ||
150 | + * @example | ||
151 | + * | ||
152 | + * var encrypted = cipher.finalize(); | ||
153 | + * var encrypted = cipher.finalize('data'); | ||
154 | + * var encrypted = cipher.finalize(wordArray); | ||
155 | + */ | ||
156 | + finalize: function (dataUpdate) { | ||
157 | + // Final data update | ||
158 | + if (dataUpdate) { | ||
159 | + this._append(dataUpdate); | ||
160 | + } | ||
161 | + | ||
162 | + // Perform concrete-cipher logic | ||
163 | + var finalProcessedData = this._doFinalize(); | ||
164 | + | ||
165 | + return finalProcessedData; | ||
166 | + }, | ||
167 | + | ||
168 | + keySize: 128/32, | ||
169 | + | ||
170 | + ivSize: 128/32, | ||
171 | + | ||
172 | + _ENC_XFORM_MODE: 1, | ||
173 | + | ||
174 | + _DEC_XFORM_MODE: 2, | ||
175 | + | ||
176 | + /** | ||
177 | + * Creates shortcut functions to a cipher's object interface. | ||
178 | + * | ||
179 | + * @param {Cipher} cipher The cipher to create a helper for. | ||
180 | + * | ||
181 | + * @return {Object} An object with encrypt and decrypt shortcut functions. | ||
182 | + * | ||
183 | + * @static | ||
184 | + * | ||
185 | + * @example | ||
186 | + * | ||
187 | + * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); | ||
188 | + */ | ||
189 | + _createHelper: (function () { | ||
190 | + function selectCipherStrategy(key) { | ||
191 | + if (typeof key == 'string') { | ||
192 | + return PasswordBasedCipher; | ||
193 | + } else { | ||
194 | + return SerializableCipher; | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + return function (cipher) { | ||
199 | + return { | ||
200 | + encrypt: function (message, key, cfg) { | ||
201 | + return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); | ||
202 | + }, | ||
203 | + | ||
204 | + decrypt: function (ciphertext, key, cfg) { | ||
205 | + return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); | ||
206 | + } | ||
207 | + }; | ||
208 | + }; | ||
209 | + }()) | ||
210 | + }); | ||
211 | + | ||
212 | + /** | ||
213 | + * Abstract base stream cipher template. | ||
214 | + * | ||
215 | + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) | ||
216 | + */ | ||
217 | + var StreamCipher = C_lib.StreamCipher = Cipher.extend({ | ||
218 | + _doFinalize: function () { | ||
219 | + // Process partial blocks | ||
220 | + var finalProcessedBlocks = this._process(!!'flush'); | ||
221 | + | ||
222 | + return finalProcessedBlocks; | ||
223 | + }, | ||
224 | + | ||
225 | + blockSize: 1 | ||
226 | + }); | ||
227 | + | ||
228 | + /** | ||
229 | + * Mode namespace. | ||
230 | + */ | ||
231 | + var C_mode = C.mode = {}; | ||
232 | + | ||
233 | + /** | ||
234 | + * Abstract base block cipher mode template. | ||
235 | + */ | ||
236 | + var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ | ||
237 | + /** | ||
238 | + * Creates this mode for encryption. | ||
239 | + * | ||
240 | + * @param {Cipher} cipher A block cipher instance. | ||
241 | + * @param {Array} iv The IV words. | ||
242 | + * | ||
243 | + * @static | ||
244 | + * | ||
245 | + * @example | ||
246 | + * | ||
247 | + * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); | ||
248 | + */ | ||
249 | + createEncryptor: function (cipher, iv) { | ||
250 | + return this.Encryptor.create(cipher, iv); | ||
251 | + }, | ||
252 | + | ||
253 | + /** | ||
254 | + * Creates this mode for decryption. | ||
255 | + * | ||
256 | + * @param {Cipher} cipher A block cipher instance. | ||
257 | + * @param {Array} iv The IV words. | ||
258 | + * | ||
259 | + * @static | ||
260 | + * | ||
261 | + * @example | ||
262 | + * | ||
263 | + * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); | ||
264 | + */ | ||
265 | + createDecryptor: function (cipher, iv) { | ||
266 | + return this.Decryptor.create(cipher, iv); | ||
267 | + }, | ||
268 | + | ||
269 | + /** | ||
270 | + * Initializes a newly created mode. | ||
271 | + * | ||
272 | + * @param {Cipher} cipher A block cipher instance. | ||
273 | + * @param {Array} iv The IV words. | ||
274 | + * | ||
275 | + * @example | ||
276 | + * | ||
277 | + * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); | ||
278 | + */ | ||
279 | + init: function (cipher, iv) { | ||
280 | + this._cipher = cipher; | ||
281 | + this._iv = iv; | ||
282 | + } | ||
283 | + }); | ||
284 | + | ||
285 | + /** | ||
286 | + * Cipher Block Chaining mode. | ||
287 | + */ | ||
288 | + var CBC = C_mode.CBC = (function () { | ||
289 | + /** | ||
290 | + * Abstract base CBC mode. | ||
291 | + */ | ||
292 | + var CBC = BlockCipherMode.extend(); | ||
293 | + | ||
294 | + /** | ||
295 | + * CBC encryptor. | ||
296 | + */ | ||
297 | + CBC.Encryptor = CBC.extend({ | ||
298 | + /** | ||
299 | + * Processes the data block at offset. | ||
300 | + * | ||
301 | + * @param {Array} words The data words to operate on. | ||
302 | + * @param {number} offset The offset where the block starts. | ||
303 | + * | ||
304 | + * @example | ||
305 | + * | ||
306 | + * mode.processBlock(data.words, offset); | ||
307 | + */ | ||
308 | + processBlock: function (words, offset) { | ||
309 | + // Shortcuts | ||
310 | + var cipher = this._cipher; | ||
311 | + var blockSize = cipher.blockSize; | ||
312 | + | ||
313 | + // XOR and encrypt | ||
314 | + xorBlock.call(this, words, offset, blockSize); | ||
315 | + cipher.encryptBlock(words, offset); | ||
316 | + | ||
317 | + // Remember this block to use with next block | ||
318 | + this._prevBlock = words.slice(offset, offset + blockSize); | ||
319 | + } | ||
320 | + }); | ||
321 | + | ||
322 | + /** | ||
323 | + * CBC decryptor. | ||
324 | + */ | ||
325 | + CBC.Decryptor = CBC.extend({ | ||
326 | + /** | ||
327 | + * Processes the data block at offset. | ||
328 | + * | ||
329 | + * @param {Array} words The data words to operate on. | ||
330 | + * @param {number} offset The offset where the block starts. | ||
331 | + * | ||
332 | + * @example | ||
333 | + * | ||
334 | + * mode.processBlock(data.words, offset); | ||
335 | + */ | ||
336 | + processBlock: function (words, offset) { | ||
337 | + // Shortcuts | ||
338 | + var cipher = this._cipher; | ||
339 | + var blockSize = cipher.blockSize; | ||
340 | + | ||
341 | + // Remember this block to use with next block | ||
342 | + var thisBlock = words.slice(offset, offset + blockSize); | ||
343 | + | ||
344 | + // Decrypt and XOR | ||
345 | + cipher.decryptBlock(words, offset); | ||
346 | + xorBlock.call(this, words, offset, blockSize); | ||
347 | + | ||
348 | + // This block becomes the previous block | ||
349 | + this._prevBlock = thisBlock; | ||
350 | + } | ||
351 | + }); | ||
352 | + | ||
353 | + function xorBlock(words, offset, blockSize) { | ||
354 | + // Shortcut | ||
355 | + var iv = this._iv; | ||
356 | + | ||
357 | + // Choose mixing block | ||
358 | + if (iv) { | ||
359 | + var block = iv; | ||
360 | + | ||
361 | + // Remove IV for subsequent blocks | ||
362 | + this._iv = undefined; | ||
363 | + } else { | ||
364 | + var block = this._prevBlock; | ||
365 | + } | ||
366 | + | ||
367 | + // XOR blocks | ||
368 | + for (var i = 0; i < blockSize; i++) { | ||
369 | + words[offset + i] ^= block[i]; | ||
370 | + } | ||
371 | + } | ||
372 | + | ||
373 | + return CBC; | ||
374 | + }()); | ||
375 | + | ||
376 | + /** | ||
377 | + * Padding namespace. | ||
378 | + */ | ||
379 | + var C_pad = C.pad = {}; | ||
380 | + | ||
381 | + /** | ||
382 | + * PKCS #5/7 padding strategy. | ||
383 | + */ | ||
384 | + var Pkcs7 = C_pad.Pkcs7 = { | ||
385 | + /** | ||
386 | + * Pads data using the algorithm defined in PKCS #5/7. | ||
387 | + * | ||
388 | + * @param {WordArray} data The data to pad. | ||
389 | + * @param {number} blockSize The multiple that the data should be padded to. | ||
390 | + * | ||
391 | + * @static | ||
392 | + * | ||
393 | + * @example | ||
394 | + * | ||
395 | + * CryptoJS.pad.Pkcs7.pad(wordArray, 4); | ||
396 | + */ | ||
397 | + pad: function (data, blockSize) { | ||
398 | + // Shortcut | ||
399 | + var blockSizeBytes = blockSize * 4; | ||
400 | + | ||
401 | + // Count padding bytes | ||
402 | + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; | ||
403 | + | ||
404 | + // Create padding word | ||
405 | + var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; | ||
406 | + | ||
407 | + // Create padding | ||
408 | + var paddingWords = []; | ||
409 | + for (var i = 0; i < nPaddingBytes; i += 4) { | ||
410 | + paddingWords.push(paddingWord); | ||
411 | + } | ||
412 | + var padding = WordArray.create(paddingWords, nPaddingBytes); | ||
413 | + | ||
414 | + // Add padding | ||
415 | + data.concat(padding); | ||
416 | + }, | ||
417 | + | ||
418 | + /** | ||
419 | + * Unpads data that had been padded using the algorithm defined in PKCS #5/7. | ||
420 | + * | ||
421 | + * @param {WordArray} data The data to unpad. | ||
422 | + * | ||
423 | + * @static | ||
424 | + * | ||
425 | + * @example | ||
426 | + * | ||
427 | + * CryptoJS.pad.Pkcs7.unpad(wordArray); | ||
428 | + */ | ||
429 | + unpad: function (data) { | ||
430 | + // Get number of padding bytes from last byte | ||
431 | + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; | ||
432 | + | ||
433 | + // Remove padding | ||
434 | + data.sigBytes -= nPaddingBytes; | ||
435 | + } | ||
436 | + }; | ||
437 | + | ||
438 | + /** | ||
439 | + * Abstract base block cipher template. | ||
440 | + * | ||
441 | + * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) | ||
442 | + */ | ||
443 | + var BlockCipher = C_lib.BlockCipher = Cipher.extend({ | ||
444 | + /** | ||
445 | + * Configuration options. | ||
446 | + * | ||
447 | + * @property {Mode} mode The block mode to use. Default: CBC | ||
448 | + * @property {Padding} padding The padding strategy to use. Default: Pkcs7 | ||
449 | + */ | ||
450 | + cfg: Cipher.cfg.extend({ | ||
451 | + mode: CBC, | ||
452 | + padding: Pkcs7 | ||
453 | + }), | ||
454 | + | ||
455 | + reset: function () { | ||
456 | + // Reset cipher | ||
457 | + Cipher.reset.call(this); | ||
458 | + | ||
459 | + // Shortcuts | ||
460 | + var cfg = this.cfg; | ||
461 | + var iv = cfg.iv; | ||
462 | + var mode = cfg.mode; | ||
463 | + | ||
464 | + // Reset block mode | ||
465 | + if (this._xformMode == this._ENC_XFORM_MODE) { | ||
466 | + var modeCreator = mode.createEncryptor; | ||
467 | + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { | ||
468 | + var modeCreator = mode.createDecryptor; | ||
469 | + // Keep at least one block in the buffer for unpadding | ||
470 | + this._minBufferSize = 1; | ||
471 | + } | ||
472 | + | ||
473 | + if (this._mode && this._mode.__creator == modeCreator) { | ||
474 | + this._mode.init(this, iv && iv.words); | ||
475 | + } else { | ||
476 | + this._mode = modeCreator.call(mode, this, iv && iv.words); | ||
477 | + this._mode.__creator = modeCreator; | ||
478 | + } | ||
479 | + }, | ||
480 | + | ||
481 | + _doProcessBlock: function (words, offset) { | ||
482 | + this._mode.processBlock(words, offset); | ||
483 | + }, | ||
484 | + | ||
485 | + _doFinalize: function () { | ||
486 | + // Shortcut | ||
487 | + var padding = this.cfg.padding; | ||
488 | + | ||
489 | + // Finalize | ||
490 | + if (this._xformMode == this._ENC_XFORM_MODE) { | ||
491 | + // Pad data | ||
492 | + padding.pad(this._data, this.blockSize); | ||
493 | + | ||
494 | + // Process final blocks | ||
495 | + var finalProcessedBlocks = this._process(!!'flush'); | ||
496 | + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { | ||
497 | + // Process final blocks | ||
498 | + var finalProcessedBlocks = this._process(!!'flush'); | ||
499 | + | ||
500 | + // Unpad data | ||
501 | + padding.unpad(finalProcessedBlocks); | ||
502 | + } | ||
503 | + | ||
504 | + return finalProcessedBlocks; | ||
505 | + }, | ||
506 | + | ||
507 | + blockSize: 128/32 | ||
508 | + }); | ||
509 | + | ||
510 | + /** | ||
511 | + * A collection of cipher parameters. | ||
512 | + * | ||
513 | + * @property {WordArray} ciphertext The raw ciphertext. | ||
514 | + * @property {WordArray} key The key to this ciphertext. | ||
515 | + * @property {WordArray} iv The IV used in the ciphering operation. | ||
516 | + * @property {WordArray} salt The salt used with a key derivation function. | ||
517 | + * @property {Cipher} algorithm The cipher algorithm. | ||
518 | + * @property {Mode} mode The block mode used in the ciphering operation. | ||
519 | + * @property {Padding} padding The padding scheme used in the ciphering operation. | ||
520 | + * @property {number} blockSize The block size of the cipher. | ||
521 | + * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. | ||
522 | + */ | ||
523 | + var CipherParams = C_lib.CipherParams = Base.extend({ | ||
524 | + /** | ||
525 | + * Initializes a newly created cipher params object. | ||
526 | + * | ||
527 | + * @param {Object} cipherParams An object with any of the possible cipher parameters. | ||
528 | + * | ||
529 | + * @example | ||
530 | + * | ||
531 | + * var cipherParams = CryptoJS.lib.CipherParams.create({ | ||
532 | + * ciphertext: ciphertextWordArray, | ||
533 | + * key: keyWordArray, | ||
534 | + * iv: ivWordArray, | ||
535 | + * salt: saltWordArray, | ||
536 | + * algorithm: CryptoJS.algo.AES, | ||
537 | + * mode: CryptoJS.mode.CBC, | ||
538 | + * padding: CryptoJS.pad.PKCS7, | ||
539 | + * blockSize: 4, | ||
540 | + * formatter: CryptoJS.format.OpenSSL | ||
541 | + * }); | ||
542 | + */ | ||
543 | + init: function (cipherParams) { | ||
544 | + this.mixIn(cipherParams); | ||
545 | + }, | ||
546 | + | ||
547 | + /** | ||
548 | + * Converts this cipher params object to a string. | ||
549 | + * | ||
550 | + * @param {Format} formatter (Optional) The formatting strategy to use. | ||
551 | + * | ||
552 | + * @return {string} The stringified cipher params. | ||
553 | + * | ||
554 | + * @throws Error If neither the formatter nor the default formatter is set. | ||
555 | + * | ||
556 | + * @example | ||
557 | + * | ||
558 | + * var string = cipherParams + ''; | ||
559 | + * var string = cipherParams.toString(); | ||
560 | + * var string = cipherParams.toString(CryptoJS.format.OpenSSL); | ||
561 | + */ | ||
562 | + toString: function (formatter) { | ||
563 | + return (formatter || this.formatter).stringify(this); | ||
564 | + } | ||
565 | + }); | ||
566 | + | ||
567 | + /** | ||
568 | + * Format namespace. | ||
569 | + */ | ||
570 | + var C_format = C.format = {}; | ||
571 | + | ||
572 | + /** | ||
573 | + * OpenSSL formatting strategy. | ||
574 | + */ | ||
575 | + var OpenSSLFormatter = C_format.OpenSSL = { | ||
576 | + /** | ||
577 | + * Converts a cipher params object to an OpenSSL-compatible string. | ||
578 | + * | ||
579 | + * @param {CipherParams} cipherParams The cipher params object. | ||
580 | + * | ||
581 | + * @return {string} The OpenSSL-compatible string. | ||
582 | + * | ||
583 | + * @static | ||
584 | + * | ||
585 | + * @example | ||
586 | + * | ||
587 | + * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); | ||
588 | + */ | ||
589 | + stringify: function (cipherParams) { | ||
590 | + // Shortcuts | ||
591 | + var ciphertext = cipherParams.ciphertext; | ||
592 | + var salt = cipherParams.salt; | ||
593 | + | ||
594 | + // Format | ||
595 | + if (salt) { | ||
596 | + var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); | ||
597 | + } else { | ||
598 | + var wordArray = ciphertext; | ||
599 | + } | ||
600 | + | ||
601 | + return wordArray.toString(Base64); | ||
602 | + }, | ||
603 | + | ||
604 | + /** | ||
605 | + * Converts an OpenSSL-compatible string to a cipher params object. | ||
606 | + * | ||
607 | + * @param {string} openSSLStr The OpenSSL-compatible string. | ||
608 | + * | ||
609 | + * @return {CipherParams} The cipher params object. | ||
610 | + * | ||
611 | + * @static | ||
612 | + * | ||
613 | + * @example | ||
614 | + * | ||
615 | + * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); | ||
616 | + */ | ||
617 | + parse: function (openSSLStr) { | ||
618 | + // Parse base64 | ||
619 | + var ciphertext = Base64.parse(openSSLStr); | ||
620 | + | ||
621 | + // Shortcut | ||
622 | + var ciphertextWords = ciphertext.words; | ||
623 | + | ||
624 | + // Test for salt | ||
625 | + if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { | ||
626 | + // Extract salt | ||
627 | + var salt = WordArray.create(ciphertextWords.slice(2, 4)); | ||
628 | + | ||
629 | + // Remove salt from ciphertext | ||
630 | + ciphertextWords.splice(0, 4); | ||
631 | + ciphertext.sigBytes -= 16; | ||
632 | + } | ||
633 | + | ||
634 | + return CipherParams.create({ ciphertext: ciphertext, salt: salt }); | ||
635 | + } | ||
636 | + }; | ||
637 | + | ||
638 | + /** | ||
639 | + * A cipher wrapper that returns ciphertext as a serializable cipher params object. | ||
640 | + */ | ||
641 | + var SerializableCipher = C_lib.SerializableCipher = Base.extend({ | ||
642 | + /** | ||
643 | + * Configuration options. | ||
644 | + * | ||
645 | + * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL | ||
646 | + */ | ||
647 | + cfg: Base.extend({ | ||
648 | + format: OpenSSLFormatter | ||
649 | + }), | ||
650 | + | ||
651 | + /** | ||
652 | + * Encrypts a message. | ||
653 | + * | ||
654 | + * @param {Cipher} cipher The cipher algorithm to use. | ||
655 | + * @param {WordArray|string} message The message to encrypt. | ||
656 | + * @param {WordArray} key The key. | ||
657 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
658 | + * | ||
659 | + * @return {CipherParams} A cipher params object. | ||
660 | + * | ||
661 | + * @static | ||
662 | + * | ||
663 | + * @example | ||
664 | + * | ||
665 | + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); | ||
666 | + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); | ||
667 | + * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); | ||
668 | + */ | ||
669 | + encrypt: function (cipher, message, key, cfg) { | ||
670 | + // Apply config defaults | ||
671 | + cfg = this.cfg.extend(cfg); | ||
672 | + | ||
673 | + // Encrypt | ||
674 | + var encryptor = cipher.createEncryptor(key, cfg); | ||
675 | + var ciphertext = encryptor.finalize(message); | ||
676 | + | ||
677 | + // Shortcut | ||
678 | + var cipherCfg = encryptor.cfg; | ||
679 | + | ||
680 | + // Create and return serializable cipher params | ||
681 | + return CipherParams.create({ | ||
682 | + ciphertext: ciphertext, | ||
683 | + key: key, | ||
684 | + iv: cipherCfg.iv, | ||
685 | + algorithm: cipher, | ||
686 | + mode: cipherCfg.mode, | ||
687 | + padding: cipherCfg.padding, | ||
688 | + blockSize: cipher.blockSize, | ||
689 | + formatter: cfg.format | ||
690 | + }); | ||
691 | + }, | ||
692 | + | ||
693 | + /** | ||
694 | + * Decrypts serialized ciphertext. | ||
695 | + * | ||
696 | + * @param {Cipher} cipher The cipher algorithm to use. | ||
697 | + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. | ||
698 | + * @param {WordArray} key The key. | ||
699 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
700 | + * | ||
701 | + * @return {WordArray} The plaintext. | ||
702 | + * | ||
703 | + * @static | ||
704 | + * | ||
705 | + * @example | ||
706 | + * | ||
707 | + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); | ||
708 | + * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); | ||
709 | + */ | ||
710 | + decrypt: function (cipher, ciphertext, key, cfg) { | ||
711 | + // Apply config defaults | ||
712 | + cfg = this.cfg.extend(cfg); | ||
713 | + | ||
714 | + // Convert string to CipherParams | ||
715 | + ciphertext = this._parse(ciphertext, cfg.format); | ||
716 | + | ||
717 | + // Decrypt | ||
718 | + var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); | ||
719 | + | ||
720 | + return plaintext; | ||
721 | + }, | ||
722 | + | ||
723 | + /** | ||
724 | + * Converts serialized ciphertext to CipherParams, | ||
725 | + * else assumed CipherParams already and returns ciphertext unchanged. | ||
726 | + * | ||
727 | + * @param {CipherParams|string} ciphertext The ciphertext. | ||
728 | + * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. | ||
729 | + * | ||
730 | + * @return {CipherParams} The unserialized ciphertext. | ||
731 | + * | ||
732 | + * @static | ||
733 | + * | ||
734 | + * @example | ||
735 | + * | ||
736 | + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); | ||
737 | + */ | ||
738 | + _parse: function (ciphertext, format) { | ||
739 | + if (typeof ciphertext == 'string') { | ||
740 | + return format.parse(ciphertext, this); | ||
741 | + } else { | ||
742 | + return ciphertext; | ||
743 | + } | ||
744 | + } | ||
745 | + }); | ||
746 | + | ||
747 | + /** | ||
748 | + * Key derivation function namespace. | ||
749 | + */ | ||
750 | + var C_kdf = C.kdf = {}; | ||
751 | + | ||
752 | + /** | ||
753 | + * OpenSSL key derivation function. | ||
754 | + */ | ||
755 | + var OpenSSLKdf = C_kdf.OpenSSL = { | ||
756 | + /** | ||
757 | + * Derives a key and IV from a password. | ||
758 | + * | ||
759 | + * @param {string} password The password to derive from. | ||
760 | + * @param {number} keySize The size in words of the key to generate. | ||
761 | + * @param {number} ivSize The size in words of the IV to generate. | ||
762 | + * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. | ||
763 | + * | ||
764 | + * @return {CipherParams} A cipher params object with the key, IV, and salt. | ||
765 | + * | ||
766 | + * @static | ||
767 | + * | ||
768 | + * @example | ||
769 | + * | ||
770 | + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); | ||
771 | + * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); | ||
772 | + */ | ||
773 | + execute: function (password, keySize, ivSize, salt) { | ||
774 | + // Generate random salt | ||
775 | + if (!salt) { | ||
776 | + salt = WordArray.random(64/8); | ||
777 | + } | ||
778 | + | ||
779 | + // Derive key and IV | ||
780 | + var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); | ||
781 | + | ||
782 | + // Separate key and IV | ||
783 | + var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); | ||
784 | + key.sigBytes = keySize * 4; | ||
785 | + | ||
786 | + // Return params | ||
787 | + return CipherParams.create({ key: key, iv: iv, salt: salt }); | ||
788 | + } | ||
789 | + }; | ||
790 | + | ||
791 | + /** | ||
792 | + * A serializable cipher wrapper that derives the key from a password, | ||
793 | + * and returns ciphertext as a serializable cipher params object. | ||
794 | + */ | ||
795 | + var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ | ||
796 | + /** | ||
797 | + * Configuration options. | ||
798 | + * | ||
799 | + * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL | ||
800 | + */ | ||
801 | + cfg: SerializableCipher.cfg.extend({ | ||
802 | + kdf: OpenSSLKdf | ||
803 | + }), | ||
804 | + | ||
805 | + /** | ||
806 | + * Encrypts a message using a password. | ||
807 | + * | ||
808 | + * @param {Cipher} cipher The cipher algorithm to use. | ||
809 | + * @param {WordArray|string} message The message to encrypt. | ||
810 | + * @param {string} password The password. | ||
811 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
812 | + * | ||
813 | + * @return {CipherParams} A cipher params object. | ||
814 | + * | ||
815 | + * @static | ||
816 | + * | ||
817 | + * @example | ||
818 | + * | ||
819 | + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); | ||
820 | + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); | ||
821 | + */ | ||
822 | + encrypt: function (cipher, message, password, cfg) { | ||
823 | + // Apply config defaults | ||
824 | + cfg = this.cfg.extend(cfg); | ||
825 | + | ||
826 | + // Derive key and other params | ||
827 | + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); | ||
828 | + | ||
829 | + // Add IV to config | ||
830 | + cfg.iv = derivedParams.iv; | ||
831 | + | ||
832 | + // Encrypt | ||
833 | + var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); | ||
834 | + | ||
835 | + // Mix in derived params | ||
836 | + ciphertext.mixIn(derivedParams); | ||
837 | + | ||
838 | + return ciphertext; | ||
839 | + }, | ||
840 | + | ||
841 | + /** | ||
842 | + * Decrypts serialized ciphertext using a password. | ||
843 | + * | ||
844 | + * @param {Cipher} cipher The cipher algorithm to use. | ||
845 | + * @param {CipherParams|string} ciphertext The ciphertext to decrypt. | ||
846 | + * @param {string} password The password. | ||
847 | + * @param {Object} cfg (Optional) The configuration options to use for this operation. | ||
848 | + * | ||
849 | + * @return {WordArray} The plaintext. | ||
850 | + * | ||
851 | + * @static | ||
852 | + * | ||
853 | + * @example | ||
854 | + * | ||
855 | + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); | ||
856 | + * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); | ||
857 | + */ | ||
858 | + decrypt: function (cipher, ciphertext, password, cfg) { | ||
859 | + // Apply config defaults | ||
860 | + cfg = this.cfg.extend(cfg); | ||
861 | + | ||
862 | + // Convert string to CipherParams | ||
863 | + ciphertext = this._parse(ciphertext, cfg.format); | ||
864 | + | ||
865 | + // Derive key and other params | ||
866 | + var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); | ||
867 | + | ||
868 | + // Add IV to config | ||
869 | + cfg.iv = derivedParams.iv; | ||
870 | + | ||
871 | + // Decrypt | ||
872 | + var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); | ||
873 | + | ||
874 | + return plaintext; | ||
875 | + } | ||
876 | + }); | ||
877 | + }()); | ||
878 | + | ||
879 | + | ||
880 | +})); |
vendors/crypto-js/core.js
0 → 100644
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 | + /** | ||
17 | + * CryptoJS core components. | ||
18 | + */ | ||
19 | + var CryptoJS = CryptoJS || (function (Math, undefined) { | ||
20 | + /* | ||
21 | + * Local polyfil of Object.create | ||
22 | + */ | ||
23 | + var create = Object.create || (function () { | ||
24 | + function F() {}; | ||
25 | + | ||
26 | + return function (obj) { | ||
27 | + var subtype; | ||
28 | + | ||
29 | + F.prototype = obj; | ||
30 | + | ||
31 | + subtype = new F(); | ||
32 | + | ||
33 | + F.prototype = null; | ||
34 | + | ||
35 | + return subtype; | ||
36 | + }; | ||
37 | + }()) | ||
38 | + | ||
39 | + /** | ||
40 | + * CryptoJS namespace. | ||
41 | + */ | ||
42 | + var C = {}; | ||
43 | + | ||
44 | + /** | ||
45 | + * Library namespace. | ||
46 | + */ | ||
47 | + var C_lib = C.lib = {}; | ||
48 | + | ||
49 | + /** | ||
50 | + * Base object for prototypal inheritance. | ||
51 | + */ | ||
52 | + var Base = C_lib.Base = (function () { | ||
53 | + | ||
54 | + | ||
55 | + return { | ||
56 | + /** | ||
57 | + * Creates a new object that inherits from this object. | ||
58 | + * | ||
59 | + * @param {Object} overrides Properties to copy into the new object. | ||
60 | + * | ||
61 | + * @return {Object} The new object. | ||
62 | + * | ||
63 | + * @static | ||
64 | + * | ||
65 | + * @example | ||
66 | + * | ||
67 | + * var MyType = CryptoJS.lib.Base.extend({ | ||
68 | + * field: 'value', | ||
69 | + * | ||
70 | + * method: function () { | ||
71 | + * } | ||
72 | + * }); | ||
73 | + */ | ||
74 | + extend: function (overrides) { | ||
75 | + // Spawn | ||
76 | + var subtype = create(this); | ||
77 | + | ||
78 | + // Augment | ||
79 | + if (overrides) { | ||
80 | + subtype.mixIn(overrides); | ||
81 | + } | ||
82 | + | ||
83 | + // Create default initializer | ||
84 | + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
85 | + subtype.init = function () { | ||
86 | + subtype.$super.init.apply(this, arguments); | ||
87 | + }; | ||
88 | + } | ||
89 | + | ||
90 | + // Initializer's prototype is the subtype object | ||
91 | + subtype.init.prototype = subtype; | ||
92 | + | ||
93 | + // Reference supertype | ||
94 | + subtype.$super = this; | ||
95 | + | ||
96 | + return subtype; | ||
97 | + }, | ||
98 | + | ||
99 | + /** | ||
100 | + * Extends this object and runs the init method. | ||
101 | + * Arguments to create() will be passed to init(). | ||
102 | + * | ||
103 | + * @return {Object} The new object. | ||
104 | + * | ||
105 | + * @static | ||
106 | + * | ||
107 | + * @example | ||
108 | + * | ||
109 | + * var instance = MyType.create(); | ||
110 | + */ | ||
111 | + create: function () { | ||
112 | + var instance = this.extend(); | ||
113 | + instance.init.apply(instance, arguments); | ||
114 | + | ||
115 | + return instance; | ||
116 | + }, | ||
117 | + | ||
118 | + /** | ||
119 | + * Initializes a newly created object. | ||
120 | + * Override this method to add some logic when your objects are created. | ||
121 | + * | ||
122 | + * @example | ||
123 | + * | ||
124 | + * var MyType = CryptoJS.lib.Base.extend({ | ||
125 | + * init: function () { | ||
126 | + * // ... | ||
127 | + * } | ||
128 | + * }); | ||
129 | + */ | ||
130 | + init: function () { | ||
131 | + }, | ||
132 | + | ||
133 | + /** | ||
134 | + * Copies properties into this object. | ||
135 | + * | ||
136 | + * @param {Object} properties The properties to mix in. | ||
137 | + * | ||
138 | + * @example | ||
139 | + * | ||
140 | + * MyType.mixIn({ | ||
141 | + * field: 'value' | ||
142 | + * }); | ||
143 | + */ | ||
144 | + mixIn: function (properties) { | ||
145 | + for (var propertyName in properties) { | ||
146 | + if (properties.hasOwnProperty(propertyName)) { | ||
147 | + this[propertyName] = properties[propertyName]; | ||
148 | + } | ||
149 | + } | ||
150 | + | ||
151 | + // IE won't copy toString using the loop above | ||
152 | + if (properties.hasOwnProperty('toString')) { | ||
153 | + this.toString = properties.toString; | ||
154 | + } | ||
155 | + }, | ||
156 | + | ||
157 | + /** | ||
158 | + * Creates a copy of this object. | ||
159 | + * | ||
160 | + * @return {Object} The clone. | ||
161 | + * | ||
162 | + * @example | ||
163 | + * | ||
164 | + * var clone = instance.clone(); | ||
165 | + */ | ||
166 | + clone: function () { | ||
167 | + return this.init.prototype.extend(this); | ||
168 | + } | ||
169 | + }; | ||
170 | + }()); | ||
171 | + | ||
172 | + /** | ||
173 | + * An array of 32-bit words. | ||
174 | + * | ||
175 | + * @property {Array} words The array of 32-bit words. | ||
176 | + * @property {number} sigBytes The number of significant bytes in this word array. | ||
177 | + */ | ||
178 | + var WordArray = C_lib.WordArray = Base.extend({ | ||
179 | + /** | ||
180 | + * Initializes a newly created word array. | ||
181 | + * | ||
182 | + * @param {Array} words (Optional) An array of 32-bit words. | ||
183 | + * @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
184 | + * | ||
185 | + * @example | ||
186 | + * | ||
187 | + * var wordArray = CryptoJS.lib.WordArray.create(); | ||
188 | + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
189 | + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
190 | + */ | ||
191 | + init: function (words, sigBytes) { | ||
192 | + words = this.words = words || []; | ||
193 | + | ||
194 | + if (sigBytes != undefined) { | ||
195 | + this.sigBytes = sigBytes; | ||
196 | + } else { | ||
197 | + this.sigBytes = words.length * 4; | ||
198 | + } | ||
199 | + }, | ||
200 | + | ||
201 | + /** | ||
202 | + * Converts this word array to a string. | ||
203 | + * | ||
204 | + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
205 | + * | ||
206 | + * @return {string} The stringified word array. | ||
207 | + * | ||
208 | + * @example | ||
209 | + * | ||
210 | + * var string = wordArray + ''; | ||
211 | + * var string = wordArray.toString(); | ||
212 | + * var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
213 | + */ | ||
214 | + toString: function (encoder) { | ||
215 | + return (encoder || Hex).stringify(this); | ||
216 | + }, | ||
217 | + | ||
218 | + /** | ||
219 | + * Concatenates a word array to this word array. | ||
220 | + * | ||
221 | + * @param {WordArray} wordArray The word array to append. | ||
222 | + * | ||
223 | + * @return {WordArray} This word array. | ||
224 | + * | ||
225 | + * @example | ||
226 | + * | ||
227 | + * wordArray1.concat(wordArray2); | ||
228 | + */ | ||
229 | + concat: function (wordArray) { | ||
230 | + // Shortcuts | ||
231 | + var thisWords = this.words; | ||
232 | + var thatWords = wordArray.words; | ||
233 | + var thisSigBytes = this.sigBytes; | ||
234 | + var thatSigBytes = wordArray.sigBytes; | ||
235 | + | ||
236 | + // Clamp excess bits | ||
237 | + this.clamp(); | ||
238 | + | ||
239 | + // Concat | ||
240 | + if (thisSigBytes % 4) { | ||
241 | + // Copy one byte at a time | ||
242 | + for (var i = 0; i < thatSigBytes; i++) { | ||
243 | + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
244 | + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
245 | + } | ||
246 | + } else { | ||
247 | + // Copy one word at a time | ||
248 | + for (var i = 0; i < thatSigBytes; i += 4) { | ||
249 | + thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; | ||
250 | + } | ||
251 | + } | ||
252 | + this.sigBytes += thatSigBytes; | ||
253 | + | ||
254 | + // Chainable | ||
255 | + return this; | ||
256 | + }, | ||
257 | + | ||
258 | + /** | ||
259 | + * Removes insignificant bits. | ||
260 | + * | ||
261 | + * @example | ||
262 | + * | ||
263 | + * wordArray.clamp(); | ||
264 | + */ | ||
265 | + clamp: function () { | ||
266 | + // Shortcuts | ||
267 | + var words = this.words; | ||
268 | + var sigBytes = this.sigBytes; | ||
269 | + | ||
270 | + // Clamp | ||
271 | + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
272 | + words.length = Math.ceil(sigBytes / 4); | ||
273 | + }, | ||
274 | + | ||
275 | + /** | ||
276 | + * Creates a copy of this word array. | ||
277 | + * | ||
278 | + * @return {WordArray} The clone. | ||
279 | + * | ||
280 | + * @example | ||
281 | + * | ||
282 | + * var clone = wordArray.clone(); | ||
283 | + */ | ||
284 | + clone: function () { | ||
285 | + var clone = Base.clone.call(this); | ||
286 | + clone.words = this.words.slice(0); | ||
287 | + | ||
288 | + return clone; | ||
289 | + }, | ||
290 | + | ||
291 | + /** | ||
292 | + * Creates a word array filled with random bytes. | ||
293 | + * | ||
294 | + * @param {number} nBytes The number of random bytes to generate. | ||
295 | + * | ||
296 | + * @return {WordArray} The random word array. | ||
297 | + * | ||
298 | + * @static | ||
299 | + * | ||
300 | + * @example | ||
301 | + * | ||
302 | + * var wordArray = CryptoJS.lib.WordArray.random(16); | ||
303 | + */ | ||
304 | + random: function (nBytes) { | ||
305 | + var words = []; | ||
306 | + | ||
307 | + var r = (function (m_w) { | ||
308 | + var m_w = m_w; | ||
309 | + var m_z = 0x3ade68b1; | ||
310 | + var mask = 0xffffffff; | ||
311 | + | ||
312 | + return function () { | ||
313 | + m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; | ||
314 | + m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; | ||
315 | + var result = ((m_z << 0x10) + m_w) & mask; | ||
316 | + result /= 0x100000000; | ||
317 | + result += 0.5; | ||
318 | + return result * (Math.random() > .5 ? 1 : -1); | ||
319 | + } | ||
320 | + }); | ||
321 | + | ||
322 | + for (var i = 0, rcache; i < nBytes; i += 4) { | ||
323 | + var _r = r((rcache || Math.random()) * 0x100000000); | ||
324 | + | ||
325 | + rcache = _r() * 0x3ade67b7; | ||
326 | + words.push((_r() * 0x100000000) | 0); | ||
327 | + } | ||
328 | + | ||
329 | + return new WordArray.init(words, nBytes); | ||
330 | + } | ||
331 | + }); | ||
332 | + | ||
333 | + /** | ||
334 | + * Encoder namespace. | ||
335 | + */ | ||
336 | + var C_enc = C.enc = {}; | ||
337 | + | ||
338 | + /** | ||
339 | + * Hex encoding strategy. | ||
340 | + */ | ||
341 | + var Hex = C_enc.Hex = { | ||
342 | + /** | ||
343 | + * Converts a word array to a hex string. | ||
344 | + * | ||
345 | + * @param {WordArray} wordArray The word array. | ||
346 | + * | ||
347 | + * @return {string} The hex string. | ||
348 | + * | ||
349 | + * @static | ||
350 | + * | ||
351 | + * @example | ||
352 | + * | ||
353 | + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
354 | + */ | ||
355 | + stringify: function (wordArray) { | ||
356 | + // Shortcuts | ||
357 | + var words = wordArray.words; | ||
358 | + var sigBytes = wordArray.sigBytes; | ||
359 | + | ||
360 | + // Convert | ||
361 | + var hexChars = []; | ||
362 | + for (var i = 0; i < sigBytes; i++) { | ||
363 | + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
364 | + hexChars.push((bite >>> 4).toString(16)); | ||
365 | + hexChars.push((bite & 0x0f).toString(16)); | ||
366 | + } | ||
367 | + | ||
368 | + return hexChars.join(''); | ||
369 | + }, | ||
370 | + | ||
371 | + /** | ||
372 | + * Converts a hex string to a word array. | ||
373 | + * | ||
374 | + * @param {string} hexStr The hex string. | ||
375 | + * | ||
376 | + * @return {WordArray} The word array. | ||
377 | + * | ||
378 | + * @static | ||
379 | + * | ||
380 | + * @example | ||
381 | + * | ||
382 | + * var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
383 | + */ | ||
384 | + parse: function (hexStr) { | ||
385 | + // Shortcut | ||
386 | + var hexStrLength = hexStr.length; | ||
387 | + | ||
388 | + // Convert | ||
389 | + var words = []; | ||
390 | + for (var i = 0; i < hexStrLength; i += 2) { | ||
391 | + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
392 | + } | ||
393 | + | ||
394 | + return new WordArray.init(words, hexStrLength / 2); | ||
395 | + } | ||
396 | + }; | ||
397 | + | ||
398 | + /** | ||
399 | + * Latin1 encoding strategy. | ||
400 | + */ | ||
401 | + var Latin1 = C_enc.Latin1 = { | ||
402 | + /** | ||
403 | + * Converts a word array to a Latin1 string. | ||
404 | + * | ||
405 | + * @param {WordArray} wordArray The word array. | ||
406 | + * | ||
407 | + * @return {string} The Latin1 string. | ||
408 | + * | ||
409 | + * @static | ||
410 | + * | ||
411 | + * @example | ||
412 | + * | ||
413 | + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
414 | + */ | ||
415 | + stringify: function (wordArray) { | ||
416 | + // Shortcuts | ||
417 | + var words = wordArray.words; | ||
418 | + var sigBytes = wordArray.sigBytes; | ||
419 | + | ||
420 | + // Convert | ||
421 | + var latin1Chars = []; | ||
422 | + for (var i = 0; i < sigBytes; i++) { | ||
423 | + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
424 | + latin1Chars.push(String.fromCharCode(bite)); | ||
425 | + } | ||
426 | + | ||
427 | + return latin1Chars.join(''); | ||
428 | + }, | ||
429 | + | ||
430 | + /** | ||
431 | + * Converts a Latin1 string to a word array. | ||
432 | + * | ||
433 | + * @param {string} latin1Str The Latin1 string. | ||
434 | + * | ||
435 | + * @return {WordArray} The word array. | ||
436 | + * | ||
437 | + * @static | ||
438 | + * | ||
439 | + * @example | ||
440 | + * | ||
441 | + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
442 | + */ | ||
443 | + parse: function (latin1Str) { | ||
444 | + // Shortcut | ||
445 | + var latin1StrLength = latin1Str.length; | ||
446 | + | ||
447 | + // Convert | ||
448 | + var words = []; | ||
449 | + for (var i = 0; i < latin1StrLength; i++) { | ||
450 | + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
451 | + } | ||
452 | + | ||
453 | + return new WordArray.init(words, latin1StrLength); | ||
454 | + } | ||
455 | + }; | ||
456 | + | ||
457 | + /** | ||
458 | + * UTF-8 encoding strategy. | ||
459 | + */ | ||
460 | + var Utf8 = C_enc.Utf8 = { | ||
461 | + /** | ||
462 | + * Converts a word array to a UTF-8 string. | ||
463 | + * | ||
464 | + * @param {WordArray} wordArray The word array. | ||
465 | + * | ||
466 | + * @return {string} The UTF-8 string. | ||
467 | + * | ||
468 | + * @static | ||
469 | + * | ||
470 | + * @example | ||
471 | + * | ||
472 | + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
473 | + */ | ||
474 | + stringify: function (wordArray) { | ||
475 | + try { | ||
476 | + return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
477 | + } catch (e) { | ||
478 | + throw new Error('Malformed UTF-8 data'); | ||
479 | + } | ||
480 | + }, | ||
481 | + | ||
482 | + /** | ||
483 | + * Converts a UTF-8 string to a word array. | ||
484 | + * | ||
485 | + * @param {string} utf8Str The UTF-8 string. | ||
486 | + * | ||
487 | + * @return {WordArray} The word array. | ||
488 | + * | ||
489 | + * @static | ||
490 | + * | ||
491 | + * @example | ||
492 | + * | ||
493 | + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
494 | + */ | ||
495 | + parse: function (utf8Str) { | ||
496 | + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
497 | + } | ||
498 | + }; | ||
499 | + | ||
500 | + /** | ||
501 | + * Abstract buffered block algorithm template. | ||
502 | + * | ||
503 | + * The property blockSize must be implemented in a concrete subtype. | ||
504 | + * | ||
505 | + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
506 | + */ | ||
507 | + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
508 | + /** | ||
509 | + * Resets this block algorithm's data buffer to its initial state. | ||
510 | + * | ||
511 | + * @example | ||
512 | + * | ||
513 | + * bufferedBlockAlgorithm.reset(); | ||
514 | + */ | ||
515 | + reset: function () { | ||
516 | + // Initial values | ||
517 | + this._data = new WordArray.init(); | ||
518 | + this._nDataBytes = 0; | ||
519 | + }, | ||
520 | + | ||
521 | + /** | ||
522 | + * Adds new data to this block algorithm's buffer. | ||
523 | + * | ||
524 | + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
525 | + * | ||
526 | + * @example | ||
527 | + * | ||
528 | + * bufferedBlockAlgorithm._append('data'); | ||
529 | + * bufferedBlockAlgorithm._append(wordArray); | ||
530 | + */ | ||
531 | + _append: function (data) { | ||
532 | + // Convert string to WordArray, else assume WordArray already | ||
533 | + if (typeof data == 'string') { | ||
534 | + data = Utf8.parse(data); | ||
535 | + } | ||
536 | + | ||
537 | + // Append | ||
538 | + this._data.concat(data); | ||
539 | + this._nDataBytes += data.sigBytes; | ||
540 | + }, | ||
541 | + | ||
542 | + /** | ||
543 | + * Processes available data blocks. | ||
544 | + * | ||
545 | + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
546 | + * | ||
547 | + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
548 | + * | ||
549 | + * @return {WordArray} The processed data. | ||
550 | + * | ||
551 | + * @example | ||
552 | + * | ||
553 | + * var processedData = bufferedBlockAlgorithm._process(); | ||
554 | + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
555 | + */ | ||
556 | + _process: function (doFlush) { | ||
557 | + // Shortcuts | ||
558 | + var data = this._data; | ||
559 | + var dataWords = data.words; | ||
560 | + var dataSigBytes = data.sigBytes; | ||
561 | + var blockSize = this.blockSize; | ||
562 | + var blockSizeBytes = blockSize * 4; | ||
563 | + | ||
564 | + // Count blocks ready | ||
565 | + var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
566 | + if (doFlush) { | ||
567 | + // Round up to include partial blocks | ||
568 | + nBlocksReady = Math.ceil(nBlocksReady); | ||
569 | + } else { | ||
570 | + // Round down to include only full blocks, | ||
571 | + // less the number of blocks that must remain in the buffer | ||
572 | + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
573 | + } | ||
574 | + | ||
575 | + // Count words ready | ||
576 | + var nWordsReady = nBlocksReady * blockSize; | ||
577 | + | ||
578 | + // Count bytes ready | ||
579 | + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
580 | + | ||
581 | + // Process blocks | ||
582 | + if (nWordsReady) { | ||
583 | + for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
584 | + // Perform concrete-algorithm logic | ||
585 | + this._doProcessBlock(dataWords, offset); | ||
586 | + } | ||
587 | + | ||
588 | + // Remove processed words | ||
589 | + var processedWords = dataWords.splice(0, nWordsReady); | ||
590 | + data.sigBytes -= nBytesReady; | ||
591 | + } | ||
592 | + | ||
593 | + // Return processed words | ||
594 | + return new WordArray.init(processedWords, nBytesReady); | ||
595 | + }, | ||
596 | + | ||
597 | + /** | ||
598 | + * Creates a copy of this object. | ||
599 | + * | ||
600 | + * @return {Object} The clone. | ||
601 | + * | ||
602 | + * @example | ||
603 | + * | ||
604 | + * var clone = bufferedBlockAlgorithm.clone(); | ||
605 | + */ | ||
606 | + clone: function () { | ||
607 | + var clone = Base.clone.call(this); | ||
608 | + clone._data = this._data.clone(); | ||
609 | + | ||
610 | + return clone; | ||
611 | + }, | ||
612 | + | ||
613 | + _minBufferSize: 0 | ||
614 | + }); | ||
615 | + | ||
616 | + /** | ||
617 | + * Abstract hasher template. | ||
618 | + * | ||
619 | + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
620 | + */ | ||
621 | + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
622 | + /** | ||
623 | + * Configuration options. | ||
624 | + */ | ||
625 | + cfg: Base.extend(), | ||
626 | + | ||
627 | + /** | ||
628 | + * Initializes a newly created hasher. | ||
629 | + * | ||
630 | + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
631 | + * | ||
632 | + * @example | ||
633 | + * | ||
634 | + * var hasher = CryptoJS.algo.SHA256.create(); | ||
635 | + */ | ||
636 | + init: function (cfg) { | ||
637 | + // Apply config defaults | ||
638 | + this.cfg = this.cfg.extend(cfg); | ||
639 | + | ||
640 | + // Set initial values | ||
641 | + this.reset(); | ||
642 | + }, | ||
643 | + | ||
644 | + /** | ||
645 | + * Resets this hasher to its initial state. | ||
646 | + * | ||
647 | + * @example | ||
648 | + * | ||
649 | + * hasher.reset(); | ||
650 | + */ | ||
651 | + reset: function () { | ||
652 | + // Reset data buffer | ||
653 | + BufferedBlockAlgorithm.reset.call(this); | ||
654 | + | ||
655 | + // Perform concrete-hasher logic | ||
656 | + this._doReset(); | ||
657 | + }, | ||
658 | + | ||
659 | + /** | ||
660 | + * Updates this hasher with a message. | ||
661 | + * | ||
662 | + * @param {WordArray|string} messageUpdate The message to append. | ||
663 | + * | ||
664 | + * @return {Hasher} This hasher. | ||
665 | + * | ||
666 | + * @example | ||
667 | + * | ||
668 | + * hasher.update('message'); | ||
669 | + * hasher.update(wordArray); | ||
670 | + */ | ||
671 | + update: function (messageUpdate) { | ||
672 | + // Append | ||
673 | + this._append(messageUpdate); | ||
674 | + | ||
675 | + // Update the hash | ||
676 | + this._process(); | ||
677 | + | ||
678 | + // Chainable | ||
679 | + return this; | ||
680 | + }, | ||
681 | + | ||
682 | + /** | ||
683 | + * Finalizes the hash computation. | ||
684 | + * Note that the finalize operation is effectively a destructive, read-once operation. | ||
685 | + * | ||
686 | + * @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
687 | + * | ||
688 | + * @return {WordArray} The hash. | ||
689 | + * | ||
690 | + * @example | ||
691 | + * | ||
692 | + * var hash = hasher.finalize(); | ||
693 | + * var hash = hasher.finalize('message'); | ||
694 | + * var hash = hasher.finalize(wordArray); | ||
695 | + */ | ||
696 | + finalize: function (messageUpdate) { | ||
697 | + // Final message update | ||
698 | + if (messageUpdate) { | ||
699 | + this._append(messageUpdate); | ||
700 | + } | ||
701 | + | ||
702 | + // Perform concrete-hasher logic | ||
703 | + var hash = this._doFinalize(); | ||
704 | + | ||
705 | + return hash; | ||
706 | + }, | ||
707 | + | ||
708 | + blockSize: 512/32, | ||
709 | + | ||
710 | + /** | ||
711 | + * Creates a shortcut function to a hasher's object interface. | ||
712 | + * | ||
713 | + * @param {Hasher} hasher The hasher to create a helper for. | ||
714 | + * | ||
715 | + * @return {Function} The shortcut function. | ||
716 | + * | ||
717 | + * @static | ||
718 | + * | ||
719 | + * @example | ||
720 | + * | ||
721 | + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
722 | + */ | ||
723 | + _createHelper: function (hasher) { | ||
724 | + return function (message, cfg) { | ||
725 | + return new hasher.init(cfg).finalize(message); | ||
726 | + }; | ||
727 | + }, | ||
728 | + | ||
729 | + /** | ||
730 | + * Creates a shortcut function to the HMAC's object interface. | ||
731 | + * | ||
732 | + * @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
733 | + * | ||
734 | + * @return {Function} The shortcut function. | ||
735 | + * | ||
736 | + * @static | ||
737 | + * | ||
738 | + * @example | ||
739 | + * | ||
740 | + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
741 | + */ | ||
742 | + _createHmacHelper: function (hasher) { | ||
743 | + return function (message, key) { | ||
744 | + return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
745 | + }; | ||
746 | + } | ||
747 | + }); | ||
748 | + | ||
749 | + /** | ||
750 | + * Algorithm namespace. | ||
751 | + */ | ||
752 | + var C_algo = C.algo = {}; | ||
753 | + | ||
754 | + return C; | ||
755 | + }(Math)); | ||
756 | + | ||
757 | + | ||
758 | + return CryptoJS; | ||
759 | + | ||
760 | +})); |
vendors/crypto-js/crypto-js.js
0 → 100644
This diff could not be displayed because it is too large.
vendors/crypto-js/enc-base64.js
0 → 100644
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 | + words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); | ||
125 | + nBytes++; | ||
126 | + } | ||
127 | + } | ||
128 | + return WordArray.create(words, nBytes); | ||
129 | + } | ||
130 | + }()); | ||
131 | + | ||
132 | + | ||
133 | + return CryptoJS.enc.Base64; | ||
134 | + | ||
135 | +})); |
vendors/crypto-js/enc-hex.js
0 → 100644
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 | +})); |
vendors/crypto-js/enc-latin1.js
0 → 100644
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 | +})); |
vendors/crypto-js/enc-utf16.js
0 → 100644
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 | +})); |
vendors/crypto-js/enc-utf8.js
0 → 100644
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 | +})); |
vendors/crypto-js/evpkdf.js
0 → 100644
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 | + // Shortcut | ||
72 | + var cfg = this.cfg; | ||
73 | + | ||
74 | + // Init hasher | ||
75 | + var hasher = cfg.hasher.create(); | ||
76 | + | ||
77 | + // Initial values | ||
78 | + var derivedKey = WordArray.create(); | ||
79 | + | ||
80 | + // Shortcuts | ||
81 | + var derivedKeyWords = derivedKey.words; | ||
82 | + var keySize = cfg.keySize; | ||
83 | + var iterations = cfg.iterations; | ||
84 | + | ||
85 | + // Generate key | ||
86 | + while (derivedKeyWords.length < keySize) { | ||
87 | + if (block) { | ||
88 | + hasher.update(block); | ||
89 | + } | ||
90 | + var block = hasher.update(password).finalize(salt); | ||
91 | + hasher.reset(); | ||
92 | + | ||
93 | + // Iterations | ||
94 | + for (var i = 1; i < iterations; i++) { | ||
95 | + block = hasher.finalize(block); | ||
96 | + hasher.reset(); | ||
97 | + } | ||
98 | + | ||
99 | + derivedKey.concat(block); | ||
100 | + } | ||
101 | + derivedKey.sigBytes = keySize * 4; | ||
102 | + | ||
103 | + return derivedKey; | ||
104 | + } | ||
105 | + }); | ||
106 | + | ||
107 | + /** | ||
108 | + * Derives a key from a password. | ||
109 | + * | ||
110 | + * @param {WordArray|string} password The password. | ||
111 | + * @param {WordArray|string} salt A salt. | ||
112 | + * @param {Object} cfg (Optional) The configuration options to use for this computation. | ||
113 | + * | ||
114 | + * @return {WordArray} The derived key. | ||
115 | + * | ||
116 | + * @static | ||
117 | + * | ||
118 | + * @example | ||
119 | + * | ||
120 | + * var key = CryptoJS.EvpKDF(password, salt); | ||
121 | + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); | ||
122 | + * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); | ||
123 | + */ | ||
124 | + C.EvpKDF = function (password, salt, cfg) { | ||
125 | + return EvpKDF.create(cfg).compute(password, salt); | ||
126 | + }; | ||
127 | + }()); | ||
128 | + | ||
129 | + | ||
130 | + return CryptoJS.EvpKDF; | ||
131 | + | ||
132 | +})); |
vendors/crypto-js/format-hex.js
0 → 100644
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 | +})); |
vendors/crypto-js/format-openssl.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-md5.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-ripemd160.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha1.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha224.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha256.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha3.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha384.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac-sha512.js
0 → 100644
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 | +})); |
vendors/crypto-js/hmac.js
0 → 100644
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 | +})); |
vendors/crypto-js/index.js
0 → 100644
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 | +})); |
vendors/crypto-js/lib-typedarrays.js
0 → 100644
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 | +})); |
vendors/crypto-js/md5.js
0 → 100644
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 | +})); |
vendors/crypto-js/mode-cfb.js
0 → 100644
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 | + // Shortcut | ||
53 | + var iv = this._iv; | ||
54 | + | ||
55 | + // Generate keystream | ||
56 | + if (iv) { | ||
57 | + var keystream = iv.slice(0); | ||
58 | + | ||
59 | + // Remove IV for subsequent blocks | ||
60 | + this._iv = undefined; | ||
61 | + } else { | ||
62 | + var keystream = this._prevBlock; | ||
63 | + } | ||
64 | + cipher.encryptBlock(keystream, 0); | ||
65 | + | ||
66 | + // Encrypt | ||
67 | + for (var i = 0; i < blockSize; i++) { | ||
68 | + words[offset + i] ^= keystream[i]; | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + return CFB; | ||
73 | + }()); | ||
74 | + | ||
75 | + | ||
76 | + return CryptoJS.mode.CFB; | ||
77 | + | ||
78 | +})); |
vendors/crypto-js/mode-ctr-gladman.js
0 → 100644
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 | +})); |
vendors/crypto-js/mode-ctr.js
0 → 100644
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 | +})); |
vendors/crypto-js/mode-ecb.js
0 → 100644
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 | +})); |
vendors/crypto-js/mode-ofb.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-ansix923.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-iso10126.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-iso97971.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-nopadding.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-pkcs7.js
0 → 100644
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 | +})); |
vendors/crypto-js/pad-zeropadding.js
0 → 100644
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 | + while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { | ||
36 | + i--; | ||
37 | + } | ||
38 | + data.sigBytes = i + 1; | ||
39 | + } | ||
40 | + }; | ||
41 | + | ||
42 | + | ||
43 | + return CryptoJS.pad.ZeroPadding; | ||
44 | + | ||
45 | +})); |
vendors/crypto-js/pbkdf2.js
0 → 100644
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 | +})); |
vendors/crypto-js/rabbit-legacy.js
0 → 100644
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 | +})); |
vendors/crypto-js/rabbit.js
0 → 100644
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 | +})); |
vendors/crypto-js/rc4.js
0 → 100644
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 | +})); |
-
Please register or login to post a comment