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

Side by Side Diff: components/webcrypto/algorithms/secret_key_util.h

Issue 1355873002: [refactor] More post-NSS WebCrypto cleanups (utility functions). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address David's comments Created 5 years, 3 months 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 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
5 #ifndef COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_
6 #define COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_
7
8 #include <string>
9 #include <vector>
10
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
12 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
13
14 // This file contains functions shared by multiple symmetric key algorithms.
15
16 namespace webcrypto {
17
18 class CryptoData;
19 class GenerateKeyResult;
20 class JwkReader;
21 class Status;
22
23 // Generates a random secret key of the given bit length. If the bit length is
24 // not a multiple of 8, then the resulting key will have ceil(keylen_bits / 8)
25 // bytes, and the "unused" bits will be set to zero. This function does not do
26 // any validation checks on the provided parameters.
27 Status GenerateWebCryptoSecretKey(const blink::WebCryptoKeyAlgorithm& algorithm,
28 bool extractable,
29 blink::WebCryptoKeyUsageMask usages,
30 unsigned int keylen_bits,
31 GenerateKeyResult* result);
32
33 // Creates a WebCrypto secret key given a the raw data. The provided |key_data|
34 // will be copied into the new key. This function does not do any validation
35 // checks for the provided parameters.
36 Status CreateWebCryptoSecretKey(const CryptoData& key_data,
37 const blink::WebCryptoKeyAlgorithm& algorithm,
38 bool extractable,
39 blink::WebCryptoKeyUsageMask usages,
40 blink::WebCryptoKey* key);
41
42 // Writes a JWK-formatted symmetric key to |jwk_key_data|.
43 // * raw_key_data: The actual key data
44 // * algorithm: The JWK algorithm name (i.e. "alg")
45 // * extractable: The JWK extractability (i.e. "ext")
46 // * usages: The JWK usages (i.e. "key_ops")
47 void WriteSecretKeyJwk(const CryptoData& raw_key_data,
48 const std::string& algorithm,
49 bool extractable,
50 blink::WebCryptoKeyUsageMask usages,
51 std::vector<uint8_t>* jwk_key_data);
52
53 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to
54 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error.
55 // In order for this to succeed:
56 // * expected_extractable must be consistent with the JWK's "ext", if
57 // present.
58 // * expected_usages must be a subset of the JWK's "key_ops" if present.
59 Status ReadSecretKeyNoExpectedAlgJwk(
60 const CryptoData& key_data,
61 bool expected_extractable,
62 blink::WebCryptoKeyUsageMask expected_usages,
63 std::vector<uint8_t>* raw_key_data,
64 JwkReader* jwk);
65
66 } // namespace webcrypto
67
68 #endif // COMPONENTS_WEBCRYPTO_ALGORITHMS_SECRET_KEY_UTIL_
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/pbkdf2.cc ('k') | components/webcrypto/algorithms/secret_key_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698