EncryptedStream.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2017 by Slavey Karadzhov
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * EncryptedOtaUpgradeStream.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "BasicStream.h"
14 #include <sodium/crypto_secretstream_xchacha20poly1305.h>
15 #include <memory>
16 
17 namespace OtaUpgrade
18 {
28 {
29 public:
30  EncryptedStream() = default;
31 
38  size_t write(const uint8_t* data, size_t size) override;
39 
40 private:
41  crypto_secretstream_xchacha20poly1305_state state;
42 
43  union {
44  uint8_t header[crypto_secretstream_xchacha20poly1305_HEADERBYTES];
46  };
47 
48  enum class Fragment {
49  Header,
50  ChunkSize,
51  Chunk,
52  None,
53  };
54 
55  Fragment fragment{Fragment::Header};
56  size_t remainingBytes{sizeof header};
57  uint8_t* fragmentPtr{header};
58  std::unique_ptr<uint8_t[]> buffer;
59  size_t bufferSize{0};
60 };
61 
62 } // namespace OtaUpgrade
uint8_t header[crypto_secretstream_xchacha20poly1305_HEADERBYTES]
Definition: EncryptedStream.h:44
Encryption wrapper for BasicStream.
Definition: EncryptedStream.h:27
Definition: BasicStream.h:23
A write-only stream to parse and apply firmware unencrypted upgrade files generated by otatool...
Definition: BasicStream.h:44
uint16_t chunkSizeMinusOne
Definition: EncryptedStream.h:45
size_t write(const uint8_t *data, size_t size) override
Process an arbitrarily sized chunk of an encrypted OTA upgrade file.