Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/RSA.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Crypto/RSA.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/RSA.js b/frontend/beta/js/Clipperz/Crypto/RSA.js index 6844dba..5a480f1 100644 --- a/frontend/beta/js/Clipperz/Crypto/RSA.js +++ b/frontend/beta/js/Clipperz/Crypto/RSA.js | |||
@@ -1,148 +1,146 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | ||
26 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.Crypto.RSA depends on Clipperz.Crypto.BigInt!"; | 25 | throw "Clipperz.Crypto.RSA depends on Clipperz.Crypto.BigInt!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.Crypto.RSA) == 'undefined') { Clipperz.Crypto.RSA = {}; } | 28 | if (typeof(Clipperz.Crypto.RSA) == 'undefined') { Clipperz.Crypto.RSA = {}; } |
31 | 29 | ||
32 | Clipperz.Crypto.RSA.VERSION = "0.1"; | 30 | Clipperz.Crypto.RSA.VERSION = "0.1"; |
33 | Clipperz.Crypto.RSA.NAME = "Clipperz.RSA"; | 31 | Clipperz.Crypto.RSA.NAME = "Clipperz.RSA"; |
34 | 32 | ||
35 | //############################################################################# | 33 | //############################################################################# |
36 | 34 | ||
37 | MochiKit.Base.update(Clipperz.Crypto.RSA, { | 35 | MochiKit.Base.update(Clipperz.Crypto.RSA, { |
38 | 36 | ||
39 | //------------------------------------------------------------------------- | 37 | //------------------------------------------------------------------------- |
40 | 38 | ||
41 | 'publicKeyWithValues': function (e, d, n) { | 39 | 'publicKeyWithValues': function (e, d, n) { |
42 | varresult; | 40 | varresult; |
43 | 41 | ||
44 | result = {}; | 42 | result = {}; |
45 | 43 | ||
46 | if (e.isBigInt) { | 44 | if (e.isBigInt) { |
47 | result.e = e; | 45 | result.e = e; |
48 | } else { | 46 | } else { |
49 | result.e = new Clipperz.Crypto.BigInt(e, 16); | 47 | result.e = new Clipperz.Crypto.BigInt(e, 16); |
50 | } | 48 | } |
51 | 49 | ||
52 | if (d.isBigInt) { | 50 | if (d.isBigInt) { |
53 | result.d = d; | 51 | result.d = d; |
54 | } else { | 52 | } else { |
55 | result.d = new Clipperz.Crypto.BigInt(d, 16); | 53 | result.d = new Clipperz.Crypto.BigInt(d, 16); |
56 | } | 54 | } |
57 | 55 | ||
58 | if (n.isBigInt) { | 56 | if (n.isBigInt) { |
59 | result.n = n; | 57 | result.n = n; |
60 | } else { | 58 | } else { |
61 | result.n = new Clipperz.Crypto.BigInt(n, 16); | 59 | result.n = new Clipperz.Crypto.BigInt(n, 16); |
62 | } | 60 | } |
63 | 61 | ||
64 | return result; | 62 | return result; |
65 | }, | 63 | }, |
66 | 64 | ||
67 | 'privateKeyWithValues': function(e, d, n) { | 65 | 'privateKeyWithValues': function(e, d, n) { |
68 | return Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); | 66 | return Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); |
69 | }, | 67 | }, |
70 | 68 | ||
71 | //----------------------------------------------------------------------------- | 69 | //----------------------------------------------------------------------------- |
72 | 70 | ||
73 | 'encryptUsingPublicKey': function (aKey, aMessage) { | 71 | 'encryptUsingPublicKey': function (aKey, aMessage) { |
74 | varmessageValue; | 72 | varmessageValue; |
75 | varresult; | 73 | varresult; |
76 | 74 | ||
77 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); | 75 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); |
78 | result = messageValue.powerModule(aKey.e, aKey.n); | 76 | result = messageValue.powerModule(aKey.e, aKey.n); |
79 | 77 | ||
80 | return result.asString(16); | 78 | return result.asString(16); |
81 | }, | 79 | }, |
82 | 80 | ||
83 | //............................................................................. | 81 | //............................................................................. |
84 | 82 | ||
85 | 'decryptUsingPublicKey': function (aKey, aMessage) { | 83 | 'decryptUsingPublicKey': function (aKey, aMessage) { |
86 | return Clipperz.Crypto.RSA.encryptUsingPublicKey(aKey, aMessage); | 84 | return Clipperz.Crypto.RSA.encryptUsingPublicKey(aKey, aMessage); |
87 | }, | 85 | }, |
88 | 86 | ||
89 | //----------------------------------------------------------------------------- | 87 | //----------------------------------------------------------------------------- |
90 | 88 | ||
91 | 'encryptUsingPrivateKey': function (aKey, aMessage) { | 89 | 'encryptUsingPrivateKey': function (aKey, aMessage) { |
92 | varmessageValue; | 90 | varmessageValue; |
93 | varresult; | 91 | varresult; |
94 | 92 | ||
95 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); | 93 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); |
96 | result = messageValue.powerModule(aKey.d, aKey.n); | 94 | result = messageValue.powerModule(aKey.d, aKey.n); |
97 | 95 | ||
98 | return result.asString(16); | 96 | return result.asString(16); |
99 | }, | 97 | }, |
100 | 98 | ||
101 | //............................................................................. | 99 | //............................................................................. |
102 | 100 | ||
103 | 'decryptUsingPrivateKey': function (aKey, aMessage) { | 101 | 'decryptUsingPrivateKey': function (aKey, aMessage) { |
104 | return Clipperz.Crypto.RSA.encryptUsingPrivateKey(aKey, aMessage); | 102 | return Clipperz.Crypto.RSA.encryptUsingPrivateKey(aKey, aMessage); |
105 | }, | 103 | }, |
106 | 104 | ||
107 | //----------------------------------------------------------------------------- | 105 | //----------------------------------------------------------------------------- |
108 | 106 | ||
109 | 'generatePublicKey': function(aNumberOfBits) { | 107 | 'generatePublicKey': function(aNumberOfBits) { |
110 | varresult; | 108 | varresult; |
111 | vare; | 109 | vare; |
112 | vard; | 110 | vard; |
113 | varn; | 111 | varn; |
114 | 112 | ||
115 | e = new Clipperz.Crypto.BigInt("10001", 16); | 113 | e = new Clipperz.Crypto.BigInt("10001", 16); |
116 | 114 | ||
117 | { | 115 | { |
118 | var p, q; | 116 | var p, q; |
119 | varphi; | 117 | varphi; |
120 | 118 | ||
121 | do { | 119 | do { |
122 | p = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); | 120 | p = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); |
123 | } while (p.module(e).equals(1)); | 121 | } while (p.module(e).equals(1)); |
124 | 122 | ||
125 | do { | 123 | do { |
126 | q = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); | 124 | q = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); |
127 | } while ((q.equals(p)) || (q.module(e).equals(1))); | 125 | } while ((q.equals(p)) || (q.module(e).equals(1))); |
128 | 126 | ||
129 | n = p.multiply(q); | 127 | n = p.multiply(q); |
130 | phi = (p.subtract(1).multiply(q.subtract(1))); | 128 | phi = (p.subtract(1).multiply(q.subtract(1))); |
131 | d = e.powerModule(-1, phi); | 129 | d = e.powerModule(-1, phi); |
132 | } | 130 | } |
133 | 131 | ||
134 | result = Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); | 132 | result = Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); |
135 | 133 | ||
136 | return result; | 134 | return result; |
137 | }, | 135 | }, |
138 | 136 | ||
139 | //------------------------------------------------------------------------- | 137 | //------------------------------------------------------------------------- |
140 | 138 | ||
141 | __syntaxFix__: "syntax fix" | 139 | __syntaxFix__: "syntax fix" |
142 | 140 | ||
143 | //------------------------------------------------------------------------- | 141 | //------------------------------------------------------------------------- |
144 | 142 | ||
145 | }); | 143 | }); |
146 | 144 | ||
147 | //############################################################################# | 145 | //############################################################################# |
148 | 146 | ||