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"
8 #include <openssl/rand.h>
10 #include "content/child/webcrypto/crypto_data.h"
11 #include "content/child/webcrypto/openssl/key_openssl.h"
12 #include "content/child/webcrypto/status.h"
13 #include "crypto/openssl_util.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
20 Status
GenerateSecretKeyOpenSsl(const blink::WebCryptoKeyAlgorithm
& algorithm
,
22 blink::WebCryptoKeyUsageMask usage_mask
,
23 unsigned keylen_bytes
,
24 blink::WebCryptoKey
* key
) {
25 crypto::OpenSSLErrStackTracer
err_tracer(FROM_HERE
);
27 std::vector
<unsigned char> random_bytes(keylen_bytes
, 0);
29 if (keylen_bytes
> 0) {
30 if (!(RAND_bytes(&random_bytes
[0], keylen_bytes
)))
31 return Status::OperationError();
35 blink::WebCryptoKey::create(new SymKeyOpenSsl(CryptoData(random_bytes
)),
36 blink::WebCryptoKeyTypeSecret
,
40 return Status::Success();
43 Status
ImportKeyRawOpenSsl(const CryptoData
& key_data
,
44 const blink::WebCryptoKeyAlgorithm
& algorithm
,
46 blink::WebCryptoKeyUsageMask usage_mask
,
47 blink::WebCryptoKey
* key
) {
48 *key
= blink::WebCryptoKey::create(new SymKeyOpenSsl(key_data
),
49 blink::WebCryptoKeyTypeSecret
,
53 return Status::Success();
56 } // namespace webcrypto
58 } // namespace content