Update debug print
This commit is contained in:
parent
45dbdf1fc7
commit
9cd10865da
|
@ -26,7 +26,7 @@ randctx rCtx = {0};
|
|||
|
||||
int encrypt(packet *packet, unsigned char *outBuf, UINT16 *len, unsigned char *key)
|
||||
{
|
||||
randinit();
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
if (sizeof(UINT16) + sizeof(UINT16) + packet->Size > *len)
|
||||
{
|
||||
return 1;
|
||||
|
@ -48,9 +48,10 @@ int encrypt(packet *packet, unsigned char *outBuf, UINT16 *len, unsigned char *k
|
|||
|
||||
// n = nonce, CRYPTO_NPUBBYTES size 16
|
||||
unsigned char npub[CRYPTO_NPUBBYTES];
|
||||
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
fill_random(npub, CRYPTO_NPUBBYTES);
|
||||
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
int ret = romulus_m_encrypt(c, &clen, m, mlen, ad, adlen, 0, &npub[0], key);
|
||||
|
||||
if (clen > *len + CRYPTO_NPUBBYTES || ret != 0)
|
||||
|
@ -66,6 +67,7 @@ int encrypt(packet *packet, unsigned char *outBuf, UINT16 *len, unsigned char *k
|
|||
memcpy(&outBuf[loc], &packet->DataType, sizeof(UINT16));
|
||||
loc += sizeof(UINT16);
|
||||
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
// data size 2 3
|
||||
UINT16 clen16 = (UINT16)clen;
|
||||
// we copy data and nonce
|
||||
|
@ -82,6 +84,7 @@ int encrypt(packet *packet, unsigned char *outBuf, UINT16 *len, unsigned char *k
|
|||
|
||||
*len = loc;
|
||||
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
free(c);
|
||||
|
||||
return 0;
|
||||
|
@ -94,7 +97,7 @@ int decrypt(packetEx *packet, unsigned char *inBuf, UINT16 len, unsigned char *k
|
|||
{
|
||||
return 1;
|
||||
}
|
||||
DEBUG_PRINT("line %d\n", 95);
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
memcpy(&packet->DataType, &inBuf[loc], sizeof(UINT16));
|
||||
loc += sizeof(UINT16);
|
||||
memcpy(&packet->Id, &inBuf[loc], sizeof(UINT32));
|
||||
|
@ -110,7 +113,7 @@ int decrypt(packetEx *packet, unsigned char *inBuf, UINT16 len, unsigned char *k
|
|||
{
|
||||
return 1;
|
||||
}
|
||||
DEBUG_PRINT("line %d\n", 111);
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
|
||||
// Data
|
||||
// Nonce|Data
|
||||
|
@ -122,7 +125,7 @@ int decrypt(packetEx *packet, unsigned char *inBuf, UINT16 len, unsigned char *k
|
|||
// ciphertext - in, MAX 16 bytes larger than plaintext - defined as CRYPTO_ABYTES
|
||||
int clen = len - loc;
|
||||
unsigned char *c = &inBuf[loc];
|
||||
DEBUG_PRINT("line %d len:%d loc:%d\n", 132, len, loc);
|
||||
DEBUG_PRINT("line %d len:%d loc:%d\n", __LINE__, len, loc);
|
||||
|
||||
// plaintext - out
|
||||
unsigned long long mlen = clen;
|
||||
|
@ -132,22 +135,26 @@ int decrypt(packetEx *packet, unsigned char *inBuf, UINT16 len, unsigned char *k
|
|||
int adlen = sizeof(packet->DataType);
|
||||
unsigned char *ad = (unsigned char *)&packet->DataType;
|
||||
|
||||
DEBUG_PRINT("line %d mlen:%d clen:%d\n", 132, mlen, clen);
|
||||
DEBUG_PRINT("line %d mlen:%d clen:%d\n", __LINE__, mlen, clen);
|
||||
int ret = romulus_m_decrypt(m, &mlen, 0, c, clen, ad, adlen, npub, key);
|
||||
DEBUG_PRINT("line %d packet:%d, mlen %d\n", 134, packet->Size, mlen);
|
||||
DEBUG_PRINT("line %d packet:%d, mlen %d\n", __LINE__, packet->Size, mlen);
|
||||
if (ret == 0)
|
||||
{
|
||||
DEBUG_PRINT("line %d\n", 138);
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
memcpy(packet->Data, m, mlen);
|
||||
packet->Size = (UINT16)mlen;
|
||||
}
|
||||
|
||||
free(m);
|
||||
DEBUG_PRINT("line %d\n", 143);
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_random(unsigned char* buffer, int length){
|
||||
DEBUG_PRINT("line %d\n", __LINE__);
|
||||
if(rCtx.randcnt == 0){
|
||||
randinit(&rCtx, RANDSIZL);
|
||||
}
|
||||
UINT32 secRandom;
|
||||
for (size_t i = 0; i < length; i += sizeof(UINT32))
|
||||
{
|
||||
|
|
|
@ -29,7 +29,6 @@ void pad (const unsigned char* m, unsigned char* mp, int l, int len8) {
|
|||
mp[i] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// G(S): generates the key stream from the internal state by multiplying the state S by the constant matrix G
|
||||
|
|
Loading…
Reference in New Issue