1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_NSSCipherStrategy_h
8 #define mozilla_dom_quota_NSSCipherStrategy_h
10 #include "CipherStrategy.h"
14 #include "mozilla/InitializedOnce.h"
15 #include "mozilla/Result.h"
16 #include "mozilla/Span.h"
17 #include "ErrorList.h"
20 #include "ScopedNSSTypes.h"
24 namespace mozilla::dom::quota
{
26 struct NSSCipherStrategy
{
27 // Use numeric literals here to avoid having to include NSS headers here.
28 // static_assert's in the cpp file check their consistency.
29 using KeyType
= std::array
<uint8_t, 32>;
30 static constexpr size_t BlockPrefixLength
= 32;
31 static constexpr size_t BasicBlockSize
= 16;
33 static Result
<KeyType
, nsresult
> GenerateKey();
35 nsresult
Init(CipherMode aCipherMode
, Span
<const uint8_t> aKey
,
36 Span
<const uint8_t> aInitialIv
= Span
<const uint8_t>{});
38 nsresult
Cipher(Span
<uint8_t> aIv
, Span
<const uint8_t> aIn
,
41 static std::array
<uint8_t, BlockPrefixLength
> MakeBlockPrefix();
43 static Span
<const uint8_t> SerializeKey(const KeyType
& aKey
);
45 static Maybe
<KeyType
> DeserializeKey(
46 const Span
<const uint8_t>& aSerializedKey
);
49 // XXX Remove EarlyDestructible, remove moving of the CipherStrategy.
50 LazyInitializedOnceEarlyDestructible
<const CipherMode
> mMode
;
51 LazyInitializedOnceEarlyDestructible
<const UniquePK11Context
> mPK11Context
;
52 nsTArray
<uint8_t> mIv
;
55 } // namespace mozilla::dom::quota