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 
16 namespace OtaUpgrade
17 {
27 {
28 public:
29  EncryptedStream() = default;
30 
32  {
33  free(buffer);
34  }
35 
42  size_t write(const uint8_t* data, size_t size) override;
43 
44 private:
45  crypto_secretstream_xchacha20poly1305_state state;
46 
47  union {
48  uint8_t header[crypto_secretstream_xchacha20poly1305_HEADERBYTES];
50  };
51 
52  enum class Fragment {
53  Header,
54  ChunkSize,
55  Chunk,
56  None,
57  };
58  Fragment fragment = Fragment::Header;
59 
60  size_t remainingBytes = sizeof(header);
61  uint8_t* fragmentPtr = header;
62  uint8_t* buffer = nullptr;
63  size_t bufferSize = 0;
64 };
65 
66 } // namespace OtaUpgrade
uint8_t header[crypto_secretstream_xchacha20poly1305_HEADERBYTES]
Definition: EncryptedStream.h:48
Encryption wrapper for BasicStream.
Definition: EncryptedStream.h:26
Definition: BasicStream.h:22
A write-only stream to parse and apply firmware unencrypted upgrade files generated by otatool...
Definition: BasicStream.h:43
~EncryptedStream()
Definition: EncryptedStream.h:31
uint16_t chunkSizeMinusOne
Definition: EncryptedStream.h:49
size_t write(const uint8_t *data, size_t size) override
Process an arbitrarily sized chunk of an encrypted OTA upgrade file.