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