Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/renderer/webcrypto/webcrypto_util.h

Issue 25906002: [webcrypto] Add JWK import for HMAC and AES-CBC key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bugfix in top level WebCryptoImpl::importKey Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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
5 #ifndef CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_
6 #define CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include "base/basictypes.h"
12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
14
15 namespace content {
16
17 namespace webcrypto {
18
19 // Returns a pointer to the start of |data|, or NULL if it is empty. This is a
20 // convenience function for getting the pointer, and should not be used beyond
21 // the expected lifetime of |data|.
22 const uint8* Uint8VectorStart(const std::vector<uint8>& data);
23
24 // Shrinks a WebArrayBuffer to a new size.
25 // TODO(eroman): This works by re-allocating a new buffer. It would be better if
26 // the WebArrayBuffer could just be truncated instead.
27 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size);
28
29 // This function decodes unpadded 'base64url' encoded data, as described in
30 // RFC4648 (http://www.ietf.org/rfc/rfc4648.txt) Section 5. To do this, first
31 // change the incoming data to 'base64' encoding by applying the appropriate
32 // transformation including adding padding if required, and then call a base64
33 // decoder.
34 // In Web Crypto, this type of encoding is only used inside JWK.
35 bool Base64DecodeUrlSafe(const std::string& input, std::string* output);
36
37 // Returns the "hash" param for an algorithm if it exists, otherwise returns
38 // a null algorithm.
39 blink::WebCryptoAlgorithm GetInnerHashAlgorithm(
40 const blink::WebCryptoAlgorithm& algorithm);
41
42 // Creates a WebCryptoAlgorithm without any parameters.
43 blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id);
44
45 // Creates an HMAC algorithm whose inner hash algorithm is determined by the
46 // specified hash output length. It is an error to call this method with an
47 // unsupported hash output length.
48 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashOutputLen(
49 unsigned short hash_output_length_bits);
50
51 // Creates an HMAC algorithm whose inner hash algorithm is determined by the
52 // specified algorithm ID. It is an error to call this method with a hash
53 // algorithm that is not SHA*.
54 blink::WebCryptoAlgorithm CreateHmacAlgorithmByHashId(
55 blink::WebCryptoAlgorithmId hash_id);
56
57 // Creates an HMAC algorithm whose parameters struct is compatible with key
58 // generation. It is an error to call this with a hash_id that is not a SHA*.
59 // The key_length_bytes parameter is optional, with zero meaning unspecified.
60 blink::WebCryptoAlgorithm CreateHmacKeyGenAlgorithm(
61 blink::WebCryptoAlgorithmId hash_id,
62 unsigned key_length_bytes);
63
64 // Creates an RSASSA-PKCS1-v1_5 algorithm. It is an error to call this with a
65 // hash_id that is not a SHA*.
66 blink::WebCryptoAlgorithm CreateRsaSsaAlgorithm(
67 blink::WebCryptoAlgorithmId hash_id);
68
69 // Creates an RSA-OAEP algorithm. It is an error to call this with a hash_id
70 // that is not a SHA*.
71 blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm(
72 blink::WebCryptoAlgorithmId hash_id);
73
74 // Creates an RSA algorithm with ID algorithm_id, whose parameters struct is
75 // compatible with key generation.
76 blink::WebCryptoAlgorithm CreateRsaKeyGenAlgorithm(
77 blink::WebCryptoAlgorithmId algorithm_id,
78 unsigned modulus_length,
79 const std::vector<uint8>& public_exponent);
80
81 // Creates an AES-CBC algorithm.
82 blink::WebCryptoAlgorithm CreateAesCbcAlgorithm(const std::vector<uint8>& iv);
83
84 // Creates and AES-GCM algorithm.
85 blink::WebCryptoAlgorithm CreateAesGcmAlgorithm(
86 const std::vector<uint8>& iv,
87 const std::vector<uint8>& additional_data,
88 uint8 tag_length_bytes);
89
90 // Creates an AES-CBC algorithm whose parameters struct is compatible with key
91 // generation.
92 blink::WebCryptoAlgorithm CreateAesCbcKeyGenAlgorithm(
93 unsigned short key_length_bits);
94
95 // Creates an AES-GCM algorithm whose parameters struct is compatible with key
96 // generation.
97 blink::WebCryptoAlgorithm CreateAesGcmKeyGenAlgorithm(
98 unsigned short key_length_bits);
99
100 } // namespace webcrypto
101
102 } // namespace content
103
104 #endif // CONTENT_RENDERER_WEBCRYPTO_WEBCRYPTO_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698