mirror of
				http://git.whoc.org.uk/git/password-manager.git
				synced 2025-11-03 20:47:35 +01:00 
			
		
		
		
	First version of the newly restructured repository
This commit is contained in:
		
							
								
								
									
										292
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/AES.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										292
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/AES.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,292 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<title>Clipperz.Crypto.AES_v3 - TEST</title>
 | 
			
		||||
	
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
	var block;
 | 
			
		||||
	var keyValue;
 | 
			
		||||
	var	key;
 | 
			
		||||
	var encryptedBlock;
 | 
			
		||||
	var startTime, endTime;
 | 
			
		||||
	
 | 
			
		||||
	startTime = new Date();
 | 
			
		||||
	
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x00010203050607080a0b0c0d0f10111214151617191a1b1c1e1f202123242526");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0x834eadfccac7e1b30664b1aba44815ab");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x1946dabf6a03a2a2c3d0b05080aed6fc", "Test 1");
 | 
			
		||||
	
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x28292a2b2d2e2f30323334353738393a3c3d3e3f41424344464748494b4c4d4e");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xd9dc4dba3021b05d67c0518f72b62bf1");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x5ed301d747d3cc715445ebdec62f2fb4", "Test 2");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x50515253555657585a5b5c5d5f60616264656667696a6b6c6e6f707173747576");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xa291d86301a4a739f7392173aa3c604c");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x6585c8f43d13a6beab6419fc5935b9d0", "Test 3");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x78797a7b7d7e7f80828384858788898a8c8d8e8f91929394969798999b9c9d9e");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0x4264b2696498de4df79788a9f83e9390");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x2a5b56a596680fcc0e05f5e0f151ecae", "Test 4");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0xa0a1a2a3a5a6a7a8aaabacadafb0b1b2b4b5b6b7b9babbbcbebfc0c1c3c4c5c6");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xee9932b3721804d5a83ef5949245b6f6");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0xf5d6ff414fd2c6181494d20c37f2b8c4", "Test 5");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0xc8c9cacbcdcecfd0d2d3d4d5d7d8d9dadcdddedfe1e2e3e4e6e7e8e9ebecedee");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xe6248f55c5fdcbca9cbbb01c88a2ea77");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x85399c01f59fffb5204f19f8482f00b8", "Test 6");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0xf0f1f2f3f5f6f7f8fafbfcfdfe01000204050607090a0b0c0e0f101113141516");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xb8358e41b9dff65fd461d55a99266247");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x92097b4c88a041ddf98144bc8d22e8e7", "Test 7");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x18191a1b1d1e1f20222324252728292a2c2d2e2f31323334363738393b3c3d3e");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0xf0e2d72260af58e21e015ab3a4c0d906");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x89bd5b73b356ab412aef9f76cea2d65c", "Test 8");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x40414243454647484a4b4c4d4f50515254555657595a5b5c5e5f606163646566");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0x475b8b823ce8893db3c44a9f2a379ff7");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x2536969093c55ff9454692f2fac2f530", "Test 9");
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x68696a6b6d6e6f70727374757778797a7c7d7e7f81828384868788898b8c8d8e");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	block = new Clipperz.ByteArray("0x688f5281945812862f5f3076cf80412f");
 | 
			
		||||
	encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
 | 
			
		||||
	is(encryptedBlock.toHexString(), "0x07fc76a872843f3f6e0081ee9396d637", "Test 10");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//		Key expansion
 | 
			
		||||
	//
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//	test vector: http://en.wikipedia.org/wiki/Rijndael_key_schedule#Test_vectors
 | 
			
		||||
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000012345678");
 | 
			
		||||
	try {
 | 
			
		||||
		key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
		is(true, false, "Unsupported key size");
 | 
			
		||||
	} catch (exception) {
 | 
			
		||||
		is(true, true, "Unsupported key size");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x00000000000000000000000000000000");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	is(	key.stretchedKey().toHexString(),
 | 
			
		||||
		"0x" +	"00000000000000000000000000000000" +
 | 
			
		||||
				"62636363626363636263636362636363" +
 | 
			
		||||
				"9b9898c9f9fbfbaa9b9898c9f9fbfbaa" +
 | 
			
		||||
				"90973450696ccffaf2f457330b0fac99" +
 | 
			
		||||
				"ee06da7b876a1581759e42b27e91ee2b" +
 | 
			
		||||
				"7f2e2b88f8443e098dda7cbbf34b9290" +
 | 
			
		||||
				"ec614b851425758c99ff09376ab49ba7" +
 | 
			
		||||
				"217517873550620bacaf6b3cc61bf09b" +
 | 
			
		||||
				"0ef903333ba9613897060a04511dfa9f" +
 | 
			
		||||
				"b1d4d8e28a7db9da1d7bb3de4c664941" +
 | 
			
		||||
				"b4ef5bcb3e92e21123e951cf6f8f188e",
 | 
			
		||||
		"Stretched empty key");
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000000000000000000000000000000000000");
 | 
			
		||||
	key = new Clipperz.Crypto.AES.Key({key:keyValue});
 | 
			
		||||
	is(	key.stretchedKey().toHexString(),
 | 
			
		||||
		"0x" +	"00000000000000000000000000000000" +
 | 
			
		||||
				"00000000000000000000000000000000" +
 | 
			
		||||
				"62636363626363636263636362636363" +
 | 
			
		||||
				"aafbfbfbaafbfbfbaafbfbfbaafbfbfb" +
 | 
			
		||||
				"6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac" +
 | 
			
		||||
				"7d8d8d6ad77676917d8d8d6ad7767691" +
 | 
			
		||||
				"5354edc15e5be26d31378ea23c38810e" +
 | 
			
		||||
				"968a81c141fcf7503c717a3aeb070cab" +
 | 
			
		||||
				"9eaa8f28c0f16d45f1c6e3e7cdfe62e9" +
 | 
			
		||||
				"2b312bdf6acddc8f56bca6b5bdbbaa1e" +
 | 
			
		||||
				"6406fd52a4f79017553173f098cf1119" +
 | 
			
		||||
				"6dbba90b0776758451cad331ec71792f" +
 | 
			
		||||
				"e7b0e89c4347788b16760b7b8eb91a62" +
 | 
			
		||||
				"74ed0ba1739b7e252251ad14ce20d43b" +
 | 
			
		||||
				"10f80a1753bf729c45c979e7cb706385",
 | 
			
		||||
		"Stretched empty key");
 | 
			
		||||
 | 
			
		||||
	var roundIndex;
 | 
			
		||||
 | 
			
		||||
	roundIndex = 0;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(0)");
 | 
			
		||||
	roundIndex = 1;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(1)");
 | 
			
		||||
	roundIndex = 2;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x62636363626363636263636362636363", "empty key, subKeyAtRound(2)");
 | 
			
		||||
	roundIndex = 3;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xaafbfbfbaafbfbfbaafbfbfbaafbfbfb", "empty key, subKeyAtRound(3)");
 | 
			
		||||
	roundIndex = 4;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac", "empty key, subKeyAtRound(4)");
 | 
			
		||||
	roundIndex = 5;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x7d8d8d6ad77676917d8d8d6ad7767691", "empty key, subKeyAtRound(5)");
 | 
			
		||||
	roundIndex = 6;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x5354edc15e5be26d31378ea23c38810e", "empty key, subKeyAtRound(6)");
 | 
			
		||||
	roundIndex = 7;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x968a81c141fcf7503c717a3aeb070cab", "empty key, subKeyAtRound(7)");
 | 
			
		||||
	roundIndex = 8;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x9eaa8f28c0f16d45f1c6e3e7cdfe62e9", "empty key, subKeyAtRound(8)");
 | 
			
		||||
	roundIndex = 9;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x2b312bdf6acddc8f56bca6b5bdbbaa1e", "empty key, subKeyAtRound(9)");
 | 
			
		||||
	roundIndex = 10;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6406fd52a4f79017553173f098cf1119", "empty key, subKeyAtRound(10)");
 | 
			
		||||
	roundIndex = 11;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6dbba90b0776758451cad331ec71792f", "empty key, subKeyAtRound(11)");
 | 
			
		||||
	roundIndex = 12;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xe7b0e89c4347788b16760b7b8eb91a62", "empty key, subKeyAtRound(12)");
 | 
			
		||||
	roundIndex = 13;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x74ed0ba1739b7e252251ad14ce20d43b", "empty key, subKeyAtRound(13)");
 | 
			
		||||
	roundIndex = 14;
 | 
			
		||||
	is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x10f80a1753bf729c45c979e7cb706385", "empty key, subKeyAtRound(14)");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//		Encrypt / decrypt
 | 
			
		||||
	//
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//	Test vectors:	http://www.zvon.org/tmRFC/RFC3686/Output/chapter6.html
 | 
			
		||||
	//					http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html
 | 
			
		||||
	//					http://www.ietf.org/rfc/rfc3686.txt
 | 
			
		||||
 | 
			
		||||
	{
 | 
			
		||||
		//
 | 
			
		||||
		//	http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html		
 | 
			
		||||
		//
 | 
			
		||||
		var key;
 | 
			
		||||
		var plainText;
 | 
			
		||||
		var cipherText;
 | 
			
		||||
		var result;
 | 
			
		||||
 | 
			
		||||
		//
 | 
			
		||||
		//	256-bit key size
 | 
			
		||||
		//
 | 
			
		||||
		
 | 
			
		||||
		//	Gladman's Test Data, 256-bit key - encrypt
 | 
			
		||||
		key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe", 16);
 | 
			
		||||
		plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16);
 | 
			
		||||
		cipherText = new Clipperz.ByteArray("0x1a6e6c2c662e7da6501ffb62bc9e93f3", 16);
 | 
			
		||||
 | 
			
		||||
		result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
 | 
			
		||||
		is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 256-bit key - encrypt");
 | 
			
		||||
 | 
			
		||||
		//	AES Specification Test Data, 256-bit key - encrypt
 | 
			
		||||
		key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16);
 | 
			
		||||
		plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16);
 | 
			
		||||
		cipherText = new Clipperz.ByteArray("0x8ea2b7ca516745bfeafc49904b496089", 16);
 | 
			
		||||
 | 
			
		||||
		result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
 | 
			
		||||
		is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 256-bit key - encrypt");
 | 
			
		||||
 | 
			
		||||
		//
 | 
			
		||||
		//	128-bit key size
 | 
			
		||||
		//
 | 
			
		||||
 | 
			
		||||
		//	Gladman's Test Data, 128-bit key - encrypt
 | 
			
		||||
		key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c", 16);
 | 
			
		||||
		plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16);
 | 
			
		||||
		cipherText = new Clipperz.ByteArray("0x3925841d02dc09fbdc118597196a0b32", 16);
 | 
			
		||||
 | 
			
		||||
		result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
 | 
			
		||||
		is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 128-bit key - encrypt");
 | 
			
		||||
 | 
			
		||||
		//	AES Specification Test Data, 128-bit key - encrypt
 | 
			
		||||
		key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f", 16);
 | 
			
		||||
		plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16);
 | 
			
		||||
		cipherText = new Clipperz.ByteArray("0x69c4e0d86a7b0430d8cdb78070b4c55a", 16);
 | 
			
		||||
 | 
			
		||||
		result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
 | 
			
		||||
		is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 128-bit key - encrypt");
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	endTime = new Date();
 | 
			
		||||
	MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime));
 | 
			
		||||
	
 | 
			
		||||
