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

Side by Side Diff: Source/platform/exported/WebCryptoAlgorithm.cpp

Issue 820523003: [webcrypto] Implement PBKDF2 (blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase and structured cloning test Created 5 years, 11 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
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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 WebCryptoAlgorithmInfo::Undefined, // Sign 246 WebCryptoAlgorithmInfo::Undefined, // Sign
247 WebCryptoAlgorithmInfo::Undefined, // Verify 247 WebCryptoAlgorithmInfo::Undefined, // Verify
248 WebCryptoAlgorithmInfo::Undefined, // Digest 248 WebCryptoAlgorithmInfo::Undefined, // Digest
249 WebCryptoAlgorithmInfo::Undefined, // GenerateKey 249 WebCryptoAlgorithmInfo::Undefined, // GenerateKey
250 WebCryptoAlgorithmParamsTypeNone, // ImportKey 250 WebCryptoAlgorithmParamsTypeNone, // ImportKey
251 WebCryptoAlgorithmParamsTypeNone, // GetKeyLength 251 WebCryptoAlgorithmParamsTypeNone, // GetKeyLength
252 WebCryptoAlgorithmParamsTypeHkdfParams, // DeriveBits 252 WebCryptoAlgorithmParamsTypeHkdfParams, // DeriveBits
253 WebCryptoAlgorithmInfo::Undefined, // WrapKey 253 WebCryptoAlgorithmInfo::Undefined, // WrapKey
254 WebCryptoAlgorithmInfo::Undefined // UnwrapKey 254 WebCryptoAlgorithmInfo::Undefined // UnwrapKey
255 } 255 }
256 }, { // Index 15
257 "PBKDF2", {
258 WebCryptoAlgorithmInfo::Undefined, // Encrypt
259 WebCryptoAlgorithmInfo::Undefined, // Decrypt
260 WebCryptoAlgorithmInfo::Undefined, // Sign
261 WebCryptoAlgorithmInfo::Undefined, // Verify
262 WebCryptoAlgorithmInfo::Undefined, // Digest
263 WebCryptoAlgorithmInfo::Undefined, // GenerateKey
264 WebCryptoAlgorithmParamsTypeNone, // ImportKey
265 WebCryptoAlgorithmParamsTypeNone, // GetKeyLength
266 WebCryptoAlgorithmParamsTypePbkdf2Params, // DeriveBits
267 WebCryptoAlgorithmInfo::Undefined, // WrapKey
268 WebCryptoAlgorithmInfo::Undefined // UnwrapKey
269 }
256 }, 270 },
257 }; 271 };
258 272
259 // Initializing the algorithmIdToInfo table above depends on knowing the enum 273 // Initializing the algorithmIdToInfo table above depends on knowing the enum
260 // values for algorithm IDs. If those ever change, the table will need to be 274 // values for algorithm IDs. If those ever change, the table will need to be
261 // updated. 275 // updated.
262 static_assert(WebCryptoAlgorithmIdAesCbc == 0, "AES CBC id must match"); 276 static_assert(WebCryptoAlgorithmIdAesCbc == 0, "AES CBC id must match");
263 static_assert(WebCryptoAlgorithmIdHmac == 1, "HMAC id must match"); 277 static_assert(WebCryptoAlgorithmIdHmac == 1, "HMAC id must match");
264 static_assert(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, "RSASSA-PKCS1-v1_5 id mu st match"); 278 static_assert(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, "RSASSA-PKCS1-v1_5 id mu st match");
265 static_assert(WebCryptoAlgorithmIdSha1 == 3, "SHA1 id must match"); 279 static_assert(WebCryptoAlgorithmIdSha1 == 3, "SHA1 id must match");
266 static_assert(WebCryptoAlgorithmIdSha256 == 4, "SHA256 id must match"); 280 static_assert(WebCryptoAlgorithmIdSha256 == 4, "SHA256 id must match");
267 static_assert(WebCryptoAlgorithmIdSha384 == 5, "SHA384 id must match"); 281 static_assert(WebCryptoAlgorithmIdSha384 == 5, "SHA384 id must match");
268 static_assert(WebCryptoAlgorithmIdSha512 == 6, "SHA512 id must match"); 282 static_assert(WebCryptoAlgorithmIdSha512 == 6, "SHA512 id must match");
269 static_assert(WebCryptoAlgorithmIdAesGcm == 7, "AES GCM id must match"); 283 static_assert(WebCryptoAlgorithmIdAesGcm == 7, "AES GCM id must match");
270 static_assert(WebCryptoAlgorithmIdRsaOaep == 8, "RSA OAEP id must match"); 284 static_assert(WebCryptoAlgorithmIdRsaOaep == 8, "RSA OAEP id must match");
271 static_assert(WebCryptoAlgorithmIdAesCtr == 9, "AES CTR id must match"); 285 static_assert(WebCryptoAlgorithmIdAesCtr == 9, "AES CTR id must match");
272 static_assert(WebCryptoAlgorithmIdAesKw == 10, "AESKW id must match"); 286 static_assert(WebCryptoAlgorithmIdAesKw == 10, "AESKW id must match");
273 static_assert(WebCryptoAlgorithmIdRsaPss == 11, "RSA-PSS id must match"); 287 static_assert(WebCryptoAlgorithmIdRsaPss == 11, "RSA-PSS id must match");
274 static_assert(WebCryptoAlgorithmIdEcdsa == 12, "ECDSA id must match"); 288 static_assert(WebCryptoAlgorithmIdEcdsa == 12, "ECDSA id must match");
275 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match"); 289 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match");
276 static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match"); 290 static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match");
277 static_assert(WebCryptoAlgorithmIdLast == 14, "last id must match"); 291 static_assert(WebCryptoAlgorithmIdPbkdf2 == 15, "Pbkdf2 id must match");
292 static_assert(WebCryptoAlgorithmIdLast == 15, "last id must match");
278 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u pdated"); 293 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u pdated");
279 294
280 } // namespace 295 } // namespace
281 296
282 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm Private> { 297 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm Private> {
283 public: 298 public:
284 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor ithmParams> params) 299 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor ithmParams> params)
285 : id(id) 300 : id(id)
286 , params(params) 301 , params(params)
287 { 302 {
(...skipping 13 matching lines...) Expand all
301 return WebCryptoAlgorithm(); 316 return WebCryptoAlgorithm();
302 } 317 }
303 318
304 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId id, WebCryptoAlgorithmParams* params) 319 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId id, WebCryptoAlgorithmParams* params)
305 { 320 {
306 return WebCryptoAlgorithm(id, adoptPtr(params)); 321 return WebCryptoAlgorithm(id, adoptPtr(params));
307 } 322 }
308 323
309 const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(WebCryptoA lgorithmId id) 324 const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(WebCryptoA lgorithmId id)
310 { 325 {
311 if (id < 0 || id >= WTF_ARRAY_LENGTH(algorithmIdToInfo)) 326 const unsigned idInt = id;
327 if (idInt >= WTF_ARRAY_LENGTH(algorithmIdToInfo))
xun.sun 2015/01/13 19:16:29 I made this change because I'm seeing the followin
eroman 2015/01/14 21:12:22 Not sure why it would do that.
312 return 0; 328 return 0;
313 return &algorithmIdToInfo[id]; 329 return &algorithmIdToInfo[id];
314 } 330 }
315 331
316 bool WebCryptoAlgorithm::isNull() const 332 bool WebCryptoAlgorithm::isNull() const
317 { 333 {
318 return m_private.isNull(); 334 return m_private.isNull();
319 } 335 }
320 336
321 WebCryptoAlgorithmId WebCryptoAlgorithm::id() const 337 WebCryptoAlgorithmId WebCryptoAlgorithm::id() const
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 469 }
454 470
455 const WebCryptoHkdfParams* WebCryptoAlgorithm::hkdfParams() const 471 const WebCryptoHkdfParams* WebCryptoAlgorithm::hkdfParams() const
456 { 472 {
457 ASSERT(!isNull()); 473 ASSERT(!isNull());
458 if (paramsType() == WebCryptoAlgorithmParamsTypeHkdfParams) 474 if (paramsType() == WebCryptoAlgorithmParamsTypeHkdfParams)
459 return static_cast<WebCryptoHkdfParams*>(m_private->params.get()); 475 return static_cast<WebCryptoHkdfParams*>(m_private->params.get());
460 return 0; 476 return 0;
461 } 477 }
462 478
479 const WebCryptoPbkdf2Params* WebCryptoAlgorithm::pbkdf2Params() const
480 {
481 ASSERT(!isNull());
482 if (paramsType() == WebCryptoAlgorithmParamsTypePbkdf2Params)
483 return static_cast<WebCryptoPbkdf2Params*>(m_private->params.get());
484 return 0;
485 }
486
463 bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id) 487 bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id)
464 { 488 {
465 switch (id) { 489 switch (id) {
466 case WebCryptoAlgorithmIdSha1: 490 case WebCryptoAlgorithmIdSha1:
467 case WebCryptoAlgorithmIdSha256: 491 case WebCryptoAlgorithmIdSha256:
468 case WebCryptoAlgorithmIdSha384: 492 case WebCryptoAlgorithmIdSha384:
469 case WebCryptoAlgorithmIdSha512: 493 case WebCryptoAlgorithmIdSha512:
470 return true; 494 return true;
471 case WebCryptoAlgorithmIdAesCbc: 495 case WebCryptoAlgorithmIdAesCbc:
472 case WebCryptoAlgorithmIdHmac: 496 case WebCryptoAlgorithmIdHmac:
473 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: 497 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
474 case WebCryptoAlgorithmIdAesGcm: 498 case WebCryptoAlgorithmIdAesGcm:
475 case WebCryptoAlgorithmIdRsaOaep: 499 case WebCryptoAlgorithmIdRsaOaep:
476 case WebCryptoAlgorithmIdAesCtr: 500 case WebCryptoAlgorithmIdAesCtr:
477 case WebCryptoAlgorithmIdAesKw: 501 case WebCryptoAlgorithmIdAesKw:
478 case WebCryptoAlgorithmIdRsaPss: 502 case WebCryptoAlgorithmIdRsaPss:
479 case WebCryptoAlgorithmIdEcdsa: 503 case WebCryptoAlgorithmIdEcdsa:
480 case WebCryptoAlgorithmIdEcdh: 504 case WebCryptoAlgorithmIdEcdh:
481 case WebCryptoAlgorithmIdHkdf: 505 case WebCryptoAlgorithmIdHkdf:
506 case WebCryptoAlgorithmIdPbkdf2:
482 break; 507 break;
483 } 508 }
484 return false; 509 return false;
485 } 510 }
486 511
487 bool WebCryptoAlgorithm::isKdf(WebCryptoAlgorithmId id) 512 bool WebCryptoAlgorithm::isKdf(WebCryptoAlgorithmId id)
488 { 513 {
489 switch (id) { 514 switch (id) {
490 case WebCryptoAlgorithmIdHkdf: 515 case WebCryptoAlgorithmIdHkdf:
516 case WebCryptoAlgorithmIdPbkdf2:
491 return true; 517 return true;
492 case WebCryptoAlgorithmIdSha1: 518 case WebCryptoAlgorithmIdSha1:
493 case WebCryptoAlgorithmIdSha256: 519 case WebCryptoAlgorithmIdSha256:
494 case WebCryptoAlgorithmIdSha384: 520 case WebCryptoAlgorithmIdSha384:
495 case WebCryptoAlgorithmIdSha512: 521 case WebCryptoAlgorithmIdSha512:
496 case WebCryptoAlgorithmIdAesCbc: 522 case WebCryptoAlgorithmIdAesCbc:
497 case WebCryptoAlgorithmIdHmac: 523 case WebCryptoAlgorithmIdHmac:
498 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: 524 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
499 case WebCryptoAlgorithmIdAesGcm: 525 case WebCryptoAlgorithmIdAesGcm:
500 case WebCryptoAlgorithmIdRsaOaep: 526 case WebCryptoAlgorithmIdRsaOaep:
(...skipping 11 matching lines...) Expand all
512 { 538 {
513 m_private = other.m_private; 539 m_private = other.m_private;
514 } 540 }
515 541
516 void WebCryptoAlgorithm::reset() 542 void WebCryptoAlgorithm::reset()
517 { 543 {
518 m_private.reset(); 544 m_private.reset();
519 } 545 }
520 546
521 } // namespace blink 547 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698