author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-21 15:54:15 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-21 15:54:15 (UTC) |
commit | 1906ddfb5d3887edeedaf8e07d14ad89abbd214d (patch) (unidiff) | |
tree | 37df37cfcd6df9931ce92e53ef8d686adc9caa09 /frontend/gamma/js/ClipperzCryptoLibrary/RSA.js | |
parent | 0608e045f6aa471916829468f48082ea07a453f4 (diff) | |
download | clipperz-1906ddfb5d3887edeedaf8e07d14ad89abbd214d.zip clipperz-1906ddfb5d3887edeedaf8e07d14ad89abbd214d.tar.gz clipperz-1906ddfb5d3887edeedaf8e07d14ad89abbd214d.tar.bz2 |
Aborted attempt to factor out the Crypto library on its own module
Diffstat (limited to 'frontend/gamma/js/ClipperzCryptoLibrary/RSA.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/ClipperzCryptoLibrary/RSA.js | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/frontend/gamma/js/ClipperzCryptoLibrary/RSA.js b/frontend/gamma/js/ClipperzCryptoLibrary/RSA.js deleted file mode 100644 index 5a480f1..0000000 --- a/frontend/gamma/js/ClipperzCryptoLibrary/RSA.js +++ b/dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { | ||
25 | throw "Clipperz.Crypto.RSA depends on Clipperz.Crypto.BigInt!"; | ||
26 | } | ||
27 | |||
28 | if (typeof(Clipperz.Crypto.RSA) == 'undefined') { Clipperz.Crypto.RSA = {}; } | ||
29 | |||
30 | Clipperz.Crypto.RSA.VERSION = "0.1"; | ||
31 | Clipperz.Crypto.RSA.NAME = "Clipperz.RSA"; | ||
32 | |||
33 | //############################################################################# | ||
34 | |||
35 | MochiKit.Base.update(Clipperz.Crypto.RSA, { | ||
36 | |||
37 | //------------------------------------------------------------------------- | ||
38 | |||
39 | 'publicKeyWithValues': function (e, d, n) { | ||
40 | varresult; | ||
41 | |||
42 | result = {}; | ||
43 | |||
44 | if (e.isBigInt) { | ||
45 | result.e = e; | ||
46 | } else { | ||
47 | result.e = new Clipperz.Crypto.BigInt(e, 16); | ||
48 | } | ||
49 | |||
50 | if (d.isBigInt) { | ||
51 | result.d = d; | ||
52 | } else { | ||
53 | result.d = new Clipperz.Crypto.BigInt(d, 16); | ||
54 | } | ||
55 | |||
56 | if (n.isBigInt) { | ||
57 | result.n = n; | ||
58 | } else { | ||
59 | result.n = new Clipperz.Crypto.BigInt(n, 16); | ||
60 | } | ||
61 | |||
62 | return result; | ||
63 | }, | ||
64 | |||
65 | 'privateKeyWithValues': function(e, d, n) { | ||
66 | return Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); | ||
67 | }, | ||
68 | |||
69 | //----------------------------------------------------------------------------- | ||
70 | |||
71 | 'encryptUsingPublicKey': function (aKey, aMessage) { | ||
72 | varmessageValue; | ||
73 | varresult; | ||
74 | |||
75 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); | ||
76 | result = messageValue.powerModule(aKey.e, aKey.n); | ||
77 | |||
78 | return result.asString(16); | ||
79 | }, | ||
80 | |||
81 | //............................................................................. | ||
82 | |||
83 | 'decryptUsingPublicKey': function (aKey, aMessage) { | ||
84 | return Clipperz.Crypto.RSA.encryptUsingPublicKey(aKey, aMessage); | ||
85 | }, | ||
86 | |||
87 | //----------------------------------------------------------------------------- | ||
88 | |||
89 | 'encryptUsingPrivateKey': function (aKey, aMessage) { | ||
90 | varmessageValue; | ||
91 | varresult; | ||
92 | |||
93 | messageValue = new Clipperz.Crypto.BigInt(aMessage, 16); | ||
94 | result = messageValue.powerModule(aKey.d, aKey.n); | ||
95 | |||
96 | return result.asString(16); | ||
97 | }, | ||
98 | |||
99 | //............................................................................. | ||
100 | |||
101 | 'decryptUsingPrivateKey': function (aKey, aMessage) { | ||
102 | return Clipperz.Crypto.RSA.encryptUsingPrivateKey(aKey, aMessage); | ||
103 | }, | ||
104 | |||
105 | //----------------------------------------------------------------------------- | ||
106 | |||
107 | 'generatePublicKey': function(aNumberOfBits) { | ||
108 | varresult; | ||
109 | vare; | ||
110 | vard; | ||
111 | varn; | ||
112 | |||
113 | e = new Clipperz.Crypto.BigInt("10001", 16); | ||
114 | |||
115 | { | ||
116 | var p, q; | ||
117 | varphi; | ||
118 | |||
119 | do { | ||
120 | p = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); | ||
121 | } while (p.module(e).equals(1)); | ||
122 | |||
123 | do { | ||
124 | q = Clipperz.Crypto.BigInt.randomPrime(aNumberOfBits); | ||
125 | } while ((q.equals(p)) || (q.module(e).equals(1))); | ||
126 | |||
127 | n = p.multiply(q); | ||
128 | phi = (p.subtract(1).multiply(q.subtract(1))); | ||
129 | d = e.powerModule(-1, phi); | ||
130 | } | ||
131 | |||
132 | result = Clipperz.Crypto.RSA.publicKeyWithValues(e, d, n); | ||
133 | |||
134 | return result; | ||
135 | }, | ||
136 | |||
137 | //------------------------------------------------------------------------- | ||
138 | |||
139 | __syntaxFix__: "syntax fix" | ||
140 | |||
141 | //------------------------------------------------------------------------- | ||
142 | |||
143 | }); | ||
144 | |||
145 | //############################################################################# | ||
146 | |||