diff --git a/test/main.cxx b/test/main.cxx index 64bcccc..b37f691 100644 --- a/test/main.cxx +++ b/test/main.cxx @@ -8,19 +8,20 @@ int main() uint8_t ik[32]{}; hash(key.c_str(), ik); + int offset = 16; char* msg = new char[256]{}; memset(msg, 0, 256); - auto len = std::snprintf(msg + 12, 256, "%s", "hello world"); - std::cout << encrypt(ik, (uint8_t*)msg, len + 12) << std::endl; - std::cout << msg + 12 << std::endl; + auto len = std::snprintf(msg + offset, 256 - offset, "%s", "hello world"); + std::cout << encrypt(ik, (uint8_t*)msg, len + offset) << std::endl; + std::cout << msg + offset << std::endl; uint8_t ik2[32]{}; hash(key.c_str(), ik2); - std::cout << decrypt(ik2, (uint8_t*)msg, len + 12) << std::endl; + std::cout << decrypt(ik2, (uint8_t*)msg, len + offset) << std::endl; - std::cout << msg + 12 << std::endl; + std::cout << msg + offset << std::endl; return 0; } \ No newline at end of file diff --git a/util/util.cpp b/util/util.cpp index d3268cb..93ce139 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -8,7 +8,7 @@ #include CTransProtocal::CTransProtocal() = default; -constexpr uint8_t kz = 12; +constexpr uint8_t kz = 16; CTransProtocal::~CTransProtocal() = default; /* @@ -309,7 +309,7 @@ bool encrypt(const uint8_t* k, uint8_t* m, size_t len) } uint8_t nonce[kz]{}; - rdm(nonce, sizeof(nonce)); + rdm(nonce, sizeof(nonce) - 4); memcpy(m, nonce, kz); struct AES_ctx ctx;