summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js b/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js
index b5beafa..278c299 100644
--- a/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js
+++ b/frontend/beta/js/Clipperz/Crypto/ECC/BinaryField/Value.js
@@ -1,118 +1,116 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
27 throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!"; 25 throw "Clipperz.Crypto.ECC depends on Clipperz.ByteArray!";
28} 26}
29if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } 27if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; }
30if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } 28if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; }
31 29
32Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase) { 30Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase) {
33 if (aValue.constructor == String) { 31 if (aValue.constructor == String) {
34 varvalue; 32 varvalue;
35 varstringLength; 33 varstringLength;
36 var numberOfWords; 34 var numberOfWords;
37 vari,c; 35 vari,c;
38 36
39 if (aBase != 16) { 37 if (aBase != 16) {
40 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; 38 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase;
41 } 39 }
42 40
43 value = aValue.replace(/ /g, ''); 41 value = aValue.replace(/ /g, '');
44 stringLength = value.length; 42 stringLength = value.length;
45 numberOfWords = Math.ceil(stringLength / 8); 43 numberOfWords = Math.ceil(stringLength / 8);
46 this._value = new Array(numberOfWords); 44 this._value = new Array(numberOfWords);
47 45
48 c = numberOfWords; 46 c = numberOfWords;
49 for (i=0; i<c; i++) { 47 for (i=0; i<c; i++) {
50 varword; 48 varword;
51 49
52 if (i < (c-1)) { 50 if (i < (c-1)) {
53 word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); 51 word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16);
54 } else { 52 } else {
55 word = parseInt(value.substr(0, stringLength-(i*8)), 16); 53 word = parseInt(value.substr(0, stringLength-(i*8)), 16);
56 } 54 }
57 55
58 this._value[i] = word; 56 this._value[i] = word;
59 } 57 }
60 } else if (aValue.constructor == Array) { 58 } else if (aValue.constructor == Array) {
61 var itemsToCopy; 59 var itemsToCopy;
62 60
63 itemsToCopy = aValue.length; 61 itemsToCopy = aValue.length;
64 while (aValue[itemsToCopy - 1] == 0) { 62 while (aValue[itemsToCopy - 1] == 0) {
65 itemsToCopy --; 63 itemsToCopy --;
66 } 64 }
67 65
68 this._value = aValue.slice(0, itemsToCopy); 66 this._value = aValue.slice(0, itemsToCopy);
69 } else if (aValue.constructor == Number) { 67 } else if (aValue.constructor == Number) {
70 this._value = [aValue]; 68 this._value = [aValue];
71 } else { 69 } else {
72 // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; 70 // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType;
73 } 71 }
74 72
75 return this; 73 return this;
76} 74}
77 75
78Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { 76Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, {
79 77
80 'value': function() { 78 'value': function() {
81 return this._value; 79 return this._value;
82 }, 80 },
83 81
84 //----------------------------------------------------------------------------- 82 //-----------------------------------------------------------------------------
85 83
86 'wordSize': function() { 84 'wordSize': function() {
87 return this._value.length 85 return this._value.length
88 }, 86 },
89 87
90 //----------------------------------------------------------------------------- 88 //-----------------------------------------------------------------------------
91 89
92 'clone': function() { 90 'clone': function() {
93 return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0)); 91 return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0));
94 }, 92 },
95 93
96 //----------------------------------------------------------------------------- 94 //-----------------------------------------------------------------------------
97 95
98 'isZero': function() { 96 'isZero': function() {
99 return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); 97 return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0);
100 }, 98 },
101 99
102 //----------------------------------------------------------------------------- 100 //-----------------------------------------------------------------------------
103 101
104 'asString': function(aBase) { 102 'asString': function(aBase) {
105 varresult; 103 varresult;
106 var i,c; 104 var i,c;
107 105
108 if (aBase != 16) { 106 if (aBase != 16) {
109 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; 107 throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase;
110 } 108 }
111 109
112 result = ""; 110 result = "";
113 c = this.wordSize(); 111 c = this.wordSize();
114 for (i=0; i<c; i++) { 112 for (i=0; i<c; i++) {
115 varwordAsString; 113 varwordAsString;
116 114
117 // wordAsString = ("00000000" + this.value()[i].toString(16)); 115 // wordAsString = ("00000000" + this.value()[i].toString(16));
118 wordAsString = ("00000000" + this._value[i].toString(16)); 116 wordAsString = ("00000000" + this._value[i].toString(16));