Wi-Fi improvements (#77)
Refactoring, new features and stability improvements.
This commit is contained in:
committed by
GitHub
parent
8086cd5d82
commit
8b6463d060
@@ -9,3 +9,16 @@ uint32_t tt_hash_string_djb2(const char* str) {
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t tt_hash_bytes_djb2(const void* data, size_t length) {
|
||||
uint32_t hash = 5381;
|
||||
uint8_t* data_bytes = (uint8_t*)data;
|
||||
uint8_t c = *data_bytes++;
|
||||
size_t index = 0;
|
||||
while (index < length) {
|
||||
hash = ((hash << 5) + hash) + (uint32_t)c; // hash * 33 + c
|
||||
c = *data_bytes++;
|
||||
index++;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -7,13 +8,19 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is quicker than the m-string.h hashing, as the latter
|
||||
* operates on raw memory blocks and thus a strlen() call is required first.
|
||||
* Implementation of DJB2 hashing algorithm.
|
||||
* @param[in] str the string to calculate the hash for
|
||||
* @return the hash
|
||||
*/
|
||||
uint32_t tt_hash_string_djb2(const char* str);
|
||||
|
||||
/**
|
||||
* Implementation of DJB2 hashing algorithm.
|
||||
* @param[in] data the bytes to calculate the hash for
|
||||
* @return the hash
|
||||
*/
|
||||
uint32_t tt_hash_bytes_djb2(const void* data, size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -120,17 +120,19 @@ static void get_key(uint8_t key[32]) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void tt_secure_get_iv_from_string(const char* input, uint8_t iv[16]) {
|
||||
void tt_secure_get_iv_from_data(const void* data, size_t data_length, uint8_t iv[16]) {
|
||||
memset((void*)iv, 0, 16);
|
||||
char c = *input++;
|
||||
int index = 0;
|
||||
while (c) {
|
||||
iv[index] = c;
|
||||
index++;
|
||||
c = *input++;
|
||||
uint8_t* data_bytes = (uint8_t*)data;
|
||||
for (int i = 0; i < data_length; ++i) {
|
||||
size_t safe_index = i % 16;
|
||||
iv[safe_index] %= data_bytes[i];
|
||||
}
|
||||
}
|
||||
|
||||
void tt_secure_get_iv_from_string(const char* input, uint8_t iv[16]) {
|
||||
tt_secure_get_iv_from_data((const void*)input, strlen(input), iv);
|
||||
}
|
||||
|
||||
static int tt_aes256_crypt_cbc(
|
||||
const uint8_t key[32],
|
||||
int mode,
|
||||
|
||||
@@ -26,7 +26,15 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Fills the IV with zeros and then copies up to 16 characters of the string into the IV.
|
||||
* @brief Fills the IV with zeros and then creates an IV based on the input data.
|
||||
* @param data input data
|
||||
* @param data_length input data length
|
||||
* @param iv output IV
|
||||
*/
|
||||
void tt_secure_get_iv_from_data(const void* data, size_t data_length, uint8_t iv[16]);
|
||||
|
||||
/**
|
||||
* @brief Fills the IV with zeros and then creates an IV based on the input data.
|
||||
* @param input input text
|
||||
* @param iv output IV
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user