Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / third_party / Promises / reworked_APIs / WebCrypto / after.idl
1 /**************************************
2  * Extracted from:
3  *    http://www.w3.org/TR/WebCryptoAPI
4  **/
5
6 /**************************************
7  * 9
8  **/
9 [NoInterfaceObject]
10 interface RandomSource {
11   ArrayBufferView getRandomValues(ArrayBufferView array);
12 };
13
14 /**************************************
15  * 10
16  **/
17 // TBD: ISSUE-28
18 typedef (Algorithm or DOMString) AlgorithmIdentifier;
19
20 dictionary AlgorithmParameters {
21 };
22
23 dictionary Algorithm {
24   DOMString name;
25   AlgorithmParameters params;
26 };
27
28 /**************************************
29  * 11
30  **/
31 enum KeyType {
32   "secret",
33   "public",
34   "private"
35 };
36
37 enum KeyUsage {
38   "encrypt",
39   "decrypt",
40   "sign",
41   "verify",
42   "derive"
43 };
44
45 interface Key {
46   readonly attribute KeyType type;
47   readonly attribute bool extractable;
48   readonly attribute Algorithm algorithm;
49   readonly attribute KeyUsage[] keyUsage;
50 };
51
52 /**************************************
53  * 12
54  **/
55 interface CryptoOperation : Future {
56   // Both process() and finish() return this for chaining.
57   CrytpoOperation process(ArrayBufferView buffer);
58   CrytpoOperation finish();
59   void abort();
60
61   readonly attribute Key? key;
62   readonly attribute Algorithm algorithm;
63   readonly attribute any result;
64 };
65
66 /**************************************
67  * 13
68  *
69  *  REMOVED: supplanted by Future
70  **/
71
72 /**************************************
73  * 14
74  **/
75 enum KeyFormat {
76   // An unformatted sequence of bytes. Intended for secret keys.
77   "raw",
78   // The DER encoding of the PrivateKeyInfo structure from RFC 5208.
79   "pkcs8",
80   // The DER encoding of the SubjectPublicKeyInfo structure from RFC 5280.
81   "spki",
82   // The key is represented as JSON according to the JSON Web Key format.
83   "jwk",
84 };
85
86 interface Crypto {
87   CryptoOperation encrypt(AlgorithmIdentifier algorithm,
88                           Key key,
89                           optional ArrayBufferView? buffer = null);
90   CryptoOperation decrypt(AlgorithmIdentifier algorithm,
91                           Key key,
92                           optional ArrayBufferView? buffer = null);
93   CryptoOperation sign(AlgorithmIdentifier algorithm,
94                        Key key,
95                        optional ArrayBufferView? buffer = null);
96   CryptoOperation verify(AlgorithmIdentifier algorithm,
97                          Key key,
98                          ArrayBufferView signature,
99                          optional ArrayBufferView? buffer = null);
100   CryptoOperation digest(AlgorithmIdentifier algorithm,
101                          optional ArrayBufferView? buffer = null);
102
103   // TBD: ISSUE-36
104   Future generateKey(AlgorithmIdentifier algorithm,
105                      bool extractable = false,
106                      KeyUsage[] keyUsages = []);
107
108   Future deriveKey(AlgorithmIdentifier algorithm,
109                    Key baseKey,
110                    AlgorithmIdentifier? derivedKeyType,
111                    bool extractable = false,
112                    KeyUsage[] keyUsages = []);
113
114   // TBD: ISSUE-35
115   Future importKey(KeyFormat format,
116                    ArrayBufferView keyData,
117                    AlgorithmIdentifier? algorithm,
118                    bool extractable = false,
119                    KeyUsage[] keyUsages = []);
120
121   Future exportKey(KeyFormat format, Key key);
122 };
123
124 Crypto implements RandomSource;
125
126 partial interface Window {
127   readonly attribute Crypto crypto;
128 };
129
130 /**************************************
131  * 15
132  **/
133 interface WorkerCrypto {
134 };
135
136 WorkerCrypto implements RandomSource;
137
138 partial interface WorkerGlobalScope {
139   readonly attribute WorkerCrypto crypto;
140 };
141
142 /**************************************
143  * 16
144  */
145 typedef Uint8Array BigInteger;
146
147
148 /**************************************
149  * 17
150  **/
151 interface KeyPair {
152   Key publicKey;
153   Key privateKey;
154 };
155
156
157 /**************************************
158  * 19.3.3
159  **/
160 dictionary RsaKeyGenParams : AlgorithmParameters {
161   // The length, in bits, of the RSA modulus
162   unsigned long modulusLength;
163   // The RSA public exponent
164   BigInteger publicExponent;
165 };
166
167 /**************************************
168  * 19.4.3
169  **/
170 dictionary RsaSsaParams : AlgorithmParameters {
171   // The hash algorithm to use
172   AlgorithmIdentifier hash;
173 };
174
175 /**************************************
176  * 19.5.3
177  **/
178 dictionary RsaPssParams : AlgorithmParameters {
179   // The hash function to apply to the message
180   AlgorithmIdentifier hash;
181   // The mask generation function
182   AlgorithmIdentifier mgf;
183   // The desired length of the random salt
184   unsigned long saltLength;
185 };
186
187 /**************************************
188  * 19.6.3
189  **/
190 dictionary RsaOaepParams : AlgorithmParameters {
191   // The hash function to apply to the message
192   AlgorithmIdentifier hash;
193   // The mask generation function
194   AlgorithmIdentifier mgf;
195   // The optional label/application data to associate with the message
196   ArrayBufferView? label;
197 };
198
199 /**************************************
200  * 19.7.3
201  **/
202 dictionary EcdsaParams : AlgorithmParameters {
203   // The hash algorithm to use
204   AlgorithmIdentifier hash;
205 };
206 enum NamedCurve {
207   // NIST recommended curve P-256, also known as secp256r1.
208   "P-256",
209   // NIST recommended curve P-384, also known as secp384r1.
210   "P-384",
211   // NIST recommended curve P-521, also known as secp521r1.
212   "P-521"
213 };
214
215 /**************************************
216  * 19.7.4
217  **/
218 dictionary EcKeyGenParams : AlgorithmParameters {
219   // A named curve
220   NamedCurve namedCurve;
221 };
222
223 /**************************************
224  * 19.8.3
225  **/
226 typedef Uint8Array ECPoint;
227
228 dictionary EcdhKeyDeriveParams : AlgorithmParameters {
229   // The peer's EC public key.
230   ECPoint public;
231 };
232
233 /**************************************
234  * 19.9.3
235  **/
236 dictionary AesCtrParams : AlgorithmParameters {
237   // The initial value of the counter block. counter MUST be 16 bytes
238   // (the AES block size). The counter bits are the rightmost length
239   // bits of the counter block. The rest of the counter block is for
240   // the nonce. The counter bits are incremented using the standard
241   // incrementing function specified in NIST SP 800-38A Appendix B.1:
242   // the counter bits are interpreted as a big-endian integer and
243   // incremented by one.
244   ArrayBuffer counter;
245   // The length, in bits, of the rightmost part of the counter block
246   // that is incremented.
247   [EnforceRange] octet length;
248 };
249
250 /**************************************
251  * 19.9.4
252  **/
253 dictionary AesKeyGenParams : AlgorithmParameters {
254   // The length, in bits, of the key.
255   [EnforceRange] unsigned short length;
256 };
257
258 /**************************************
259  * 19.10.3
260  **/
261 dictionary AesCbcParams : AlgorithmParameters {
262   // The initialization vector. MUST be 16 bytes.
263   ArrayBufferView iv;
264 };
265
266 /**************************************
267  * 19.11.3
268  **/
269 dictionary AesGcmParams : AlgorithmParameters {
270   // The initialization vector to use. May be up to 2^56 bytes long.
271   ArrayBufferView? iv;
272   // The additional authentication data to include.
273   ArrayBufferView? additionalData;
274   // The desired length of the authentication tag. May be 0 - 128.
275   [EnforceRange] octet? tagLength = 0;
276 };
277
278 /**************************************
279  * 19.12.3
280  **/
281 dictionary HmacParams : AlgorithmParameters {
282   // The inner hash function to use.
283   AlgorithmIdentifier hash;
284 };
285
286 /**************************************
287  * 19.13.3
288  **/
289 dictionary DhKeyGenParams : AlgorithmParameters {
290   // The prime p.
291   BigInteger prime;
292   // The base g.
293   BigInteger generator;
294 };
295
296 /**************************************
297  * 19.13.4
298  **/
299 dictionary DhKeyDeriveParams : AlgorithmParameters {
300   // The peer's public value.
301   BigInteger public;
302 };
303
304 /**************************************
305  * 19.15.4
306  **/
307 dictionary ConcatParams : AlgorithmParameters {
308   // The digest method to use to derive the keying material.
309   AlgorithmIdentifier hash;
310
311   // A bit string corresponding to the AlgorithmId field of the OtherInfo parameter.
312   // The AlgorithmId indicates how the derived keying material will be parsed and for which
313   // algorithm(s) the derived secret keying material will be used.
314   ArrayBufferView algorithmId;
315
316   // A bit string that corresponds to the PartyUInfo field of the OtherInfo parameter.
317   ArrayBufferView partyUInfo;
318   // A bit string that corresponds to the PartyVInfo field of the OtherInfo parameter.
319   ArrayBufferView partyVInfo;
320   // An optional bit string that corresponds to the SuppPubInfo field of the OtherInfo parameter.
321   ArrayBufferView? publicInfo;
322   // An optional bit string that corresponds to the SuppPrivInfo field of the OtherInfo parameter.
323   ArrayBufferView? privateInfo;
324 };
325
326 /**************************************
327  * 19.16.3
328  **/
329 dictionary Pbkdf2Params : AlgorithmParameters {
330   ArrayBufferView salt;
331   [Clamp] unsigned long iterations;
332   AlgorithmIdentifier prf;
333   ArrayBufferView? password;
334 }
335
336 /**************************************
337  * 21.1
338
339 // Algorithm Object
340 var algorithmKeyGen = {
341   name: "RSASSA-PKCS1-v1_5",
342   // RsaKeyGenParams
343   params: {
344     modulusLength: 2048,
345     publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
346   }
347 };
348
349 var algorithmSign = {
350   name: "RSASSA-PKCS1-v1_5",
351   // RsaSsaParams
352   params: {
353     hash: {
354       name: "SHA-256",
355     }
356   }
357 };
358
359 window.crypto.generateKey(algorithmKeyGen, false, ["sign"]).done(
360   function(key) {
361     var dataPart1 = convertPlainTextToArrayBufferView("hello,");
362     var dataPart2 = convertPlainTextToArrayBufferView(" world!");
363     // TODO: create example utility function that converts text -> ArrayBufferView
364
365     // Because we are not supplying data to .sign(), a multi-part
366     // CryptoOperation will be returned, which requires us to call .process()
367     // and .finish().
368     window.crypt.sign(algorithmSign, key.privateKey)
369       .process(dataPart1)
370       .process(dataPart2)
371       .finish()
372       .done(console.log.bind(console, "The signature is: "),
373             console.error.bind(console, "Unable to sign"));
374   },
375   console.error.bind(console, "Unable to generate a key:")
376 );
377 **/
378
379 /**************************************
380  * 21.2
381 var clearDataArrayBufferView = convertPlainTextToArrayBufferView("Plain Text Data");
382 // TODO: create example utility function that converts text -> ArrayBufferView
383
384 var aesAlgorithmKeyGen = {
385   name: "AES-CBC",
386   // AesKeyGenParams
387   params: {
388     length: 128
389   }
390 };
391
392 var aesAlgorithmEncrypt = {
393   name: "AES-CBC",
394   // AesCbcParams
395   params: {
396     iv: window.crypto.getRandomValues(new Uint8Array(16))
397   }
398 };
399
400 // Create a keygenerator to produce a one-time-use AES key to encrypt some data
401 window.crypto.generateKey(aesAlgorithmKeyGen, false, ["encrypt"]).done(
402   function(aesKey) { // A new, random AES key has been generated.
403     // Unlike the signing example, which showed multi-part encryption, here we
404     // will perform the entire AES operation in a single call.
405     window.crypto.encrypt(aesAlgorithmEncrypt,
406                           aesKey,
407                           clearDataArrayBufferView)
408     .done(
409       function(cipherText) {
410         console.log("Ciphertext is:", cipherText);
411       },
412       console.error.bind(console, "Unable to AES encrypt.");
413     );
414   }
415 );
416
417 **/