| OLD | NEW |
| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 WebCryptoAlgorithmInfo::Undefined, // Sign | 232 WebCryptoAlgorithmInfo::Undefined, // Sign |
| 233 WebCryptoAlgorithmInfo::Undefined, // Verify | 233 WebCryptoAlgorithmInfo::Undefined, // Verify |
| 234 WebCryptoAlgorithmInfo::Undefined, // Digest | 234 WebCryptoAlgorithmInfo::Undefined, // Digest |
| 235 WebCryptoAlgorithmParamsTypeEcKeyGenParams, // GenerateKey | 235 WebCryptoAlgorithmParamsTypeEcKeyGenParams, // GenerateKey |
| 236 WebCryptoAlgorithmParamsTypeEcKeyImportParams, // ImportKey | 236 WebCryptoAlgorithmParamsTypeEcKeyImportParams, // ImportKey |
| 237 WebCryptoAlgorithmInfo::Undefined, // GetKeyLength | 237 WebCryptoAlgorithmInfo::Undefined, // GetKeyLength |
| 238 WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams, // DeriveBits | 238 WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams, // DeriveBits |
| 239 WebCryptoAlgorithmParamsTypeNone, // WrapKey | 239 WebCryptoAlgorithmParamsTypeNone, // WrapKey |
| 240 WebCryptoAlgorithmParamsTypeNone // UnwrapKey | 240 WebCryptoAlgorithmParamsTypeNone // UnwrapKey |
| 241 } | 241 } |
| 242 }, { // Index 14 |
| 243 "HKDF", { |
| 244 WebCryptoAlgorithmInfo::Undefined, // Encrypt |
| 245 WebCryptoAlgorithmInfo::Undefined, // Decrypt |
| 246 WebCryptoAlgorithmInfo::Undefined, // Sign |
| 247 WebCryptoAlgorithmInfo::Undefined, // Verify |
| 248 WebCryptoAlgorithmInfo::Undefined, // Digest |
| 249 WebCryptoAlgorithmInfo::Undefined, // GenerateKey |
| 250 WebCryptoAlgorithmParamsTypeNone, // ImportKey |
| 251 WebCryptoAlgorithmParamsTypeNone, // GetKeyLength |
| 252 WebCryptoAlgorithmParamsTypeHkdfParams, // DeriveBits |
| 253 WebCryptoAlgorithmInfo::Undefined, // WrapKey |
| 254 WebCryptoAlgorithmInfo::Undefined // UnwrapKey |
| 255 } |
| 242 }, | 256 }, |
| 243 }; | 257 }; |
| 244 | 258 |
| 245 // Initializing the algorithmIdToInfo table above depends on knowing the enum | 259 // Initializing the algorithmIdToInfo table above depends on knowing the enum |
| 246 // values for algorithm IDs. If those ever change, the table will need to be | 260 // values for algorithm IDs. If those ever change, the table will need to be |
| 247 // updated. | 261 // updated. |
| 248 static_assert(WebCryptoAlgorithmIdAesCbc == 0, "AES CBC id must match"); | 262 static_assert(WebCryptoAlgorithmIdAesCbc == 0, "AES CBC id must match"); |
| 249 static_assert(WebCryptoAlgorithmIdHmac == 1, "HMAC id must match"); | 263 static_assert(WebCryptoAlgorithmIdHmac == 1, "HMAC id must match"); |
| 250 static_assert(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, "RSASSA-PKCS1-v1_5 id mu
st match"); | 264 static_assert(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2, "RSASSA-PKCS1-v1_5 id mu
st match"); |
| 251 static_assert(WebCryptoAlgorithmIdSha1 == 3, "SHA1 id must match"); | 265 static_assert(WebCryptoAlgorithmIdSha1 == 3, "SHA1 id must match"); |
| 252 static_assert(WebCryptoAlgorithmIdSha256 == 4, "SHA256 id must match"); | 266 static_assert(WebCryptoAlgorithmIdSha256 == 4, "SHA256 id must match"); |
| 253 static_assert(WebCryptoAlgorithmIdSha384 == 5, "SHA384 id must match"); | 267 static_assert(WebCryptoAlgorithmIdSha384 == 5, "SHA384 id must match"); |
| 254 static_assert(WebCryptoAlgorithmIdSha512 == 6, "SHA512 id must match"); | 268 static_assert(WebCryptoAlgorithmIdSha512 == 6, "SHA512 id must match"); |
| 255 static_assert(WebCryptoAlgorithmIdAesGcm == 7, "AES GCM id must match"); | 269 static_assert(WebCryptoAlgorithmIdAesGcm == 7, "AES GCM id must match"); |
| 256 static_assert(WebCryptoAlgorithmIdRsaOaep == 8, "RSA OAEP id must match"); | 270 static_assert(WebCryptoAlgorithmIdRsaOaep == 8, "RSA OAEP id must match"); |
| 257 static_assert(WebCryptoAlgorithmIdAesCtr == 9, "AES CTR id must match"); | 271 static_assert(WebCryptoAlgorithmIdAesCtr == 9, "AES CTR id must match"); |
| 258 static_assert(WebCryptoAlgorithmIdAesKw == 10, "AESKW id must match"); | 272 static_assert(WebCryptoAlgorithmIdAesKw == 10, "AESKW id must match"); |
| 259 static_assert(WebCryptoAlgorithmIdRsaPss == 11, "RSA-PSS id must match"); | 273 static_assert(WebCryptoAlgorithmIdRsaPss == 11, "RSA-PSS id must match"); |
| 260 static_assert(WebCryptoAlgorithmIdEcdsa == 12, "ECDSA id must match"); | 274 static_assert(WebCryptoAlgorithmIdEcdsa == 12, "ECDSA id must match"); |
| 261 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match"); | 275 static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match"); |
| 262 static_assert(WebCryptoAlgorithmIdLast == 13, "last id must match"); | 276 static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match"); |
| 277 static_assert(WebCryptoAlgorithmIdLast == 14, "last id must match"); |
| 263 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u
pdated"); | 278 static_assert(10 == WebCryptoOperationLast, "the parameter mapping needs to be u
pdated"); |
| 264 | 279 |
| 265 } // namespace | 280 } // namespace |
| 266 | 281 |
| 267 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm
Private> { | 282 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm
Private> { |
| 268 public: | 283 public: |
| 269 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor
ithmParams> params) | 284 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor
ithmParams> params) |
| 270 : id(id) | 285 : id(id) |
| 271 , params(params) | 286 , params(params) |
| 272 { | 287 { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 445 } |
| 431 | 446 |
| 432 const WebCryptoAesDerivedKeyParams* WebCryptoAlgorithm::aesDerivedKeyParams() co
nst | 447 const WebCryptoAesDerivedKeyParams* WebCryptoAlgorithm::aesDerivedKeyParams() co
nst |
| 433 { | 448 { |
| 434 ASSERT(!isNull()); | 449 ASSERT(!isNull()); |
| 435 if (paramsType() == WebCryptoAlgorithmParamsTypeAesDerivedKeyParams) | 450 if (paramsType() == WebCryptoAlgorithmParamsTypeAesDerivedKeyParams) |
| 436 return static_cast<WebCryptoAesDerivedKeyParams*>(m_private->params.get(
)); | 451 return static_cast<WebCryptoAesDerivedKeyParams*>(m_private->params.get(
)); |
| 437 return 0; | 452 return 0; |
| 438 } | 453 } |
| 439 | 454 |
| 455 const WebCryptoHkdfParams* WebCryptoAlgorithm::hkdfParams() const |
| 456 { |
| 457 ASSERT(!isNull()); |
| 458 if (paramsType() == WebCryptoAlgorithmParamsTypeHkdfParams) |
| 459 return static_cast<WebCryptoHkdfParams*>(m_private->params.get()); |
| 460 return 0; |
| 461 } |
| 462 |
| 440 bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id) | 463 bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id) |
| 441 { | 464 { |
| 442 switch (id) { | 465 switch (id) { |
| 443 case WebCryptoAlgorithmIdSha1: | 466 case WebCryptoAlgorithmIdSha1: |
| 444 case WebCryptoAlgorithmIdSha256: | 467 case WebCryptoAlgorithmIdSha256: |
| 445 case WebCryptoAlgorithmIdSha384: | 468 case WebCryptoAlgorithmIdSha384: |
| 446 case WebCryptoAlgorithmIdSha512: | 469 case WebCryptoAlgorithmIdSha512: |
| 447 return true; | 470 return true; |
| 448 case WebCryptoAlgorithmIdAesCbc: | 471 case WebCryptoAlgorithmIdAesCbc: |
| 449 case WebCryptoAlgorithmIdHmac: | 472 case WebCryptoAlgorithmIdHmac: |
| 450 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 473 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 451 case WebCryptoAlgorithmIdAesGcm: | 474 case WebCryptoAlgorithmIdAesGcm: |
| 452 case WebCryptoAlgorithmIdRsaOaep: | 475 case WebCryptoAlgorithmIdRsaOaep: |
| 453 case WebCryptoAlgorithmIdAesCtr: | 476 case WebCryptoAlgorithmIdAesCtr: |
| 454 case WebCryptoAlgorithmIdAesKw: | 477 case WebCryptoAlgorithmIdAesKw: |
| 455 case WebCryptoAlgorithmIdRsaPss: | 478 case WebCryptoAlgorithmIdRsaPss: |
| 456 case WebCryptoAlgorithmIdEcdsa: | 479 case WebCryptoAlgorithmIdEcdsa: |
| 457 case WebCryptoAlgorithmIdEcdh: | 480 case WebCryptoAlgorithmIdEcdh: |
| 481 case WebCryptoAlgorithmIdHkdf: |
| 482 break; |
| 483 } |
| 484 return false; |
| 485 } |
| 486 |
| 487 bool WebCryptoAlgorithm::isKdf(WebCryptoAlgorithmId id) |
| 488 { |
| 489 switch (id) { |
| 490 case WebCryptoAlgorithmIdHkdf: |
| 491 return true; |
| 492 case WebCryptoAlgorithmIdSha1: |
| 493 case WebCryptoAlgorithmIdSha256: |
| 494 case WebCryptoAlgorithmIdSha384: |
| 495 case WebCryptoAlgorithmIdSha512: |
| 496 case WebCryptoAlgorithmIdAesCbc: |
| 497 case WebCryptoAlgorithmIdHmac: |
| 498 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 499 case WebCryptoAlgorithmIdAesGcm: |
| 500 case WebCryptoAlgorithmIdRsaOaep: |
| 501 case WebCryptoAlgorithmIdAesCtr: |
| 502 case WebCryptoAlgorithmIdAesKw: |
| 503 case WebCryptoAlgorithmIdRsaPss: |
| 504 case WebCryptoAlgorithmIdEcdsa: |
| 505 case WebCryptoAlgorithmIdEcdh: |
| 458 break; | 506 break; |
| 459 } | 507 } |
| 460 return false; | 508 return false; |
| 461 } | 509 } |
| 462 | 510 |
| 463 void WebCryptoAlgorithm::assign(const WebCryptoAlgorithm& other) | 511 void WebCryptoAlgorithm::assign(const WebCryptoAlgorithm& other) |
| 464 { | 512 { |
| 465 m_private = other.m_private; | 513 m_private = other.m_private; |
| 466 } | 514 } |
| 467 | 515 |
| 468 void WebCryptoAlgorithm::reset() | 516 void WebCryptoAlgorithm::reset() |
| 469 { | 517 { |
| 470 m_private.reset(); | 518 m_private.reset(); |
| 471 } | 519 } |
| 472 | 520 |
| 473 } // namespace blink | 521 } // namespace blink |
| OLD | NEW |