//#############################################################################
 | 
			
		||||
 
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										344
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										344
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										428
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										428
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,428 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	var secretKey;
 | 
			
		||||
	var	publicKey;
 | 
			
		||||
	var	plainString;
 | 
			
		||||
	var	encryptedString;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	secretKey = "s3cr37k39";
 | 
			
		||||
	plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
 | 
			
		||||
	encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Secret key encryption / decryption
 | 
			
		||||
	//
 | 
			
		||||
	is (isUndefinedOrNull(encryptedString), false, "An encrypted string should not be empty");
 | 
			
		||||
	is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
		var	decryptedText;
 | 
			
		||||
 | 
			
		||||
        decryptedText = Clipperz.Crypto.Base.decryptUsingSecretKey("anotherKey", encryptedString);
 | 
			
		||||
		ok( false, "It should not be possible to decrypt a text with a different passphrase (decrypted text: " + decryptedText + ")" );
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
		ok( e instanceof Error, "Trying to decrypt a message with the wrong passphrase raised an error" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	is (encryptedString == Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString), false, "Two consecutive encryption of the same text should return different values");
 | 
			
		||||
 | 
			
		||||
	secretKey = "trustno1";
 | 
			
		||||
	plainString = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1";
 | 
			
		||||
	encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
 | 
			
		||||
	is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
 | 
			
		||||
 | 
			
		||||
	secretKey = "trustno1";
 | 
			
		||||
	plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.";
 | 
			
		||||
	encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
 | 
			
		||||
	is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
 | 
			
		||||
 | 
			
		||||
	secretKey = "trustno1";
 | 
			
		||||
	plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas./n/n/nMorbi vel leo non justo condimentum convallis. Vestibulum posuere aliquam nunc. Donec magna magna, euismod nec, pharetra fringilla, tristique mattis, turpis. Duis condimentum lacus eu felis. Sed ultricies. Nullam lacinia ante id diam. Ut quis enim. Fusce at felis quis neque vehicula tempor. Sed feugiat sodales sem. Duis cursus massa in ligula. Vestibulum volutpat, risus in ornare porta, tortor orci vestibulum felis, et eleifend risus odio nec eros. Integer lorem turpis, imperdiet eu, tempor eu, ultricies nec, est. Ut congue. Morbi lacinia vehicula pede. Cras neque sapien, feugiat ac, eleifend eget, mattis et, nisl. Morbi at augue vitae massa laoreet gravida./n/n/nSuspendisse vehicula convallis sem. Sed vel urna. Proin dolor diam, malesuada in, aliquet a, sagittis et, magna. Cras at dui eu mi porta fermentum. Donec pharetra purus sed velit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque euismod ornare neque. In odio nisi, bibendum non, vulputate ut, tincidunt a, ante. Sed risus arcu, tempus laoreet, euismod id, laoreet mollis, arcu. Ut tempor orci in nibh. Suspendisse potenti. Maecenas accumsan augue at nisl. Donec elementum diam nec metus. Sed vitae lacus sed libero varius semper. Aenean hendrerit tristique arcu. Praesent adipiscing ornare purus. Vestibulum quis eros nec risus accumsan laoreet. Duis consequat ante ut turpis. Curabitur aliquam suscipit ligula. Vivamus adipiscing./n/n/nCurabitur facilisis neque sit amet erat. Aliquam odio augue, vulputate lobortis, rutrum ut, tristique id, leo. Vivamus eu magna. Maecenas et libero. Integer porta, lorem at mollis ullamcorper, purus metus vestibulum erat, ut fringilla dui ante id mi. Morbi vitae ligula. Praesent ornare sapien sed massa. Mauris rhoncus fermentum dolor. Mauris gravida, justo et mollis malesuada, dolor erat fermentum nulla, vel suscipit leo ligula vel augue. Praesent magna enim, dignissim sed, aliquet quis, fermentum viverra, nisi. Vivamus condimentum, nisi quis posuere viverra, enim nunc faucibus lectus, mollis aliquam ipsum enim vel lacus. Suspendisse eget ligula. Aliquam ut metus et justo consectetuer ornare. Donec dapibus tristique pede. Vestibulum interdum ultricies tortor./n/n/nNunc nonummy dictum tortor. Quisque at elit a arcu nonummy elementum. Quisque auctor, risus et sodales euismod, turpis tellus consectetuer ante, quis egestas justo enim quis mi. Nunc fermentum sodales felis. Vivamus odio mi, dignissim vitae, auctor nec, tempus eget, lacus. Ut sapien massa, hendrerit eget, sagittis at, eleifend condimentum, arcu. Curabitur purus orci, facilisis vel, dapibus id, varius rutrum, tortor. Fusce accumsan viverra sem. Quisque tincidunt venenatis risus. Sed tortor justo, volutpat malesuada, sodales ut, vehicula id, magna. Nunc placerat, nibh et imperdiet ultricies, urna nulla luctus sapien, et porta mi odio ac neque. Morbi dignissim. Sed risus pede, adipiscing gravida, pharetra sit amet, convallis non, orci. Morbi adipiscing mauris id massa. Nullam fermentum. Suspendisse eget est";
 | 
			
		||||
	encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
 | 
			
		||||
	is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
 | 
			
		||||
 | 
			
		||||
//	secretKey = "trustno1";
 | 
			
		||||
//	plainString = "{}";
 | 
			
		||||
//	plainString = "{'tags': {'personal': ['ref_1', 'ref_3'], 'business': ['ref_2', 'ref_3']}, 'records': {'ref_1': {'label': 'record_1', 'key': 'key_1'}, 'ref_2': {'label': 'record_2', 'key': 'key_2'}, 'ref_3': {'label': 'record_3', 'key': 'key_3'}}}	";
 | 
			
		||||
//	plainString = "{'tags': {}, 'records': {'07a5a92fcb334f757998ba14f3251f126d038318b3ac5e584bd712804c548084': {'label': 'Un bel record', 'key': '2a3f261c20a6a98dcc82b13fba013130b759f20602b4b13c5760879e087482a4'}}}";
 | 
			
		||||
//	encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
 | 
			
		||||
//	is(encryptedString, "{}", "encrypted value");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//	secretKey = "trustno1";
 | 
			
		||||
//	encryptedString = "0d43a4544424ffa519f2e43b7a46f703884fd94ff9879479563f6f252a573b253d3e77bc4f5f30f17bd11d2907718921ab8c9e1faccbe4314793fa323eb85eaf1bfbce5f7deea601e15b781782181cbff3c649dafef39abb70e8573e4f9be220f2286b01c3bd51d5c4a79b9d44a27be3b0994667302e301ca3dc074fb1bc7abc03d12b9e58ba0249435a120858c96e8ae99570718541499ab958a8fb92b63390be070ff61fc6ef107061693ab14c1915118cc6671ab7cf99b9cca553d6b5a7c314bffcd933e0a59f056d842a47cfe8571110b4764c5225443210d99b43b80a23c20fe953de3e1329d72cfb20139fe1ca";
 | 
			
		||||
//	plainString = Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString);
 | 
			
		||||
//	is(plainString, "{}", "decrypted value");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Java secret key encryption / JavaScript decryption
 | 
			
		||||
	//
 | 
			
		||||
	secretKey = "s3cr37k39";
 | 
			
		||||
	plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
 | 
			
		||||
	encryptedString = "9be538c3dde4dfab9384c0ef71dc624299fbbe71be8d1fe8991fd6cae88a883cf459d7cd56913a2b69815782cf74d7ce5c2c08034661f7f8aa59cf420e913086896840ebb45102d44d733d32de2a7dc8";
 | 
			
		||||
	is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Public key encryption -> Private key decryption
 | 
			
		||||
	//
 | 
			
		||||
	{
 | 
			
		||||
		var	cleanKey;
 | 
			
		||||
		var	t1, t2;
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//		128
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039";	//	a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"202700adbd85e2d7182720c3a0ee19c1",
 | 
			
		||||
						"30db31542ace0f7d37a629ee5eba28cb"
 | 
			
		||||
		);
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 128");
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely  - PUBLIC 128");
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 128");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//		256
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
 | 
			
		||||
						"2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
 | 
			
		||||
		);
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 256");
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely  - PUBLIC 256");
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 256");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	512
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
 | 
			
		||||
						"8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
//is("Encrypting with public key (512)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 512");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely  - PUBLIC 512");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
//is("Decrypting with private key (512)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 512");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	1024
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
 | 
			
		||||
						"130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Encrypting with public key (1024)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 1024");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely  - PUBLIC 1024");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Decrypting with private key (1024)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 1024");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	2048
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
 | 
			
		||||
						"9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Encrypting with public key (2048)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 2048");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely  - PUBLIC 2048");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Decrypting with private key (2048)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 2048");
 | 
			
		||||
*/
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Private key encryption -> Public key decryption
 | 
			
		||||
	//
 | 
			
		||||
	{
 | 
			
		||||
		var	cleanKey;
 | 
			
		||||
		var	t1, t2;
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//		128
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039";	//	a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"202700adbd85e2d7182720c3a0ee19c1",
 | 
			
		||||
						"30db31542ace0f7d37a629ee5eba28cb"
 | 
			
		||||
		);
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 128");
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 128");
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 128");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//		256
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
 | 
			
		||||
						"2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
 | 
			
		||||
		);
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 256");
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 256");
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 256");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	512
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
 | 
			
		||||
						"8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
//is("Encrypting with private key (512)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 512");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 512");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
//is("Decrypting with public key (512)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 512");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	1024
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
 | 
			
		||||
						"130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Encrypting with private key (1024)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 1024");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 1024");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Decrypting with public key (1024)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 1024");
 | 
			
		||||
*/
 | 
			
		||||
/*
 | 
			
		||||
		//
 | 
			
		||||
		//	2048
 | 
			
		||||
		//
 | 
			
		||||
		cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
		publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
 | 
			
		||||
						"10001",
 | 
			
		||||
						"409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
 | 
			
		||||
						"9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
 | 
			
		||||
		);
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Encrypting with private key (2048)", (t2 - t1));
 | 
			
		||||
 | 
			
		||||
		is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 2048");
 | 
			
		||||
t1 = new Date().getTime();
 | 
			
		||||
		is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 2048");
 | 
			
		||||
t2 = new Date().getTime();
 | 
			
		||||
is("Decrypting with public key (2048)", (t2 - t1));
 | 
			
		||||
		isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 2048");
 | 
			
		||||
*/
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var	originalMessage;
 | 
			
		||||
	var	processedMessage;
 | 
			
		||||
	var expectedResult;
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Hash	SHA-256
 | 
			
		||||
	//
 | 
			
		||||
	
 | 
			
		||||
	originalMessage = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
 | 
			
		||||
	expectedResult =  "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "";
 | 
			
		||||
	expectedResult =  "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
	
 | 
			
		||||
	originalMessage = "abc";
 | 
			
		||||
	expectedResult =  "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "message digest";
 | 
			
		||||
	expectedResult =  "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "secure hash algorithm";
 | 
			
		||||
	expectedResult =  "f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "SHA256 is considered to be safe";
 | 
			
		||||
	expectedResult =  "6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "For this sample, this 63-byte string will be used as input data";
 | 
			
		||||
	expectedResult =  "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "This is exactly 64 bytes long, not counting the terminating byte";
 | 
			
		||||
	expectedResult =  "ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	originalMessage = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut urna diam, vulputate quis, tempus vel, pretium in, mauris. Mauris aliquet sem a elit. Nunc molestie rutrum sem.";
 | 
			
		||||
	expectedResult =  "528059709af4087fb8cd4427e291d89f24d8c0429b2a3b6fd152c32ce5b4680f";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Hash	MD5
 | 
			
		||||
	//
 | 
			
		||||
	originalMessage = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da9";
 | 
			
		||||
	expectedResult =  "fde790d7da7d0d54a8db4ac500f1bbdb";
 | 
			
		||||
	processedMessage = Clipperz.Crypto.Base.computeMD5HashValue(originalMessage);
 | 
			
		||||
	is(processedMessage, expectedResult, "");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Random seed
 | 
			
		||||
	//
 | 
			
		||||
	var	randomSeed;
 | 
			
		||||
	
 | 
			
		||||
	randomSeed = Clipperz.Crypto.Base.generateRandomSeed();
 | 
			
		||||
	is(randomSeed.length, 64, "");
 | 
			
		||||
 | 
			
		||||
	ok(randomSeed != Clipperz.Crypto.Base.generateRandomSeed(), "");
 | 
			
		||||
 | 
			
		||||
