author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-06 00:36:10 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-06 00:36:10 (UTC) |
commit | 6ba274c79e60e417132b260bd0117c5a68121387 (patch) (unidiff) | |
tree | 57c1f95d0fbf9b80312c5c6b6f4a4f951e31c770 /frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js | |
parent | 13ebf1b1987a1566d081ff1ba89b4dca197b7d2e (diff) | |
download | clipperz-6ba274c79e60e417132b260bd0117c5a68121387.zip clipperz-6ba274c79e60e417132b260bd0117c5a68121387.tar.gz clipperz-6ba274c79e60e417132b260bd0117c5a68121387.tar.bz2 |
Fixed the copyright headers
Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js b/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js index 5a430d1..b705a20 100644 --- a/frontend/gamma/js/Clipperz/Crypto/ECC/BinaryField/Value.js +++ b/frontend/gamma/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) == 'undefined') { Clipperz = {}; } | 29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
33 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 30 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
34 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } | 31 | if (typeof(Clipperz.Crypto.ECC) == 'undefined') { Clipperz.Crypto.ECC = {}; } |
35 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } | 32 | if (typeof(Clipperz.Crypto.ECC.BinaryField) == 'undefined') { Clipperz.Crypto.ECC.BinaryField = {}; } |
36 | 33 | ||
37 | Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { | 34 | Clipperz.Crypto.ECC.BinaryField.Value = function(aValue, aBase, aBitSize) { |
38 | if (aValue.constructor == String) { | 35 | if (aValue.constructor == String) { |
39 | varvalue; | 36 | varvalue; |
40 | varstringLength; | 37 | varstringLength; |
41 | var numberOfWords; | 38 | var numberOfWords; |
42 | vari,c; | 39 | vari,c; |
43 | 40 | ||
44 | if (aBase != 16) { | 41 | if (aBase != 16) { |
45 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; | 42 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; |
46 | } | 43 | } |
47 | 44 | ||
48 | value = aValue.replace(/ /g, ''); | 45 | value = aValue.replace(/ /g, ''); |
49 | stringLength = value.length; | 46 | stringLength = value.length; |
50 | numberOfWords = Math.ceil(stringLength / 8); | 47 | numberOfWords = Math.ceil(stringLength / 8); |
51 | this._value = new Array(numberOfWords); | 48 | this._value = new Array(numberOfWords); |
52 | 49 | ||
53 | c = numberOfWords; | 50 | c = numberOfWords; |
54 | for (i=0; i<c; i++) { | 51 | for (i=0; i<c; i++) { |
55 | varword; | 52 | varword; |
56 | 53 | ||
57 | if (i < (c-1)) { | 54 | if (i < (c-1)) { |
58 | word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); | 55 | word = parseInt(value.substr(stringLength-((i+1)*8), 8), 16); |
59 | } else { | 56 | } else { |
60 | word = parseInt(value.substr(0, stringLength-(i*8)), 16); | 57 | word = parseInt(value.substr(0, stringLength-(i*8)), 16); |
61 | } | 58 | } |
62 | 59 | ||
63 | this._value[i] = word; | 60 | this._value[i] = word; |
64 | } | 61 | } |
65 | } else if (aValue.constructor == Array) { | 62 | } else if (aValue.constructor == Array) { |
66 | var itemsToCopy; | 63 | var itemsToCopy; |
67 | 64 | ||
68 | itemsToCopy = aValue.length; | 65 | itemsToCopy = aValue.length; |
69 | while (aValue[itemsToCopy - 1] == 0) { | 66 | while (aValue[itemsToCopy - 1] == 0) { |
70 | itemsToCopy --; | 67 | itemsToCopy --; |
71 | } | 68 | } |
72 | 69 | ||
73 | this._value = aValue.slice(0, itemsToCopy); | 70 | this._value = aValue.slice(0, itemsToCopy); |
74 | } else if (aValue.constructor == Number) { | 71 | } else if (aValue.constructor == Number) { |
75 | this._value = [aValue]; | 72 | this._value = [aValue]; |
76 | } else { | 73 | } else { |
77 | // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; | 74 | // throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedConstructorValueType; |
78 | } | 75 | } |
79 | 76 | ||
80 | this._bitSize == aBitSize || null; | 77 | this._bitSize == aBitSize || null; |
81 | 78 | ||
82 | return this; | 79 | return this; |
83 | } | 80 | } |
84 | 81 | ||
85 | Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { | 82 | Clipperz.Crypto.ECC.BinaryField.Value.prototype = MochiKit.Base.update(null, { |
86 | 83 | ||
87 | 'value': function() { | 84 | 'value': function() { |
88 | return this._value; | 85 | return this._value; |
89 | }, | 86 | }, |
90 | 87 | ||
91 | //----------------------------------------------------------------------------- | 88 | //----------------------------------------------------------------------------- |
92 | 89 | ||
93 | 'wordSize': function() { | 90 | 'wordSize': function() { |
94 | return this._value.length | 91 | return this._value.length |
95 | }, | 92 | }, |
96 | 93 | ||
97 | //----------------------------------------------------------------------------- | 94 | //----------------------------------------------------------------------------- |
98 | 95 | ||
99 | 'clone': function() { | 96 | 'clone': function() { |
100 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0), null, this._bitSize); | 97 | return new Clipperz.Crypto.ECC.BinaryField.Value(this._value.slice(0), null, this._bitSize); |
101 | }, | 98 | }, |
102 | 99 | ||
103 | //----------------------------------------------------------------------------- | 100 | //----------------------------------------------------------------------------- |
104 | 101 | ||
105 | 'isZero': function() { | 102 | 'isZero': function() { |
106 | return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); | 103 | return (this.compare(Clipperz.Crypto.ECC.BinaryField.Value.O) == 0); |
107 | }, | 104 | }, |
108 | 105 | ||
109 | //----------------------------------------------------------------------------- | 106 | //----------------------------------------------------------------------------- |
110 | 107 | ||
111 | 'asString': function(aBase) { | 108 | 'asString': function(aBase) { |
112 | varresult; | 109 | varresult; |
113 | var i,c; | 110 | var i,c; |
114 | 111 | ||
115 | if (aBase != 16) { | 112 | if (aBase != 16) { |
116 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; | 113 | throw Clipperz.Crypto.ECC.BinaryField.Value.exception.UnsupportedBase; |
117 | } | 114 | } |
118 | 115 | ||
119 | result = ""; | 116 | result = ""; |
120 | c = this.wordSize(); | 117 | c = this.wordSize(); |