algorithm_implementation.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/webcrypto/algorithm_implementation.h"
  5. #include "base/notreached.h"
  6. #include "components/webcrypto/algorithms/asymmetric_key_util.h"
  7. #include "components/webcrypto/blink_key_handle.h"
  8. #include "components/webcrypto/status.h"
  9. namespace webcrypto {
  10. AlgorithmImplementation::~AlgorithmImplementation() {
  11. }
  12. Status AlgorithmImplementation::Encrypt(
  13. const blink::WebCryptoAlgorithm& algorithm,
  14. const blink::WebCryptoKey& key,
  15. base::span<const uint8_t> data,
  16. std::vector<uint8_t>* buffer) const {
  17. return Status::ErrorUnsupported();
  18. }
  19. Status AlgorithmImplementation::Decrypt(
  20. const blink::WebCryptoAlgorithm& algorithm,
  21. const blink::WebCryptoKey& key,
  22. base::span<const uint8_t> data,
  23. std::vector<uint8_t>* buffer) const {
  24. return Status::ErrorUnsupported();
  25. }
  26. Status AlgorithmImplementation::Sign(const blink::WebCryptoAlgorithm& algorithm,
  27. const blink::WebCryptoKey& key,
  28. base::span<const uint8_t> data,
  29. std::vector<uint8_t>* buffer) const {
  30. return Status::ErrorUnsupported();
  31. }
  32. Status AlgorithmImplementation::Verify(
  33. const blink::WebCryptoAlgorithm& algorithm,
  34. const blink::WebCryptoKey& key,
  35. base::span<const uint8_t> signature,
  36. base::span<const uint8_t> data,
  37. bool* signature_match) const {
  38. return Status::ErrorUnsupported();
  39. }
  40. Status AlgorithmImplementation::Digest(
  41. const blink::WebCryptoAlgorithm& algorithm,
  42. base::span<const uint8_t> data,
  43. std::vector<uint8_t>* buffer) const {
  44. return Status::ErrorUnsupported();
  45. }
  46. Status AlgorithmImplementation::GenerateKey(
  47. const blink::WebCryptoAlgorithm& algorithm,
  48. bool extractable,
  49. blink::WebCryptoKeyUsageMask usages,
  50. GenerateKeyResult* result) const {
  51. return Status::ErrorUnsupported();
  52. }
  53. Status AlgorithmImplementation::DeriveBits(
  54. const blink::WebCryptoAlgorithm& algorithm,
  55. const blink::WebCryptoKey& base_key,
  56. bool has_optional_length_bits,
  57. unsigned int optional_length_bits,
  58. std::vector<uint8_t>* derived_bytes) const {
  59. return Status::ErrorUnsupported();
  60. }
  61. Status AlgorithmImplementation::GetKeyLength(
  62. const blink::WebCryptoAlgorithm& key_length_algorithm,
  63. bool* has_length_bits,
  64. unsigned int* length_bits) const {
  65. return Status::ErrorUnsupported();
  66. }
  67. Status AlgorithmImplementation::ImportKey(
  68. blink::WebCryptoKeyFormat format,
  69. base::span<const uint8_t> key_data,
  70. const blink::WebCryptoAlgorithm& algorithm,
  71. bool extractable,
  72. blink::WebCryptoKeyUsageMask usages,
  73. blink::WebCryptoKey* key) const {
  74. return Status::ErrorUnsupported();
  75. }
  76. Status AlgorithmImplementation::ExportKey(blink::WebCryptoKeyFormat format,
  77. const blink::WebCryptoKey& key,
  78. std::vector<uint8_t>* buffer) const {
  79. return Status::ErrorUnsupported();
  80. }
  81. Status AlgorithmImplementation::SerializeKeyForClone(
  82. const blink::WebCryptoKey& key,
  83. blink::WebVector<uint8_t>* key_data) const {
  84. switch (key.GetType()) {
  85. case blink::kWebCryptoKeyTypeSecret:
  86. *key_data = GetSymmetricKeyData(key);
  87. return Status::Success();
  88. case blink::kWebCryptoKeyTypePublic: {
  89. std::vector<uint8_t> vec;
  90. Status status = ExportPKeySpki(GetEVP_PKEY(key), &vec);
  91. if (status.IsSuccess()) {
  92. *key_data = vec;
  93. }
  94. return status;
  95. }
  96. case blink::kWebCryptoKeyTypePrivate: {
  97. std::vector<uint8_t> vec;
  98. Status status = ExportPKeyPkcs8(GetEVP_PKEY(key), &vec);
  99. if (status.IsSuccess()) {
  100. *key_data = vec;
  101. }
  102. return status;
  103. }
  104. }
  105. NOTREACHED();
  106. return Status::ErrorUnexpected();
  107. }
  108. Status AlgorithmImplementation::DeserializeKeyForClone(
  109. const blink::WebCryptoKeyAlgorithm& algorithm,
  110. blink::WebCryptoKeyType type,
  111. bool extractable,
  112. blink::WebCryptoKeyUsageMask usages,
  113. base::span<const uint8_t> key_data,
  114. blink::WebCryptoKey* key) const {
  115. return Status::ErrorUnsupported();
  116. }
  117. } // namespace webcrypto