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