//#############################################################################
 | 
			
		||||
 
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										478
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										478
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,478 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	var	bigInt_1;
 | 
			
		||||
	var	bigInt_2;
 | 
			
		||||
	var	result;
 | 
			
		||||
	var	expectedResult;
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	Constructur and equality test
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("110");
 | 
			
		||||
	is (bigInt_1.equals(bigInt_1), true, "");
 | 
			
		||||
	
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("110");
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("110", 10);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("110");
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(110);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("110", 2);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("110", 3);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), false, "");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	Addition test
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(110);
 | 
			
		||||
	result = bigInt_1.add(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(116);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
	is (result.equals(Clipperz.Crypto.BigInt.add(bigInt_1, bigInt_2)), true, "instance method === static function");
 | 
			
		||||
	
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	result = bigInt_1.add(6);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(12);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = 			new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
 | 
			
		||||
	bigInt_2 = 			new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
 | 
			
		||||
	result = bigInt_1.add(bigInt_2);
 | 
			
		||||
	expectedResult = 	new Clipperz.Crypto.BigInt("58585858585858585858585858585858585858585858585858585");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = 			new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
 | 
			
		||||
	bigInt_2 = 			new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
 | 
			
		||||
	result = bigInt_1.add(bigInt_2);
 | 
			
		||||
	expectedResult = 	new Clipperz.Crypto.BigInt("58585858585858585858585851585858585858585858585858585");
 | 
			
		||||
	is (result.equals(expectedResult), false, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = 			new Clipperz.Crypto.BigInt("86161616161616161616161616161616161616161616161616161");
 | 
			
		||||
	bigInt_2 = 			new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
 | 
			
		||||
	result = bigInt_1.add(bigInt_2);
 | 
			
		||||
	expectedResult = 	new Clipperz.Crypto.BigInt("128585858585858585858585858585858585858585858585858585");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = 			new Clipperz.Crypto.BigInt(	"6541652165410321654063516540621063540654" + 
 | 
			
		||||
													"0654065106540654165416521654103216540635" +
 | 
			
		||||
													"1654062106354065406540651065406541");
 | 
			
		||||
	bigInt_2 = 			new Clipperz.Crypto.BigInt(	"3046540351035403510354035103510351351351" +
 | 
			
		||||
													"0351350435103213540634132135401351035403" +
 | 
			
		||||
													"5403540354103540");
 | 
			
		||||
	result = bigInt_1.add(bigInt_2);
 | 
			
		||||
	expectedResult = 	new Clipperz.Crypto.BigInt(	"6541652165410321657110056891656467051008" +
 | 
			
		||||
													"1005100210054167675767872089206430081269" +
 | 
			
		||||
													"2975416119864419441944191419510081");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	Moltiplication test
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(110);
 | 
			
		||||
	result = bigInt_1.multiply(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(660);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	result = bigInt_1.multiply(5);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(30);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
	
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(	"5465465165465465132743540354354032135463" +
 | 
			
		||||
											"5435135403513516843052413543054035");
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(	"3543513543543213543032135435413054365430" +
 | 
			
		||||
											"5130513540351354354305435403");
 | 
			
		||||
	result = bigInt_1.multiply(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(	"1936694983559052629352223965314822970014" +
 | 
			
		||||
												"6364423657014976098029153153101751605574" +
 | 
			
		||||
												"5077086464435601381095664357540911830059" +
 | 
			
		||||
												"9503335163757031001105");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	Module test
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(106);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(10);
 | 
			
		||||
	result = bigInt_1.module(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(106);
 | 
			
		||||
	result = bigInt_1.module(10);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(	"5465465465468468465468463541358438543513" +
 | 
			
		||||
											"8543135435135423545624354235123512531235" +
 | 
			
		||||
											"1356463543840351351305135435121354305413" +
 | 
			
		||||
											"543");
 | 
			
		||||
											
 | 
			
		||||
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(	"3543543213543213540543545463542354385768" +
 | 
			
		||||
											"512584354354215");
 | 
			
		||||
	result = bigInt_1.module(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt("52689987206612998786765715819079250963638640081836513");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	Power (Module) test
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt(3);
 | 
			
		||||
	result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt(1000));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(216);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt(6);
 | 
			
		||||
	result = bigInt_1.powerModule(3, 1000);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(216);
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("354354354354687638546846846846846576876468746846846846");
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("354");
 | 
			
		||||
	result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt("3543541354354354354354351354354351354354354354354354"));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt("1957028940698171231089373321334263118681605242465644");
 | 
			
		||||
	is (result.equals(expectedResult), true, "");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", 16);
 | 
			
		||||
//	is(bigInt_1.toString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "IE bug");
 | 
			
		||||
	is(bigInt_1.asString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "fix for IE bug");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	is(bigInt_1.asString(16, 64), "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "fix to ensure the string representation has a minimum fixed length");
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
	//
 | 
			
		||||
	//	Comparison
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("0", 10);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("0", 10);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), true, "bigInt(0) = bigInt(0)");
 | 
			
		||||
	is (bigInt_1.equals(0), true, "bigInt(0) = 0");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	is (bigInt_1.equals(bigInt_2), false, "bigInt(xxxxxx) != bigInt(0)");
 | 
			
		||||
	is (bigInt_1.equals(0), false, "bigInt(xxxxx) != 0");
 | 
			
		||||
	
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("0", 16);
 | 
			
		||||
	is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(0)");
 | 
			
		||||
	is(bigInt_2.compare(bigInt_1), -1, "bigInt(0) < bigInt(xxxx)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
 | 
			
		||||
	is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(05)");
 | 
			
		||||
	is(bigInt_2.compare(bigInt_1), -1, "bigInt(05) < bigInt(xxxx)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("-10", 10);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("10", 10);
 | 
			
		||||
	is(bigInt_1.equals(bigInt_2), true, "bigInt(-10) - bigInt(10). No negative number are managed");
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	XOR
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.xor(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt(0);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.xor(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('295147905179352825856');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "single bit difference");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("01", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.xor(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('102987336249554097029535212322581322789799900648198034993674544906295017912404');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "01 xor value");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.xor(bigInt_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('7237005577332262213973186563042994240829374041602535252466099000494570602496');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	isBitSet
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(1);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'ff'.isBitSet(1)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(1);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(1)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(3);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(3)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(4);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(4)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(7);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'ff00'.isBitSet(7)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(8);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'ff00'.isBitSet(8)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("05000000000000", 16);
 | 
			
		||||
	result = bigInt_1.isBitSet(47);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(47)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(48);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(48)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(49);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(49)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(50);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(50)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(51);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(51)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(52);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(53);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(54);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(55);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(56);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(57);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(58);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(59);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
 | 
			
		||||
 | 
			
		||||
	result = bigInt_1.isBitSet(60);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	shiftLeft
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("7f", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('fe', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('01fe', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('411949344998216388118140849290325291159199602592792139973517588004462660346196', 10);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(8);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(8)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(10);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('105459032319543395358244057418323274536755098263754787833220502529142441048626176', 10);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(4096);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('266319164760353889206396941232739217557890883507082863997979538237408246532747151496450837043424377376926977212182012023686831226737377369852125202402098145876219029018646049576792205484267848170179157853023266287725961304046416750146445344507869587461686016719979944538177432428730245324189334334817497396705169439104855885416460935698516539852892760625369984672271807592980051379072961966267124963131928067770749329011150668180796667192392027523071601150548205543997146350727148885425131890513407882508735446345822174200042918879518190588482963417582471561436215675823872015307629566605147920139961896995509627341070659007877630760561618021922340198636222738900413041589858099507891702174848695380017286939422770656819923801325579542295611580916900945707539132241939193098989585491346846486694653352501301851631933610655701026861715541355665900384634131852357081890301147104554877895768806174478161952060916705243614916310627428392386264214492834954273769685672081818149530274447979003153864646452529328518204716201193108795473912970645455457215455929896570875795325190705652768977680951535622436287312272907838194995042100153360373621439300266297151905265332115434133380301670205335338558744799343198526203012170200626802804318535680', 10);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
 | 
			
		||||
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
 | 
			
		||||
	result = bigInt_1.shiftLeft(5000);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.BigInt('36017909319555363939297846508911757008556852467205798478749046189356513330989041570231272721076143922520578818149998351104871978707844731275672652360293180474918203352225676748028889909508585302690242044220987556901043359920075229167479636668489487021705618421769517884399224788393498408327257966673365451264730932480701037648195190724361287852846952667257156204462064385766889505990099642052739974651257588866645027017486311782036674195285521311468922365736517586569614071211079825802088151607502649165228246449902253708785396560087430392277977851200155957347440614508171640900912431375050142178348130480158080696562512167652410483775588091117019722112093545783277082149415339867358805673644654236371762589715111732737686904860620316822561292797144756685380676343141118415434643259498221414744450502163805872581378284735047416230112208369784803081434462030568662742790926051825877463257023387907801068796855629691810029349692983890802136654401365294584656484852908751516361546884362396124203127393434938355516740711953765305060269622960662047729516459906444429108776596594293559927265789943280929098971285454533928986078946124455350540187565506016643147748500262510780357259199808936108629893209819473029835119866186316144675107047007737043503194737001430981972314376700993832503282107582239603281145093446879837002884732470988727066207277180181469885503549870618810897831820650576980763622189213611885522245978572420535750015505830146119605502167931087454823309031494727688701857532561113118183883936890880', 10);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	BigInt compare vs ByteArray compare
 | 
			
		||||
	//
 | 
			
		||||
	var bigInt_byteArray_1;
 | 
			
		||||
	var bigInt_byteArray_2;
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "equal compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "second term with one more bit at the leftmost - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "first term with one more bit at the leftmost - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "first term with one more bit in the middle - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "first term with one more bit in the middle - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
 | 
			
		||||
	bitInt_byteArray_1 = bigInt_1.asByteArray();
 | 
			
		||||
	bitInt_byteArray_2 = bigInt_2.asByteArray();
 | 
			
		||||
	
 | 
			
		||||
	result = bigInt_1.compare(bigInt_2);
 | 
			
		||||
	expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
 | 
			
		||||
	is(result, expectedResult, "equal compare");
 | 
			
		||||
*/
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,155 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
<!-- - ->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
<!- - -->
 | 
			
		||||
<!-- -->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
 | 
			
		||||
<!-- -->
 | 
			
		||||
 | 
			
		||||
<!-- - ->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
 | 
			
		||||
<!- - -->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
 | 
			
		||||
	var deferredResult;
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	deferredResult = new MochiKit.Async.Deferred();
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	ECC.Curve.multiplication
 | 
			
		||||
	//
 | 
			
		||||
	var	curve;
 | 
			
		||||
	var f2m;
 | 
			
		||||
	var f2m_improved;
 | 
			
		||||
	var value;
 | 
			
		||||
	var moduledValue;
 | 
			
		||||
	var result;
 | 
			
		||||
	var result_improved;
 | 
			
		||||
	var expectedResul;
 | 
			
		||||
 | 
			
		||||
	f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
 | 
			
		||||
	f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
 | 
			
		||||
 | 
			
		||||
	curve = Clipperz.Crypto.ECC.StandardCurves.B283();
 | 
			
		||||
	
 | 
			
		||||
/** /
 | 
			
		||||
	value = new Clipperz.Crypto.ECC.BinaryField.Value("7b", 16);
 | 
			
		||||
	result = curve.multiply(value, curve.G());
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
 | 
			
		||||
		x: new Clipperz.Crypto.ECC.BinaryField.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
 | 
			
		||||
		y: new Clipperz.Crypto.ECC.BinaryField.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
 | 
			
		||||
	});
 | 
			
		||||
	is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
 | 
			
		||||
	is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
 | 
			
		||||
/ **/
 | 
			
		||||
 | 
			
		||||
	value = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
 | 
			
		||||
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
 | 
			
		||||
//	deferredResult.addCallback(console.time, 'B283.deferred.multiply - moduled value');
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
 | 
			
		||||
	deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
 | 
			
		||||
//	deferredResult.addBoth(function(res) {console.timeEnd('B283.deferred.multiply - moduled value'); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
 | 
			
		||||
	deferredResult.addCallback(function(res) {
 | 
			
		||||
		var expectedResult;
 | 
			
		||||
		
 | 
			
		||||
		expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
 | 
			
		||||
			x: new Clipperz.Crypto.ECC.BinaryField.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
 | 
			
		||||
			y: new Clipperz.Crypto.ECC.BinaryField.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
 | 
			
		||||
		is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
 | 
			
		||||
	})
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
 | 
			
		||||
	deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
 | 
			
		||||
	deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug(res); return res;});
 | 
			
		||||
	deferredResult.callback();
 | 
			
		||||
	
 | 
			
		||||
	SimpleTest.waitForExplicitFinish();
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,209 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	//
 | 
			
		||||
	//	ECC.BinaryFiniteField
 | 
			
		||||
	//
 | 
			
		||||
	var	f2m;
 | 
			
		||||
	var	f2m_improved;
 | 
			
		||||
	var a, a1, b;
 | 
			
		||||
	var result;
 | 
			
		||||
	var result_improved;
 | 
			
		||||
	var expectedResul;
 | 
			
		||||
 | 
			
		||||
	f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
 | 
			
		||||
	f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("05c91e41 d9ca17ef 9d8a33c1 a44eba6d 368fde02 1c492077 1a46eb01 a481e5f7 f430749d", 16);
 | 
			
		||||
	b = new Clipperz.Crypto.ECC.BinaryField.Value("07377071 2de7d57b a803f65f 45786c06 876b8066 db75ec47 81c053b0 a0f78e2c a6ab5187", 16);
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	addition
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.add(a, b);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	negation
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.negate(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	multiplication
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.multiply(a, b);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	fast multiplication
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.fastMultiply(a, b);
 | 
			
		||||
	expectedResult = f2m.multiply(a, b);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
 | 
			
		||||
	b = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
 | 
			
		||||
	result = f2m.fastMultiply(a, b);
 | 
			
		||||
	expectedResult = f2m.multiply(a, b);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.B283.fastMultiply");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	square
 | 
			
		||||
	//
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	inverse
 | 
			
		||||
	//
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
 | 
			
		||||
	result = f2m.inverse(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("3812fc574f3728c60384e141c0e2a808e21adec22dcd407b9e25dd13c6d1bf22defd84a", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	module
 | 
			
		||||
	//
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved)");
 | 
			
		||||
	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("15e2097d116e745ac47480807cb5eb99dad902728aaf5692241063bc70a5b372dbce798", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (2)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (2)");
 | 
			
		||||
	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (2)");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("40f04cec8fe9caedf82adeff7e1aa06dcb9d08e097db8be2ad54b2ddc2e752152395623", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (3)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (3)");
 | 
			
		||||
	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (3)");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
 | 
			
		||||
	is(a.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value as expected (4)")
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (4)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (4)");
 | 
			
		||||
	is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (4)");
 | 
			
		||||
	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (4)");
 | 
			
		||||
 | 
			
		||||
	is(a.asString(16),  "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by standard method (4)")
 | 
			
		||||
	is(a1.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by improved method (4)")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("2f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
 | 
			
		||||
	result_improved = f2m_improved.module(a);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (5)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (5)");
 | 
			
		||||
	is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (5)");
 | 
			
		||||
	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (5)");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,183 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	//
 | 
			
		||||
	//	ECC.BinaryFiniteField
 | 
			
		||||
	//
 | 
			
		||||
	var	f2m;
 | 
			
		||||
	var	f2m_improved;
 | 
			
		||||
	var a, b;
 | 
			
		||||
	var result;
 | 
			
		||||
	var result_improved;
 | 
			
		||||
	var expectedResul;
 | 
			
		||||
 | 
			
		||||
	f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16)})
 | 
			
		||||
	f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B571().finiteField();
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("01401ca8 7b8f1446 84a2c58a e9308c23 7789e4bf 1f36dd11 7c150b7d 6076dd1d a6197fe4 c5225a06 4db0e422 2589d5ca 50eb6bb6 b7147a03 f6152843 8a8767c6 a6c4a688 3fd6f067", 16);
 | 
			
		||||
	b = new Clipperz.Crypto.ECC.BinaryField.Value("0112f5c9 7e74737b 38925faf e22cea3e 12b868d4 ddea5b33 41db8fc2 e788cab7 4f0a7a3c c27087a8 93659453 69938650 a99217d5 66e13f80 dc87f082 73f7411b 6b01ef1d 399c772a", 16);
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	addition
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.add(a, b);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	negation
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.negate(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	multiplication
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.multiply(a, b);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	fast multiplication
 | 
			
		||||
	//
 | 
			
		||||
	result = f2m.fastMultiply(a, b);
 | 
			
		||||
	expectedResult = f2m.multiply(a, b);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
 | 
			
		||||
	b = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	result = f2m.fastMultiply(a, b);
 | 
			
		||||
	expectedResult = f2m.multiply(a, b);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	square
 | 
			
		||||
	//
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	result = f2m.square(a);
 | 
			
		||||
	expectedResult = f2m.multiply(a, a);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	inverse
 | 
			
		||||
	//
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	result = f2m.inverse(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1f898c60983c4e807e619b9cbe528585fc33aaae419d5e5cb2107269ccdcf21d5ad5b5d78d37fa435a0d0a8a75f2506240c325c6a2eee1a03008f9e1b9c6c0a511b730cdaf9b97e", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	module
 | 
			
		||||
	//
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved)");
 | 
			
		||||
//	is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
 | 
			
		||||
	a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1704018ce75dc462a5ccd1eb18b8002ecb8536c616ec625f440f6888f8c32387e53a5cb3b6050688e9b64a32215a385ee98c518d6a484d5ac0ceeafa825743c84b075bdfabc341b", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
 | 
			
		||||
	is(a.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
 | 
			
		||||
	is(a1.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	result = f2m.module(a);
 | 
			
		||||
	result_improved = f2m_improved.module(a);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("e160dd4a436e63877e1343d06576beaa66e06863ffe4335be38d6a37460a62d11133584a5bc6ac0590e18942e1fa88bb64a4d9fc6c1fd7b55d7e57b50b70a9e7cb2ed904ad77f4", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
 | 
			
		||||
	is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,496 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	var value_1;
 | 
			
		||||
	var value_2;
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("a", 16);
 | 
			
		||||
	is(value_1.asString(16), "0a");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff", 16);
 | 
			
		||||
	is(value_1.asString(16), "ffff");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7fff", 16);
 | 
			
		||||
	is(value_1.asString(16), "7fff");
 | 
			
		||||
 | 
			
		||||
	is(parseInt("ffff", 16), 65535);
 | 
			
		||||
	is(parseInt("ffffff", 16), 16777215);
 | 
			
		||||
	is(parseInt("ffffffff", 16), 4294967295);
 | 
			
		||||
	is(parseInt("ffffffffff", 16), 1099511627775);
 | 
			
		||||
	is(parseInt("ffffffffffff", 16), 281474976710655);
 | 
			
		||||
	is(parseInt("ffffffffffffff", 16), 72057594037927940);
 | 
			
		||||
	is(parseInt("ffffffffffffffff", 16), 18446744073709552000);
 | 
			
		||||
	is(parseInt("10000000000000000", 16), 18446744073709552001);
 | 
			
		||||
	is(parseInt("10000000000000001", 16), 18446744073709552002);
 | 
			
		||||
	is(parseInt("10000000000000009", 16), 18446744073709552010);
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	is(value_1.wordSize(), 8, "check the number of words of a 64 char hex string using the 'wordSize' method");
 | 
			
		||||
 | 
			
		||||
//	000108cb bacda1f0 3ea93603 01045434 ec7d82ba 150936df 08a229cb b4832ce1	
 | 
			
		||||
	is(value_1.value()[0], parseInt("b4832ce1", 16), "word[0]");
 | 
			
		||||
	is(value_1.value()[1], parseInt("08a229cb", 16), "word[1]");
 | 
			
		||||
	is(value_1.value()[2], parseInt("150936df", 16), "word[2]");
 | 
			
		||||
	is(value_1.value()[3], parseInt("ec7d82ba", 16), "word[3]");
 | 
			
		||||
	is(value_1.value()[4], parseInt("01045434", 16), "word[4]");
 | 
			
		||||
	is(value_1.value()[5], parseInt("3ea93603", 16), "word[5]");
 | 
			
		||||
	is(value_1.value()[6], parseInt("bacda1f0", 16), "word[6]");
 | 
			
		||||
	is(value_1.value()[7], parseInt("000108cb", 16), "word[7]");
 | 
			
		||||
	
 | 
			
		||||
	is(value_1.asString(16), "0108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "asString(16)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
 | 
			
		||||
	is(value_1.wordSize(), 3, "check the number of words of a value with only a bit set on the first slot of byte at position 17");
 | 
			
		||||
	is(value_1.value()[0], parseInt("00000000", 16), "word[0]");
 | 
			
		||||
	is(value_1.value()[1], parseInt("00000000", 16), "word[1]");
 | 
			
		||||
	is(value_1.value()[2], parseInt("10", 16), "word[2]");
 | 
			
		||||
	is(value_1.asString(16), "100000000000000000", "2^17 asString(16)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	XOR
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855', 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b935c a495991b 7852b855', 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "single bit difference");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855', 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b854', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "01 xor value");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('1000000000000000000000000000000000000000000000000000000000000000', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('84a2c58a', 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('38925faf', 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('bc309a25', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "84a2c58a XOR 38925faf = bc309a25");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
 | 
			
		||||
	result = value_1.xor(value_2);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0052e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "xor");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("01ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f816429a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "xor");
 | 
			
		||||
	is(result.bitSize(), 1120, "xor.bitSize");
 | 
			
		||||
	is(result.wordSize(), 35, "result wordSize");
 | 
			
		||||
	is(expectedResult.bitSize(), 1120, "xor.bitSize");
 | 
			
		||||
	is(expectedResult.wordSize(), 35, "expectedResult wordSize");
 | 
			
		||||
	is(result.compare(expectedResult), 0, "compare");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "xor");
 | 
			
		||||
	is(result.bitSize(), 1119, "xor.bitSize");
 | 
			
		||||
	is(expectedResult.bitSize(), 1119, "xor.bitSize");
 | 
			
		||||
	is(result.compare(expectedResult), 0, "compare");
 | 
			
		||||
//	value_1 = 
 | 
			
		||||
//	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 16);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	value_1 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010 01010101 00000000", 16)).value();
 | 
			
		||||
	value_2 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010", 16)).value();
 | 
			
		||||
	result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("01010101 00000000", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "xor with offset 2");
 | 
			
		||||
 | 
			
		||||
	value_1 = 		(new Clipperz.Crypto.ECC.BinaryField.Value("         10101010 01010101 00000000", 16)).value();
 | 
			
		||||
	value_2 = 		(new Clipperz.Crypto.ECC.BinaryField.Value("10101010 10101010", 16)).value();
 | 
			
		||||
	result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("10101010 00000000 01010101 00000000", 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "xor with offset 2 (2)");
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	isZero
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
 | 
			
		||||
	is(value_1.isZero(), true, "0.isZero() == true");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16);
 | 
			
		||||
	is(value_1.isZero(), false, "1.isZero() == false");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	Comparison
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
 | 
			
		||||
	is (value_1.compare(value_2), 0, "BinaryField.value(0) = BinaryField.value(0)");
 | 
			
		||||
//	is (value_1.compare(0), 0, "BinaryField.value(0) = 0");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	is (value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) != BinaryField.value(0)");
 | 
			
		||||
	
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
 | 
			
		||||
	is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(0)");
 | 
			
		||||
	is(value_2.compare(value_1), -1, "BinaryField.value(0) < BinaryField.value(xxxx)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
 | 
			
		||||
	is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(05)");
 | 
			
		||||
	is(value_2.compare(value_1), -1, "BinaryField.value(05) < BinaryField.value(xxxx)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("-10", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
 | 
			
		||||
	is(value_1.compare(value_2), -1, "BinaryField.value(-10) - BinaryField.value(10). No negative number are managed");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	more comparison
 | 
			
		||||
	//
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 0, "equal compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, -1, "second term with one more bit at the leftmost - compare (1)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, -1, "second term with one more bit at the leftmost - compare (2)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, -1, "second term with one more bit at the leftmost - compare (3)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, -1, "second term with one more bit at the leftmost - compare (n)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "first term with one more bit at the leftmost - compare (1)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "first term with one more bit at the leftmost - compare (2)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "first term with one more bit at the leftmost - compare (n)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "first term with one more bit in the middle - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "first term with one more bit in the middle - compare");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
 | 
			
		||||
	result = value_1.compare(value_2);
 | 
			
		||||
	is(result, 1, "equal compare");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	isBitSet
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	result = value_1.isBitSet(1);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'ff'.isBitSet(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
 | 
			
		||||
	result =value_1.isBitSet(1);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
 | 
			
		||||
	result = value_1.isBitSet(3);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(3)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
 | 
			
		||||
	result = value_1.isBitSet(4);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'f0'.isBitSet(4)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
 | 
			
		||||
	result = value_1.isBitSet(7);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'ff00'.isBitSet(7)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
 | 
			
		||||
	result = value_1.isBitSet(8);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'ff00'.isBitSet(8)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("05000000000000", 16);
 | 
			
		||||
	result = value_1.isBitSet(47);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(47)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(48);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(48)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(49);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(49)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(50);
 | 
			
		||||
	expectedResult = true;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(50)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(51);
 | 
			
		||||
	expectedResult = false;
 | 
			
		||||
	is(result, expectedResult, "'05000000000000'.isBitSet(51)");
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(52);
 | 
			
		||||
	is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(53);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(54);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(55);
 | 
			
		||||
	is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(56);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(57);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(58);
 | 
			
		||||
	is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(59);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
 | 
			
		||||
 | 
			
		||||
	result = value_1.isBitSet(60);
 | 
			
		||||
	is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//
 | 
			
		||||
	//	shiftLeft
 | 
			
		||||
	//
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7f", 16);
 | 
			
		||||
	result = value_1.shiftLeft(1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('fe', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	result = value_1.shiftLeft(1);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('01fe', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value(  'ffff', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('ffff00', 16);
 | 
			
		||||
	result = value_1.shiftLeft(8);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ffff.shiftLeft(8)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value(  '80000000', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('1 00000000', 16);
 | 
			
		||||
	result = value_1.shiftLeft(1);
 | 
			
		||||
	is(result.compare(expectedResult) == 0, true, '8000000.shiftLeft(1).compare');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "80000000.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value('20000000', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
 | 
			
		||||
	result = value_1.shiftLeft(1);
 | 
			
		||||
	is(result.compare(expectedResult) == 0, true, '2000000.shiftLeft(1).compare');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "20000000.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('80000000', 16);
 | 
			
		||||
	result = value_1.shiftLeft(1);
 | 
			
		||||
	is(result.compare(expectedResult) == 0, true, '4000000.shiftLeft(1).compare');
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "40000000.shiftLeft(1)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value(   'ff7fffff', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('ff 7fffff00', 16);
 | 
			
		||||
	result = value_1.shiftLeft(8);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ff7fffff.shiftLeft(8)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value(   'ffffffff', 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('ff ffffff00', 16);
 | 
			
		||||
	result = value_1.shiftLeft(8);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ffffffff.shiftLeft(8)");
 | 
			
		||||
 | 
			
		||||
	value_1 =			new Clipperz.Crypto.ECC.BinaryField.Value(  "e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
 | 
			
		||||
	expectedResult =	new Clipperz.Crypto.ECC.BinaryField.Value('3 8ec3110a 63f07052 6befd322 65bee490 9eb90791 926e4d32 9256646d e14ae154', 16);
 | 
			
		||||
	result = value_1.shiftLeft(2);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = value_1.shiftLeft(8);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(8)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
 | 
			
		||||
	result = value_1.shiftLeft(10);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('38e c3110a63 f070526b efd32265 bee4909e b9079192 6e4d3292 56646de1 4ae15400', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	result = value_1.shiftLeft(32);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "ff.shiftLeft(32)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	result = value_1.shiftLeft(4096);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	result = value_1.shiftLeft(5000);
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
 | 
			
		||||
	is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
 | 
			
		||||
	is(value_1.bitSize(), 0, "0.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
 | 
			
		||||
	is(value_1.bitSize(), 5, "10.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80", 16);
 | 
			
		||||
	is(value_1.bitSize(), 8, "80.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
 | 
			
		||||
	is(value_1.bitSize(), 8, "ff.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("100", 16);
 | 
			
		||||
	is(value_1.bitSize(), 9, "100.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80000000", 16);
 | 
			
		||||
	is(value_1.bitSize(), 32, "80000000.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffffffff", 16);
 | 
			
		||||
	is(value_1.bitSize(), 32, "ffffffff.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("1 00000000", 16);
 | 
			
		||||
	is(value_1.bitSize(), 33, "100000000.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("8000 00000000", 16);
 | 
			
		||||
	is(value_1.bitSize(), 48, "8000 00000000.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff ffffffff", 16);
 | 
			
		||||
	is(value_1.bitSize(), 48, "ffff ffffffff.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10000 00000000", 16);
 | 
			
		||||
	is(value_1.bitSize(), 49, "10000 00000000.bitSize()");
 | 
			
		||||
 | 
			
		||||
	value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
 | 
			
		||||
	is(value_1.bitSize(), 1119, "6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16.bitSize()");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@@ -0,0 +1,160 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
<!-- - ->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
<!- - -->
 | 
			
		||||
<!-- -->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
 | 
			
		||||
<!-- -->
 | 
			
		||||
 | 
			
		||||
<!-- - ->
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
 | 
			
		||||
<!- - -->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
 | 
			
		||||
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>-->
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>-->
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Value.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Point.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/FiniteField.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Curve.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
 | 
			
		||||
	var deferredResult;
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	deferredResult = new MochiKit.Async.Deferred();
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
 | 
			
		||||
	
 | 
			
		||||
	//
 | 
			
		||||
	//	ECC.Curve.multiplication
 | 
			
		||||
	//
 | 
			
		||||
	var	curve;
 | 
			
		||||
	var f2m;
 | 
			
		||||
	var f2m_improved;
 | 
			
		||||
	var value;
 | 
			
		||||
	var moduledValue;
 | 
			
		||||
	var result;
 | 
			
		||||
	var result_improved;
 | 
			
		||||
	var expectedResul;
 | 
			
		||||
 | 
			
		||||
	f2m = new Clipperz.Crypto.ECC.Koblitz.FiniteField({modulus:new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
 | 
			
		||||
	f2m_improved = Clipperz.Crypto.ECC.StandardCurves.K283().finiteField();
 | 
			
		||||
 | 
			
		||||
	curve = Clipperz.Crypto.ECC.StandardCurves.K283();
 | 
			
		||||
	
 | 
			
		||||
/** /
 | 
			
		||||
	value = new Clipperz.Crypto.ECC.Koblitz.Value("7b", 16);
 | 
			
		||||
	result = curve.multiply(value, curve.G());
 | 
			
		||||
	expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
 | 
			
		||||
		x: new Clipperz.Crypto.ECC.Koblitz.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
 | 
			
		||||
		y: new Clipperz.Crypto.ECC.Koblitz.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
 | 
			
		||||
	});
 | 
			
		||||
	is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
 | 
			
		||||
	is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
 | 
			
		||||
/ **/
 | 
			
		||||
 | 
			
		||||
	value = new Clipperz.Crypto.ECC.Koblitz.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
 | 
			
		||||
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
 | 
			
		||||
//	deferredResult.addCallback(console.time, 'K283.deferred.multiply - moduled value');
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
 | 
			
		||||
	deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
 | 
			
		||||
//	deferredResult.addBoth(function(res) {console.timeEnd('K283.deferred.multiply - moduled value'); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
 | 
			
		||||
	deferredResult.addCallback(function(res) {
 | 
			
		||||
		var expectedResult;
 | 
			
		||||
		
 | 
			
		||||
		expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
 | 
			
		||||
			x: new Clipperz.Crypto.ECC.Koblitz.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
 | 
			
		||||
			y: new Clipperz.Crypto.ECC.Koblitz.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
 | 
			
		||||
		is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
 | 
			
		||||
	})
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
 | 
			
		||||
	deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
 | 
			
		||||
//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 11: " + res); return res;});
 | 
			
		||||
	deferredResult.callback();
 | 
			
		||||
	
 | 
			
		||||
	SimpleTest.waitForExplicitFinish();
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -0,0 +1,418 @@
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
//function logElapsedTime(aDescription, aStartTime, anEndTime) {
 | 
			
		||||
//	MochiKit.Logging.logDebug(aDescription + " - took " + (anEndTime - aStartTime) + "ms");
 | 
			
		||||
//	SimpleTest.ok(true, aDescription + " - took " + (anEndTime - aStartTime) + "ms");
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
var asciiTestString		= longAsciiText;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString;
 | 
			
		||||
//asciiTestString = asciiTestString + asciiTestString;
 | 
			
		||||
 | 
			
		||||
var isoLatin1TestString	= longIsoLatin1Text;
 | 
			
		||||
//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
 | 
			
		||||
//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
 | 
			
		||||
//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
 | 
			
		||||
//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
 | 
			
		||||
//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
 | 
			
		||||
 | 
			
		||||
var utf8TestString		= longUtf8Text;
 | 
			
		||||
//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
 | 
			
		||||
//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
 | 
			
		||||
//utf8TestString = utf8TestString + utf8TestString;
 | 
			
		||||
//utf8TestString = utf8TestString + utf8TestString;
 | 
			
		||||
 | 
			
		||||
var times = {
 | 
			
		||||
	'Clipperz': {},
 | 
			
		||||
	'JSCrypto': {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function appendResults (aDescription, aTimer) {
 | 
			
		||||
	MochiKit.DOM.appendChildNodes(MochiKit.DOM.getElement('timerTBODY'),
 | 
			
		||||
		MochiKit.DOM.TR(null, 
 | 
			
		||||
			MochiKit.DOM.TH({align:'left'}, aDescription),
 | 
			
		||||
			MochiKit.DOM.TH(null, aTimer['ascii']['encrypt'] 		+ ' - ' + aTimer['ascii']['decrypt'])//,
 | 
			
		||||
//			MochiKit.DOM.TH(null, aTimer['isoLatin1']['encrypt']	+ ' - ' + aTimer['isoLatin1']['decrypt']),
 | 
			
		||||
//			MochiKit.DOM.TH(null, aTimer['utf8']['encrypt'] 		+ ' - ' + aTimer['utf8']['decrypt'])
 | 
			
		||||
		)
 | 
			
		||||
	);
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
function timeRegularFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey) {
 | 
			
		||||
	var start;
 | 
			
		||||
	var end;
 | 
			
		||||
	var encryptTime;
 | 
			
		||||
	var decryptTime;
 | 
			
		||||
	var ciphertext;
 | 
			
		||||
	var plaintext;
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	ciphertext = anEncryptFunction('trustno1', aString);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	encryptTime = end - start;
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	plaintext = aDecryptFunction('trustno1', ciphertext);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	decryptTime = end - start;
 | 
			
		||||
	aTimer[aKey] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
 | 
			
		||||
	SimpleTest.is(aString, plaintext, aDescription);
 | 
			
		||||
}
 | 
			
		||||
/*
 | 
			
		||||
function timeRegularFunction (anEncryptFunction, aDecryptFunction, aTimer) {
 | 
			
		||||
	var start;
 | 
			
		||||
	var end;
 | 
			
		||||
	var encryptTime;
 | 
			
		||||
	var decryptTime;
 | 
			
		||||
	var ciphertext;
 | 
			
		||||
	var plaintext;
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	ciphertext = anEncryptFunction('trustno1', asciiTestString);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	encryptTime = end - start;
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	plaintext = aDecryptFunction('trustno1', ciphertext);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	decryptTime = end - start;
 | 
			
		||||
	aTimer['ascii'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
 | 
			
		||||
	SimpleTest.is(asciiTestString, plaintext, "Encrypt/decrypt the ASCII text");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	ciphertext = anEncryptFunction('trustno1', isoLatin1TestString);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	encryptTime = end - start;
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	plaintext = aDecryptFunction('trustno1', ciphertext);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	decryptTime = end - start;
 | 
			
		||||
	aTimer['isoLatin1'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
 | 
			
		||||
	SimpleTest.is(isoLatin1TestString, plaintext, "Encrypt/decrypt the ISO-Latin 1 text");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	ciphertext = anEncryptFunction('trustno1', utf8TestString);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	encryptTime = end - start;
 | 
			
		||||
 | 
			
		||||
	start = new Date();
 | 
			
		||||
	plaintext = aDecryptFunction('trustno1', ciphertext);
 | 
			
		||||
	end = new Date();
 | 
			
		||||
	decryptTime = end - start;
 | 
			
		||||
	aTimer['utf8'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
 | 
			
		||||
	SimpleTest.is(utf8TestString, plaintext, "Encrypt/decrypt the UTF-8 text");
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
function timeDeferredFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey, someTestArgs) {
 | 
			
		||||
	var start;
 | 
			
		||||
	var end;
 | 
			
		||||
	
 | 
			
		||||
	var deferredResult;
 | 
			
		||||
 | 
			
		||||
	aTimer[aKey] = {};
 | 
			
		||||
	
 | 
			
		||||
	deferredResult = new Clipperz.Async.Deferred("timeDeferredFunction", someTestArgs);
 | 
			
		||||
	deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
 | 
			
		||||
	deferredResult.addCallback(anEncryptFunction, 'trustno1', aString);
 | 
			
		||||
	deferredResult.addCallback(function (aValue) {
 | 
			
		||||
		end = new Date();
 | 
			
		||||
		aTimer[aKey]['encrypt'] = end-start;
 | 
			
		||||
		return aValue;
 | 
			
		||||
	});
 | 
			
		||||
	deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
 | 
			
		||||
	deferredResult.addCallback(aDecryptFunction, 'trustno1');
 | 
			
		||||
	deferredResult.addCallback(function (aValue) {
 | 
			
		||||
		end = new Date();
 | 
			
		||||
		aTimer[aKey]['decrypt'] = end-start;
 | 
			
		||||
		return aValue;
 | 
			
		||||
	});
 | 
			
		||||
	deferredResult.addCallback(function (aValue) {
 | 
			
		||||
		SimpleTest.is(aString, aValue, aDescription);
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	deferredResult.callback();
 | 
			
		||||
	
 | 
			
		||||
	return deferredResult;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
function encryptUsingJSCrypto (aKey, aValue) {
 | 
			
		||||
	var salt;
 | 
			
		||||
	var key;
 | 
			
		||||
	var cipher;
 | 
			
		||||
	var iv;
 | 
			
		||||
	var plaintext;
 | 
			
		||||
	var ciphertext;
 | 
			
		||||
	var tag;
 | 
			
		||||
	var adata;
 | 
			
		||||
	
 | 
			
		||||
	salt = [1,2,3,4,5,6,7,8];
 | 
			
		||||
	key = generateKey(aKey, salt);
 | 
			
		||||
 | 
			
		||||
	cipher = new aes(key, CCM);
 | 
			
		||||
	iv = Random.random_words(4);
 | 
			
		||||
 | 
			
		||||
	plaintext = aValue;
 | 
			
		||||
	ciphertext = [];
 | 
			
		||||
	tag = [];
 | 
			
		||||
	adata = "";
 | 
			
		||||
 | 
			
		||||
	cipher.encrypt(iv, plaintext, ciphertext, adata, tag);
 | 
			
		||||
 | 
			
		||||
	return ciphertext;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
function decryptUsingJSCrypto (aKey, aValue) {
 | 
			
		||||
	var salt;
 | 
			
		||||
	var key;
 | 
			
		||||
	var cipher;
 | 
			
		||||
	var ciphertext;
 | 
			
		||||
	var plaintext;
 | 
			
		||||
	var tag;
 | 
			
		||||
	var adata;
 | 
			
		||||
	
 | 
			
		||||
	salt = [1,2,3,4,5,6,7,8];
 | 
			
		||||
	key = generateKey(aKey, salt);
 | 
			
		||||
	tag = [];
 | 
			
		||||
	adata = "";
 | 
			
		||||
 | 
			
		||||
	cipher = new aes(key, CCM);
 | 
			
		||||
	ciphertext = aValue;
 | 
			
		||||
	plaintext = cipher.decrypt(ciphertext, adata, tag);
 | 
			
		||||
 | 
			
		||||
	return plaintext;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
function encryptUsingClipperz (aKey, aValue) {
 | 
			
		||||
	var key;
 | 
			
		||||
	var value;
 | 
			
		||||
	var data;
 | 
			
		||||
	var encryptedData;
 | 
			
		||||
	
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	value = aValue;
 | 
			
		||||
	data = new Clipperz.ByteArray(value);
 | 
			
		||||
	encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
 | 
			
		||||
	return encryptedData.toBase64String();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
function decryptUsingClipperz (aKey, aValue) {
 | 
			
		||||
	var key;
 | 
			
		||||
	var value;
 | 
			
		||||
	var decryptedData;
 | 
			
		||||
	
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	value = new Clipperz.ByteArray().appendBase64String(aValue);
 | 
			
		||||
 | 
			
		||||
	decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
 | 
			
		||||
 | 
			
		||||
	return decryptedData;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
function encryptUsingClipperzAndJSON (aKey, aValue) {
 | 
			
		||||
	var key;
 | 
			
		||||
	var value;
 | 
			
		||||
	var data;
 | 
			
		||||
	var encryptedData;
 | 
			
		||||
	
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	value = Clipperz.Base.serializeJSON(aValue);
 | 
			
		||||
	data = new Clipperz.ByteArray(value);
 | 
			
		||||
	encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
 | 
			
		||||
	return encryptedData.toBase64String();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
function decryptUsingClipperzAndJSON (aKey, aValue) {
 | 
			
		||||
	var key;
 | 
			
		||||
	var value;
 | 
			
		||||
	var decryptedData;
 | 
			
		||||
	
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	value = new Clipperz.ByteArray().appendBase64String(aValue);
 | 
			
		||||
 | 
			
		||||
	decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
 | 
			
		||||
 | 
			
		||||
	return Clipperz.Base.evalJSON(decryptedData);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
function deferredEncryptUsingClipperz (aKey, aValue) {
 | 
			
		||||
	var deferredResult;
 | 
			
		||||
	var	key;
 | 
			
		||||
	var data;
 | 
			
		||||
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	data = new Clipperz.ByteArray(aValue);
 | 
			
		||||
	
 | 
			
		||||
	deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredEncrypt", {trace:false});
 | 
			
		||||
	deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data);
 | 
			
		||||
	deferredResult.addCallback(function(aResult) {
 | 
			
		||||
		return aResult.toBase64String();
 | 
			
		||||
	})
 | 
			
		||||
	deferredResult.callback();
 | 
			
		||||
	
 | 
			
		||||
	return deferredResult;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
function deferredDecryptUsingClipperz (aKey, aValue) {
 | 
			
		||||
	var key, value;
 | 
			
		||||
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
 | 
			
		||||
	value = new Clipperz.ByteArray().appendBase64String(aValue);
 | 
			
		||||
 | 
			
		||||
	deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredDecrypt", {trace:false});
 | 
			
		||||
	deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value);
 | 
			
		||||
	deferredResult.addCallback(function(aResult) {
 | 
			
		||||
		return aResult.asString();
 | 
			
		||||
	});
 | 
			
		||||
	deferredResult.callback();
 | 
			
		||||
	
 | 
			
		||||
	return deferredResult;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
var tests = {
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'encryptMultipleStringsUsingClipperzFunctions': function (someTestArgs) {
 | 
			
		||||
//		timeRegularFunction(encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['Regular']);
 | 
			
		||||
		times['Clipperz']['NO JSON'] = {};
 | 
			
		||||
 | 
			
		||||
		timeRegularFunction("Clipperz - NO JSON - Ascii",		asciiTestString,		encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'ascii');
 | 
			
		||||
		timeRegularFunction("Clipperz - NO JSON - ISO Latin 1",	isoLatin1TestString,	encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'isoLatin1');
 | 
			
		||||
		timeRegularFunction("Clipperz - NO JSON - UTF-8",		utf8TestString,			encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'utf8');
 | 
			
		||||
 | 
			
		||||
		appendResults("Clipperz - NO JSON", times['Clipperz']['NO JSON']);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'encryptMultipleStringsUsingClipperzAndJSONFunctions': function (someTestArgs) {
 | 
			
		||||
//		timeRegularFunction(encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON']);
 | 
			
		||||
		times['Clipperz']['JSON'] = {};
 | 
			
		||||
		
 | 
			
		||||
		timeRegularFunction("Clipperz - JSON - Ascii",			asciiTestString,		encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'ascii');
 | 
			
		||||
		timeRegularFunction("Clipperz - JSON - ISO Latin 1",	isoLatin1TestString,	encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'isoLatin1');
 | 
			
		||||
		timeRegularFunction("Clipperz - JSON - UTF-8",			utf8TestString,			encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'utf8');
 | 
			
		||||
 | 
			
		||||
		appendResults("Clipperz - JSON", times['Clipperz']['JSON']);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'encryptMultipleStringsUsingClipperzDeferredFunctions': function (someTestArgs) {
 | 
			
		||||
		times['Clipperz']['Deferred'] = {};
 | 
			
		||||
		times['Clipperz']['Deferred [NO JSON]'] = {};
 | 
			
		||||
 | 
			
		||||
		return Clipperz.Async.callbacks("encryptMultipleStringsUsingClipperzDeferredFunctions", [
 | 
			
		||||
			MochiKit.Base.partial(timeDeferredFunction, "Deferred Ascii",		asciiTestString,		deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'ascii',		someTestArgs),
 | 
			
		||||
//			MochiKit.Base.partial(timeDeferredFunction, "Deferred IsoLatin1",	isoLatin1TestString,	deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'isoLatin1',	someTestArgs),
 | 
			
		||||
//			MochiKit.Base.partial(timeDeferredFunction, "Deferred UTF-8",		utf8TestString,			deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'utf8',		someTestArgs),
 | 
			
		||||
 | 
			
		||||
			MochiKit.Base.partial(appendResults, "Clipperz - deferred [NO JSON]", times['Clipperz']['Deferred [NO JSON]']),
 | 
			
		||||
			
 | 
			
		||||
			MochiKit.Base.partial(timeDeferredFunction, "Deferred Ascii",		asciiTestString,		Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'ascii',		someTestArgs),
 | 
			
		||||
//			MochiKit.Base.partial(timeDeferredFunction, "Deferred IsoLatin1",	isoLatin1TestString,	Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'isoLatin1',	someTestArgs),
 | 
			
		||||
//			MochiKit.Base.partial(timeDeferredFunction, "Deferred UTF-8",		utf8TestString,			Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'utf8',		someTestArgs),
 | 
			
		||||
 | 
			
		||||
			MochiKit.Base.partial(appendResults, "Clipperz - PM", times['Clipperz']['Deferred'])
 | 
			
		||||
		], someTestArgs);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'encryptMultipleStringsUsingJSCryptoFunctions': function (someTestArgs) {
 | 
			
		||||
		timeRegularFunction("JSCrypto - Ascii",			asciiTestString,		encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'ascii');
 | 
			
		||||
		timeRegularFunction("JSCrypto - ISO Latin 1",	isoLatin1TestString,	encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'isoLatin1');
 | 
			
		||||
		timeRegularFunction("JSCrypto - UTF-8",			utf8TestString,			encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'utf8');
 | 
			
		||||
 | 
			
		||||
		appendResults("JSCrypto", times['JSCrypto']);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
    'syntaxFix': MochiKit.Base.noop
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//#############################################################################
 | 
			
		||||
 | 
			
		||||
SimpleTest.waitForExplicitFinish();
 | 
			
		||||
Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
 | 
			
		||||
Random.set_default_paranoia(0);
 | 
			
		||||
 | 
			
		||||
//Random.addEventListener("seeded", MochiKit.Base.partial(SimpleTest.runDeferredTests, "Clipperz.Crypto.JSCrypto_vs_Clipperz", tests, {trace:false}));
 | 
			
		||||
//Random.addEventListener("seeded", function () { console.log("SEEDED!")});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body,
 | 
			
		||||
	MochiKit.DOM.TABLE({border:'1', cellpadding:'4', cellspacing:'0'}, 
 | 
			
		||||
		MochiKit.DOM.THEAD(),
 | 
			
		||||
		MochiKit.DOM.TBODY({id:'timerTBODY'}, 
 | 
			
		||||
			MochiKit.DOM.TR(null, 
 | 
			
		||||
				MochiKit.DOM.TH(null, "algorithm"),
 | 
			
		||||
				MochiKit.DOM.TH(null, "ascii [" + asciiTestString.length + "]"),
 | 
			
		||||
				MochiKit.DOM.TH(null, "ISO Latin 1 [" + isoLatin1TestString.length * 2 + "]"),
 | 
			
		||||
				MochiKit.DOM.TH(null, "UTF 8 [" + utf8TestString.length * 3 + "]")
 | 
			
		||||
			)
 | 
			
		||||
		),
 | 
			
		||||
		MochiKit.DOM.TFOOT()
 | 
			
		||||
	)//,
 | 
			
		||||
//	MochiKit.DOM.H4(null, "AES chunkSize: " + Clipperz.Crypto.AES.DeferredExecution.chunkSize),
 | 
			
		||||
//	MochiKit.DOM.H4(null, "AES pauseTime: " + Clipperz.Crypto.AES.DeferredExecution.pauseTime)
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
SimpleTest.runDeferredTests("Clipperz.Crypto.JSCrypto_vs_Clipperz", tests, {trace:false});
 | 
			
		||||
							
								
								
									
										117
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,117 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script> jslog_config_enabled = true; </script>
 | 
			
		||||
	
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
 | 
			
		||||
 | 
			
		||||
<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Statistics.js'></script>-->
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
test_PRNG = function() {
 | 
			
		||||
	var	rand1, rand2;
 | 
			
		||||
	var i,c;
 | 
			
		||||
	
 | 
			
		||||
	c = 10;
 | 
			
		||||
	for (i=0; i<c; i++) {
 | 
			
		||||
//		jslog.debug(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
 | 
			
		||||
	is(rand1.byteAtIndex(0) <= 255, true, "getRandomByte returns always a single byte");
 | 
			
		||||
 | 
			
		||||
	rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
 | 
			
		||||
	is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
 | 
			
		||||
	rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
 | 
			
		||||
	is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
 | 
			
		||||
	is(rand1.split(0,1).equals(rand2.split(0,1)), false, "getRandomByte should almost always return two different values when called into sequence");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 1", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 2", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 3", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 4", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 5", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 6", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 7", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 8", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 9", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 10", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 11", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 12", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 13", "Value for random test");
 | 
			
		||||
//	is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 14", "Value for random test");
 | 
			
		||||
//jslog.debug(rand1.toHexString());
 | 
			
		||||
//jslog.debug(rand2.toHexString());
 | 
			
		||||
 | 
			
		||||
	SimpleTest.finish();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
	MochiKit.Signal.connect(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'readyToGenerateRandomBytes', test_PRNG);
 | 
			
		||||
	Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
 | 
			
		||||
	SimpleTest.waitForExplicitFinish();
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										90
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/RSA.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
try {
 | 
			
		||||
	var	rsaPublicKey;
 | 
			
		||||
	var	randomValue;
 | 
			
		||||
	var	publicEncryptedValue;
 | 
			
		||||
	var privateEncryptedValue;
 | 
			
		||||
 | 
			
		||||
	var	startTime;
 | 
			
		||||
	var	endTime;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
startTime=new Date();
 | 
			
		||||
	rsaPublicKey = Clipperz.Crypto.RSA.generatePublicKey(512);
 | 
			
		||||
 | 
			
		||||
endTime=new Date();
 | 
			
		||||
is(true, true, 'Time to generate the RSA public key (size 512 bit): '+(endTime.getTime()-startTime.getTime())/1000.0);
 | 
			
		||||
 | 
			
		||||
	randomValue = Clipperz.Crypto.Base.generateRandomSeed();
 | 
			
		||||
	publicEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPublicKey(rsaPublicKey, randomValue);
 | 
			
		||||
	privateEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPrivateKey(rsaPublicKey, randomValue);
 | 
			
		||||
	
 | 
			
		||||
	is(publicEncryptedValue == privateEncryptedValue, false);
 | 
			
		||||
	is(Clipperz.Crypto.RSA.decryptUsingPrivateKey(rsaPublicKey, publicEncryptedValue), randomValue);
 | 
			
		||||
	is(Clipperz.Crypto.RSA.decryptUsingPublicKey(rsaPublicKey, privateEncryptedValue), randomValue);
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										175
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,175 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<title>Clipperz.Crypto.SHA - TEST</title>
 | 
			
		||||
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../js/JSON/json2.js'></script>
 | 
			
		||||
                                        
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript" src="SHA.test.js"></script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<!-- html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script>
 | 
			
		||||
		jslog_config_enabled = true;
 | 
			
		||||
		clipperz_profiling_enabled = true;
 | 
			
		||||
	</script>
 | 
			
		||||
	
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
	var	byteArray;
 | 
			
		||||
	var	hash;
 | 
			
		||||
	var longText;
 | 
			
		||||
	var startTime, endTime;
 | 
			
		||||
	
 | 
			
		||||
	longText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nunc sapien, condimentum vitae, varius vel, pharetra in, augue. Mauris quam magna, pretium sit amet, accumsan id, volutpat lobortis, nibh. Fusce sagittis. Aenean justo. Curabitur euismod pede. Morbi at ante. Proin nisl leo, ultrices sed, facilisis et, nonummy sit amet, lorem. Praesent mauris tellus, pulvinar sed, nonummy vitae, rhoncus non, nunc. Proin placerat malesuada nisl. Nunc id enim. Maecenas commodo enim ac nibh. Sed condimentum, urna sit amet euismod gravida, mi urna varius odio, luctus pretium lectus justo nec felis. Ut in augue et est malesuada rhoncus. Sed vel orci. Mauris suscipit.  Praesent cursus velit non turpis. Donec tristique dolor ac est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est sapien, vulputate eget, bibendum id, pharetra nec, mauris. Aliquam faucibus tincidunt dui. Proin iaculis. Maecenas sagittis. Integer et augue. Donec vitae urna in orci aliquet commodo. Vestibulum lorem sem, suscipit ac, placerat nec, mollis in, felis. Donec laoreet odio a mauris. Integer rutrum, sapien id varius molestie, mauris odio egestas orci, non bibendum sem felis in metus.  Phasellus consectetuer lectus adipiscing mauris. Ut magna tellus, euismod ac, suscipit tincidunt, ullamcorper adipiscing, massa. Etiam orci. Phasellus a urna. Cras neque quam, laoreet at, tempus eget, euismod nec, nibh. Etiam hendrerit. Aenean vel lorem. Ut ligula lacus, congue eu, lobortis sit amet, venenatis in, magna. Nullam cursus felis quis est. Sed sem est, condimentum eu, vestibulum a, mattis vel, diam. Curabitur tincidunt pede quis pede. Sed neque diam, convallis vel, luctus at, porta id, nisl. Suspendisse potenti. Sed volutpat lobortis orci. Praesent mi. In interdum. Suspendisse suscipit ipsum eget dolor. Curabitur et tellus sed velit hendrerit varius. Cras sit amet est.  Donec arcu nulla, vehicula et, pretium in, placerat id, felis. Integer mollis auctor lectus. Integer ultrices elementum sapien. Nam et erat. Nam pulvinar porta tortor. Nam at risus. Quisque nulla. Integer vestibulum, lacus id bibendum laoreet, ligula mi pharetra lorem, sit amet pharetra felis mauris quis justo. Aliquam ultricies. Duis a pede eget lorem dapibus rhoncus. Aenean eu elit non libero consectetuer viverra. Maecenas velit mi, eleifend vel, malesuada vel, condimentum quis, odio. Mauris tempus augue sed turpis. Pellentesque condimentum, lacus vitae pellentesque ultricies, risus tellus posuere nisi, et dictum turpis pede nec elit. Sed eu lectus eu justo sagittis euismod. Vestibulum lobortis, urna id mollis rhoncus, orci quam euismod ligula, at malesuada lacus magna vitae massa. Phasellus mattis fermentum velit.  Nulla vulputate consequat enim. Maecenas quis neque. Curabitur sagittis facilisis neque. In elementum, eros non porttitor rhoncus, libero turpis sodales odio, vitae porta tellus purus et ante. Nullam molestie sollicitudin metus. Donec a elit. Morbi ut lacus. Donec at arcu. Quisque velit diam, interdum a, lacinia at, varius et, odio. Cras neque magna, ornare id, sollicitudin id, consequat a, est. Phasellus vestibulum est at leo. Nam facilisis, nulla dapibus condimentum pellentesque, est magna viverra ligula, at sollicitudin urna augue ut sapien. Fusce justo.";
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
	//
 | 
			
		||||
	//	Test of SHA-256 algorithm
 | 
			
		||||
	//
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray();
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(hash.toHexString(), "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "sha256('')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0xbd");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(hash.toHexString(), "0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b", "sha256('0xbd')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0x5fd4");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(hash.toHexString(), "0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788", "sha256('0x5fd4')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0xc98c8e55");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(hash.toHexString(), "0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504", "sha256('0xc98c8e55')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0x0df1cd526b5a4edd");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(hash.toHexString(), "0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c", "sha256('0x0df1cd526b5a4edd')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0xfdf4700984ee11b70af1880d0e0fefd4");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(	hash.toHexString(),
 | 
			
		||||
		"0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c",
 | 
			
		||||
		"sha256('0xfdf4700984ee11b70af1880d0e0fefd4')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(	hash.toHexString(),
 | 
			
		||||
		"0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d",
 | 
			
		||||
		"sha256('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(	hash.toHexString(),
 | 
			
		||||
		"0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3",
 | 
			
		||||
		"sha256('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a')");
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray("0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
	is(	hash.toHexString(),
 | 
			
		||||
		"0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454",
 | 
			
		||||
		"sha256('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad')");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	byteArray = new Clipperz.ByteArray(longText);
 | 
			
		||||
startTime = new Date();
 | 
			
		||||
//console.profile("SHA256");
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArray);
 | 
			
		||||
//console.profileEnd("SHA256");
 | 
			
		||||
endTime = new Date();
 | 
			
		||||
	is(	hash.toHexString(),
 | 
			
		||||
		"0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949",
 | 
			
		||||
		"sha256(longText)");
 | 
			
		||||
	is((endTime - startTime) < 500, true, "Long text hash performance (" + (endTime - startTime) + ")");
 | 
			
		||||
	MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime));
 | 
			
		||||
 | 
			
		||||
//#############################################################################
 | 
			
		||||
 
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html -->
 | 
			
		||||
							
								
								
									
										84
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
var testSHA = function (aValue, anExpectedResult) {
 | 
			
		||||
	var byteArrayValue;
 | 
			
		||||
	
 | 
			
		||||
	byteArrayValue = new Clipperz.ByteArray(aValue);
 | 
			
		||||
	hash = Clipperz.Crypto.SHA.sha256(byteArrayValue);
 | 
			
		||||
	is(hash.toHexString(), anExpectedResult, "sha256(' " + byteArrayValue.toHexString() + "')");
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var tests = {
 | 
			
		||||
 | 
			
		||||
	'basic_tests': function (someTestArgs) {
 | 
			
		||||
		testSHA('', '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
 | 
			
		||||
		testSHA('0xbd', '0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b');
 | 
			
		||||
		testSHA('0x5fd4', '0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788');
 | 
			
		||||
		testSHA('0xc98c8e55', '0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504');
 | 
			
		||||
		testSHA('0x0df1cd526b5a4edd', '0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c');
 | 
			
		||||
		testSHA('0xfdf4700984ee11b70af1880d0e0fefd4', '0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c');
 | 
			
		||||
		testSHA('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb', '0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d');
 | 
			
		||||
		testSHA('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a', '0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3');
 | 
			
		||||
		testSHA('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad', '0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454');
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'aldo_cortesi_tests': function (someTestArgs) {
 | 
			
		||||
		testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',	'0xa3f01b6939256127582ac8ae9fb47a382a244680806a3f613a118851c1ca1d47');
 | 
			
		||||
		testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',	'0xb35439a4ac6f0948b6d6f9e3c6af0f5f590ce20f1bde7090ef7970686ec6738a');
 | 
			
		||||
		testSHA('0x79',														'0xa1fce4363854ff888cff4b8e7875d600c2682390412a8cf79b37d0b11148b0fa');
 | 
			
		||||
		testSHA('0x80',														'0x76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71');
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	'longTextPerformance_test': function (someTestArgs) {
 | 
			
		||||
		var longText;
 | 
			
		||||
		var startTime;
 | 
			
		||||
		var endTime;
 | 
			
		||||
		
 | 
			
		||||
		longText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nunc sapien, condimentum vitae, varius vel, pharetra in, augue. Mauris quam magna, pretium sit amet, accumsan id, volutpat lobortis, nibh. Fusce sagittis. Aenean justo. Curabitur euismod pede. Morbi at ante. Proin nisl leo, ultrices sed, facilisis et, nonummy sit amet, lorem. Praesent mauris tellus, pulvinar sed, nonummy vitae, rhoncus non, nunc. Proin placerat malesuada nisl. Nunc id enim. Maecenas commodo enim ac nibh. Sed condimentum, urna sit amet euismod gravida, mi urna varius odio, luctus pretium lectus justo nec felis. Ut in augue et est malesuada rhoncus. Sed vel orci. Mauris suscipit.  Praesent cursus velit non turpis. Donec tristique dolor ac est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est sapien, vulputate eget, bibendum id, pharetra nec, mauris. Aliquam faucibus tincidunt dui. Proin iaculis. Maecenas sagittis. Integer et augue. Donec vitae urna in orci aliquet commodo. Vestibulum lorem sem, suscipit ac, placerat nec, mollis in, felis. Donec laoreet odio a mauris. Integer rutrum, sapien id varius molestie, mauris odio egestas orci, non bibendum sem felis in metus.  Phasellus consectetuer lectus adipiscing mauris. Ut magna tellus, euismod ac, suscipit tincidunt, ullamcorper adipiscing, massa. Etiam orci. Phasellus a urna. Cras neque quam, laoreet at, tempus eget, euismod nec, nibh. Etiam hendrerit. Aenean vel lorem. Ut ligula lacus, congue eu, lobortis sit amet, venenatis in, magna. Nullam cursus felis quis est. Sed sem est, condimentum eu, vestibulum a, mattis vel, diam. Curabitur tincidunt pede quis pede. Sed neque diam, convallis vel, luctus at, porta id, nisl. Suspendisse potenti. Sed volutpat lobortis orci. Praesent mi. In interdum. Suspendisse suscipit ipsum eget dolor. Curabitur et tellus sed velit hendrerit varius. Cras sit amet est.  Donec arcu nulla, vehicula et, pretium in, placerat id, felis. Integer mollis auctor lectus. Integer ultrices elementum sapien. Nam et erat. Nam pulvinar porta tortor. Nam at risus. Quisque nulla. Integer vestibulum, lacus id bibendum laoreet, ligula mi pharetra lorem, sit amet pharetra felis mauris quis justo. Aliquam ultricies. Duis a pede eget lorem dapibus rhoncus. Aenean eu elit non libero consectetuer viverra. Maecenas velit mi, eleifend vel, malesuada vel, condimentum quis, odio. Mauris tempus augue sed turpis. Pellentesque condimentum, lacus vitae pellentesque ultricies, risus tellus posuere nisi, et dictum turpis pede nec elit. Sed eu lectus eu justo sagittis euismod. Vestibulum lobortis, urna id mollis rhoncus, orci quam euismod ligula, at malesuada lacus magna vitae massa. Phasellus mattis fermentum velit.  Nulla vulputate consequat enim. Maecenas quis neque. Curabitur sagittis facilisis neque. In elementum, eros non porttitor rhoncus, libero turpis sodales odio, vitae porta tellus purus et ante. Nullam molestie sollicitudin metus. Donec a elit. Morbi ut lacus. Donec at arcu. Quisque velit diam, interdum a, lacinia at, varius et, odio. Cras neque magna, ornare id, sollicitudin id, consequat a, est. Phasellus vestibulum est at leo. Nam facilisis, nulla dapibus condimentum pellentesque, est magna viverra ligula, at sollicitudin urna augue ut sapien. Fusce justo.";
 | 
			
		||||
		startTime = new Date();
 | 
			
		||||
		testSHA(longText, '0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949');
 | 
			
		||||
		endTime = new Date();
 | 
			
		||||
 | 
			
		||||
		is((endTime - startTime) < 100, true, "Long text hash performance (" + (endTime - startTime) + ")");
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    //-------------------------------------------------------------------------
 | 
			
		||||
    'syntaxFix': MochiKit.Base.noop
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//=============================================================================
 | 
			
		||||
 | 
			
		||||
SimpleTest.runDeferredTests("Clipperz.Crypto.SHA", tests, {trace:false});
 | 
			
		||||
							
								
								
									
										161
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,161 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SRP.js'></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
hashString = function(aValue) {
 | 
			
		||||
	return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aValue)).toHexString().substring(2)	
 | 
			
		||||
}
 | 
			
		||||
try {
 | 
			
		||||
	var	username;
 | 
			
		||||
	var	passphrase;
 | 
			
		||||
	
 | 
			
		||||
	var C;
 | 
			
		||||
	var P;
 | 
			
		||||
	var encryptedText_1;
 | 
			
		||||
	var encryptedText_2;
 | 
			
		||||
	var	salt;
 | 
			
		||||
	var	x;
 | 
			
		||||
	var v;
 | 
			
		||||
	var v1;
 | 
			
		||||
	
 | 
			
		||||
	username = "giulio.cesare";
 | 
			
		||||
	passphrase = "trustno1";
 | 
			
		||||
	
 | 
			
		||||
	C = hashString(username);
 | 
			
		||||
	is (C, "bde3c7b5fdcd9d6ce72782ca1ae912fc4397d668fcb3a73a04e5d47852670c4a", "C");
 | 
			
		||||
	
 | 
			
		||||
	P  = hashString(passphrase + username);
 | 
			
		||||
	is (P, "d79f5c5a04e91e1c85fb64cb6ee9481cb52c181047f69da02cd6c3ce6d058a76", "P");
 | 
			
		||||
 | 
			
		||||
	salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
 | 
			
		||||
 | 
			
		||||
	x = hashString(salt + P);
 | 
			
		||||
	is(x, "21fe88a158e420aade86e00b5eb12a4c19bf15482fa34c542c90b1afdbd5b5fd", "x");
 | 
			
		||||
	
 | 
			
		||||
	v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
 | 
			
		||||
	is(v.asString(10), "33816467430011076413789931449607305355248467973000153409872503376381719918118", "v");
 | 
			
		||||
	is(v.asString(16), "4ac37139dbf32ebabd2c43f91dd085066d3c457d059efd5902d32ed247fcb626", "v (base 16)");
 | 
			
		||||
 | 
			
		||||
//	encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
 | 
			
		||||
//	encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
 | 
			
		||||
//	is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
 | 
			
		||||
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	username = "giulio.cesare.debug";
 | 
			
		||||
	passphrase = "trustno1";
 | 
			
		||||
	
 | 
			
		||||
	C = hashString(username);
 | 
			
		||||
	is (C, "fa1af609123b97a10d676158ed538d4657a89ac33a102b22bd9a66712039e208", "C");
 | 
			
		||||
 | 
			
		||||
	P  = hashString(passphrase + username);
 | 
			
		||||
	is (P, "e1bfba03dd626b12f29458a6ad63fb2c01b4765548504e1e2f6b1503c82e4253", "P");
 | 
			
		||||
 | 
			
		||||
	salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
 | 
			
		||||
 | 
			
		||||
	x = hashString(salt + P);
 | 
			
		||||
	is(x, "93d4af3cdcd2447a745d309826dff3161feed4b15f32db8e909ff032a2bc8fb8", "x");
 | 
			
		||||
	
 | 
			
		||||
	v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
 | 
			
		||||
	is(v.asString(10), "115049747015252903452664067168789229427785288458366249918596663144588656606556", "v");
 | 
			
		||||
 | 
			
		||||
//	encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
 | 
			
		||||
//	encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
 | 
			
		||||
//	is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
 | 
			
		||||
	
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
	var srpConnection;
 | 
			
		||||
	var C, P, salt;
 | 
			
		||||
	
 | 
			
		||||
	C = 	"da8602c2f847306f4eb9acdaad925277d1fad1408f173f128a078aea15e60b1e";
 | 
			
		||||
	P =		"77643559beca49dd21c1c31db10bb0a9009662cb504413dc3fa3b7303c7e02ba";
 | 
			
		||||
	salt =	"000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1";
 | 
			
		||||
	
 | 
			
		||||
	srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
 | 
			
		||||
	srpConnection._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10);
 | 
			
		||||
	srpConnection.set_s(new Clipperz.Crypto.BigInt(salt, 16));
 | 
			
		||||
	is (srpConnection.s().asString(16, 64), salt, "salt read/write is coherent");
 | 
			
		||||
	srpConnection.set_B(new Clipperz.Crypto.BigInt("123541032067854367017620977654446651448957899464139861291542193929199957895435", 10));
 | 
			
		||||
 | 
			
		||||
	is(	srpConnection.serverSideCredentialsWithSalt(salt).v,
 | 
			
		||||
		"c73169c8236d37bf9ef11a2349e3064b7dc6e883a58d64443ea9235677520030",
 | 
			
		||||
		"server side credentials - v"
 | 
			
		||||
	)
 | 
			
		||||
	is(srpConnection.S(), "84134227508133659832466942692590826994401065200828529664948840490489960952050", "Server side 'S'");
 | 
			
		||||
//MochiKit.Logging.logDebug("=== serverSideCredentials: " + MochiKit.Base.serializeJSON(srpConnection.serverSideCredentialsWithSalt(salt)));
 | 
			
		||||
 | 
			
		||||
	srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
 | 
			
		||||
	try {
 | 
			
		||||
		srpConnection.set_B(new Clipperz.Crypto.BigInt("0", 10));
 | 
			
		||||
		ok(false, "Setting B to 0 should raise an exception");
 | 
			
		||||
	} catch(e) {
 | 
			
		||||
		ok(true, "Setting B to 0 should raise an exception");
 | 
			
		||||
	}
 | 
			
		||||
	//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										122
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,122 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<title>Clipperz.Crypto.Usage - TEST</title>
 | 
			
		||||
	
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
 | 
			
		||||
    <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
 | 
			
		||||
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
 | 
			
		||||
    <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
 | 
			
		||||
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
 | 
			
		||||
	<script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
 | 
			
		||||
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<pre id="test">
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
 | 
			
		||||
 | 
			
		||||
MochiKit.Base.update(Clipperz, {
 | 
			
		||||
	'PM': {
 | 
			
		||||
		'Crypto': {
 | 
			
		||||
			'passwordEntropy': function(aValue) {
 | 
			
		||||
				var result;
 | 
			
		||||
				var	bitPerChar;
 | 
			
		||||
 | 
			
		||||
				bitPerChar = 4;
 | 
			
		||||
				if (/[a-z]/.test(aValue)) {
 | 
			
		||||
					bitPerChar ++;
 | 
			
		||||
				}
 | 
			
		||||
				if (/[A-Z]/.test(aValue)) {
 | 
			
		||||
					bitPerChar ++;
 | 
			
		||||
				}
 | 
			
		||||
				if (/[^a-zA-Z0-9]/.test(aValue)) {
 | 
			
		||||
					bitPerChar ++;
 | 
			
		||||
				}
 | 
			
		||||
				//MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar);
 | 
			
		||||
 | 
			
		||||
				result = aValue.length * bitPerChar;
 | 
			
		||||
 | 
			
		||||
				return result;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
	var keyValue;
 | 
			
		||||
	var keyEntropy;
 | 
			
		||||
	var	key;
 | 
			
		||||
	var plainText;
 | 
			
		||||
	var cypherText;
 | 
			
		||||
	var randomBytes;
 | 
			
		||||
	var hashedValue;
 | 
			
		||||
	
 | 
			
		||||
	key = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("This is my long and complex passphrase"));
 | 
			
		||||
	keyEntropy = Clipperz.PM.Crypto.passwordEntropy(key);
 | 
			
		||||
 | 
			
		||||
	cypherText = Clipperz.Crypto.AES.encrypt(key, new Clipperz.ByteArray("some text to encrypt"));
 | 
			
		||||
	plainText = Clipperz.Crypto.AES.decrypt(key, cypherText).asString();
 | 
			
		||||
	is(plainText, "some text to encrypt");
 | 
			
		||||
 | 
			
		||||
	randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(256/8);
 | 
			
		||||
	hashedValue = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("text to hash"));
 | 
			
		||||
 | 
			
		||||
//#############################################################################
 | 
			
		||||
 
 | 
			
		||||
} catch (err) {
 | 
			
		||||
    
 | 
			
		||||
    var s = "test suite failure!\n";
 | 
			
		||||
    var o = {};
 | 
			
		||||
    var k = null;
 | 
			
		||||
    for (k in err) {
 | 
			
		||||
        // ensure unique keys?!
 | 
			
		||||
        if (!o[k]) {
 | 
			
		||||
            s +=  k + ": " + err[k] + "\n";
 | 
			
		||||
            o[k] = err[k];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ok ( false, s );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
</pre>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										58
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<!--
 | 
			
		||||
 | 
			
		||||
Copyright 2008-2011 Clipperz Srl
 | 
			
		||||
 | 
			
		||||
This file is part of Clipperz's Javascript Crypto Library.
 | 
			
		||||
Javascript Crypto Library provides web developers with an extensive
 | 
			
		||||
and efficient set of cryptographic functions. The library aims to
 | 
			
		||||
obtain maximum execution speed while preserving modularity and
 | 
			
		||||
reusability.
 | 
			
		||||
For further information about its features and functionalities please
 | 
			
		||||
refer to http://www.clipperz.com
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is free software: you can redistribute
 | 
			
		||||
  it and/or modify it under the terms of the GNU Affero General Public
 | 
			
		||||
  License as published by the Free Software Foundation, either version
 | 
			
		||||
  3 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
* Javascript Crypto Library is distributed in the hope that it will
 | 
			
		||||
  be useful, but WITHOUT ANY WARRANTY; without even the implied
 | 
			
		||||
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
			
		||||
  See the GNU Affero General Public License for more details.
 | 
			
		||||
 | 
			
		||||
* You should have received a copy of the GNU Affero General Public
 | 
			
		||||
  License along with Javascript Crypto Library.  If not, see
 | 
			
		||||
  <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
	<title>Clipperz.Crypto.* - tests</title>
 | 
			
		||||
 | 
			
		||||
	<script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
 | 
			
		||||
	<script type="text/javascript" src="../../../SimpleTest/TestRunner.js"></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<script>
 | 
			
		||||
TestRunner.runTests(
 | 
			
		||||
	'AES.html',
 | 
			
		||||
	'AES.performance.html',
 | 
			
		||||
	'Base.html',
 | 
			
		||||
	'BigInt.html',
 | 
			
		||||
	
 | 
			
		||||
//	'ECC.B283.deferred.html',
 | 
			
		||||
//	'ECC.BinaryField.FiniteField.html',
 | 
			
		||||
//	'ECC.BinaryField.FiniteField.B283.html',
 | 
			
		||||
//	'ECC.BinaryField.Value.html',
 | 
			
		||||
//#	'ECC.K283.deferred.html',
 | 
			
		||||
 | 
			
		||||
	'PRNG.html',
 | 
			
		||||
//	'RSA.html',
 | 
			
		||||
	'SHA.html',
 | 
			
		||||
	'SRP.html',
 | 
			
		||||
	'Usage.html'
 | 
			
		||||
);
 | 
			
		||||
</script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										1577
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1577
									
								
								frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user