rsa_ssa.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <stdint.h>
  5. #include <memory>
  6. #include "components/webcrypto/algorithms/rsa.h"
  7. #include "components/webcrypto/algorithms/rsa_sign.h"
  8. #include "components/webcrypto/status.h"
  9. namespace webcrypto {
  10. namespace {
  11. class RsaSsaImplementation : public RsaHashedAlgorithm {
  12. public:
  13. RsaSsaImplementation()
  14. : RsaHashedAlgorithm(blink::kWebCryptoKeyUsageVerify,
  15. blink::kWebCryptoKeyUsageSign) {}
  16. const char* GetJwkAlgorithm(
  17. const blink::WebCryptoAlgorithmId hash) const override {
  18. switch (hash) {
  19. case blink::kWebCryptoAlgorithmIdSha1:
  20. return "RS1";
  21. case blink::kWebCryptoAlgorithmIdSha256:
  22. return "RS256";
  23. case blink::kWebCryptoAlgorithmIdSha384:
  24. return "RS384";
  25. case blink::kWebCryptoAlgorithmIdSha512:
  26. return "RS512";
  27. default:
  28. return nullptr;
  29. }
  30. }
  31. Status Sign(const blink::WebCryptoAlgorithm& algorithm,
  32. const blink::WebCryptoKey& key,
  33. base::span<const uint8_t> data,
  34. std::vector<uint8_t>* buffer) const override {
  35. return RsaSign(key, 0, data, buffer);
  36. }
  37. Status Verify(const blink::WebCryptoAlgorithm& algorithm,
  38. const blink::WebCryptoKey& key,
  39. base::span<const uint8_t> signature,
  40. base::span<const uint8_t> data,
  41. bool* signature_match) const override {
  42. return RsaVerify(key, 0, signature, data, signature_match);
  43. }
  44. };
  45. } // namespace
  46. std::unique_ptr<AlgorithmImplementation> CreateRsaSsaImplementation() {
  47. return std::make_unique<RsaSsaImplementation>();
  48. }
  49. } // namespace webcrypto