diff --git a/README.md b/README.md index f696eab97..add083e34 100755 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ List of Definitions * [Commander](http://github.com/visionmedia/commander.js) (by [Marcelo Dezem](https://github.com/mdezem)) * [Couchbase / Couchnode](https://github.com/couchbase/couchnode) (by [Basarat Ali Syed](https://github.com/basarat)) * [Crossfilter](https://github.com/square/crossfilter) (by [Schmulik Raskin](https://github.com/schmuli)) +* [crypto-js](https://code.google.com/p/crypto-js/) (by [Gia Bảo @ Sân Đình](https://github.com/giabao)). @see [cryptojs.d.ts repo](https://github.com/giabao/cryptojs.d.ts) * [d3.js](http://d3js.org/) (from TypeScript samples) * [dhtmlxGantt](http://dhtmlx.com/docs/products/dhtmlxGantt) (by [Maksim Kozhukh](http://github.com/mkozhukh)) * [dhtmlxScheduler](http://dhtmlx.com/docs/products/dhtmlxScheduler) (by [Maksim Kozhukh](http://github.com/mkozhukh)) diff --git a/cryptojs/all-tests.ts b/cryptojs/all-tests.ts new file mode 100644 index 000000000..207ecda6b --- /dev/null +++ b/cryptojs/all-tests.ts @@ -0,0 +1,57 @@ +/// + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/cryptojs/all-tests.ts.tscparams b/cryptojs/all-tests.ts.tscparams new file mode 100644 index 000000000..e16c76dff --- /dev/null +++ b/cryptojs/all-tests.ts.tscparams @@ -0,0 +1 @@ +"" diff --git a/cryptojs/cryptojs.d.ts b/cryptojs/cryptojs.d.ts new file mode 100644 index 000000000..fc52995b6 --- /dev/null +++ b/cryptojs/cryptojs.d.ts @@ -0,0 +1,465 @@ +// Type definitions for CryptoJS 3.1.2 +// Project: https://code.google.com/p/crypto-js/ +// Definitions by: +// Gia Bảo @ Sân Đình +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var CryptoJS: CryptoJS.CryptoJSStatic; + +declare module CryptoJS{ + module lib{ + interface Base{ + extend(overrides: Object): Object + init(...args: any[]): void + //arguments of create() is same as init(). This is true for all subclasses + create(...args: any[]): Base + mixIn(properties: Object): void + clone(): Base + } + + interface WordArray extends Base{ + words: number[] + sigBytes: number + init(words?: number[], sigBytes?: number): void + create(words?: number[], sigBytes?: number): WordArray + + init(typedArray: ArrayBuffer): void + init(typedArray: Int8Array): void + + //Because TypeScript uses a structural type system then we don't need (& can't) + //declare oveload function init, create for the following type (same as Int8Array): + //then Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array + //Note also: Uint8ClampedArray is not defined in lib.d.ts & not supported in IE + //@see http://compatibility.shwups-cms.ch/en/home?&property=Uint8ClampedArray + + create(typedArray: ArrayBuffer): WordArray + create(typedArray: Int8Array): WordArray + + toString(encoder?: enc.IEncoder): string + concat(wordArray: WordArray): WordArray + clamp(): void + clone(): WordArray + random(nBytes: number): WordArray + } + + interface BufferedBlockAlgorithm extends Base{ + reset(): void + clone(): BufferedBlockAlgorithm + } + + //tparam C - Configuration type + interface IHasher extends BufferedBlockAlgorithm{ + cfg: C + init(cfg?: C): void + create(cfg?: C): IHasher + + update(messageUpdate: WordArray): Hasher + update(messageUpdate: string): Hasher + + finalize(messageUpdate?: WordArray): WordArray + finalize(messageUpdate?: string): WordArray + + blockSize: number + + _createHelper(hasher: Hasher): IHasherHelper + _createHmacHelper(hasher: Hasher): IHasherHmacHelper + + clone(): IHasher + } + interface Hasher extends IHasher{} + + //tparam C - Configuration type + interface IHasherHelper{ + (message: WordArray, cfg?: C): WordArray + (message: string, cfg?: C): WordArray + } + interface HasherHelper extends IHasherHelper{} + + interface IHasherHmacHelper{ + (message: WordArray, key: WordArray): WordArray + (message: string, key: WordArray): WordArray + (message: WordArray, key: string): WordArray + (message: string, key: string): WordArray + } + + //tparam C - Configuration type + interface ICipher extends BufferedBlockAlgorithm{ + cfg: C + createEncryptor(key: WordArray, cfg?: C): ICipher + createDecryptor(key: WordArray, cfg?: C): ICipher + + create(xformMode: number, key: WordArray, cfg?: C): ICipher + init(xformMode: number, key: WordArray, cfg?: C): void + + process(dataUpdate: WordArray): WordArray + process(dataUpdate: string): WordArray + + finalize(dataUpdate?: WordArray): WordArray + finalize(dataUpdate?: string): WordArray + + keySize: number + ivSize: number + + _createHelper(cipher: Cipher): ICipherHelper + + clone(): ICipher + } + interface Cipher extends ICipher{} + + interface IStreamCipher extends ICipher{ + createEncryptor(key: WordArray, cfg?: C): IStreamCipher + createDecryptor(key: WordArray, cfg?: C): IStreamCipher + + create(xformMode: number, key: WordArray, cfg?: C): IStreamCipher + + blockSize: number + } + interface StreamCipher extends IStreamCipher{} + + interface BlockCipherMode extends Base{ + createEncryptor(cipher: Cipher, iv: number[]): mode.IBlockCipherEncryptor + createDecryptor(cipher: Cipher, iv: number[]): mode.IBlockCipherDecryptor + init(cipher: Cipher, iv: number[]): void + create(cipher: Cipher, iv: number[]): BlockCipherMode + } + + //BlockCipher has interface same as IStreamCipher + interface BlockCipher extends IStreamCipher{} + + interface IBlockCipherCfg{ + mode?: mode.IBlockCipherModeImpl //default CBC + padding?: pad.IPaddingImpl //default Pkcs7 + } + + interface CipherParamsData{ + ciphertext?: lib.WordArray + key?: lib.WordArray + iv?: lib.WordArray + salt?: lib.WordArray + algorithm?: Cipher + mode?: mode.IBlockCipherModeImpl + padding?: pad.IPaddingImpl + blockSize?: number + formatter?: format.IFormatter + } + + interface CipherParams extends Base, CipherParamsData{ + init(cipherParams: CipherParamsData): void + create(cipherParams: CipherParamsData): CipherParams + toString(formatter?: format.IFormatter): string + } + + //tparam C - Configuration type + interface ISerializableCipher extends Base{ + cfg: C + encrypt(cipher: Cipher, message: WordArray, key: WordArray, cfg?: C): CipherParams + encrypt(cipher: Cipher, message: string, key: WordArray, cfg?: C): CipherParams + + decrypt(cipher: Cipher, ciphertext: CipherParamsData, key: WordArray, cfg?: C): WordArray + decrypt(cipher: Cipher, ciphertext: string, key: WordArray, cfg?: C): WordArray + } + + interface SerializableCipher extends ISerializableCipher{} + interface ISerializableCipherCfg{ + format?: format.IFormatter //default OpenSSLFormatter + } + + interface IPasswordBasedCipher extends Base{ + cfg: C + encrypt(cipher: Cipher, message: WordArray, password: string, cfg?: C): CipherParams + encrypt(cipher: Cipher, message: string, password: string, cfg?: C): CipherParams + + decrypt(cipher: Cipher, ciphertext: CipherParamsData, password: string, cfg?: C): WordArray + decrypt(cipher: Cipher, ciphertext: string, password: string, cfg?: C): WordArray + } + + interface PasswordBasedCipher extends IPasswordBasedCipher{} + interface IPasswordBasedCipherCfg extends ISerializableCipherCfg{ + kdf?: kdf.IKdfImpl //default OpenSSLKdf + } + + /** see Cipher._createHelper */ + interface ICipherHelper{ + encrypt(message: WordArray, key: WordArray, cfg?: C): CipherParams + encrypt(message: string, key: WordArray, cfg?: C): CipherParams + encrypt(message: WordArray, password: string, cfg?: C): CipherParams + encrypt(message: string, password: string, cfg?: C): CipherParams + + decrypt(ciphertext: CipherParamsData, key: WordArray, cfg?: C): WordArray + decrypt(ciphertext: string, key: WordArray, cfg?: C): WordArray + decrypt(ciphertext: CipherParamsData, password: string, cfg?: C): WordArray + decrypt(ciphertext: string, password: string, cfg?: C): WordArray + } + + interface CipherHelper extends ICipherHelper{} + interface LibStatic{ + Base: lib.Base + WordArray: lib.WordArray + CipherParams: lib.CipherParams + SerializableCipher: lib.SerializableCipher + PasswordBasedCipher: lib.PasswordBasedCipher + } + } + + module enc{ + interface IEncoder{ + stringify(wordArray: lib.WordArray): string + } + interface IDecoder{ + parse(s: string): lib.WordArray + } + interface ICoder extends IEncoder, IDecoder {} + + interface EncStatic{ + Hex: ICoder + Latin1: ICoder + Utf8: ICoder + Base64: ICoder + Utf16: ICoder + Utf16BE: ICoder + Utf16LE: ICoder + } + } + + module kdf{ + interface KdfStatic{ + OpenSSL: IKdfImpl + } + + interface IKdfImpl{ + execute(password: string, keySize: number, ivSize: number, salt?: lib.WordArray): lib.CipherParams + execute(password: string, keySize: number, ivSize: number, salt?: string): lib.CipherParams + } + } + + module format{ + interface FormatStatic{ + OpenSSL: IFormatter + Hex: IFormatter + } + + interface IFormatter{ + stringify(cipherParams: lib.CipherParamsData): string + parse(s: string): lib.CipherParams + } + } + + module algo{ + interface AlgoStatic{ + AES: algo.AES + DES: algo.DES + TripleDES: algo.TripleDES + + RabbitLegacy: algo.RabbitLegacy + Rabbit: algo.Rabbit + RC4: algo.RC4 + + MD5: algo.MD5 + RIPEMD160: algo.RIPEMD160 + SHA1: algo.SHA1 + SHA256: algo.SHA256 + SHA224: algo.SHA224 + SHA384: algo.SHA384 + SHA512: algo.SHA512 + + SHA3: algo.SHA3 + + HMAC: algo.HMAC + + EvpKDF: algo.EvpKDF + PBKDF2: algo.PBKDF2 + + RC4Drop: algo.RC4Drop + } + + interface IBlockCipherImpl extends lib.BlockCipher{ + encryptBlock(M: number[], offset: number): void + decryptBlock(M: number[], offset: number): void + + createEncryptor(key: lib.WordArray, cfg?: lib.IBlockCipherCfg): IBlockCipherImpl + createDecryptor(key: lib.WordArray, cfg?: lib.IBlockCipherCfg): IBlockCipherImpl + + create(xformMode: number, key: lib.WordArray, cfg?: lib.IBlockCipherCfg): IBlockCipherImpl + } + + interface AES extends IBlockCipherImpl{} + interface DES extends IBlockCipherImpl{} + interface TripleDES extends IBlockCipherImpl{} + + interface RabbitLegacy extends lib.StreamCipher{} + interface Rabbit extends lib.StreamCipher{} + interface RC4 extends lib.StreamCipher{} + + interface MD5 extends lib.Hasher{} + interface RIPEMD160 extends lib.Hasher{} + interface SHA1 extends lib.Hasher{} + interface SHA256 extends lib.Hasher{} + interface SHA224 extends lib.Hasher{} + interface SHA384 extends lib.Hasher{} + interface SHA512 extends lib.Hasher{} + + interface SHA3 extends lib.IHasher{} + interface ISHA3Cfg{ + outputLength?: number //default 512 + } + + interface HMAC extends lib.Base{ + init(hasher: lib.Hasher, key: lib.WordArray): void + init(hasher: lib.Hasher, key: string): void + create(hasher: lib.Hasher, key: lib.WordArray): HMAC + create(hasher: lib.Hasher, key: string): HMAC + + update(messageUpdate: lib.WordArray): HMAC + update(messageUpdate: string): HMAC + + finalize(messageUpdate?: lib.WordArray): lib.WordArray + finalize(messageUpdate?: string): lib.WordArray + } + + interface EvpKDF extends lib.Base{ + cfg: IEvpKDFCfg + init(cfg?: IEvpKDFCfg): void + create(cfg?: IEvpKDFCfg): EvpKDF + compute(password: lib.WordArray, salt: lib.WordArray): lib.WordArray + compute(password: string, salt: lib.WordArray): lib.WordArray + compute(password: lib.WordArray, salt: string): lib.WordArray + compute(password: string, salt: string): lib.WordArray + } + interface IEvpKDFCfg{ + keySize?: number //default 128/32 + hasher?: lib.Hasher //default MD5, or SHA1 with PBKDF2 + iterations?: number //default 1 + } + interface IEvpKDFHelper{ + (password: lib.WordArray, salt: lib.WordArray, cfg?: IEvpKDFCfg): lib.WordArray + (password: string, salt: lib.WordArray, cfg?: IEvpKDFCfg): lib.WordArray + (password: lib.WordArray, salt: string, cfg?: IEvpKDFCfg): lib.WordArray + (password: string, salt: string, cfg?: IEvpKDFCfg): lib.WordArray + } + + interface PBKDF2 extends EvpKDF{} //PBKDF2 is same as EvpKDF + + interface RC4Drop extends RC4, lib.ICipher{} + interface IRC4DropCfg{ + drop?: number //default 192 + } + } + + module mode{ + interface ModeStatic{ + CBC: mode.CBC + CFB: mode.CFB + CTR: mode.CTR + CTRGladman: mode.CTRGladman + ECB: mode.ECB + OFB: mode.OFB + } + + interface IBlockCipherEncryptor extends lib.BlockCipherMode{ + processBlock(words: number[], offset: number): void + } + interface IBlockCipherDecryptor extends lib.BlockCipherMode{ //exactly as IBlockCipherEncryptor + processBlock(words: number[], offset: number): void + } + interface IBlockCipherModeImpl extends lib.BlockCipherMode{ + Encryptor: IBlockCipherEncryptor + Decryptor: IBlockCipherDecryptor + } + + interface CBC extends IBlockCipherModeImpl{} + interface CFB extends IBlockCipherModeImpl{} + interface CTR extends IBlockCipherModeImpl{} + interface CTRGladman extends IBlockCipherModeImpl{} + interface ECB extends IBlockCipherModeImpl{} + interface OFB extends IBlockCipherModeImpl{} + } + + module pad{ + interface PadStatic{ + Pkcs7: pad.Pkcs7 + AnsiX923: pad.AnsiX923 + Iso10126: pad.Iso10126 + Iso97971: pad.Iso97971 + ZeroPadding: pad.ZeroPadding + NoPadding: pad.NoPadding + } + + interface IPaddingImpl{ + pad(data: lib.WordArray, blockSize: number): void + unpad(data: lib.WordArray): void + } + + interface Pkcs7 extends IPaddingImpl{} + interface AnsiX923 extends IPaddingImpl{} + interface Iso10126 extends IPaddingImpl{} + interface Iso97971 extends IPaddingImpl{} + interface ZeroPadding extends IPaddingImpl{} + interface NoPadding extends IPaddingImpl{} + } + + module x64{ + interface X64Static{ + Word: x64.Word + WordArray: x64.WordArray + } + + interface Word extends lib.Base{ + high: number + low: number + + init(high: number, low: number): void + create(high: number, low: number): Word + } + + interface WordArray extends lib.Base{ + words: Word[] + sigBytes: number + + init(words?: Word[], sigBytes?: number): void + create(words?: Word[], sigBytes?: number): WordArray + toX32(): lib.WordArray + clone(): WordArray + } + } + + interface CryptoJSStatic{ + lib: lib.LibStatic + enc: enc.EncStatic + kdf: kdf.KdfStatic + format: format.FormatStatic + algo: algo.AlgoStatic + mode: mode.ModeStatic + pad: pad.PadStatic + x64: x64.X64Static + + AES: CryptoJS.lib.ICipherHelper + DES: CryptoJS.lib.ICipherHelper + TripleDES: CryptoJS.lib.ICipherHelper + + RabbitLegacy: CryptoJS.lib.CipherHelper + Rabbit: CryptoJS.lib.CipherHelper + RC4: CryptoJS.lib.CipherHelper + RC4Drop: CryptoJS.lib.ICipherHelper + + MD5: CryptoJS.lib.HasherHelper + HmacMD5: CryptoJS.lib.IHasherHmacHelper + RIPEMD160: CryptoJS.lib.HasherHelper + HmacRIPEMD160: CryptoJS.lib.IHasherHmacHelper + SHA1: CryptoJS.lib.HasherHelper + HmacSHA1: CryptoJS.lib.IHasherHmacHelper + SHA256: CryptoJS.lib.HasherHelper + HmacSHA256: CryptoJS.lib.IHasherHmacHelper + SHA224: CryptoJS.lib.HasherHelper + HmacSHA224: CryptoJS.lib.IHasherHmacHelper + SHA512: CryptoJS.lib.HasherHelper + HmacSHA512: CryptoJS.lib.IHasherHmacHelper + SHA384: CryptoJS.lib.HasherHelper + HmacSHA384: CryptoJS.lib.IHasherHmacHelper + + SHA3: CryptoJS.lib.IHasherHelper + HmacSHA3: CryptoJS.lib.IHasherHmacHelper + + EvpKDF: CryptoJS.algo.IEvpKDFHelper + PBKDF2: CryptoJS.algo.IEvpKDFHelper //PBKDF2 is same as EvpKDF + } +} diff --git a/cryptojs/test/aes-profile-tests.ts b/cryptojs/test/aes-profile-tests.ts new file mode 100644 index 000000000..2e9df8ceb --- /dev/null +++ b/cryptojs/test/aes-profile-tests.ts @@ -0,0 +1,37 @@ +/// +/// + +YUI.add('algo-aes-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'AES', + + setUp: function () { + this.data = { + key: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), + iv: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f') + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv }).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var aes = C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv }); + for (var i = 0; i < 500; i++) { + aes.process('12345678901234567890123456789012345678901234567890') + ''; + } + aes.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/aes-profile-tests.ts.tscparams b/cryptojs/test/aes-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/aes-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/aes-tests.ts b/cryptojs/test/aes-tests.ts new file mode 100644 index 000000000..eaef25447 --- /dev/null +++ b/cryptojs/test/aes-tests.ts @@ -0,0 +1,83 @@ +/// +/// + +YUI.add('algo-aes-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'AES', + + testEncryptKeySize128: function () { + Y.Assert.areEqual('69c4e0d86a7b0430d8cdb78070b4c55a', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncryptKeySize192: function () { + Y.Assert.areEqual('dda97ca4864cdfe06eaf70a0ec0d7191', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncryptKeySize256: function () { + Y.Assert.areEqual('8ea2b7ca516745bfeafc49904b496089', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testDecryptKeySize128: function () { + Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('69c4e0d86a7b0430d8cdb78070b4c55a') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecryptKeySize192: function () { + Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('dda97ca4864cdfe06eaf70a0ec0d7191') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecryptKeySize256: function () { + Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('8ea2b7ca516745bfeafc49904b496089') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testMultiPart: function () { + var aes = C.algo.AES.createEncryptor(C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'), { mode: C.mode.ECB, padding: C.pad.NoPadding }); + var ciphertext1 = aes.process(C.enc.Hex.parse('001122334455')); + var ciphertext2 = aes.process(C.enc.Hex.parse('66778899aa')); + var ciphertext3 = aes.process(C.enc.Hex.parse('bbccddeeff')); + var ciphertext4 = aes.finalize(); + + Y.Assert.areEqual('69c4e0d86a7b0430d8cdb78070b4c55a', ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('00112233445566778899aabbccddeeff'); + var key = C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'); + var iv = C.enc.Hex.parse('101112131415161718191a1b1c1d1e1f'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + var expectedIv = iv.toString(); + + C.AES.encrypt(message, key, { iv: iv }); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + Y.Assert.areEqual(expectedIv, iv.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.AES.createEncryptor(C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).finalize('Hi There').toString(), C.AES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.AES, 'Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.AES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.AES.encrypt('Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/aes-tests.ts.tscparams b/cryptojs/test/aes-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/aes-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/des-profile-tests.ts b/cryptojs/test/des-profile-tests.ts new file mode 100644 index 000000000..edc9321fc --- /dev/null +++ b/cryptojs/test/des-profile-tests.ts @@ -0,0 +1,37 @@ +/// +/// + +YUI.add('algo-des-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'DES', + + setUp: function () { + this.data = { + key: C.enc.Hex.parse('0001020304050607'), + iv: C.enc.Hex.parse('08090a0b0c0d0e0f') + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 100; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.DES.createEncryptor(this.data.key, { iv: this.data.iv }).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var des = C.algo.DES.createEncryptor(this.data.key, { iv: this.data.iv }); + for (var i = 0; i < 100; i++) { + des.process('12345678901234567890123456789012345678901234567890') + ''; + } + des.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/des-profile-tests.ts.tscparams b/cryptojs/test/des-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/des-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/des-tests.ts b/cryptojs/test/des-tests.ts new file mode 100644 index 000000000..5e18608e0 --- /dev/null +++ b/cryptojs/test/des-tests.ts @@ -0,0 +1,107 @@ +/// +/// + +YUI.add('algo-des-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'DES', + + testEncrypt1: function () { + Y.Assert.areEqual('95a8d72813daa94d', C.DES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('8000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt2: function () { + Y.Assert.areEqual('1de5279dae3bed6f', C.DES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('0000000000002000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt3: function () { + Y.Assert.areEqual('1d1ca853ae7c0c5f', C.DES.encrypt(C.enc.Hex.parse('0000000000002000'), C.enc.Hex.parse('0000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt4: function () { + Y.Assert.areEqual('ac978c247863388f', C.DES.encrypt(C.enc.Hex.parse('3232323232323232'), C.enc.Hex.parse('3232323232323232'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt5: function () { + Y.Assert.areEqual('3af1703d76442789', C.DES.encrypt(C.enc.Hex.parse('6464646464646464'), C.enc.Hex.parse('6464646464646464'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt6: function () { + Y.Assert.areEqual('a020003c5554f34c', C.DES.encrypt(C.enc.Hex.parse('9696969696969696'), C.enc.Hex.parse('9696969696969696'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testDecrypt1: function () { + Y.Assert.areEqual('0000000000000000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('95a8d72813daa94d') }), C.enc.Hex.parse('8000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt2: function () { + Y.Assert.areEqual('0000000000000000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('1de5279dae3bed6f') }), C.enc.Hex.parse('0000000000002000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt3: function () { + Y.Assert.areEqual('0000000000002000', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('1d1ca853ae7c0c5f') }), C.enc.Hex.parse('0000000000000000'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt4: function () { + Y.Assert.areEqual('3232323232323232', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('ac978c247863388f') }), C.enc.Hex.parse('3232323232323232'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt5: function () { + Y.Assert.areEqual('6464646464646464', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('3af1703d76442789') }), C.enc.Hex.parse('6464646464646464'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt6: function () { + Y.Assert.areEqual('9696969696969696', C.DES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('a020003c5554f34c') }), C.enc.Hex.parse('9696969696969696'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testMultiPart: function () { + var des = C.algo.DES.createEncryptor(C.enc.Hex.parse('0123456789abcdef'), { mode: C.mode.ECB, padding: C.pad.NoPadding }); + var ciphertext1 = des.process(C.enc.Hex.parse('001122334455')); + var ciphertext2 = des.process(C.enc.Hex.parse('66778899aa')); + var ciphertext3 = des.process(C.enc.Hex.parse('bbccddeeff')); + var ciphertext4 = des.finalize(); + + Y.Assert.areEqual(C.DES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('0123456789abcdef'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString(), ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('00112233445566778899aabbccddeeff'); + var key = C.enc.Hex.parse('0001020304050607'); + var iv = C.enc.Hex.parse('08090a0b0c0d0e0f'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + var expectedIv = iv.toString(); + + C.DES.encrypt(message, key, { iv: iv }); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + Y.Assert.areEqual(expectedIv, iv.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.DES.createEncryptor(C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).finalize('Hi There').toString(), C.DES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.DES, 'Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.DES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.DES, 'Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.DES.encrypt('Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/des-tests.ts.tscparams b/cryptojs/test/des-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/des-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/enc-base64-tests.ts b/cryptojs/test/enc-base64-tests.ts new file mode 100644 index 000000000..87bfd5776 --- /dev/null +++ b/cryptojs/test/enc-base64-tests.ts @@ -0,0 +1,74 @@ +/// +/// + +YUI.add('enc-base64-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Base64', + + testStringify0: function () { + Y.Assert.areEqual('', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 0))); + }, + + testStringify1: function () { + Y.Assert.areEqual('Zg==', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 1))); + }, + + testStringify2: function () { + Y.Assert.areEqual('Zm8=', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 2))); + }, + + testStringify3: function () { + Y.Assert.areEqual('Zm9v', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 3))); + }, + + testStringify4: function () { + Y.Assert.areEqual('Zm9vYg==', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 4))); + }, + + testStringify5: function () { + Y.Assert.areEqual('Zm9vYmE=', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 5))); + }, + + testStringify6: function () { + Y.Assert.areEqual('Zm9vYmFy', C.enc.Base64.stringify(C.lib.WordArray.create([0x666f6f62, 0x61720000], 6))); + }, + + testStringify15: function () { + Y.Assert.areEqual('Pj4+Pz8/Pj4+Pz8/PS8r', C.enc.Base64.stringify(C.lib.WordArray.create([0x3e3e3e3f, 0x3f3f3e3e, 0x3e3f3f3f, 0x3d2f2b00], 15))); + }, + + testParse0: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 0).toString(), C.enc.Base64.parse('').toString()); + }, + + testParse1: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 1).toString(), C.enc.Base64.parse('Zg==').toString()); + }, + + testParse2: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 2).toString(), C.enc.Base64.parse('Zm8=').toString()); + }, + + testParse3: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 3).toString(), C.enc.Base64.parse('Zm9v').toString()); + }, + + testParse4: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 4).toString(), C.enc.Base64.parse('Zm9vYg==').toString()); + }, + + testParse5: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 5).toString(), C.enc.Base64.parse('Zm9vYmE=').toString()); + }, + + testParse6: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x666f6f62, 0x61720000], 6).toString(), C.enc.Base64.parse('Zm9vYmFy').toString()); + }, + + testParse15: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x3e3e3e3f, 0x3f3f3e3e, 0x3e3f3f3f, 0x3d2f2b00], 15).toString(), C.enc.Base64.parse('Pj4+Pz8/Pj4+Pz8/PS8r').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/enc-base64-tests.ts.tscparams b/cryptojs/test/enc-base64-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/enc-base64-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/enc-hex-tests.ts b/cryptojs/test/enc-hex-tests.ts new file mode 100644 index 000000000..dc960ba45 --- /dev/null +++ b/cryptojs/test/enc-hex-tests.ts @@ -0,0 +1,18 @@ +/// +/// + +YUI.add('enc-hex-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Hex', + + testStringify: function () { + Y.Assert.areEqual('12345678', C.enc.Hex.stringify(C.lib.WordArray.create([0x12345678]))); + }, + + testParse: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x12345678]).toString(), C.enc.Hex.parse('12345678').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/enc-hex-tests.ts.tscparams b/cryptojs/test/enc-hex-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/enc-hex-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/enc-latin1-tests.ts b/cryptojs/test/enc-latin1-tests.ts new file mode 100644 index 000000000..5e163912e --- /dev/null +++ b/cryptojs/test/enc-latin1-tests.ts @@ -0,0 +1,18 @@ +/// +/// + +YUI.add('enc-latin1-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Latin1', + + testStringify: function () { + Y.Assert.areEqual('\x12\x34\x56\x78', C.enc.Latin1.stringify(C.lib.WordArray.create([0x12345678]))); + }, + + testParse: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x12345678]).toString(), C.enc.Latin1.parse('\x12\x34\x56\x78').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/enc-latin1-tests.ts.tscparams b/cryptojs/test/enc-latin1-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/enc-latin1-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/enc-utf16-tests.ts b/cryptojs/test/enc-utf16-tests.ts new file mode 100644 index 000000000..8191cd72c --- /dev/null +++ b/cryptojs/test/enc-utf16-tests.ts @@ -0,0 +1,58 @@ +/// +/// + +YUI.add('enc-utf16-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Utf16', + + testStringify1: function () { + Y.Assert.areEqual('z', C.enc.Utf16.stringify(C.lib.WordArray.create([0x007a0000], 2))); + }, + + testStringify2: function () { + Y.Assert.areEqual('水', C.enc.Utf16.stringify(C.lib.WordArray.create([0x6c340000], 2))); + }, + + testStringify3: function () { + Y.Assert.areEqual('𐀀', C.enc.Utf16.stringify(C.lib.WordArray.create([0xd800dc00], 4))); + }, + + testStringify4: function () { + Y.Assert.areEqual('𝄞', C.enc.Utf16.stringify(C.lib.WordArray.create([0xd834dd1e], 4))); + }, + + testStringify5: function () { + Y.Assert.areEqual('􏿽', C.enc.Utf16.stringify(C.lib.WordArray.create([0xdbffdffd], 4))); + }, + + testStringifyLE: function () { + Y.Assert.areEqual('􏿽', C.enc.Utf16LE.stringify(C.lib.WordArray.create([0xffdbfddf], 4))); + }, + + testParse1: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x007a0000], 2).toString(), C.enc.Utf16.parse('z').toString()); + }, + + testParse2: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x6c340000], 2).toString(), C.enc.Utf16.parse('水').toString()); + }, + + testParse3: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xd800dc00], 4).toString(), C.enc.Utf16.parse('𐀀').toString()); + }, + + testParse4: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xd834dd1e], 4).toString(), C.enc.Utf16.parse('𝄞').toString()); + }, + + testParse5: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xdbffdffd], 4).toString(), C.enc.Utf16.parse('􏿽').toString()); + }, + + testParseLE: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xffdbfddf], 4).toString(), C.enc.Utf16LE.parse('􏿽').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/enc-utf16-tests.ts.tscparams b/cryptojs/test/enc-utf16-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/enc-utf16-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/enc-utf8-tests.ts b/cryptojs/test/enc-utf8-tests.ts new file mode 100644 index 000000000..7c0a0583c --- /dev/null +++ b/cryptojs/test/enc-utf8-tests.ts @@ -0,0 +1,42 @@ +/// +/// + +YUI.add('enc-utf8-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Utf8', + + testStringify1: function () { + Y.Assert.areEqual('$', C.enc.Utf8.stringify(C.lib.WordArray.create([0x24000000], 1))); + }, + + testStringify2: function () { + Y.Assert.areEqual('¢', C.enc.Utf8.stringify(C.lib.WordArray.create([0xc2a20000], 2))); + }, + + testStringify3: function () { + Y.Assert.areEqual('€', C.enc.Utf8.stringify(C.lib.WordArray.create([0xe282ac00], 3))); + }, + + testStringify4: function () { + Y.Assert.areEqual('𤭢', C.enc.Utf8.stringify(C.lib.WordArray.create([0xf0a4ada2], 4))); + }, + + testParse1: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0x24000000], 1).toString(), C.enc.Utf8.parse('$').toString()); + }, + + testParse2: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xc2a20000], 2).toString(), C.enc.Utf8.parse('¢').toString()); + }, + + testParse3: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xe282ac00], 3).toString(), C.enc.Utf8.parse('€').toString()); + }, + + testParse4: function () { + Y.Assert.areEqual(C.lib.WordArray.create([0xf0a4ada2], 4).toString(), C.enc.Utf8.parse('𤭢').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/enc-utf8-tests.ts.tscparams b/cryptojs/test/enc-utf8-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/enc-utf8-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/evpkdf-profile-tests.ts b/cryptojs/test/evpkdf-profile-tests.ts new file mode 100644 index 000000000..7af922fbf --- /dev/null +++ b/cryptojs/test/evpkdf-profile-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +YUI.add('algo-evpkdf-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'EvpKDF', + + profileKeySize256Iterations20: function () { + C.algo.EvpKDF.create({ keySize: 256/32, iterations: 20 }).compute('password', 'ATHENA.MIT.EDUraeburn'); + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/evpkdf-profile-tests.ts.tscparams b/cryptojs/test/evpkdf-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/evpkdf-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/evpkdf-tests.ts b/cryptojs/test/evpkdf-tests.ts new file mode 100644 index 000000000..d02a304f4 --- /dev/null +++ b/cryptojs/test/evpkdf-tests.ts @@ -0,0 +1,35 @@ +/// +/// + +YUI.add('algo-evpkdf-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'EvpKDF', + + testVector: function () { + Y.Assert.areEqual('fdbdf3419fff98bdb0241390f62a9db35f4aba29d77566377997314ebfc709f20b5ca7b1081f94b1ac12e3c8ba87d05a', C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString()); + }, + + // There are no official test vectors that I could find, and the EVP implementation is short on comments. + // Need to use the C code to generate more test vectors. + // The iteration count in particular needs to be tested. + + testInputIntegrity: function () { + var password = C.lib.WordArray.create([0x12345678]); + var salt = C.lib.WordArray.create([0x12345678]); + + var expectedPassword = password.toString(); + var expectedSalt = salt.toString(); + + C.EvpKDF(password, salt); + + Y.Assert.areEqual(expectedPassword, password.toString()); + Y.Assert.areEqual(expectedSalt, salt.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.EvpKDF.create({ keySize: (256+128)/32 }).compute('password', 'saltsalt').toString(), C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/evpkdf-tests.ts.tscparams b/cryptojs/test/evpkdf-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/evpkdf-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/format-openssl-tests.ts b/cryptojs/test/format-openssl-tests.ts new file mode 100644 index 000000000..3f863bd8d --- /dev/null +++ b/cryptojs/test/format-openssl-tests.ts @@ -0,0 +1,40 @@ +/// +/// + +YUI.add('format-openssl-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'OpenSSLFormatter', + + setUp: function () { + this.data = {}; + + this.data.ciphertext = C.lib.WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]); + this.data.salt = C.lib.WordArray.create([0x01234567, 0x89abcdef]); + }, + + testSaltedToString: function () { + Y.Assert.areEqual(C.enc.Latin1.parse('Salted__').concat(this.data.salt).concat(this.data.ciphertext).toString(C.enc.Base64), C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext, salt: this.data.salt }))); + }, + + testUnsaltedToString: function () { + Y.Assert.areEqual(this.data.ciphertext.toString(C.enc.Base64), C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext }))); + }, + + testSaltedFromString: function () { + var openSSLStr = C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext, salt: this.data.salt })); + var cipherParams = C.format.OpenSSL.parse(openSSLStr); + + Y.Assert.areEqual(this.data.ciphertext.toString(), cipherParams.ciphertext.toString()); + Y.Assert.areEqual(this.data.salt.toString(), cipherParams.salt.toString()); + }, + + testUnsaltedFromString: function () { + var openSSLStr = C.format.OpenSSL.stringify(C.lib.CipherParams.create({ ciphertext: this.data.ciphertext })); + var cipherParams = C.format.OpenSSL.parse(openSSLStr); + + Y.Assert.areEqual(this.data.ciphertext.toString(), cipherParams.ciphertext.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/format-openssl-tests.ts.tscparams b/cryptojs/test/format-openssl-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/format-openssl-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/hmac-profile-tests.ts b/cryptojs/test/hmac-profile-tests.ts new file mode 100644 index 000000000..1d9a1ba75 --- /dev/null +++ b/cryptojs/test/hmac-profile-tests.ts @@ -0,0 +1,36 @@ +/// +/// + +YUI.add('algo-hmac-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'HMAC', + + setUp: function () { + this.data = { + key: C.lib.WordArray.random(128/8) + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.HMAC.create(C.algo.MD5, this.data.key).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var hmac = C.algo.HMAC.create(C.algo.MD5, this.data.key); + for (var i = 0; i < 500; i++) { + hmac.update('12345678901234567890123456789012345678901234567890'); + } + hmac.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/hmac-profile-tests.ts.tscparams b/cryptojs/test/hmac-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/hmac-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/hmac-tests.ts b/cryptojs/test/hmac-tests.ts new file mode 100644 index 000000000..d40f6ce42 --- /dev/null +++ b/cryptojs/test/hmac-tests.ts @@ -0,0 +1,54 @@ +/// +/// + +YUI.add('algo-hmac-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'HMAC', + + testVector1: function () { + Y.Assert.areEqual('9294727a3638bb1c13f48ef8158bfc9d', C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('750c783e6ab0b503eaa86e310a5db738', C.HmacMD5('what do ya want for nothing?', 'Jefe').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('56be34521d144c88dbb8c733f0e8b3f6', C.HmacMD5(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString()); + }, + + testUpdate: function () { + var hmac = C.algo.HMAC.create(C.algo.MD5, C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + hmac.update(C.enc.Hex.parse('dddddddddddddddddddddddddddddddd')); + + Y.Assert.areEqual(C.HmacMD5(C.enc.Hex.parse('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'), C.enc.Hex.parse('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')).toString(), hmac.finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + var key = C.lib.WordArray.create([0x12345678]); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.HmacMD5(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testRespectKeySigBytes: function () { + var key = C.lib.WordArray.random(8); + key.sigBytes = 4; + + var keyClamped = key.clone(); + keyClamped.clamp(); + + Y.Assert.areEqual(CryptoJS.HmacSHA256("Message", keyClamped).toString(), CryptoJS.HmacSHA256("Message", key).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/hmac-tests.ts.tscparams b/cryptojs/test/hmac-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/hmac-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/kdf-openssl-tests.ts b/cryptojs/test/kdf-openssl-tests.ts new file mode 100644 index 000000000..cc353d7e4 --- /dev/null +++ b/cryptojs/test/kdf-openssl-tests.ts @@ -0,0 +1,18 @@ +/// +/// + +YUI.add('kdf-openssl-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'OpenSSLKdf', + + testVector: function () { + var derivedParams = C.kdf.OpenSSL.execute('password', 256/32, 128/32, C.enc.Hex.parse('0a9d8620cf7219f1')); + + Y.Assert.areEqual('50f32e0ec9408e02ff42364a52aac95c3694fc027256c6f488bf84b8e60effcd', derivedParams.key.toString()); + Y.Assert.areEqual('81381e39b94fd692dff7e2239a298cb6', derivedParams.iv.toString()); + Y.Assert.areEqual('0a9d8620cf7219f1', derivedParams.salt.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/kdf-openssl-tests.ts.tscparams b/cryptojs/test/kdf-openssl-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/kdf-openssl-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-base-tests.ts b/cryptojs/test/lib-base-tests.ts new file mode 100644 index 000000000..38467b907 --- /dev/null +++ b/cryptojs/test/lib-base-tests.ts @@ -0,0 +1,89 @@ +/// +/// + +YUI.add('lib-base-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Base', + + setUp: function () { + this.data = {}; + + this.data.overrides = { + init: function (arg: Object) { + this.initFired = true; + this.initArg = arg; + }, + + toString: function () { + } + }; + + this.data.mixins = { + mixinMethod: function () { + } + }; + + this.data.Obj = C.lib.Base.extend(this.data.overrides); + + this.data.Obj.mixIn(this.data.mixins); + + this.data.obj = this.data.Obj.create('argValue'); + + this.data.objClone = this.data.obj.clone(); + }, + + testExtendInheritance: function () { + Y.Assert.areEqual(C.lib.Base.extend, this.data.Obj.extend); + Y.Assert.isFalse(this.data.Obj.hasOwnProperty('extend')); + }, + + testExtendSuper: function () { + Y.Assert.areEqual(C.lib.Base, this.data.Obj.$super); + }, + + testExtendOverrideInit: function () { + Y.Assert.areEqual(this.data.overrides.init, this.data.Obj.init); + Y.Assert.isTrue(this.data.Obj.hasOwnProperty('init')); + }, + + testExtendOverrideToString: function () { + Y.Assert.areEqual(this.data.overrides.toString, this.data.Obj.toString); + Y.Assert.isTrue(this.data.Obj.hasOwnProperty('toString')); + }, + + testCreateInheritanceFromBase: function () { + Y.Assert.areEqual(C.lib.Base.extend, this.data.obj.extend); + Y.Assert.isFalse(this.data.obj.hasOwnProperty('extend')); + }, + + testCreateSuper: function () { + Y.Assert.areEqual(this.data.Obj, this.data.obj.$super); + }, + + testCreateInit: function () { + Y.Assert.isTrue(this.data.obj.initFired); + Y.Assert.areEqual('argValue', this.data.obj.initArg); + }, + + testMixIn: function () { + Y.Assert.areEqual(this.data.mixins.mixinMethod, this.data.Obj.mixinMethod); + Y.Assert.isTrue(this.data.Obj.hasOwnProperty('mixinMethod')); + }, + + testCloneDistinct: function () { + Y.Assert.areNotEqual(this.data.obj, this.data.objClone); + }, + + testCloneCopy: function () { + Y.Assert.areEqual(this.data.obj.initArg, this.data.objClone.initArg); + }, + + testCloneIndependent: function () { + this.data.obj.initArg = 'newValue'; + + Y.Assert.areNotEqual(this.data.obj.initArg, this.data.objClone.initArg); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/lib-base-tests.ts.tscparams b/cryptojs/test/lib-base-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-base-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-cipherparams-tests.ts b/cryptojs/test/lib-cipherparams-tests.ts new file mode 100644 index 000000000..2b87034fa --- /dev/null +++ b/cryptojs/test/lib-cipherparams-tests.ts @@ -0,0 +1,62 @@ +/// +/// + +YUI.add('lib-cipherparams-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'CipherParams', + + setUp: function () { + this.data = {}; + + this.data.ciphertext = C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f'); + this.data.key = C.enc.Hex.parse('101112131415161718191a1b1c1d1e1f'); + this.data.iv = C.enc.Hex.parse('202122232425262728292a2b2c2d2e2f'); + this.data.salt = C.enc.Hex.parse('0123456789abcdef'); + this.data.algorithm = C.algo.AES; + this.data.mode = C.mode.CBC; + this.data.padding = C.pad.Pkcs7; + this.data.blockSize = this.data.algorithm.blockSize; + this.data.formatter = C.format.OpenSSL; + + this.data.cipherParams = C.lib.CipherParams.create({ + ciphertext: this.data.ciphertext, + key: this.data.key, + iv: this.data.iv, + salt: this.data.salt, + algorithm: this.data.algorithm, + mode: this.data.mode, + padding: this.data.padding, + blockSize: this.data.blockSize, + formatter: this.data.formatter + }); + }, + + testInit: function () { + Y.Assert.areEqual(this.data.ciphertext, this.data.cipherParams.ciphertext); + Y.Assert.areEqual(this.data.key, this.data.cipherParams.key); + Y.Assert.areEqual(this.data.iv, this.data.cipherParams.iv); + Y.Assert.areEqual(this.data.salt, this.data.cipherParams.salt); + Y.Assert.areEqual(this.data.algorithm, this.data.cipherParams.algorithm); + Y.Assert.areEqual(this.data.mode, this.data.cipherParams.mode); + Y.Assert.areEqual(this.data.padding, this.data.cipherParams.padding); + Y.Assert.areEqual(this.data.blockSize, this.data.cipherParams.blockSize); + Y.Assert.areEqual(this.data.formatter, this.data.cipherParams.formatter); + }, + + testToString0: function () { + Y.Assert.areEqual(C.format.OpenSSL.stringify(this.data.cipherParams), this.data.cipherParams.toString()); + }, + + testToString1: function () { + var JsonFormatter = { + stringify: function (cipherParams: CryptoJS.lib.CipherParamsData) { + return '{ ct: ' + cipherParams.ciphertext + ', iv: ' + cipherParams.iv + ' }'; + } + }; + + Y.Assert.areEqual(JsonFormatter.stringify(this.data.cipherParams), this.data.cipherParams.toString(JsonFormatter)); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/lib-cipherparams-tests.ts.tscparams b/cryptojs/test/lib-cipherparams-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-cipherparams-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-passwordbasedcipher-tests.ts b/cryptojs/test/lib-passwordbasedcipher-tests.ts new file mode 100644 index 000000000..d18128896 --- /dev/null +++ b/cryptojs/test/lib-passwordbasedcipher-tests.ts @@ -0,0 +1,28 @@ +/// +/// + +YUI.add('lib-passwordbasedcipher-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'PasswordBasedCipher', + + testEncrypt: function () { + // Compute actual + var actual = C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hello, World!', 'password'); + + // Compute expected + var aes = C.algo.AES.createEncryptor(actual.key, { iv: actual.iv }); + var expected = aes.finalize('Hello, World!'); + + Y.Assert.areEqual(expected.toString(), actual.ciphertext.toString()); + }, + + testDecrypt: function () { + var ciphertext = C.lib.PasswordBasedCipher.encrypt(C.algo.AES, 'Hello, World!', 'password'); + var plaintext = C.lib.PasswordBasedCipher.decrypt(C.algo.AES, ciphertext, 'password'); + + Y.Assert.areEqual('Hello, World!', plaintext.toString(C.enc.Utf8)); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/lib-passwordbasedcipher-tests.ts.tscparams b/cryptojs/test/lib-passwordbasedcipher-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-passwordbasedcipher-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-serializablecipher-tests.ts b/cryptojs/test/lib-serializablecipher-tests.ts new file mode 100644 index 000000000..6ea097a34 --- /dev/null +++ b/cryptojs/test/lib-serializablecipher-tests.ts @@ -0,0 +1,54 @@ +/// +/// + +YUI.add('lib-serializablecipher-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SerializableCipher', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]); + this.data.key = C.lib.WordArray.create([0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f]); + this.data.iv = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + }, + + testEncrypt: function () { + // Compute expected + var aes = C.algo.AES.createEncryptor(this.data.key, { iv: this.data.iv }); + var ciphertext = aes.finalize(this.data.message); + var expected = C.lib.CipherParams.create({ + ciphertext: ciphertext, + key: this.data.key, + iv: this.data.iv, + algorithm: C.algo.AES, + mode: aes.cfg.mode, + padding: aes.cfg.padding, + blockSize: aes.blockSize, + formatter: C.format.OpenSSL + }); + + // Compute actual + var actual = C.lib.SerializableCipher.encrypt(C.algo.AES, this.data.message, this.data.key, { iv: this.data.iv }); + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + Y.Assert.areEqual(expected.ciphertext.toString(), actual.ciphertext.toString()); + Y.Assert.areEqual(expected.key.toString(), actual.key.toString()); + Y.Assert.areEqual(expected.iv.toString(), actual.iv.toString()); + Y.Assert.areEqual(expected.algorithm, actual.algorithm); + Y.Assert.areEqual(expected.mode, actual.mode); + Y.Assert.areEqual(expected.padding, actual.padding); + Y.Assert.areEqual(expected.blockSize, actual.blockSize); + }, + + testDecrypt: function () { + var encrypted = C.lib.SerializableCipher.encrypt(C.algo.AES, this.data.message, this.data.key, { iv: this.data.iv }) + ''; + var decrypted = C.lib.SerializableCipher.decrypt(C.algo.AES, encrypted, this.data.key, { iv: this.data.iv }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/lib-serializablecipher-tests.ts.tscparams b/cryptojs/test/lib-serializablecipher-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-serializablecipher-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-typedarrays-tests.ts b/cryptojs/test/lib-typedarrays-tests.ts new file mode 100644 index 000000000..beb3d667a --- /dev/null +++ b/cryptojs/test/lib-typedarrays-tests.ts @@ -0,0 +1,62 @@ +/// +/// + +YUI.add('lib-wordarray-test', function (Y) { + var C = CryptoJS; + + if (typeof ArrayBuffer != 'undefined') { + Y.Test.Runner.add(new Y.Test.Case({ + name: 'TypedArrays', + + setUp: function () { + this.data = {}; + + this.data.buffer = new ArrayBuffer(8); + + var uint8View = new Uint8Array(this.data.buffer); + uint8View[0] = 0x01; + uint8View[1] = 0x23; + uint8View[2] = 0x45; + uint8View[3] = 0x67; + uint8View[4] = 0x89; + uint8View[5] = 0xab; + uint8View[6] = 0xcd; + uint8View[7] = 0xef; + }, + + testInt8Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int8Array(this.data.buffer)).toString()); + }, + + testUint8Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint8Array(this.data.buffer)).toString()); + }, + + testUint8ClampedArray: function () { + //Note also: Uint8ClampedArray is not defined in lib.d.ts & not supported in IE + //@see http://compatibility.shwups-cms.ch/en/home?&property=Uint8ClampedArray +// Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint8ClampedArray(this.data.buffer)).toString()); + }, + + testInt16Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int16Array(this.data.buffer)).toString()); + }, + + testUint16Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint16Array(this.data.buffer)).toString()); + }, + + testInt32Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Int32Array(this.data.buffer)).toString()); + }, + + testUint32Array: function () { + Y.Assert.areEqual('0123456789abcdef', C.lib.WordArray.create(new Uint32Array(this.data.buffer)).toString()); + }, + + testPartialView: function () { + Y.Assert.areEqual('456789ab', C.lib.WordArray.create(new Int16Array(this.data.buffer, 2, 2)).toString()); + } + })); + } +}, '$Rev$'); diff --git a/cryptojs/test/lib-typedarrays-tests.ts.tscparams b/cryptojs/test/lib-typedarrays-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-typedarrays-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/lib-wordarray-tests.ts b/cryptojs/test/lib-wordarray-tests.ts new file mode 100644 index 000000000..0f210aa66 --- /dev/null +++ b/cryptojs/test/lib-wordarray-tests.ts @@ -0,0 +1,88 @@ +/// +/// + +YUI.add('lib-wordarray-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'WordArray', + + testInit0: function () { + Y.Assert.areEqual('', C.lib.WordArray.create().toString()); + }, + + testInit1: function () { + Y.Assert.areEqual('12345678', C.lib.WordArray.create([0x12345678]).toString()); + }, + + testInit2: function () { + Y.Assert.areEqual('1234', C.lib.WordArray.create([0x12345678], 2).toString()); + }, + + testToStringPassedEncoder: function () { + Y.Assert.areEqual('\x12\x34\x56\x78', C.lib.WordArray.create([0x12345678]).toString(C.enc.Latin1)); + }, + + testToStringDefaultEncoder: function () { + Y.Assert.areEqual('12345678', C.lib.WordArray.create([0x12345678]).toString()); + }, + + testConcat3: function () { + var wordArray1 = C.lib.WordArray.create([0x12345678], 3); + var wordArray2 = C.lib.WordArray.create([0x12345678], 3); + + Y.Assert.areEqual('123456123456', wordArray1.concat(wordArray2).toString()); + Y.Assert.areEqual('123456123456', wordArray1.toString()); + }, + + testConcat4: function () { + var wordArray1 = C.lib.WordArray.create([0x12345678], 4); + var wordArray2 = C.lib.WordArray.create([0x12345678], 3); + + Y.Assert.areEqual('12345678123456', wordArray1.concat(wordArray2).toString()); + Y.Assert.areEqual('12345678123456', wordArray1.toString()); + }, + + testConcat5: function () { + var wordArray1 = C.lib.WordArray.create([0x12345678], 5); + var wordArray2 = C.lib.WordArray.create([0x12345678], 3); + + Y.Assert.areEqual('1234567800123456', wordArray1.concat(wordArray2).toString()); + Y.Assert.areEqual('1234567800123456', wordArray1.toString()); + }, + + testConcatLong: function () { + var wordArray1 = C.lib.WordArray.create(); + + var wordArray2 = C.lib.WordArray.create(); + var wordArray3 = C.lib.WordArray.create(); + for (var i = 0; i < 500000; i++) { + wordArray2.words[i] = i; + wordArray3.words[i] = i; + } + wordArray2.sigBytes = wordArray3.sigBytes = 500000; + + Y.Assert.areEqual(wordArray2.toString() + wordArray3.toString(), wordArray1.concat(wordArray2.concat(wordArray3)).toString()); + }, + + testClamp: function () { + var wordArray = C.lib.WordArray.create([0x12345678, 0x12345678], 3); + wordArray.clamp(); + + Y.Assert.areEqual([0x12345600].toString(), wordArray.words.toString()); + }, + + testClone: function () { + var wordArray = C.lib.WordArray.create([0x12345678]); + var clone = wordArray.clone(); + clone.words[0] = 0; + + Y.Assert.areNotEqual(wordArray.toString(), clone.toString()); + }, + + testRandom: function () { + Y.Assert.areNotEqual(C.lib.WordArray.random(8).toString(), C.lib.WordArray.random(8).toString()); + Y.Assert.areEqual(8, C.lib.WordArray.random(8).sigBytes); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/lib-wordarray-tests.ts.tscparams b/cryptojs/test/lib-wordarray-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/lib-wordarray-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/md5-profile-tests.ts b/cryptojs/test/md5-profile-tests.ts new file mode 100644 index 000000000..c51c735b5 --- /dev/null +++ b/cryptojs/test/md5-profile-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +YUI.add('algo-md5-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'MD5', + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.MD5.create().finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var md5 = C.algo.MD5.create(); + for (var i = 0; i < 500; i++) { + md5.update('12345678901234567890123456789012345678901234567890'); + } + md5.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/md5-profile-tests.ts.tscparams b/cryptojs/test/md5-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/md5-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/md5-tests.ts b/cryptojs/test/md5-tests.ts new file mode 100644 index 000000000..71056d1b6 --- /dev/null +++ b/cryptojs/test/md5-tests.ts @@ -0,0 +1,73 @@ +/// +/// + +YUI.add('algo-md5-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'MD5', + + testVector1: function () { + Y.Assert.areEqual('d41d8cd98f00b204e9800998ecf8427e', C.MD5('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('0cc175b9c0f1b6a831c399e269772661', C.MD5('a').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('900150983cd24fb0d6963f7d28e17f72', C.MD5('abc').toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('f96b697d7cb7938d525a2f31aaf161d0', C.MD5('message digest').toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('c3fcd3d76192e4007dfb496cca67e13b', C.MD5('abcdefghijklmnopqrstuvwxyz').toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('d174ab98d277d9f5a5611c2c9f419d9f', C.MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').toString()); + }, + + testVector7: function () { + Y.Assert.areEqual('57edf4a22be3c955ac49da2e2107b67a', C.MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890').toString()); + }, + + testUpdateAndLongMessage: function () { + var md5 = C.algo.MD5.create(); + for (var i = 0; i < 100; i++) { + md5.update('12345678901234567890123456789012345678901234567890'); + } + + Y.Assert.areEqual('7d017545e0268a6a12f2b507871d0429', md5.finalize().toString()); + }, + + testClone: function () { + var md5 = C.algo.MD5.create(); + + Y.Assert.areEqual(C.MD5('a').toString(), md5.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.MD5('ab').toString(), md5.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.MD5('abc').toString(), md5.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.MD5(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.MD5.create().finalize('').toString(), C.MD5('').toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.MD5, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacMD5('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/md5-tests.ts.tscparams b/cryptojs/test/md5-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/md5-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/mode-cbc-tests.ts b/cryptojs/test/mode-cbc-tests.ts new file mode 100644 index 000000000..cb6b4e18c --- /dev/null +++ b/cryptojs/test/mode-cbc-tests.ts @@ -0,0 +1,52 @@ +/// +/// + +YUI.add('mode-cbc-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'CBC', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([ + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f + ]); + this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]); + }, + + testEncryptor: function () { + // Compute expected + var expected = this.data.message.clone(); + var aes = C.algo.AES.createEncryptor(this.data.key); + + // First block XORed with IV, then encrypted + for (var i = 0; i < 4; i++) { + expected.words[i] ^= this.data.iv.words[i]; + } + aes.encryptBlock(expected.words, 0); + + // Subsequent blocks XORed with previous crypted block, then encrypted + for (var i = 4; i < 8; i++) { + expected.words[i] ^= expected.words[i - 4]; + } + aes.encryptBlock(expected.words, 4); + + // Compute actual + var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding }).ciphertext; + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + }, + + testDecryptor: function () { + var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding }); + var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.CBC, padding: C.pad.NoPadding }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/mode-cbc-tests.ts.tscparams b/cryptojs/test/mode-cbc-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/mode-cbc-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/mode-cfb-tests.ts b/cryptojs/test/mode-cfb-tests.ts new file mode 100644 index 000000000..8727946ba --- /dev/null +++ b/cryptojs/test/mode-cfb-tests.ts @@ -0,0 +1,54 @@ +/// +/// + +YUI.add('mode-cfb-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'CFB', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([ + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f + ]); + this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]); + }, + + testEncryptor: function () { + // Compute expected + var expected = this.data.message.clone(); + var aes = C.algo.AES.createEncryptor(this.data.key); + + // First block XORed with encrypted IV + var keystream = this.data.iv.words.slice(0); + aes.encryptBlock(keystream, 0); + for (var i = 0; i < 4; i++) { + expected.words[i] ^= keystream[i]; + } + + // Subsequent blocks XORed with encrypted previous crypted block + var keystream = expected.words.slice(0, 4); + aes.encryptBlock(keystream, 0); + for (var i = 4; i < 8; i++) { + expected.words[i] ^= keystream[i % 4]; + } + + // Compute actual + var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding }).ciphertext; + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + }, + + testDecryptor: function () { + var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding }); + var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.CFB, padding: C.pad.NoPadding }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/mode-cfb-tests.ts.tscparams b/cryptojs/test/mode-cfb-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/mode-cfb-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/mode-ctr-tests.ts b/cryptojs/test/mode-ctr-tests.ts new file mode 100644 index 000000000..a9ca0ddbb --- /dev/null +++ b/cryptojs/test/mode-ctr-tests.ts @@ -0,0 +1,58 @@ +/// +/// + +YUI.add('mode-ctr-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'CTR', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([ + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f + ]); + this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]); + }, + + testEncryptor: function () { + // Compute expected + var expected = this.data.message.clone(); + var aes = C.algo.AES.createEncryptor(this.data.key); + + // Counter initialized with IV + var counter = this.data.iv.words.slice(0); + + // First block XORed with encrypted counter + var keystream = counter.slice(0); + aes.encryptBlock(keystream, 0); + for (var i = 0; i < 4; i++) { + expected.words[i] ^= keystream[i]; + } + + // Subsequent blocks XORed with encrypted incremented counter + counter[3]++; + var keystream = counter.slice(0); + aes.encryptBlock(keystream, 0); + for (var i = 4; i < 8; i++) { + expected.words[i] ^= keystream[i % 4]; + } + + // Compute actual + var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CTR, padding: C.pad.NoPadding }).ciphertext; + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + }, + + testDecryptor: function () { + var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.CTR, padding: C.pad.NoPadding }); + var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.CTR, padding: C.pad.NoPadding }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/mode-ctr-tests.ts.tscparams b/cryptojs/test/mode-ctr-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/mode-ctr-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/mode-ecb-tests.ts b/cryptojs/test/mode-ecb-tests.ts new file mode 100644 index 000000000..249c2b6d2 --- /dev/null +++ b/cryptojs/test/mode-ecb-tests.ts @@ -0,0 +1,41 @@ +/// +/// + +YUI.add('mode-ecb-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'ECB', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([ + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f + ]); + this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + }, + + testEncryptor: function () { + // Compute expected + var expected = this.data.message.clone(); + var aes = C.algo.AES.createEncryptor(this.data.key); + aes.encryptBlock(expected.words, 0); + aes.encryptBlock(expected.words, 4); + + // Compute actual + var actual = C.AES.encrypt(this.data.message, this.data.key, { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext; + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + }, + + testDecryptor: function () { + var encrypted = C.AES.encrypt(this.data.message, this.data.key, { mode: C.mode.ECB, padding: C.pad.NoPadding }); + var decrypted = C.AES.decrypt(encrypted, this.data.key, { mode: C.mode.ECB, padding: C.pad.NoPadding }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/mode-ecb-tests.ts.tscparams b/cryptojs/test/mode-ecb-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/mode-ecb-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/mode-ofb-tests.ts b/cryptojs/test/mode-ofb-tests.ts new file mode 100644 index 000000000..89aa36c68 --- /dev/null +++ b/cryptojs/test/mode-ofb-tests.ts @@ -0,0 +1,53 @@ +/// +/// + +YUI.add('mode-ofb-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'OFB', + + setUp: function () { + this.data = {}; + + this.data.message = C.lib.WordArray.create([ + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f + ]); + this.data.key = C.lib.WordArray.create([0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f]); + this.data.iv = C.lib.WordArray.create([0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f]); + }, + + testEncryptor: function () { + // Compute expected + var expected = this.data.message.clone(); + var aes = C.algo.AES.createEncryptor(this.data.key); + + // First block XORed with encrypted IV + var keystream = this.data.iv.words.slice(0); + aes.encryptBlock(keystream, 0); + for (var i = 0; i < 4; i++) { + expected.words[i] ^= keystream[i]; + } + + // Subsequent blocks XORed with encrypted previous keystream + aes.encryptBlock(keystream, 0); + for (var i = 4; i < 8; i++) { + expected.words[i] ^= keystream[i % 4]; + } + + // Compute actual + var actual = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.OFB, padding: C.pad.NoPadding }).ciphertext; + + // Test + Y.Assert.areEqual(expected.toString(), actual.toString()); + }, + + testDecryptor: function () { + var encrypted = C.AES.encrypt(this.data.message, this.data.key, { iv: this.data.iv, mode: C.mode.OFB, padding: C.pad.NoPadding }); + var decrypted = C.AES.decrypt(encrypted, this.data.key, { iv: this.data.iv, mode: C.mode.OFB, padding: C.pad.NoPadding }); + + Y.Assert.areEqual(this.data.message.toString(), decrypted.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/mode-ofb-tests.ts.tscparams b/cryptojs/test/mode-ofb-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/mode-ofb-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pad-ansix923-tests.ts b/cryptojs/test/pad-ansix923-tests.ts new file mode 100644 index 000000000..6b610728c --- /dev/null +++ b/cryptojs/test/pad-ansix923-tests.ts @@ -0,0 +1,31 @@ +/// +/// + +YUI.add('pad-ansix923-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'AnsiX923', + + testPad: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.AnsiX923.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00, 0x00000005]).toString(), data.toString()); + }, + + testPadClamp: function () { + var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3); + C.pad.AnsiX923.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00, 0x00000005]).toString(), data.toString()); + }, + + testUnpad: function () { + var data = C.lib.WordArray.create([0xdddddd00, 0x00000005]); + C.pad.AnsiX923.unpad(data); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pad-ansix923-tests.ts.tscparams b/cryptojs/test/pad-ansix923-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pad-ansix923-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pad-iso10126-tests.ts b/cryptojs/test/pad-iso10126-tests.ts new file mode 100644 index 000000000..de46f7d81 --- /dev/null +++ b/cryptojs/test/pad-iso10126-tests.ts @@ -0,0 +1,53 @@ +/// +/// + +YUI.add('pad-iso10126-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Iso10126', + + setUp: function () { + this.data = {}; + + // Save original random method + this.data.random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + }, + + tearDown: function () { + // Restore random method + C.lib.WordArray.random = this.data.random; + }, + + testPad: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.Iso10126.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd11, 0x22334405]).toString(), data.toString()); + }, + + testPadClamp: function () { + var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3); + C.pad.Iso10126.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd11, 0x22334405]).toString(), data.toString()); + }, + + testUnpad: function () { + var data = C.lib.WordArray.create([0xdddddd11, 0x22334405]); + C.pad.Iso10126.unpad(data); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pad-iso10126-tests.ts.tscparams b/cryptojs/test/pad-iso10126-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pad-iso10126-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pad-iso97971-tests.ts b/cryptojs/test/pad-iso97971-tests.ts new file mode 100644 index 000000000..29f1ef6af --- /dev/null +++ b/cryptojs/test/pad-iso97971-tests.ts @@ -0,0 +1,38 @@ +/// +/// + +YUI.add('pad-iso97971-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Iso97971', + + testPad1: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.Iso97971.pad(data, 1); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd80]).toString(), data.toString()); + }, + + testPad2: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.Iso97971.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd80, 0x00000000]).toString(), data.toString()); + }, + + testPadClamp: function () { + var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3); + C.pad.Iso97971.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd80, 0x00000000]).toString(), data.toString()); + }, + + testUnpad: function () { + var data = C.lib.WordArray.create([0xdddddd80, 0x00000000]); + C.pad.Iso97971.unpad(data); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pad-iso97971-tests.ts.tscparams b/cryptojs/test/pad-iso97971-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pad-iso97971-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pad-pkcs7-tests.ts b/cryptojs/test/pad-pkcs7-tests.ts new file mode 100644 index 000000000..b56381daf --- /dev/null +++ b/cryptojs/test/pad-pkcs7-tests.ts @@ -0,0 +1,31 @@ +/// +/// + +YUI.add('pad-pkcs7-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Pkcs7', + + testPad: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.Pkcs7.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd05, 0x05050505]).toString(), data.toString()); + }, + + testPadClamp: function () { + var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3); + C.pad.Pkcs7.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd05, 0x05050505]).toString(), data.toString()); + }, + + testUnpad: function () { + var data = C.lib.WordArray.create([0xdddddd05, 0x05050505]); + C.pad.Pkcs7.unpad(data); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pad-pkcs7-tests.ts.tscparams b/cryptojs/test/pad-pkcs7-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pad-pkcs7-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pad-zeropadding-tests.ts b/cryptojs/test/pad-zeropadding-tests.ts new file mode 100644 index 000000000..f2fdfe8f4 --- /dev/null +++ b/cryptojs/test/pad-zeropadding-tests.ts @@ -0,0 +1,31 @@ +/// +/// + +YUI.add('pad-zeropadding-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'ZeroPadding', + + testPad: function () { + var data = C.lib.WordArray.create([0xdddddd00], 3); + C.pad.ZeroPadding.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00, 0x00000000]).toString(), data.toString()); + }, + + testPadClamp: function () { + var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3); + C.pad.ZeroPadding.pad(data, 2); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00, 0x00000000]).toString(), data.toString()); + }, + + testUnpad: function () { + var data = C.lib.WordArray.create([0xdddddd00, 0x00000000]); + C.pad.ZeroPadding.unpad(data); + + Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pad-zeropadding-tests.ts.tscparams b/cryptojs/test/pad-zeropadding-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pad-zeropadding-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pbkdf2-profile-tests.ts b/cryptojs/test/pbkdf2-profile-tests.ts new file mode 100644 index 000000000..adb684c36 --- /dev/null +++ b/cryptojs/test/pbkdf2-profile-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +YUI.add('algo-pbkdf2-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'PBKDF2', + + profileKeySize256Iterations20: function () { + C.algo.PBKDF2.create({ keySize: 256/32, iterations: 20 }).compute('password', 'ATHENA.MIT.EDUraeburn'); + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/pbkdf2-profile-tests.ts.tscparams b/cryptojs/test/pbkdf2-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pbkdf2-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/pbkdf2-tests.ts b/cryptojs/test/pbkdf2-tests.ts new file mode 100644 index 000000000..0b7cf411f --- /dev/null +++ b/cryptojs/test/pbkdf2-tests.ts @@ -0,0 +1,83 @@ +/// +/// + +YUI.add('algo-pbkdf2-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'PBKDF2', + + testKeySize128: function () { + Y.Assert.areEqual('cdedb5281bb2f801565a1122b2563515', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128/32 }).toString()); + }, + + testKeySize256: function () { + Y.Assert.areEqual('cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256/32 }).toString()); + }, + + testKeySize128Iterations2: function () { + Y.Assert.areEqual('01dbee7f4a9e243e988b62c73cda935d', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128/32, iterations: 2 }).toString()); + }, + + testKeySize256Iterations2: function () { + Y.Assert.areEqual('01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256/32, iterations: 2 }).toString()); + }, + + testKeySize128Iterations1200: function () { + Y.Assert.areEqual('5c08eb61fdf71e4e4ec3cf6ba1f5512b', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128/32, iterations: 1200 }).toString()); + }, + + testKeySize256Iterations1200: function () { + Y.Assert.areEqual('5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13', C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256/32, iterations: 1200 }).toString()); + }, + + testKeySize128Iterations5: function () { + Y.Assert.areEqual('d1daa78615f287e6a1c8b120d7062a49', C.PBKDF2('password', C.enc.Hex.parse('1234567878563412'), { keySize: 128/32, iterations: 5 }).toString()); + }, + + testKeySize256Iterations5: function () { + Y.Assert.areEqual('d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee', C.PBKDF2('password', C.enc.Hex.parse('1234567878563412'), { keySize: 256/32, iterations: 5 }).toString()); + }, + + testKeySize128Iterations1200PassPhraseEqualsBlockSize: function () { + Y.Assert.areEqual('139c30c0966bc32ba55fdbf212530ac9', C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase equals block size', { keySize: 128/32, iterations: 1200 }).toString()); + }, + + testKeySize256Iterations1200PassPhraseEqualsBlockSize: function () { + Y.Assert.areEqual('139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1', C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase equals block size', { keySize: 256/32, iterations: 1200 }).toString()); + }, + + testKeySize128Iterations1200PassPhraseExceedsBlockSize: function () { + Y.Assert.areEqual('9ccad6d468770cd51b10e6a68721be61', C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase exceeds block size', { keySize: 128/32, iterations: 1200 }).toString()); + }, + + testKeySize256Iterations1200PassPhraseExceedsBlockSize: function () { + Y.Assert.areEqual('9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a', C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase exceeds block size', { keySize: 256/32, iterations: 1200 }).toString()); + }, + + testKeySize128Iterations50: function () { + Y.Assert.areEqual('6b9cf26d45455a43a5b8bb276a403b39', C.PBKDF2(C.enc.Hex.parse('f09d849e'), 'EXAMPLE.COMpianist', { keySize: 128/32, iterations: 50 }).toString()); + }, + + testKeySize256Iterations50: function () { + Y.Assert.areEqual('6b9cf26d45455a43a5b8bb276a403b39e7fe37a0c41e02c281ff3069e1e94f52', C.PBKDF2(C.enc.Hex.parse('f09d849e'), 'EXAMPLE.COMpianist', { keySize: 256/32, iterations: 50 }).toString()); + }, + + testInputIntegrity: function () { + var password = C.lib.WordArray.create([0x12345678]); + var salt = C.lib.WordArray.create([0x12345678]); + + var expectedPassword = password.toString(); + var expectedSalt = salt.toString(); + + C.PBKDF2(password, salt); + + Y.Assert.areEqual(expectedPassword, password.toString()); + Y.Assert.areEqual(expectedSalt, salt.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.PBKDF2.create({ keySize: 128/32 }).compute('password', 'ATHENA.MIT.EDUraeburn').toString(), C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128/32 }).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/pbkdf2-tests.ts.tscparams b/cryptojs/test/pbkdf2-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/pbkdf2-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/rabbit-legacy-tests.ts b/cryptojs/test/rabbit-legacy-tests.ts new file mode 100644 index 000000000..658d62b25 --- /dev/null +++ b/cryptojs/test/rabbit-legacy-tests.ts @@ -0,0 +1,83 @@ +/// +/// + +YUI.add('algo-rabbit-legacy-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'RabbitLegacy', + + testVector1: function () { + Y.Assert.areEqual('02f74a1c26456bf5ecd6a536f05457b1', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('00000000000000000000000000000000')).ciphertext.toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('9c51e28784c37fe9a127f63ec8f32d3d', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('dc51c3ac3bfc62f12e3d36fe91281329')).ciphertext.toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('9b60d002fd5ceb32accd41a0cd0db10c', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('c09b0043e9e9ab0187e0c73383957415')).ciphertext.toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('edb70567375dcd7cd89554f85e27a7c6', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('00000000000000000000000000000000'), { iv: C.enc.Hex.parse('0000000000000000') }).ciphertext.toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('6d7d012292ccdce0e2120058b94ecd1f', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('00000000000000000000000000000000'), { iv: C.enc.Hex.parse('597e26c175f573c3') }).ciphertext.toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('4d1051a123afb670bf8d8505c8d85a44', C.RabbitLegacy.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('00000000000000000000000000000000'), { iv: C.enc.Hex.parse('2717f4d21a56eba6') }).ciphertext.toString()); + }, + + testMultiPart: function () { + var rabbit = C.algo.RabbitLegacy.createEncryptor(C.enc.Hex.parse('00000000000000000000000000000000')); + var ciphertext1 = rabbit.process(C.enc.Hex.parse('000000000000')); + var ciphertext2 = rabbit.process(C.enc.Hex.parse('0000000000')); + var ciphertext3 = rabbit.process(C.enc.Hex.parse('0000000000')); + var ciphertext4 = rabbit.finalize(); + + Y.Assert.areEqual('02f74a1c26456bf5ecd6a536f05457b1', ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('00000000000000000000000000000000'); + var key = C.enc.Hex.parse('00000000000000000000000000000000'); + var iv = C.enc.Hex.parse('0000000000000000'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + var expectedIv = iv.toString(); + + C.RabbitLegacy.encrypt(message, key, { iv: iv }); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + Y.Assert.areEqual(expectedIv, iv.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.RabbitLegacy.createEncryptor(C.MD5('Jefe')).finalize('Hi There').toString(), C.RabbitLegacy.encrypt('Hi There', C.MD5('Jefe')).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.RabbitLegacy, 'Hi There', C.MD5('Jefe')).toString(), C.RabbitLegacy.encrypt('Hi There', C.MD5('Jefe')).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.RabbitLegacy, 'Hi There', 'Jefe').toString(), C.RabbitLegacy.encrypt('Hi There', 'Jefe').toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/rabbit-legacy-tests.ts.tscparams b/cryptojs/test/rabbit-legacy-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/rabbit-legacy-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/rabbit-profile-tests.ts b/cryptojs/test/rabbit-profile-tests.ts new file mode 100644 index 000000000..05bdc9a4e --- /dev/null +++ b/cryptojs/test/rabbit-profile-tests.ts @@ -0,0 +1,36 @@ +/// +/// + +YUI.add('algo-rabbit-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'Rabbit', + + setUp: function () { + this.data = { + key: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f') + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.Rabbit.createEncryptor(this.data.key).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var rabbit = C.algo.Rabbit.createEncryptor(this.data.key); + for (var i = 0; i < 500; i++) { + rabbit.process('12345678901234567890123456789012345678901234567890') + ''; + } + rabbit.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/rabbit-profile-tests.ts.tscparams b/cryptojs/test/rabbit-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/rabbit-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/rabbit-tests.ts b/cryptojs/test/rabbit-tests.ts new file mode 100644 index 000000000..e8e0d3e3c --- /dev/null +++ b/cryptojs/test/rabbit-tests.ts @@ -0,0 +1,87 @@ +/// +/// + +YUI.add('algo-rabbit-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'Rabbit', + + testVector1: function () { + Y.Assert.areEqual('02f74a1c26456bf5ecd6a536f05457b1', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('00000000000000000000000000000000')).ciphertext.toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('3d02e0c730559112b473b790dee018df', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('c21fcf3881cd5ee8628accb0a9890df8')).ciphertext.toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('a3a97abb80393820b7e50c4abb53823d', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('1d272c6a2d8e3dfcac14056b78d633a0')).ciphertext.toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('75d186d6bc6905c64f1b2dfdd51f7bfc', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('0053a6f94c9ff24598eb3e91e4378add'), { iv: C.enc.Hex.parse('0d74db42a91077de') }).ciphertext.toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('476e2750c73856c93563b5f546f56a6a', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('0558abfe51a4f74a9df04396e93c8fe2'), { iv: C.enc.Hex.parse('167de44bb21980e7') }).ciphertext.toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('921fcf4983891365a7dc901924b5e24b', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('0a5db00356a9fc4fa2f5489bee4194e7'), { iv: C.enc.Hex.parse('1f86ed54bb2289f0') }).ciphertext.toString()); + }, + + testVector7: function () { + Y.Assert.areEqual('613cb0ba96aff6cacf2a459a102a7f78', C.Rabbit.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('0f62b5085bae0154a7fa4da0f34699ec'), { iv: C.enc.Hex.parse('288ff65dc42b92f9') }).ciphertext.toString()); + }, + + testMultiPart: function () { + var rabbit = C.algo.Rabbit.createEncryptor(C.enc.Hex.parse('00000000000000000000000000000000')); + var ciphertext1 = rabbit.process(C.enc.Hex.parse('000000000000')); + var ciphertext2 = rabbit.process(C.enc.Hex.parse('0000000000')); + var ciphertext3 = rabbit.process(C.enc.Hex.parse('0000000000')); + var ciphertext4 = rabbit.finalize(); + + Y.Assert.areEqual('02f74a1c26456bf5ecd6a536f05457b1', ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('00000000000000000000000000000000'); + var key = C.enc.Hex.parse('00000000000000000000000000000000'); + var iv = C.enc.Hex.parse('0000000000000000'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + var expectedIv = iv.toString(); + + C.Rabbit.encrypt(message, key, { iv: iv }); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + Y.Assert.areEqual(expectedIv, iv.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.Rabbit.createEncryptor(C.MD5('Jefe')).finalize('Hi There').toString(), C.Rabbit.encrypt('Hi There', C.MD5('Jefe')).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.Rabbit, 'Hi There', C.MD5('Jefe')).toString(), C.Rabbit.encrypt('Hi There', C.MD5('Jefe')).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.Rabbit, 'Hi There', 'Jefe').toString(), C.Rabbit.encrypt('Hi There', 'Jefe').toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/rabbit-tests.ts.tscparams b/cryptojs/test/rabbit-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/rabbit-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/rc4-profile-tests.ts b/cryptojs/test/rc4-profile-tests.ts new file mode 100644 index 000000000..6d3145e56 --- /dev/null +++ b/cryptojs/test/rc4-profile-tests.ts @@ -0,0 +1,36 @@ +/// +/// + +YUI.add('algo-rc4-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'RC4', + + setUp: function () { + this.data = { + key: C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f') + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.RC4.createEncryptor(this.data.key).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var rc4 = C.algo.RC4.createEncryptor(this.data.key); + for (var i = 0; i < 500; i++) { + rc4.process('12345678901234567890123456789012345678901234567890') + ''; + } + rc4.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/rc4-profile-tests.ts.tscparams b/cryptojs/test/rc4-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/rc4-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/rc4-tests.ts b/cryptojs/test/rc4-tests.ts new file mode 100644 index 000000000..5a4e5aa6f --- /dev/null +++ b/cryptojs/test/rc4-tests.ts @@ -0,0 +1,71 @@ +/// +/// + +YUI.add('algo-rc4-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'RC4', + + testVector1: function () { + Y.Assert.areEqual('7494c2e7104b0879', C.RC4.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('0123456789abcdef')).ciphertext.toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('f13829c9de', C.RC4.encrypt(C.enc.Hex.parse('dcee4cf92c'), C.enc.Hex.parse('618a63d2fb')).ciphertext.toString()); + }, + + testDrop: function () { + Y.Assert.areEqual( + C.RC4.encrypt(C.enc.Hex.parse('00000000000000000000000000000000'), C.enc.Hex.parse('0123456789abcdef')).ciphertext.toString().substr(16), + C.RC4Drop.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('0123456789abcdef'), { drop: 2 }).ciphertext.toString() + ); + }, + + testMultiPart: function () { + var rc4 = C.algo.RC4.createEncryptor(C.enc.Hex.parse('0123456789abcdef')); + var ciphertext1 = rc4.process(C.enc.Hex.parse('00000000')); + var ciphertext2 = rc4.process(C.enc.Hex.parse('0000')); + var ciphertext3 = rc4.process(C.enc.Hex.parse('0000')); + var ciphertext4 = rc4.finalize(); + + Y.Assert.areEqual('7494c2e7104b0879', ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('0000000000000000'); + var key = C.enc.Hex.parse('0123456789abcdef'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + + C.RC4.encrypt(message, key); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.RC4.createEncryptor(C.SHA256('Jefe')).finalize('Hi There').toString(), C.RC4.encrypt('Hi There', C.SHA256('Jefe')).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.RC4, 'Hi There', C.SHA256('Jefe')).toString(), C.RC4.encrypt('Hi There', C.SHA256('Jefe')).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.RC4, 'Hi There', 'Jefe').toString(), C.RC4.encrypt('Hi There', 'Jefe').toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/rc4-tests.ts.tscparams b/cryptojs/test/rc4-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/rc4-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/ripemd160-tests.ts b/cryptojs/test/ripemd160-tests.ts new file mode 100644 index 000000000..317398388 --- /dev/null +++ b/cryptojs/test/ripemd160-tests.ts @@ -0,0 +1,22 @@ +/// +/// + +YUI.add('algo-ripemd160-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'RIPEMD160', + + testVector1: function () { + Y.Assert.areEqual('37f332f68db77bd9d7edd4969571ad671cf9dd3b', C.RIPEMD160('The quick brown fox jumps over the lazy dog').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('132072df690933835eb8b6ad0b77e7b6f14acad7', C.RIPEMD160('The quick brown fox jumps over the lazy cog').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('9c1185a5c5e9fc54612808977ee8f548b2258d31', C.RIPEMD160('').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/ripemd160-tests.ts.tscparams b/cryptojs/test/ripemd160-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/ripemd160-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha1-profile-tests.ts b/cryptojs/test/sha1-profile-tests.ts new file mode 100644 index 000000000..e0d46c49b --- /dev/null +++ b/cryptojs/test/sha1-profile-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +YUI.add('algo-sha1-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'SHA1', + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.SHA1.create().finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var sha1 = C.algo.SHA1.create(); + for (var i = 0; i < 500; i++) { + sha1.update('12345678901234567890123456789012345678901234567890'); + } + sha1.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/sha1-profile-tests.ts.tscparams b/cryptojs/test/sha1-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha1-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha1-tests.ts b/cryptojs/test/sha1-tests.ts new file mode 100644 index 000000000..92f87d210 --- /dev/null +++ b/cryptojs/test/sha1-tests.ts @@ -0,0 +1,73 @@ +/// +/// + +YUI.add('algo-sha1-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA1', + + testVector1: function () { + Y.Assert.areEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709', C.SHA1('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', C.SHA1('a').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('a9993e364706816aba3e25717850c26c9cd0d89d', C.SHA1('abc').toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('c12252ceda8be8994d5fa0290a47231c1d16aae3', C.SHA1('message digest').toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('32d10c7b8cf96570ca04ce37f2a19d84240d3a89', C.SHA1('abcdefghijklmnopqrstuvwxyz').toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('761c457bf73b14d27e9e9265c46f4b4dda11f940', C.SHA1('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').toString()); + }, + + testVector7: function () { + Y.Assert.areEqual('50abf5706a150990a08b2c5ea40fa0e585554732', C.SHA1('12345678901234567890123456789012345678901234567890123456789012345678901234567890').toString()); + }, + + testUpdateAndLongMessage: function () { + var sha1 = C.algo.SHA1.create(); + for (var i = 0; i < 100; i++) { + sha1.update('12345678901234567890123456789012345678901234567890'); + } + + Y.Assert.areEqual('85e4c4b3933d5553ebf82090409a9d90226d845c', sha1.finalize().toString()); + }, + + testClone: function () { + var sha1 = C.algo.SHA1.create(); + + Y.Assert.areEqual(C.SHA1('a').toString(), sha1.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA1('ab').toString(), sha1.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA1('abc').toString(), sha1.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.SHA1(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.SHA1.create().finalize('').toString(), C.SHA1('').toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.SHA1, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacSHA1('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha1-tests.ts.tscparams b/cryptojs/test/sha1-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha1-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha224-tests.ts b/cryptojs/test/sha224-tests.ts new file mode 100644 index 000000000..49413aaef --- /dev/null +++ b/cryptojs/test/sha224-tests.ts @@ -0,0 +1,22 @@ +/// +/// + +YUI.add('algo-sha224-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA224', + + testVector1: function () { + Y.Assert.areEqual('d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', C.SHA224('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525', C.SHA224('The quick brown fox jumps over the lazy dog').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4c', C.SHA224('The quick brown fox jumps over the lazy dog.').toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha224-tests.ts.tscparams b/cryptojs/test/sha224-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha224-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha256-profile-tests.ts b/cryptojs/test/sha256-profile-tests.ts new file mode 100644 index 000000000..899202743 --- /dev/null +++ b/cryptojs/test/sha256-profile-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +YUI.add('algo-sha256-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'SHA256', + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.SHA256.create().finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var sha256 = C.algo.SHA256.create(); + for (var i = 0; i < 500; i++) { + sha256.update('12345678901234567890123456789012345678901234567890'); + } + sha256.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/sha256-profile-tests.ts.tscparams b/cryptojs/test/sha256-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha256-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha256-tests.ts b/cryptojs/test/sha256-tests.ts new file mode 100644 index 000000000..0daf3223e --- /dev/null +++ b/cryptojs/test/sha256-tests.ts @@ -0,0 +1,73 @@ +/// +/// + +YUI.add('algo-sha256-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA256', + + testVector1: function () { + Y.Assert.areEqual('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', C.SHA256('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', C.SHA256('a').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', C.SHA256('abc').toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650', C.SHA256('message digest').toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73', C.SHA256('abcdefghijklmnopqrstuvwxyz').toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0', C.SHA256('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789').toString()); + }, + + testVector7: function () { + Y.Assert.areEqual('f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e', C.SHA256('12345678901234567890123456789012345678901234567890123456789012345678901234567890').toString()); + }, + + testUpdateAndLongMessage: function () { + var sha256 = C.algo.SHA256.create(); + for (var i = 0; i < 100; i++) { + sha256.update('12345678901234567890123456789012345678901234567890'); + } + + Y.Assert.areEqual('f8146961d9b73d8da49ccd526fca65439cdd5b402f76971556d5f52fd129843e', sha256.finalize().toString()); + }, + + testClone: function () { + var sha256 = C.algo.SHA256.create(); + + Y.Assert.areEqual(C.SHA256('a').toString(), sha256.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA256('ab').toString(), sha256.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA256('abc').toString(), sha256.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.SHA256(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.SHA256.create().finalize('').toString(), C.SHA256('').toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.SHA256, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacSHA256('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha256-tests.ts.tscparams b/cryptojs/test/sha256-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha256-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha3-profile-tests.ts b/cryptojs/test/sha3-profile-tests.ts new file mode 100644 index 000000000..015c326d0 --- /dev/null +++ b/cryptojs/test/sha3-profile-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +YUI.add('algo-sha3-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'SHA3', + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.SHA3.create().finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var sha3 = C.algo.SHA3.create(); + for (var i = 0; i < 500; i++) { + sha3.update('12345678901234567890123456789012345678901234567890'); + } + sha3.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/sha3-profile-tests.ts.tscparams b/cryptojs/test/sha3-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha3-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha3-tests.ts b/cryptojs/test/sha3-tests.ts new file mode 100644 index 000000000..c8ab5d642 --- /dev/null +++ b/cryptojs/test/sha3-tests.ts @@ -0,0 +1,72 @@ +/// +/// + +YUI.add('algo-sha3-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA3', + + testVector1: function () { + Y.Assert.areEqual('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e', C.SHA3('', { outputLength: 512 }).toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('81950e7096d31d4f22e3db71cac725bf59e81af54c7ca9e6aeee71c010fc5467466312a01aa5c137cfb140646941556796f612c9351268737c7e9a2b9631d1fa', C.SHA3(C.enc.Hex.parse('3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1'), { outputLength: 512 }).toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff', C.SHA3('', { outputLength: 384 }).toString()); + }, + + testVector4: function () { + Y.Assert.areEqual('6bff1c8405a3fe594e360e3bccea1ebcd509310dc79b9e45c263783d7a5dd662c6789b18bd567dbdda1554f5bee6a860', C.SHA3(C.enc.Hex.parse('3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1'), { outputLength: 384 }).toString()); + }, + + testVector5: function () { + Y.Assert.areEqual('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', C.SHA3('', { outputLength: 256 }).toString()); + }, + + testVector6: function () { + Y.Assert.areEqual('348fb774adc970a16b1105669442625e6adaa8257a89effdb5a802f161b862ea', C.SHA3(C.enc.Hex.parse('3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1'), { outputLength: 256 }).toString()); + }, + + testVector7: function () { + Y.Assert.areEqual('f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd', C.SHA3('', { outputLength: 224 }).toString()); + }, + + testVector8: function () { + Y.Assert.areEqual('5af56987ea9cf11fcd0eac5ebc14b037365e9b1123e31cb2dfc7929a', C.SHA3(C.enc.Hex.parse('3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1'), { outputLength: 224 }).toString()); + }, + + testDefaultOutputLength: function () { + Y.Assert.areEqual('0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e', C.SHA3('').toString()); + }, + + testClone: function () { + var sha3 = C.algo.SHA3.create(); + + Y.Assert.areEqual(C.SHA3('a').toString(), sha3.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA3('ab').toString(), sha3.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA3('abc').toString(), sha3.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.SHA3(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.SHA3.create({ outputLength: 256 }).finalize('').toString(), C.SHA3('', { outputLength: 256 }).toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.SHA3, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacSHA3('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha3-tests.ts.tscparams b/cryptojs/test/sha3-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha3-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha384-tests.ts b/cryptojs/test/sha384-tests.ts new file mode 100644 index 000000000..fd4f4a409 --- /dev/null +++ b/cryptojs/test/sha384-tests.ts @@ -0,0 +1,57 @@ +/// +/// + +YUI.add('algo-sha384-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA384', + + testVector1: function () { + Y.Assert.areEqual('38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b', C.SHA384('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1', C.SHA384('The quick brown fox jumps over the lazy dog').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7', C.SHA384('The quick brown fox jumps over the lazy dog.').toString()); + }, + + testUpdateAndLongMessage: function () { + var sha384 = C.algo.SHA384.create(); + for (var i = 0; i < 100; i++) { + sha384.update('12345678901234567890123456789012345678901234567890'); + } + + Y.Assert.areEqual('297a519246d6f639a4020119e1f03fc8d77171647b2ff75ea4125b7150fed0cdcc93f8dca1c3c6a624d5e88d780d82cd', sha384.finalize().toString()); + }, + + testClone: function () { + var sha384 = C.algo.SHA384.create(); + + Y.Assert.areEqual(C.SHA384('a').toString(), sha384.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA384('ab').toString(), sha384.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA384('abc').toString(), sha384.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.SHA384(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.SHA384.create().finalize('').toString(), C.SHA384('').toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.SHA384, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacSHA384('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha384-tests.ts.tscparams b/cryptojs/test/sha384-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha384-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha512-profile-tests.ts b/cryptojs/test/sha512-profile-tests.ts new file mode 100644 index 000000000..82baed5a8 --- /dev/null +++ b/cryptojs/test/sha512-profile-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +YUI.add('algo-sha512-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'SHA512', + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 500; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.SHA512.create().finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var sha512 = C.algo.SHA512.create(); + for (var i = 0; i < 500; i++) { + sha512.update('12345678901234567890123456789012345678901234567890'); + } + sha512.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/sha512-profile-tests.ts.tscparams b/cryptojs/test/sha512-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha512-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/sha512-tests.ts b/cryptojs/test/sha512-tests.ts new file mode 100644 index 000000000..c6559d7c7 --- /dev/null +++ b/cryptojs/test/sha512-tests.ts @@ -0,0 +1,57 @@ +/// +/// + +YUI.add('algo-sha512-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'SHA512', + + testVector1: function () { + Y.Assert.areEqual('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e', C.SHA512('').toString()); + }, + + testVector2: function () { + Y.Assert.areEqual('07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6', C.SHA512('The quick brown fox jumps over the lazy dog').toString()); + }, + + testVector3: function () { + Y.Assert.areEqual('91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed', C.SHA512('The quick brown fox jumps over the lazy dog.').toString()); + }, + + testUpdateAndLongMessage: function () { + var sha512 = C.algo.SHA512.create(); + for (var i = 0; i < 100; i++) { + sha512.update('12345678901234567890123456789012345678901234567890'); + } + + Y.Assert.areEqual('9bc64f37c54606dff234b6607e06683c7ba248558d0ec74a11525d9f59e0be566489cc9413c00ca5e9db705fc52ba71214bcf118f65072fe284af8f8cf9500af', sha512.finalize().toString()); + }, + + testClone: function () { + var sha512 = C.algo.SHA512.create(); + + Y.Assert.areEqual(C.SHA512('a').toString(), sha512.update('a').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA512('ab').toString(), sha512.update('b').clone().finalize().toString()); + Y.Assert.areEqual(C.SHA512('abc').toString(), sha512.update('c').clone().finalize().toString()); + }, + + testInputIntegrity: function () { + var message = C.lib.WordArray.create([0x12345678]); + + var expected = message.toString(); + + C.SHA512(message); + + Y.Assert.areEqual(expected, message.toString()); + }, + + testHelper: function () { + Y.Assert.areEqual(C.algo.SHA512.create().finalize('').toString(), C.SHA512('').toString()); + }, + + testHmacHelper: function () { + Y.Assert.areEqual(C.algo.HMAC.create(C.algo.SHA512, C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).finalize('Hi There').toString(), C.HmacSHA512('Hi There', C.enc.Hex.parse('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b')).toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/sha512-tests.ts.tscparams b/cryptojs/test/sha512-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/sha512-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/tripledes-profile-tests.ts b/cryptojs/test/tripledes-profile-tests.ts new file mode 100644 index 000000000..e1543ff48 --- /dev/null +++ b/cryptojs/test/tripledes-profile-tests.ts @@ -0,0 +1,37 @@ +/// +/// + +YUI.add('algo-tripledes-profile', function (Y) { + var C = CryptoJS; + + //Profiler is removed in YUI 3.10.2 + //@see http://www.yuiblog.com/blog/2013/06/04/yui-3-10-2-released/ + //Y.Profiler.add({ + var obj = { + name: 'TripleDES', + + setUp: function () { + this.data = { + key: C.enc.Hex.parse('0001020304050607'), + iv: C.enc.Hex.parse('08090a0b0c0d0e0f') + }; + }, + + profileSinglePartMessage: function () { + var singlePartMessage = ''; + for (var i = 0; i < 100; i++) { + singlePartMessage += '12345678901234567890123456789012345678901234567890'; + } + + C.algo.TripleDES.createEncryptor(this.data.key, { iv: this.data.iv }).finalize(singlePartMessage) + ''; + }, + + profileMultiPartMessage: function () { + var des = C.algo.TripleDES.createEncryptor(this.data.key, { iv: this.data.iv }); + for (var i = 0; i < 100; i++) { + des.process('12345678901234567890123456789012345678901234567890') + ''; + } + des.finalize() + ''; + } + }; +}, '$Rev$'); diff --git a/cryptojs/test/tripledes-profile-tests.ts.tscparams b/cryptojs/test/tripledes-profile-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/tripledes-profile-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/tripledes-tests.ts b/cryptojs/test/tripledes-tests.ts new file mode 100644 index 000000000..2227d3710 --- /dev/null +++ b/cryptojs/test/tripledes-tests.ts @@ -0,0 +1,91 @@ +/// +/// + +YUI.add('algo-tripledes-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'TripleDES', + + testEncrypt1: function () { + Y.Assert.areEqual('95a8d72813daa94d', C.TripleDES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('800101010101010180010101010101018001010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt2: function () { + Y.Assert.areEqual('869efd7f9f265a09', C.TripleDES.encrypt(C.enc.Hex.parse('0000000000000000'), C.enc.Hex.parse('010101010101010201010101010101020101010101010102'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt3: function () { + Y.Assert.areEqual('95f8a5e5dd31d900', C.TripleDES.encrypt(C.enc.Hex.parse('8000000000000000'), C.enc.Hex.parse('010101010101010101010101010101010101010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testEncrypt4: function () { + Y.Assert.areEqual('166b40b44aba4bd6', C.TripleDES.encrypt(C.enc.Hex.parse('0000000000000001'), C.enc.Hex.parse('010101010101010101010101010101010101010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + }, + + testDecrypt1: function () { + Y.Assert.areEqual('0000000000000000', C.TripleDES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('95a8d72813daa94d') }), C.enc.Hex.parse('800101010101010180010101010101018001010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt2: function () { + Y.Assert.areEqual('0000000000000000', C.TripleDES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('869efd7f9f265a09') }), C.enc.Hex.parse('010101010101010201010101010101020101010101010102'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt3: function () { + Y.Assert.areEqual('8000000000000000', C.TripleDES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('95f8a5e5dd31d900') }), C.enc.Hex.parse('010101010101010101010101010101010101010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testDecrypt4: function () { + Y.Assert.areEqual('0000000000000001', C.TripleDES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('166b40b44aba4bd6') }), C.enc.Hex.parse('010101010101010101010101010101010101010101010101'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + }, + + testMultiPart: function () { + var des = C.algo.TripleDES.createEncryptor(C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }); + var ciphertext1 = des.process(C.enc.Hex.parse('001122334455')); + var ciphertext2 = des.process(C.enc.Hex.parse('66778899aa')); + var ciphertext3 = des.process(C.enc.Hex.parse('bbccddeeff')); + var ciphertext4 = des.finalize(); + + Y.Assert.areEqual(C.TripleDES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString(), ciphertext1.concat(ciphertext2).concat(ciphertext3).concat(ciphertext4).toString()); + }, + + testInputIntegrity: function () { + var message = C.enc.Hex.parse('00112233445566778899aabbccddeeff'); + var key = C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f1011121314151617'); + var iv = C.enc.Hex.parse('08090a0b0c0d0e0f'); + + var expectedMessage = message.toString(); + var expectedKey = key.toString(); + var expectedIv = iv.toString(); + + C.TripleDES.encrypt(message, key, { iv: iv }); + + Y.Assert.areEqual(expectedMessage, message.toString()); + Y.Assert.areEqual(expectedKey, key.toString()); + Y.Assert.areEqual(expectedIv, iv.toString()); + }, + + testHelper: function () { + // Save original random method + var random = C.lib.WordArray.random; + + // Replace random method with one that returns a predictable value + C.lib.WordArray.random = function (nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push([0x11223344]); + } + + return C.lib.WordArray.create(words, nBytes); + }; + + // Test + Y.Assert.areEqual(C.algo.TripleDES.createEncryptor(C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).finalize('Hi There').toString(), C.TripleDES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).ciphertext.toString()); + Y.Assert.areEqual(C.lib.SerializableCipher.encrypt(C.algo.TripleDES, 'Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.TripleDES.encrypt('Hi There', C.SHA256('Jefe'), { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + Y.Assert.areEqual(C.lib.PasswordBasedCipher.encrypt(C.algo.TripleDES, 'Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString(), C.TripleDES.encrypt('Hi There', 'Jefe', { mode: C.mode.ECB, padding: C.pad.NoPadding }).toString()); + + // Restore random method + C.lib.WordArray.random = random; + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/tripledes-tests.ts.tscparams b/cryptojs/test/tripledes-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/tripledes-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/x64-word-tests.ts b/cryptojs/test/x64-word-tests.ts new file mode 100644 index 000000000..f5ee66ce2 --- /dev/null +++ b/cryptojs/test/x64-word-tests.ts @@ -0,0 +1,102 @@ +/// +/// + +YUI.add('x64-word-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'X64Word', + + testInit: function () { + var word = C.x64.Word.create(0x00010203, 0x04050607); + + Y.Assert.areEqual(0x00010203, word.high, 'word.high'); + Y.Assert.areEqual(0x04050607, word.low, 'word.low'); + } + + // testNot: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).not(); + + // Y.Assert.areEqual(~0x00010203, word.high, 'word.high'); + // Y.Assert.areEqual(~0x04050607, word.low, 'word.low'); + // }, + + // testAnd: function () { + // var word1 = C.x64.Word.create(0x00010203, 0x04050607); + // var word2 = C.x64.Word.create(0x18191a1b, 0x1c1d1e1f); + // var anded = word1.and(word2); + + // Y.Assert.areEqual(0x00010203 & 0x18191a1b, anded.high, 'word.high'); + // Y.Assert.areEqual(0x04050607 & 0x1c1d1e1f, anded.low, 'word.low'); + // }, + + // testOr: function () { + // var word1 = C.x64.Word.create(0x00010203, 0x04050607); + // var word2 = C.x64.Word.create(0x18191a1b, 0x1c1d1e1f); + // var ored = word1.or(word2); + + // Y.Assert.areEqual(0x00010203 | 0x18191a1b, ored.high, 'word.high'); + // Y.Assert.areEqual(0x04050607 | 0x1c1d1e1f, ored.low, 'word.low'); + // }, + + // testXor: function () { + // var word1 = C.x64.Word.create(0x00010203, 0x04050607); + // var word2 = C.x64.Word.create(0x18191a1b, 0x1c1d1e1f); + // var xored = word1.xor(word2); + + // Y.Assert.areEqual(0x00010203 ^ 0x18191a1b, xored.high, 'word.high'); + // Y.Assert.areEqual(0x04050607 ^ 0x1c1d1e1f, xored.low, 'word.low'); + // }, + + // testShiftL25: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).shiftL(25); + + // Y.Assert.areEqual(0x06080a0c, word.high, 'word.high'); + // Y.Assert.areEqual(0x0e000000, word.low, 'word.low'); + // }, + + // testShiftL32: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).shiftL(32); + + // Y.Assert.areEqual(0x04050607, word.high, 'word.high'); + // Y.Assert.areEqual(0x00000000, word.low, 'word.low'); + // }, + + // testShiftR7: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).shiftR(7); + + // Y.Assert.areEqual(0x00000204, word.high, 'word.high'); + // Y.Assert.areEqual(0x06080A0C, word.low, 'word.low'); + // }, + + // testShiftR32: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).shiftR(32); + + // Y.Assert.areEqual(0x00000000, word.high, 'word.high'); + // Y.Assert.areEqual(0x00010203, word.low, 'word.low'); + // }, + + // testRotL: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).rotL(25); + + // Y.Assert.areEqual(0x06080a0c, word.high, 'word.high'); + // Y.Assert.areEqual(0x0e000204, word.low, 'word.low'); + // }, + + // testRotR: function () { + // var word = C.x64.Word.create(0x00010203, 0x04050607).rotR(7); + + // Y.Assert.areEqual(0x0e000204, word.high, 'word.high'); + // Y.Assert.areEqual(0x06080a0c, word.low, 'word.low'); + // }, + + // testAdd: function () { + // var word1 = C.x64.Word.create(0x00010203, 0x04050607); + // var word2 = C.x64.Word.create(0x18191a1b, 0x1c1d1e1f); + // var added = word1.add(word2); + + // Y.Assert.areEqual(0x181a1c1e, added.high, 'word.high'); + // Y.Assert.areEqual(0x20222426, added.low, 'word.low'); + // } + })); +}, '$Rev$'); diff --git a/cryptojs/test/x64-word-tests.ts.tscparams b/cryptojs/test/x64-word-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/x64-word-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/cryptojs/test/x64-wordarray-tests.ts b/cryptojs/test/x64-wordarray-tests.ts new file mode 100644 index 000000000..7b11830b9 --- /dev/null +++ b/cryptojs/test/x64-wordarray-tests.ts @@ -0,0 +1,41 @@ +/// +/// + +YUI.add('x64-wordarray-test', function (Y) { + var C = CryptoJS; + + Y.Test.Runner.add(new Y.Test.Case({ + name: 'X64WordArray', + + testInit0: function () { + Y.Assert.areEqual('', C.x64.WordArray.create().toX32().toString()); + }, + + testInit1: function () { + var wordArray = C.x64.WordArray.create([ + C.x64.Word.create(0x00010203, 0x04050607), + C.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + ]); + + Y.Assert.areEqual('000102030405060718191a1b1c1d1e1f', wordArray.toX32().toString()); + }, + + testInit2: function () { + var wordArray = C.x64.WordArray.create([ + C.x64.Word.create(0x00010203, 0x04050607), + C.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + ], 10); + + Y.Assert.areEqual('00010203040506071819', wordArray.toX32().toString()); + }, + + testToX32: function () { + var wordArray = C.x64.WordArray.create([ + C.x64.Word.create(0x00010203, 0x04050607), + C.x64.Word.create(0x18191a1b, 0x1c1d1e1f) + ], 10); + + Y.Assert.areEqual('00010203040506071819', wordArray.toX32().toString()); + } + })); +}, '$Rev$'); diff --git a/cryptojs/test/x64-wordarray-tests.ts.tscparams b/cryptojs/test/x64-wordarray-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/cryptojs/test/x64-wordarray-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/yui/README.md b/yui/README.md new file mode 100644 index 000000000..d0e2a6493 --- /dev/null +++ b/yui/README.md @@ -0,0 +1,11 @@ +yui.d.ts +======== + +typescript definition type for [yui3](https://github.com/yui/yui3). + +The definition is based on [yui 3.14.0](https://github.com/yui/yui3/tree/release-3.14.0). + +I create it only for writing test files of [cryptojs.d.ts](../cryptojs/test). +So, the definition is incomplete now (22/11/2013). + +Gia Bảo @ [Sân Đình](https://sandinh.com) diff --git a/yui/yui-test.d.ts b/yui/yui-test.d.ts new file mode 100644 index 000000000..f72784ffa --- /dev/null +++ b/yui/yui-test.d.ts @@ -0,0 +1,104 @@ +// Type definitions for yui 3.14.0 +// Project: https://github.com/yui/yui3/blob/release-3.14.0/src/test/js +// Definitions by: +// Gia Bảo @ Sân Đình + +declare module YUITest { + interface YUITestStatic{ + Assert: IAssert + Case: TestCase + Runner: TestRunner + } + + interface EventTarget{ + attach(type: string, listener: Function): void + subscribe(type: string, listener: Function): void + fire(event: Object): void + fire(event: string): void + detach(type: string, listener: Function): void + unsubscribe(type: string, listener: Function): void + } + + interface TestRunner extends EventTarget{ + TEST_CASE_BEGIN_EVENT: string + TEST_CASE_COMPLETE_EVENT: string + TEST_SUITE_BEGIN_EVENT: string + TEST_SUITE_COMPLETE_EVENT: string + TEST_PASS_EVENT: string + TEST_FAIL_EVENT: string + ERROR_EVENT: string + TEST_IGNORE_EVENT: string + COMPLETE_EVENT: string + BEGIN_EVENT: string + + getName(): string + setName(name: string): void + + add(testObject: TestSuite): void + add(testObject: TestCase): void + + clear(): void + isWaiting(): boolean + isRunning(): boolean + + getResults(format?: Function): any //Object|String + getCoverage(format?: Function): any //Object|String + callback(...args: any[]): Function + resume(segment?: Function): void + run(options?: Object): void + run(options?: boolean): void + } + + interface TestSuite{ + name: string +// items: any[] //Array of test suites and test cases. @private + add(testObject: TestSuite): void + add(testObject: TestCase): void + setUp(): void + tearDown(): void + } + + interface TestCase{ + new (template: Object): TestCase + DEFAULT_WAIT: number + callback(...args: any[]): Function + resume(segment?: Function): void + wait(segment?: Function, delay?: number): void + waitFor(condition: Function, segment: Function, timeout?: number, increment?: number): void + assert(condition: boolean, message: string): void + fail(message?: string): void + init(): void + destroy(): void + setUp(): void + tearDown(): void + } + + interface IAssert{ + fail(message?: string): void + pass(message?: string): void + areEqual(expected: Object, actual: Object, message?: string): void + areNotEqual(unexpected: Object, actual: Object, message?: string): void + areNotSame(unexpected: Object, actual: Object, message?: string): void + areSame(expected: Object, actual: Object, message?: string): void + isFalse(actual: Object, message?: string): void + isTrue(actual: Object, message?: string): void + isNaN(actual: Object, message?: string): void + isNotNaN(actual: Object, message?: string): void + isNotNull(actual: Object, message?: string): void + isNotUndefined(actual: Object, message?: string): void + isNull(actual: Object, message?: string): void + isUndefined(actual: Object, message?: string): void + isArray(actual: Object, message?: string): void + isBoolean(actual: Object, message?: string): void + isFunction(actual: Object, message?: string): void + isInstanceOf(expected: Function, actual: Object, message?: string): void + isNumber(actual: Object, message?: string): void + isObject(actual: Object, message?: string): void + isString(actual: Object, message?: string): void + isTypeOf(expectedType: string, actualValue: Object, message?: string): void + + throwsError(expectedError: string, method: Object, message?: string): void + throwsError(expectedError: Function, method: Object, message?: string): void + throwsError(expectedError: Object, method: Object, message?: string): void + } +} diff --git a/yui/yui.d.ts b/yui/yui.d.ts new file mode 100644 index 000000000..acc448899 --- /dev/null +++ b/yui/yui.d.ts @@ -0,0 +1,29 @@ +// Type definitions for yui 3.14.0 +// Project: https://github.com/yui/yui3/blob/release-3.14.0/src/yui/js +// Definitions by: +// Gia Bảo @ Sân Đình + +/// + +interface YUI{ + Test: YUITest.YUITestStatic + Assert: YUITest.IAssert + + add(name: string, fn: (Y: YUI, name: string) => any, version: string, details?: Y.IConfig): YUI; + + mix(receiver: Function, supplier: Function, overwrite?: boolean, whitelist?: string[], mode?: number, merge?: boolean): any//Function|Object|YUI + mix(receiver: Object, supplier: Function, overwrite?: boolean, whitelist?: string[], mode?: number, merge?: boolean): any//Function|Object|YUI + mix(receiver: Function, supplier: Object, overwrite?: boolean, whitelist?: string[], mode?: number, merge?: boolean): any//Function|Object|YUI + mix(receiver: Object, supplier: Object, overwrite?: boolean, whitelist?: string[], mode?: number, merge?: boolean): any//Function|Object|YUI +} + +declare module Y{ + interface IConfig{ + requires: string[] + optional: string[] + use: string[] + } +} + +declare var Y: YUI; +declare var YUI: YUI;