Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / openssl / rsa_pss_openssl.cc
blobe74698e3cb028bfa30c60ce87df0604c653e756a
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 "content/child/webcrypto/openssl/rsa_hashed_algorithm_openssl.h"
6 #include "content/child/webcrypto/openssl/rsa_sign_openssl.h"
7 #include "content/child/webcrypto/status.h"
8 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
10 namespace content {
12 namespace webcrypto {
14 namespace {
16 class RsaPssImplementation : public RsaHashedAlgorithm {
17 public:
18 RsaPssImplementation()
19 : RsaHashedAlgorithm(blink::WebCryptoKeyUsageVerify,
20 blink::WebCryptoKeyUsageSign) {}
22 const char* GetJwkAlgorithm(
23 const blink::WebCryptoAlgorithmId hash) const override {
24 switch (hash) {
25 case blink::WebCryptoAlgorithmIdSha1:
26 return "PS1";
27 case blink::WebCryptoAlgorithmIdSha256:
28 return "PS256";
29 case blink::WebCryptoAlgorithmIdSha384:
30 return "PS384";
31 case blink::WebCryptoAlgorithmIdSha512:
32 return "PS512";
33 default:
34 return NULL;
38 Status Sign(const blink::WebCryptoAlgorithm& algorithm,
39 const blink::WebCryptoKey& key,
40 const CryptoData& data,
41 std::vector<uint8_t>* buffer) const override {
42 return RsaSign(key, algorithm.rsaPssParams()->saltLengthBytes(), data,
43 buffer);
46 Status Verify(const blink::WebCryptoAlgorithm& algorithm,
47 const blink::WebCryptoKey& key,
48 const CryptoData& signature,
49 const CryptoData& data,
50 bool* signature_match) const override {
51 return RsaVerify(key, algorithm.rsaPssParams()->saltLengthBytes(),
52 signature, data, signature_match);
56 } // namespace
58 AlgorithmImplementation* CreatePlatformRsaPssImplementation() {
59 return new RsaPssImplementation;
62 } // namespace webcrypto
64 } // namespace content