1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
|
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "public/platform/WebCryptoAlgorithm.h"
#include "public/platform/WebCryptoAlgorithmParams.h"
#include "wtf/Assertions.h"
#include "wtf/PtrUtil.h"
#include "wtf/StdLibExtras.h"
#include "wtf/ThreadSafeRefCounted.h"
#include <memory>
namespace blink {
namespace {
// A mapping from the algorithm ID to information about the algorithm.
const WebCryptoAlgorithmInfo algorithmIdToInfo[] = {
{// Index 0
"AES-CBC",
{
WebCryptoAlgorithmParamsTypeAesCbcParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesCbcParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeAesDerivedKeyParams, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesCbcParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesCbcParams // UnwrapKey
}},
{// Index 1
"HMAC",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeNone, // Sign
WebCryptoAlgorithmParamsTypeNone, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeHmacKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeHmacImportParams, // ImportKey
WebCryptoAlgorithmParamsTypeHmacImportParams, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 2
"RSASSA-PKCS1-v1_5",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeNone, // Sign
WebCryptoAlgorithmParamsTypeNone, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 3
"SHA-1",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 4
"SHA-256",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 5
"SHA-384",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 6
"SHA-512",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmParamsTypeNone, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmInfo::Undefined, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 7
"AES-GCM",
{
WebCryptoAlgorithmParamsTypeAesGcmParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesGcmParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeAesDerivedKeyParams, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesGcmParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesGcmParams // UnwrapKey
}},
{// Index 8
"RSA-OAEP",
{
WebCryptoAlgorithmParamsTypeRsaOaepParams, // Encrypt
WebCryptoAlgorithmParamsTypeRsaOaepParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeRsaOaepParams, // WrapKey
WebCryptoAlgorithmParamsTypeRsaOaepParams // UnwrapKey
}},
{// Index 9
"AES-CTR",
{
WebCryptoAlgorithmParamsTypeAesCtrParams, // Encrypt
WebCryptoAlgorithmParamsTypeAesCtrParams, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeAesDerivedKeyParams, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeAesCtrParams, // WrapKey
WebCryptoAlgorithmParamsTypeAesCtrParams // UnwrapKey
}},
{// Index 10
"AES-KW",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeAesKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeAesDerivedKeyParams, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmParamsTypeNone, // WrapKey
WebCryptoAlgorithmParamsTypeNone // UnwrapKey
}},
{// Index 11
"RSA-PSS",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeRsaPssParams, // Sign
WebCryptoAlgorithmParamsTypeRsaPssParams, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeRsaHashedImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 12
"ECDSA",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmParamsTypeEcdsaParams, // Sign
WebCryptoAlgorithmParamsTypeEcdsaParams, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeEcKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeEcKeyImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmInfo::Undefined, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 13
"ECDH",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmParamsTypeEcKeyGenParams, // GenerateKey
WebCryptoAlgorithmParamsTypeEcKeyImportParams, // ImportKey
WebCryptoAlgorithmInfo::Undefined, // GetKeyLength
WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 14
"HKDF",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeNone, // GetKeyLength
WebCryptoAlgorithmParamsTypeHkdfParams, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
{// Index 15
"PBKDF2",
{
WebCryptoAlgorithmInfo::Undefined, // Encrypt
WebCryptoAlgorithmInfo::Undefined, // Decrypt
WebCryptoAlgorithmInfo::Undefined, // Sign
WebCryptoAlgorithmInfo::Undefined, // Verify
WebCryptoAlgorithmInfo::Undefined, // Digest
WebCryptoAlgorithmInfo::Undefined, // GenerateKey
WebCryptoAlgorithmParamsTypeNone, // ImportKey
WebCryptoAlgorithmParamsTypeNone, // GetKeyLength
WebCryptoAlgorithmParamsTypePbkdf2Params, // DeriveBits
WebCryptoAlgorithmInfo::Undefined, // WrapKey
WebCryptoAlgorithmInfo::Undefined // UnwrapKey
}},
};
// Initializing the algorithmIdToInfo table above depends on knowing the enum
// values for algorithm IDs. If those ever change, the table will need to be
// updated.
static_assert(WebCryptoAlgorithmIdAesCbc == 0, "AES CBC id must match");
static_assert(WebCryptoAlgorithmIdHmac == 1, "HMAC id must match");
static_assert(WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 == 2,
"RSASSA-PKCS1-v1_5 id must match");
static_assert(WebCryptoAlgorithmIdSha1 == 3, "SHA1 id must match");
static_assert(WebCryptoAlgorithmIdSha256 == 4, "SHA256 id must match");
static_assert(WebCryptoAlgorithmIdSha384 == 5, "SHA384 id must match");
static_assert(WebCryptoAlgorithmIdSha512 == 6, "SHA512 id must match");
static_assert(WebCryptoAlgorithmIdAesGcm == 7, "AES GCM id must match");
static_assert(WebCryptoAlgorithmIdRsaOaep == 8, "RSA OAEP id must match");
static_assert(WebCryptoAlgorithmIdAesCtr == 9, "AES CTR id must match");
static_assert(WebCryptoAlgorithmIdAesKw == 10, "AESKW id must match");
static_assert(WebCryptoAlgorithmIdRsaPss == 11, "RSA-PSS id must match");
static_assert(WebCryptoAlgorithmIdEcdsa == 12, "ECDSA id must match");
static_assert(WebCryptoAlgorithmIdEcdh == 13, "ECDH id must match");
static_assert(WebCryptoAlgorithmIdHkdf == 14, "HKDF id must match");
static_assert(WebCryptoAlgorithmIdPbkdf2 == 15, "Pbkdf2 id must match");
static_assert(WebCryptoAlgorithmIdLast == 15, "last id must match");
static_assert(10 == WebCryptoOperationLast,
"the parameter mapping needs to be updated");
} // namespace
class WebCryptoAlgorithmPrivate
: public ThreadSafeRefCounted<WebCryptoAlgorithmPrivate> {
public:
WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id,
std::unique_ptr<WebCryptoAlgorithmParams> params)
: id(id), params(std::move(params)) {}
WebCryptoAlgorithmId id;
std::unique_ptr<WebCryptoAlgorithmParams> params;
};
WebCryptoAlgorithm::WebCryptoAlgorithm(
WebCryptoAlgorithmId id,
std::unique_ptr<WebCryptoAlgorithmParams> params)
: m_private(
adoptRef(new WebCryptoAlgorithmPrivate(id, std::move(params)))) {}
WebCryptoAlgorithm WebCryptoAlgorithm::createNull() {
return WebCryptoAlgorithm();
}
WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(
WebCryptoAlgorithmId id,
WebCryptoAlgorithmParams* params) {
return WebCryptoAlgorithm(id, WTF::wrapUnique(params));
}
const WebCryptoAlgorithmInfo* WebCryptoAlgorithm::lookupAlgorithmInfo(
WebCryptoAlgorithmId id) {
const unsigned idInt = id;
if (idInt >= WTF_ARRAY_LENGTH(algorithmIdToInfo))
return 0;
return &algorithmIdToInfo[id];
}
bool WebCryptoAlgorithm::isNull() const {
return m_private.isNull();
}
WebCryptoAlgorithmId WebCryptoAlgorithm::id() const {
ASSERT(!isNull());
return m_private->id;
}
WebCryptoAlgorithmParamsType WebCryptoAlgorithm::paramsType() const {
ASSERT(!isNull());
if (!m_private->params)
return WebCryptoAlgorithmParamsTypeNone;
return m_private->params->type();
}
const WebCryptoAesCbcParams* WebCryptoAlgorithm::aesCbcParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesCbcParams)
return static_cast<WebCryptoAesCbcParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesCtrParams* WebCryptoAlgorithm::aesCtrParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesCtrParams)
return static_cast<WebCryptoAesCtrParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesKeyGenParams* WebCryptoAlgorithm::aesKeyGenParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesKeyGenParams)
return static_cast<WebCryptoAesKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoHmacImportParams* WebCryptoAlgorithm::hmacImportParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeHmacImportParams)
return static_cast<WebCryptoHmacImportParams*>(m_private->params.get());
return 0;
}
const WebCryptoHmacKeyGenParams* WebCryptoAlgorithm::hmacKeyGenParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeHmacKeyGenParams)
return static_cast<WebCryptoHmacKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesGcmParams* WebCryptoAlgorithm::aesGcmParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesGcmParams)
return static_cast<WebCryptoAesGcmParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaOaepParams* WebCryptoAlgorithm::rsaOaepParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaOaepParams)
return static_cast<WebCryptoRsaOaepParams*>(m_private->params.get());
return 0;
}
const WebCryptoRsaHashedImportParams*
WebCryptoAlgorithm::rsaHashedImportParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaHashedImportParams)
return static_cast<WebCryptoRsaHashedImportParams*>(
m_private->params.get());
return 0;
}
const WebCryptoRsaHashedKeyGenParams*
WebCryptoAlgorithm::rsaHashedKeyGenParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams)
return static_cast<WebCryptoRsaHashedKeyGenParams*>(
m_private->params.get());
return 0;
}
const WebCryptoRsaPssParams* WebCryptoAlgorithm::rsaPssParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeRsaPssParams)
return static_cast<WebCryptoRsaPssParams*>(m_private->params.get());
return 0;
}
const WebCryptoEcdsaParams* WebCryptoAlgorithm::ecdsaParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeEcdsaParams)
return static_cast<WebCryptoEcdsaParams*>(m_private->params.get());
return 0;
}
const WebCryptoEcKeyGenParams* WebCryptoAlgorithm::ecKeyGenParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeEcKeyGenParams)
return static_cast<WebCryptoEcKeyGenParams*>(m_private->params.get());
return 0;
}
const WebCryptoEcKeyImportParams* WebCryptoAlgorithm::ecKeyImportParams()
const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeEcKeyImportParams)
return static_cast<WebCryptoEcKeyImportParams*>(m_private->params.get());
return 0;
}
const WebCryptoEcdhKeyDeriveParams* WebCryptoAlgorithm::ecdhKeyDeriveParams()
const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeEcdhKeyDeriveParams)
return static_cast<WebCryptoEcdhKeyDeriveParams*>(m_private->params.get());
return 0;
}
const WebCryptoAesDerivedKeyParams* WebCryptoAlgorithm::aesDerivedKeyParams()
const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeAesDerivedKeyParams)
return static_cast<WebCryptoAesDerivedKeyParams*>(m_private->params.get());
return 0;
}
const WebCryptoHkdfParams* WebCryptoAlgorithm::hkdfParams() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypeHkdfParams)
return static_cast<WebCryptoHkdfParams*>(m_private->params.get());
return 0;
}
const WebCryptoPbkdf2Params* WebCryptoAlgorithm::pbkdf2Params() const {
ASSERT(!isNull());
if (paramsType() == WebCryptoAlgorithmParamsTypePbkdf2Params)
return static_cast<WebCryptoPbkdf2Params*>(m_private->params.get());
return 0;
}
bool WebCryptoAlgorithm::isHash(WebCryptoAlgorithmId id) {
switch (id) {
case WebCryptoAlgorithmIdSha1:
case WebCryptoAlgorithmIdSha256:
case WebCryptoAlgorithmIdSha384:
case WebCryptoAlgorithmIdSha512:
return true;
case WebCryptoAlgorithmIdAesCbc:
case WebCryptoAlgorithmIdHmac:
case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
case WebCryptoAlgorithmIdAesGcm:
case WebCryptoAlgorithmIdRsaOaep:
case WebCryptoAlgorithmIdAesCtr:
case WebCryptoAlgorithmIdAesKw:
case WebCryptoAlgorithmIdRsaPss:
case WebCryptoAlgorithmIdEcdsa:
case WebCryptoAlgorithmIdEcdh:
case WebCryptoAlgorithmIdHkdf:
case WebCryptoAlgorithmIdPbkdf2:
break;
}
return false;
}
bool WebCryptoAlgorithm::isKdf(WebCryptoAlgorithmId id) {
switch (id) {
case WebCryptoAlgorithmIdHkdf:
case WebCryptoAlgorithmIdPbkdf2:
return true;
case WebCryptoAlgorithmIdSha1:
case WebCryptoAlgorithmIdSha256:
case WebCryptoAlgorithmIdSha384:
case WebCryptoAlgorithmIdSha512:
case WebCryptoAlgorithmIdAesCbc:
case WebCryptoAlgorithmIdHmac:
case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
case WebCryptoAlgorithmIdAesGcm:
case WebCryptoAlgorithmIdRsaOaep:
case WebCryptoAlgorithmIdAesCtr:
case WebCryptoAlgorithmIdAesKw:
case WebCryptoAlgorithmIdRsaPss:
case WebCryptoAlgorithmIdEcdsa:
case WebCryptoAlgorithmIdEcdh:
break;
}
return false;
}
void WebCryptoAlgorithm::assign(const WebCryptoAlgorithm& other) {
m_private = other.m_private;
}
void WebCryptoAlgorithm::reset() {
m_private.reset();
}
} // namespace blink
|