mirror of
https://github.com/kamilsss655/uv-k5-firmware-custom
synced 2024-11-22 19:18:56 +00:00
256bit key generation function
This commit is contained in:
parent
5b02ce3e90
commit
21bea186e6
@ -22,9 +22,11 @@
|
||||
// salt used for hashing encryption key from eeprom used for sending packets
|
||||
// we never actually use the key stored in eeprom directly
|
||||
// actually salt should be [16] + key [16] and then we hash it and get encryption key [32]
|
||||
static const uint8_t encryptionSalt[32] = {
|
||||
0xEF, 0x58, 0x0A, 0xC6, 0x12, 0x4A, 0xFA, 0x4F, 0xAE, 0x6F, 0x9D, 0x3C, 0xBB, 0x80, 0xAC, 0x4A,
|
||||
0xF3, 0x5E, 0x11, 0x69, 0xC7, 0x97, 0xFB, 0xC6, 0x27, 0x4F, 0xB7, 0x1A, 0xA7, 0xE5, 0x77, 0x9C
|
||||
static const uint8_t encryptionSalt[4][8] = {
|
||||
{0xEF, 0x58, 0x0A, 0xC6, 0x12, 0x4A, 0xFA, 0x4F},
|
||||
{0xAE, 0x6F, 0x9D, 0x3C, 0xBB, 0x80, 0xAC, 0x4A},
|
||||
{0xF3, 0x5E, 0x11, 0x69, 0xC7, 0x97, 0xFB, 0xC6},
|
||||
{0x27, 0x4F, 0xB7, 0x1A, 0xA7, 0xE5, 0x77, 0x9C}
|
||||
};
|
||||
|
||||
// salt used to display encryption key hash in menu
|
||||
@ -82,9 +84,9 @@ void CRYPTO_Random(void *output, int len)
|
||||
// input can be upto 255 bytes
|
||||
void CRYPTO_HashSalted(const void *input, void *output, const void *salt, int input_len, int salt_len)
|
||||
{
|
||||
// FNV offset basis
|
||||
union eight_bytes hash;
|
||||
|
||||
|
||||
// FNV offset basis
|
||||
hash.u64 = 0xcbf29ce484222325;
|
||||
// FNV prime
|
||||
const uint64_t fnvPrime = 0x100000001b3;
|
||||
@ -111,18 +113,20 @@ void CRYPTO_HashSalted(const void *input, void *output, const void *salt, int in
|
||||
// it is not used for an actual encryption
|
||||
void CRYPTO_DisplayHash(void *input, void *output, int input_len)
|
||||
{
|
||||
(void)encryptionSalt;
|
||||
// char stringHash[10];
|
||||
CRYPTO_HashSalted(input, output, displaySalt, input_len, sizeof(displaySalt));
|
||||
|
||||
// convert uint8_t to ASCII chars
|
||||
for(int i=0; i<8; i++){
|
||||
((uint8_t *)output)[i]=(((uint8_t *)output)[i] % 91) + 32;
|
||||
}
|
||||
}
|
||||
// so to generate the 256bit key we need 4 hash operations
|
||||
// void CRYPTO_EncryptionKeyHash(void *input, void *output, int input_len)
|
||||
// {
|
||||
|
||||
// }
|
||||
// generate 32 bytes (256 bits) key by combining 4 x 8 byte hash of the same
|
||||
// 10 byte (80 bits) encryption key (each hash with different salt)
|
||||
void CRYPTO_Generate256BitKey(void *input, void *output, int input_len)
|
||||
{
|
||||
for(int i=0; i<4; i++){
|
||||
CRYPTO_HashSalted(input, output+(i*8), encryptionSalt[i], input_len, sizeof(encryptionSalt[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t encryptionSalt[32];
|
||||
static const uint8_t encryptionSalt[4][8];
|
||||
static const uint8_t displaySalt[32];
|
||||
|
||||
union eight_bytes {
|
||||
@ -29,5 +29,5 @@ void CRYPTO_Crypt(void *input, int input_len, void *output, void *nonce, const v
|
||||
void CRYPTO_Random(void *output, int len);
|
||||
uint8_t CRYPTO_RandomByte();
|
||||
void CRYPTO_DisplayHash(void *input, void *output, int input_len);
|
||||
// void CRYPTO_EncryptionKeyHash(void *input, void *output, int input_len);
|
||||
void CRYPTO_Generate256BitKey(void *input, void *output, int input_len);
|
||||
void CRYPTO_HashSalted(const void *input, void *output, const void *salt, int input_len, int salt_len);
|
Loading…
Reference in New Issue
Block a user