cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / child / webcrypto / openssl / sym_key_openssl.cc
blob39238335a26677fa9e3cb96d1872f80508131d62
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/sym_key_openssl.h"
7 #include <vector>
8 #include <openssl/rand.h>
10 #include "content/child/webcrypto/crypto_data.h"
11 #include "content/child/webcrypto/generate_key_result.h"
12 #include "content/child/webcrypto/openssl/key_openssl.h"
13 #include "content/child/webcrypto/status.h"
14 #include "crypto/openssl_util.h"
15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
17 namespace content {
19 namespace webcrypto {
21 Status GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm& algorithm,
22 bool extractable,
23 blink::WebCryptoKeyUsageMask usages,
24 unsigned keylen_bytes,
25 GenerateKeyResult* result) {
26 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
28 std::vector<unsigned char> random_bytes(keylen_bytes, 0);
30 if (keylen_bytes > 0) {
31 if (!(RAND_bytes(&random_bytes[0], keylen_bytes)))
32 return Status::OperationError();
35 result->AssignSecretKey(
36 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes)),
37 blink::WebCryptoKeyTypeSecret,
38 extractable,
39 algorithm,
40 usages));
42 return Status::Success();
45 Status ImportKeyRawOpenSsl(const CryptoData& key_data,
46 const blink::WebCryptoKeyAlgorithm& algorithm,
47 bool extractable,
48 blink::WebCryptoKeyUsageMask usages,
49 blink::WebCryptoKey* key) {
50 *key = blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data),
51 blink::WebCryptoKeyTypeSecret,
52 extractable,
53 algorithm,
54 usages);
55 return Status::Success();
58 } // namespace webcrypto
60 } // namespace content