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 CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_
6#define CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_
7
8#include <vector>
9
10#include <openssl/ossl_typ.h>
11
12#include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
13#include "third_party/WebKit/public/platform/WebCryptoKey.h"
14
15namespace content {
16
17namespace webcrypto {
18
19class CryptoData;
20class Status;
21
22// The values of these constants correspond with the "enc" parameter of
23// EVP_CipherInit_ex(), do not change.
24enum EncryptOrDecrypt { DECRYPT=0, ENCRYPT=1 };
25
26const EVP_MD* GetDigest(blink::WebCryptoAlgorithmId id);
27
28// Does either encryption or decryption for an AEAD algorithm.
29//   * |mode| controls whether encryption or decryption is done
30//   * |aead_alg| the algorithm (for instance AES-GCM)
31//   * |buffer| where the ciphertext or plaintext is written to.
32Status AeadEncryptDecrypt(EncryptOrDecrypt mode,
33                          const std::vector<uint8_t>& raw_key,
34                          const CryptoData& data,
35                          unsigned int tag_length_bytes,
36                          const CryptoData& iv,
37                          const CryptoData& additional_data,
38                          const EVP_AEAD* aead_alg,
39                          std::vector<uint8_t>* buffer);
40
41}  // namespace webcrypto
42
43}  // namespace content
44
45#endif  // CONTENT_CHILD_WEBCRYPTO_OPENSSL_UTIL_OPENSSL_H_
46