WIP update

Implemented X25519.
This commit is contained in:
attermann 2023-10-07 15:03:21 -06:00
parent 1b919a9489
commit 4b062aa485
22 changed files with 490 additions and 165 deletions

View file

@ -39,27 +39,6 @@ int8_t Bytes::compare(const Bytes &bytes) const {
}
}
char const hex_upper_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char const hex_lower_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
std::string Bytes::toHex(bool upper /*= true*/) const {
if (!_data) {
return "";
}
std::string hex;
for (uint8_t byte : *_data) {
if (upper) {
hex += hex_upper_chars[ (byte & 0xF0) >> 4];
hex += hex_upper_chars[ (byte & 0x0F) >> 0];
}
else {
hex += hex_lower_chars[ (byte & 0xF0) >> 4];
hex += hex_lower_chars[ (byte & 0x0F) >> 0];
}
}
return hex;
}
void Bytes::assignHex(const char* hex) {
// if assignment is empty then clear data and don't bother creating new
if (hex == nullptr || hex[0] == 0) {
@ -86,3 +65,34 @@ void Bytes::appendHex(const char* hex) {
_data->push_back(byte);
}
}
char const hex_upper_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char const hex_lower_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
std::string Bytes::toHex(bool upper /*= true*/) const {
if (!_data) {
return "";
}
std::string hex;
for (uint8_t byte : *_data) {
if (upper) {
hex += hex_upper_chars[ (byte & 0xF0) >> 4];
hex += hex_upper_chars[ (byte & 0x0F) >> 0];
}
else {
hex += hex_lower_chars[ (byte & 0xF0) >> 4];
hex += hex_lower_chars[ (byte & 0x0F) >> 0];
}
}
return hex;
}
Bytes Bytes::mid(size_t pos, size_t len) const {
if (!_data || pos >= size()) {
return NONE;
}
if ((pos + len) >= size()) {
len = (size() - pos);
}
return {data() + pos, len};
}