Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / webcrypto / algorithms / rsa_pss.cc
blob14166bd9a13b21a5883cee276de51c7ad16b234b
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.
5 #include "components/webcrypto/algorithms/rsa.h"
6 #include "components/webcrypto/algorithms/rsa_sign.h"
7 #include "components/webcrypto/status.h"
8 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
10 namespace webcrypto {
12 namespace {
14 class RsaPssImplementation : public RsaHashedAlgorithm {
15 public:
16 RsaPssImplementation()
17 : RsaHashedAlgorithm(blink::WebCryptoKeyUsageVerify,
18 blink::WebCryptoKeyUsageSign) {}
20 const char* GetJwkAlgorithm(
21 const blink::WebCryptoAlgorithmId hash) const override {
22 switch (hash) {
23 case blink::WebCryptoAlgorithmIdSha1:
24 return "PS1";
25 case blink::WebCryptoAlgorithmIdSha256:
26 return "PS256";
27 case blink::WebCryptoAlgorithmIdSha384:
28 return "PS384";
29 case blink::WebCryptoAlgorithmIdSha512:
30 return "PS512";
31 default:
32 return NULL;
36 Status Sign(const blink::WebCryptoAlgorithm& algorithm,
37 const blink::WebCryptoKey& key,
38 const CryptoData& data,
39 std::vector<uint8_t>* buffer) const override {
40 return RsaSign(key, algorithm.rsaPssParams()->saltLengthBytes(), data,
41 buffer);
44 Status Verify(const blink::WebCryptoAlgorithm& algorithm,
45 const blink::WebCryptoKey& key,
46 const CryptoData& signature,
47 const CryptoData& data,
48 bool* signature_match) const override {
49 return RsaVerify(key, algorithm.rsaPssParams()->saltLengthBytes(),
50 signature, data, signature_match);
54 } // namespace
56 scoped_ptr<AlgorithmImplementation> CreateRsaPssImplementation() {
57 return make_scoped_ptr(new RsaPssImplementation);
60 } // namespace webcrypto