Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 180323002: [webcrypto] Add parameter parsing for AES-GCM. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 struct OperationParamsMapping { 63 struct OperationParamsMapping {
64 blink::WebCryptoAlgorithmId algorithmId; 64 blink::WebCryptoAlgorithmId algorithmId;
65 AlgorithmOperation operation; 65 AlgorithmOperation operation;
66 AlgorithmParamsForOperation params; 66 AlgorithmParamsForOperation params;
67 }; 67 };
68 68
69 const AlgorithmNameMapping algorithmNameMappings[] = { 69 const AlgorithmNameMapping algorithmNameMappings[] = {
70 {"AES-CBC", blink::WebCryptoAlgorithmIdAesCbc}, 70 {"AES-CBC", blink::WebCryptoAlgorithmIdAesCbc},
71 {"AES-CTR", blink::WebCryptoAlgorithmIdAesCtr}, 71 {"AES-CTR", blink::WebCryptoAlgorithmIdAesCtr},
72 {"AES-GCM", blink::WebCryptoAlgorithmIdAesGcm},
72 {"HMAC", blink::WebCryptoAlgorithmIdHmac}, 73 {"HMAC", blink::WebCryptoAlgorithmIdHmac},
73 {"RSASSA-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, 74 {"RSASSA-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5},
74 {"RSAES-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, 75 {"RSAES-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5},
75 {"SHA-1", blink::WebCryptoAlgorithmIdSha1}, 76 {"SHA-1", blink::WebCryptoAlgorithmIdSha1},
76 {"SHA-224", blink::WebCryptoAlgorithmIdSha224}, 77 {"SHA-224", blink::WebCryptoAlgorithmIdSha224},
77 {"SHA-256", blink::WebCryptoAlgorithmIdSha256}, 78 {"SHA-256", blink::WebCryptoAlgorithmIdSha256},
78 {"SHA-384", blink::WebCryptoAlgorithmIdSha384}, 79 {"SHA-384", blink::WebCryptoAlgorithmIdSha384},
79 {"SHA-512", blink::WebCryptoAlgorithmIdSha512}, 80 {"SHA-512", blink::WebCryptoAlgorithmIdSha512},
80 {"AES-KW", blink::WebCryptoAlgorithmIdAesKw}, 81 {"AES-KW", blink::WebCryptoAlgorithmIdAesKw},
81 }; 82 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 {blink::WebCryptoAlgorithmIdSha224, Digest, blink::WebCryptoAlgorithmParamsT ypeNone}, 124 {blink::WebCryptoAlgorithmIdSha224, Digest, blink::WebCryptoAlgorithmParamsT ypeNone},
124 {blink::WebCryptoAlgorithmIdSha256, Digest, blink::WebCryptoAlgorithmParamsT ypeNone}, 125 {blink::WebCryptoAlgorithmIdSha256, Digest, blink::WebCryptoAlgorithmParamsT ypeNone},
125 {blink::WebCryptoAlgorithmIdSha384, Digest, blink::WebCryptoAlgorithmParamsT ypeNone}, 126 {blink::WebCryptoAlgorithmIdSha384, Digest, blink::WebCryptoAlgorithmParamsT ypeNone},
126 {blink::WebCryptoAlgorithmIdSha512, Digest, blink::WebCryptoAlgorithmParamsT ypeNone}, 127 {blink::WebCryptoAlgorithmIdSha512, Digest, blink::WebCryptoAlgorithmParamsT ypeNone},
127 128
128 // AES-KW 129 // AES-KW
129 {blink::WebCryptoAlgorithmIdAesKw, GenerateKey, blink::WebCryptoAlgorithmPar amsTypeAesKeyGenParams}, 130 {blink::WebCryptoAlgorithmIdAesKw, GenerateKey, blink::WebCryptoAlgorithmPar amsTypeAesKeyGenParams},
130 {blink::WebCryptoAlgorithmIdAesKw, ImportKey, blink::WebCryptoAlgorithmParam sTypeNone}, 131 {blink::WebCryptoAlgorithmIdAesKw, ImportKey, blink::WebCryptoAlgorithmParam sTypeNone},
131 {blink::WebCryptoAlgorithmIdAesKw, UnwrapKey, blink::WebCryptoAlgorithmParam sTypeNone}, 132 {blink::WebCryptoAlgorithmIdAesKw, UnwrapKey, blink::WebCryptoAlgorithmParam sTypeNone},
132 {blink::WebCryptoAlgorithmIdAesKw, WrapKey, blink::WebCryptoAlgorithmParamsT ypeNone}, 133 {blink::WebCryptoAlgorithmIdAesKw, WrapKey, blink::WebCryptoAlgorithmParamsT ypeNone},
134
135 // AES-GCM
136 {blink::WebCryptoAlgorithmIdAesGcm, GenerateKey, blink::WebCryptoAlgorithmPa ramsTypeAesKeyGenParams},
137 {blink::WebCryptoAlgorithmIdAesGcm, ImportKey, blink::WebCryptoAlgorithmPara msTypeNone},
138 {blink::WebCryptoAlgorithmIdAesGcm, Encrypt, blink::WebCryptoAlgorithmParams TypeAesGcmParams},
139 {blink::WebCryptoAlgorithmIdAesGcm, Decrypt, blink::WebCryptoAlgorithmParams TypeAesGcmParams},
140 {blink::WebCryptoAlgorithmIdAesGcm, UnwrapKey, blink::WebCryptoAlgorithmPara msTypeAesGcmParams},
141 {blink::WebCryptoAlgorithmIdAesGcm, WrapKey, blink::WebCryptoAlgorithmParams TypeAesGcmParams},
133 }; 142 };
134 143
135 // This structure describes an algorithm and its supported operations. 144 // This structure describes an algorithm and its supported operations.
136 struct AlgorithmInfo { 145 struct AlgorithmInfo {
137 AlgorithmInfo() 146 AlgorithmInfo()
138 : algorithmName(0) 147 : algorithmName(0)
139 { 148 {
140 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i) 149 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i)
141 paramsForOperation[i] = UnsupportedOp; 150 paramsForOperation[i] = UnsupportedOp;
142 } 151 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 stack.add(message2); 259 stack.add(message2);
251 return stack.toString(); 260 return stack.toString();
252 } 261 }
253 262
254 private: 263 private:
255 // This inline size is large enough to avoid having to grow the Vector in 264 // This inline size is large enough to avoid having to grow the Vector in
256 // the majority of cases (up to 1 nested algorithm identifier). 265 // the majority of cases (up to 1 nested algorithm identifier).
257 Vector<const char*, 10> m_messages; 266 Vector<const char*, 10> m_messages;
258 }; 267 };
259 268
260 bool getArrayBufferView(const Dictionary& raw, const char* propertyName, RefPtr< ArrayBufferView>& buffer, const ErrorContext& context, String& errorDetails) 269 // Defined by the WebCrypto spec as:
270 //
271 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData;
272 //
273 // FIXME: Currently only supports ArrayBufferView.
274 bool getOptionalCryptoOperationData(const Dictionary& raw, const char* propertyN ame, bool& hasProperty, RefPtr<ArrayBufferView>& buffer, const ErrorContext& con text, String& errorDetails)
261 { 275 {
262 if (!raw.get(propertyName, buffer) || !buffer) { 276 bool ok = raw.get(propertyName, buffer, hasProperty);
263 errorDetails = context.toString(propertyName, "Missing or not a ArrayBuf ferView"); 277
278 if (!hasProperty)
279 return true;
280
281 if (!ok || !buffer) {
282 errorDetails = context.toString(propertyName, "Not an ArrayBufferView");
264 return false; 283 return false;
265 } 284 }
285
266 return true; 286 return true;
267 } 287 }
268 288
289 // Defined by the WebCrypto spec as:
290 //
291 // typedef (ArrayBuffer or ArrayBufferView) CryptoOperationData;
292 //
293 // FIXME: Currently only supports ArrayBufferView.
294 bool getCryptoOperationData(const Dictionary& raw, const char* propertyName, Ref Ptr<ArrayBufferView>& buffer, const ErrorContext& context, String& errorDetails)
295 {
296 bool hasProperty;
297 bool ok = getOptionalCryptoOperationData(raw, propertyName, hasProperty, buf fer, context, errorDetails);
298 if (!hasProperty) {
299 errorDetails = context.toString(propertyName, "Missing required property ");
300 return false;
301 }
302 return ok;
303 }
304
269 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8 Array>& array, const ErrorContext& context, String& errorDetails) 305 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8 Array>& array, const ErrorContext& context, String& errorDetails)
270 { 306 {
271 if (!raw.get(propertyName, array) || !array) { 307 if (!raw.get(propertyName, array) || !array) {
272 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr ay"); 308 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr ay");
273 return false; 309 return false;
274 } 310 }
275 return true; 311 return true;
276 } 312 }
277 313
314 // Defined by the WebCrypto spec as:
315 //
316 // typedef Uint8Array BigInteger;
317 bool getBigInteger(const Dictionary& raw, const char* propertyName, RefPtr<Uint8 Array>& array, const ErrorContext& context, String& errorDetails)
318 {
319 if (!getUint8Array(raw, propertyName, array, context, errorDetails))
320 return false;
321
322 if (!array->byteLength()) {
323 errorDetails = context.toString(propertyName, "BigInteger should not be empty");
324 return false;
325 }
326
327 if (!raw.get(propertyName, array) || !array) {
328 errorDetails = context.toString(propertyName, "Missing or not a Uint8Arr ay");
329 return false;
330 }
331 return true;
332 }
333
278 // Gets an integer according to WebIDL's [EnforceRange]. 334 // Gets an integer according to WebIDL's [EnforceRange].
279 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h asProperty, double& value, double minValue, double maxValue, const ErrorContext& context, String& errorDetails) 335 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h asProperty, double& value, double minValue, double maxValue, const ErrorContext& context, String& errorDetails)
280 { 336 {
281 double number; 337 double number;
282 bool ok = raw.get(propertyName, number, hasProperty); 338 bool ok = raw.get(propertyName, number, hasProperty);
283 339
284 if (!hasProperty) 340 if (!hasProperty)
285 return true; 341 return true;
286 342
287 if (!ok || std::isnan(number)) { 343 if (!ok || std::isnan(number)) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha sValue, uint32_t& value, const ErrorContext& context, String& errorDetails) 400 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha sValue, uint32_t& value, const ErrorContext& context, String& errorDetails)
345 { 401 {
346 double number; 402 double number;
347 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF, context, errorDetails)) 403 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF, context, errorDetails))
348 return false; 404 return false;
349 if (hasValue) 405 if (hasValue)
350 value = number; 406 value = number;
351 return true; 407 return true;
352 } 408 }
353 409
410 // Defined by the WebCrypto spec as:
411 //
412 // dictionary AesCbcParams : Algorithm {
413 // CryptoOperationData iv;
414 // };
354 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails) 415 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails)
355 { 416 {
356 RefPtr<ArrayBufferView> iv; 417 RefPtr<ArrayBufferView> iv;
357 if (!getArrayBufferView(raw, "iv", iv, context, errorDetails)) 418 if (!getCryptoOperationData(raw, "iv", iv, context, errorDetails))
358 return false; 419 return false;
359 420
360 if (iv->byteLength() != 16) { 421 if (iv->byteLength() != 16) {
361 errorDetails = context.toString("iv", "Must be 16 bytes"); 422 errorDetails = context.toString("iv", "Must be 16 bytes");
362 return false; 423 return false;
363 } 424 }
364 425
365 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char *>(iv->baseAddress()), iv->byteLength())); 426 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char *>(iv->baseAddress()), iv->byteLength()));
366 return true; 427 return true;
367 } 428 }
368 429
430 // Defined by the WebCrypto spec as:
431 //
432 // dictionary AesKeyGenParams : Algorithm {
433 // [EnforceRange] unsigned short length;
434 // };
369 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith mParams>& params, const ErrorContext& context, String& errorDetails) 435 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith mParams>& params, const ErrorContext& context, String& errorDetails)
370 { 436 {
371 uint16_t length; 437 uint16_t length;
372 if (!getUint16(raw, "length", length, context, errorDetails)) 438 if (!getUint16(raw, "length", length, context, errorDetails))
373 return false; 439 return false;
374 440
375 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); 441 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length));
376 return true; 442 return true;
377 } 443 }
378 444
379 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor ithm&, ErrorContext, String&); 445 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor ithm&, ErrorContext, String&);
380 446
381 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont ext context, String& errorDetails) 447 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont ext context, String& errorDetails)
382 { 448 {
383 Dictionary rawHash; 449 Dictionary rawHash;
384 if (!raw.get("hash", rawHash)) { 450 if (!raw.get("hash", rawHash)) {
385 errorDetails = context.toString("hash", "Missing or not a dictionary"); 451 errorDetails = context.toString("hash", "Missing or not a dictionary");
386 return false; 452 return false;
387 } 453 }
388 454
389 context.add("hash"); 455 context.add("hash");
390 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); 456 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails);
391 } 457 }
392 458
459 // Defined by the WebCrypto spec as:
460 //
461 // dictionary HmacImportParams : Algorithm {
462 // // The inner hash function to use.
463 // AlgorithmIdentifier hash;
464 // };
393 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara ms>& params, const ErrorContext& context, String& errorDetails) 465 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara ms>& params, const ErrorContext& context, String& errorDetails)
394 { 466 {
395 blink::WebCryptoAlgorithm hash; 467 blink::WebCryptoAlgorithm hash;
396 if (!parseHash(raw, hash, context, errorDetails)) 468 if (!parseHash(raw, hash, context, errorDetails))
397 return false; 469 return false;
398 470
399 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); 471 params = adoptPtr(new blink::WebCryptoHmacParams(hash));
400 return true; 472 return true;
401 } 473 }
402 474
475 // Defined by the WebCrypto spec as:
476 //
477 // dictionary HmacKeyGenParams : Algorithm {
478 // AlgorithmIdentifier hash;
479 // // The length (in bytes) of the key to generate. If unspecified, the
480 // // recommended length will be used, which is the size of the associated hash function's block
481 // // size.
482 // unsigned long length;
483 // };
403 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP arams>& params, const ErrorContext& context, String& errorDetails) 484 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP arams>& params, const ErrorContext& context, String& errorDetails)
404 { 485 {
405 blink::WebCryptoAlgorithm hash; 486 blink::WebCryptoAlgorithm hash;
406 if (!parseHash(raw, hash, context, errorDetails)) 487 if (!parseHash(raw, hash, context, errorDetails))
407 return false; 488 return false;
408 489
409 bool hasLength; 490 bool hasLength;
410 uint32_t length = 0; 491 uint32_t length = 0;
411 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai ls)) 492 if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetai ls))
412 return false; 493 return false;
413 494
414 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length) ); 495 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length) );
415 return true; 496 return true;
416 } 497 }
417 498
418 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails) 499 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails)
419 { 500 {
420 blink::WebCryptoAlgorithm hash; 501 blink::WebCryptoAlgorithm hash;
421 if (!parseHash(raw, hash, context, errorDetails)) 502 if (!parseHash(raw, hash, context, errorDetails))
422 return false; 503 return false;
423 504
424 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); 505 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash));
425 return true; 506 return true;
426 } 507 }
427 508
509 // Defined by the WebCrypto spec as:
510 //
511 // dictionary RsaKeyGenParams : Algorithm {
512 // unsigned long modulusLength;
513 // BigInteger publicExponent;
514 // };
428 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith mParams>& params, const ErrorContext& context, String& errorDetails) 515 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith mParams>& params, const ErrorContext& context, String& errorDetails)
429 { 516 {
430 uint32_t modulusLength; 517 uint32_t modulusLength;
431 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) 518 if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails))
432 return false; 519 return false;
433 520
434 RefPtr<Uint8Array> publicExponent; 521 RefPtr<Uint8Array> publicExponent;
435 if (!getUint8Array(raw, "publicExponent", publicExponent, context, errorDeta ils)) 522 if (!getBigInteger(raw, "publicExponent", publicExponent, context, errorDeta ils))
436 return false; 523 return false;
437 524
438 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_ cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL ength())); 525 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_ cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL ength()));
439 return true; 526 return true;
440 } 527 }
441 528
442 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& es) 529 // Defined by the WebCrypto spec as:
530 //
531 // dictionary AesCtrParams : Algorithm {
532 // CryptoOperationData counter;
533 // [EnforceRange] octet length;
534 // };
535 bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails)
443 { 536 {
444 RefPtr<Uint8Array> counter; 537 RefPtr<ArrayBufferView> counter;
445 if (!getUint8Array(raw, "counter", counter, context, es)) 538 if (!getCryptoOperationData(raw, "counter", counter, context, errorDetails))
446 return false; 539 return false;
447 540
448 uint8_t length; 541 uint8_t length;
449 if (!getUint8(raw, "length", length, context, es)) 542 if (!getUint8(raw, "length", length, context, errorDetails))
450 return false; 543 return false;
451 544
452 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const unsigned char*>(counter->baseAddress()), counter->byteLength())); 545 params = adoptPtr(new blink::WebCryptoAesCtrParams(length, static_cast<const unsigned char*>(counter->baseAddress()), counter->byteLength()));
453 return true; 546 return true;
454 } 547 }
455 548
549 // Defined by the WebCrypto spec as:
550 //
551 // dictionary AesGcmParams : Algorithm {
552 // CryptoOperationData iv;
553 // CryptoOperationData? additionalData;
554 // [EnforceRange] octet? tagLength; // May be 0-128
555 // }
556 bool parseAesGcmParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa rams>& params, const ErrorContext& context, String& errorDetails)
557 {
558 RefPtr<ArrayBufferView> iv;
559 if (!getCryptoOperationData(raw, "iv", iv, context, errorDetails))
560 return false;
561
562 bool hasAdditionalData;
563 RefPtr<ArrayBufferView> additionalData;
564 if (!getOptionalCryptoOperationData(raw, "additionalData", hasAdditionalData , additionalData, context, errorDetails))
565 return false;
566
567 double tagLength;
568 bool hasTagLength;
569 if (!getOptionalInteger(raw, "tagLength", hasTagLength, tagLength, 0, 128, c ontext, errorDetails))
570 return false;
571
572 const unsigned char* ivStart = static_cast<const unsigned char*>(iv->baseAdd ress());
573 unsigned ivLength = iv->byteLength();
574
575 const unsigned char* additionalDataStart = hasAdditionalData ? static_cast<c onst unsigned char*>(additionalData->baseAddress()) : 0;
576 unsigned additionalDataLength = hasAdditionalData ? additionalData->byteLeng th() : 0;
577
578 params = adoptPtr(new blink::WebCryptoAesGcmParams(ivStart, ivLength, hasAdd itionalData, additionalDataStart, additionalDataLength, hasTagLength, tagLength) );
579 return true;
580 }
581
456 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex t, String& errorDetails) 582 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& contex t, String& errorDetails)
457 { 583 {
458 switch (type) { 584 switch (type) {
459 case blink::WebCryptoAlgorithmParamsTypeNone: 585 case blink::WebCryptoAlgorithmParamsTypeNone:
460 return true; 586 return true;
461 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: 587 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams:
462 context.add("AesCbcParams"); 588 context.add("AesCbcParams");
463 return parseAesCbcParams(raw, params, context, errorDetails); 589 return parseAesCbcParams(raw, params, context, errorDetails);
464 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: 590 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams:
465 context.add("AesKeyGenParams"); 591 context.add("AesKeyGenParams");
466 return parseAesKeyGenParams(raw, params, context, errorDetails); 592 return parseAesKeyGenParams(raw, params, context, errorDetails);
467 case blink::WebCryptoAlgorithmParamsTypeHmacParams: 593 case blink::WebCryptoAlgorithmParamsTypeHmacParams:
468 context.add("HmacParams"); 594 context.add("HmacParams");
469 return parseHmacParams(raw, params, context, errorDetails); 595 return parseHmacParams(raw, params, context, errorDetails);
470 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: 596 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams:
471 context.add("HmacKeyParams"); 597 context.add("HmacKeyParams");
472 return parseHmacKeyParams(raw, params, context, errorDetails); 598 return parseHmacKeyParams(raw, params, context, errorDetails);
473 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: 599 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams:
474 context.add("RsaSSaParams"); 600 context.add("RsaSSaParams");
475 return parseRsaSsaParams(raw, params, context, errorDetails); 601 return parseRsaSsaParams(raw, params, context, errorDetails);
476 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: 602 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams:
477 context.add("RsaKeyGenParams"); 603 context.add("RsaKeyGenParams");
478 return parseRsaKeyGenParams(raw, params, context, errorDetails); 604 return parseRsaKeyGenParams(raw, params, context, errorDetails);
479 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: 605 case blink::WebCryptoAlgorithmParamsTypeAesCtrParams:
480 context.add("AesCtrParams"); 606 context.add("AesCtrParams");
481 return parseAesCtrParams(raw, params, context, errorDetails); 607 return parseAesCtrParams(raw, params, context, errorDetails);
482 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: 608 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams:
609 context.add("AesGcmParams");
610 return parseAesGcmParams(raw, params, context, errorDetails);
483 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: 611 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams:
484 // TODO 612 // TODO
485 notImplemented(); 613 notImplemented();
486 break; 614 break;
487 } 615 }
488 ASSERT_NOT_REACHED(); 616 ASSERT_NOT_REACHED();
489 return false; 617 return false;
490 } 618 }
491 619
492 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp toAlgorithm& algorithm, ErrorContext context, String& errorDetails) 620 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp toAlgorithm& algorithm, ErrorContext context, String& errorDetails)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 665 }
538 return true; 666 return true;
539 } 667 }
540 668
541 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) 669 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id)
542 { 670 {
543 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; 671 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName;
544 } 672 }
545 673
546 } // namespace WebCore 674 } // namespace WebCore
OLDNEW
« Source/bindings/v8/Dictionary.cpp ('K') | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698