mirror of
https://github.com/YunoHost-Apps/hubzilla_ynh.git
synced 2024-09-03 19:26:21 +02:00
290 lines
8.5 KiB
JavaScript
290 lines
8.5 KiB
JavaScript
/*
|
|
CryptoJS v3.1.2
|
|
code.google.com/p/crypto-js
|
|
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
|
code.google.com/p/crypto-js/wiki/License
|
|
*/
|
|
(function (undefined) {
|
|
// Shortcuts
|
|
var C = CryptoJS;
|
|
var C_lib = C.lib;
|
|
var Base = C_lib.Base;
|
|
var X32WordArray = C_lib.WordArray;
|
|
|
|
/**
|
|
* x64 namespace.
|
|
*/
|
|
var C_x64 = C.x64 = {};
|
|
|
|
/**
|
|
* A 64-bit word.
|
|
*/
|
|
var X64Word = C_x64.Word = Base.extend({
|
|
/**
|
|
* Initializes a newly created 64-bit word.
|
|
*
|
|
* @param {number} high The high 32 bits.
|
|
* @param {number} low The low 32 bits.
|
|
*
|
|
* @example
|
|
*
|
|
* var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
|
|
*/
|
|
init: function (high, low) {
|
|
this.high = high;
|
|
this.low = low;
|
|
}
|
|
|
|
/**
|
|
* Bitwise NOTs this word.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after negating.
|
|
*
|
|
* @example
|
|
*
|
|
* var negated = x64Word.not();
|
|
*/
|
|
// not: function () {
|
|
// var high = ~this.high;
|
|
// var low = ~this.low;
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Bitwise ANDs this word with the passed word.
|
|
*
|
|
* @param {X64Word} word The x64-Word to AND with this word.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after ANDing.
|
|
*
|
|
* @example
|
|
*
|
|
* var anded = x64Word.and(anotherX64Word);
|
|
*/
|
|
// and: function (word) {
|
|
// var high = this.high & word.high;
|
|
// var low = this.low & word.low;
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Bitwise ORs this word with the passed word.
|
|
*
|
|
* @param {X64Word} word The x64-Word to OR with this word.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after ORing.
|
|
*
|
|
* @example
|
|
*
|
|
* var ored = x64Word.or(anotherX64Word);
|
|
*/
|
|
// or: function (word) {
|
|
// var high = this.high | word.high;
|
|
// var low = this.low | word.low;
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Bitwise XORs this word with the passed word.
|
|
*
|
|
* @param {X64Word} word The x64-Word to XOR with this word.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after XORing.
|
|
*
|
|
* @example
|
|
*
|
|
* var xored = x64Word.xor(anotherX64Word);
|
|
*/
|
|
// xor: function (word) {
|
|
// var high = this.high ^ word.high;
|
|
// var low = this.low ^ word.low;
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Shifts this word n bits to the left.
|
|
*
|
|
* @param {number} n The number of bits to shift.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after shifting.
|
|
*
|
|
* @example
|
|
*
|
|
* var shifted = x64Word.shiftL(25);
|
|
*/
|
|
// shiftL: function (n) {
|
|
// if (n < 32) {
|
|
// var high = (this.high << n) | (this.low >>> (32 - n));
|
|
// var low = this.low << n;
|
|
// } else {
|
|
// var high = this.low << (n - 32);
|
|
// var low = 0;
|
|
// }
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Shifts this word n bits to the right.
|
|
*
|
|
* @param {number} n The number of bits to shift.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after shifting.
|
|
*
|
|
* @example
|
|
*
|
|
* var shifted = x64Word.shiftR(7);
|
|
*/
|
|
// shiftR: function (n) {
|
|
// if (n < 32) {
|
|
// var low = (this.low >>> n) | (this.high << (32 - n));
|
|
// var high = this.high >>> n;
|
|
// } else {
|
|
// var low = this.high >>> (n - 32);
|
|
// var high = 0;
|
|
// }
|
|
|
|
// return X64Word.create(high, low);
|
|
// },
|
|
|
|
/**
|
|
* Rotates this word n bits to the left.
|
|
*
|
|
* @param {number} n The number of bits to rotate.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after rotating.
|
|
*
|
|
* @example
|
|
*
|
|
* var rotated = x64Word.rotL(25);
|
|
*/
|
|
// rotL: function (n) {
|
|
// return this.shiftL(n).or(this.shiftR(64 - n));
|
|
// },
|
|
|
|
/**
|
|
* Rotates this word n bits to the right.
|
|
*
|
|
* @param {number} n The number of bits to rotate.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after rotating.
|
|
*
|
|
* @example
|
|
*
|
|
* var rotated = x64Word.rotR(7);
|
|
*/
|
|
// rotR: function (n) {
|
|
// return this.shiftR(n).or(this.shiftL(64 - n));
|
|
// },
|
|
|
|
/**
|
|
* Adds this word with the passed word.
|
|
*
|
|
* @param {X64Word} word The x64-Word to add with this word.
|
|
*
|
|
* @return {X64Word} A new x64-Word object after adding.
|
|
*
|
|
* @example
|
|
*
|
|
* var added = x64Word.add(anotherX64Word);
|
|
*/
|
|
// add: function (word) {
|
|
// var low = (this.low + word.low) | 0;
|
|
// var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
|
|
// var high = (this.high + word.high + carry) | 0;
|
|
|
|
// return X64Word.create(high, low);
|
|
// }
|
|
});
|
|
|
|
/**
|
|
* An array of 64-bit words.
|
|
*
|
|
* @property {Array} words The array of CryptoJS.x64.Word objects.
|
|
* @property {number} sigBytes The number of significant bytes in this word array.
|
|
*/
|
|
var X64WordArray = C_x64.WordArray = Base.extend({
|
|
/**
|
|
* Initializes a newly created word array.
|
|
*
|
|
* @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
|
|
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
|
*
|
|
* @example
|
|
*
|
|
* var wordArray = CryptoJS.x64.WordArray.create();
|
|
*
|
|
* var wordArray = CryptoJS.x64.WordArray.create([
|
|
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
|
|
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
|
|
* ]);
|
|
*
|
|
* var wordArray = CryptoJS.x64.WordArray.create([
|
|
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
|
|
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
|
|
* ], 10);
|
|
*/
|
|
init: function (words, sigBytes) {
|
|
words = this.words = words || [];
|
|
|
|
if (sigBytes != undefined) {
|
|
this.sigBytes = sigBytes;
|
|
} else {
|
|
this.sigBytes = words.length * 8;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Converts this 64-bit word array to a 32-bit word array.
|
|
*
|
|
* @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
|
|
*
|
|
* @example
|
|
*
|
|
* var x32WordArray = x64WordArray.toX32();
|
|
*/
|
|
toX32: function () {
|
|
// Shortcuts
|
|
var x64Words = this.words;
|
|
var x64WordsLength = x64Words.length;
|
|
|
|
// Convert
|
|
var x32Words = [];
|
|
for (var i = 0; i < x64WordsLength; i++) {
|
|
var x64Word = x64Words[i];
|
|
x32Words.push(x64Word.high);
|
|
x32Words.push(x64Word.low);
|
|
}
|
|
|
|
return X32WordArray.create(x32Words, this.sigBytes);
|
|
},
|
|
|
|
/**
|
|
* Creates a copy of this word array.
|
|
*
|
|
* @return {X64WordArray} The clone.
|
|
*
|
|
* @example
|
|
*
|
|
* var clone = x64WordArray.clone();
|
|
*/
|
|
clone: function () {
|
|
var clone = Base.clone.call(this);
|
|
|
|
// Clone "words" array
|
|
var words = clone.words = this.words.slice(0);
|
|
|
|
// Clone each X64Word object
|
|
var wordsLength = words.length;
|
|
for (var i = 0; i < wordsLength; i++) {
|
|
words[i] = words[i].clone();
|
|
}
|
|
|
|
return clone;
|
|
}
|
|
});
|
|
}());
|