mirror of https://github.com/AxioDL/nod.git
fixed decrypting loop
This commit is contained in:
parent
b461f63ae4
commit
84ca6a62e3
|
@ -11,8 +11,8 @@ namespace NOD
|
|||
class IAES
|
||||
{
|
||||
public:
|
||||
virtual void encrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
|
||||
virtual void decrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
|
||||
virtual void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
|
||||
virtual void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
|
||||
virtual void setKey(const uint8_t* key)=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -290,9 +290,10 @@ public:
|
|||
size_t block = m_offset / 0x7c00;
|
||||
size_t cacheOffset = m_offset % 0x7c00;
|
||||
uint64_t cacheSize;
|
||||
uint64_t rem = length;
|
||||
uint8_t* dst = (uint8_t*)buf;
|
||||
|
||||
while (length)
|
||||
while (rem)
|
||||
{
|
||||
if (block != m_curBlock)
|
||||
{
|
||||
|
@ -300,13 +301,13 @@ public:
|
|||
m_curBlock = block;
|
||||
}
|
||||
|
||||
cacheSize = length;
|
||||
cacheSize = rem;
|
||||
if (cacheSize + cacheOffset > 0x7c00)
|
||||
cacheSize = 0x7c00 - cacheOffset;
|
||||
|
||||
memcpy(dst, m_decBuf + cacheOffset, cacheSize);
|
||||
dst += cacheSize;
|
||||
length -= cacheSize;
|
||||
rem -= cacheSize;
|
||||
cacheOffset = 0;
|
||||
++block;
|
||||
}
|
||||
|
|
20
lib/aes.cpp
20
lib/aes.cpp
|
@ -76,8 +76,8 @@ protected:
|
|||
void _decrypt(uint8_t* buff);
|
||||
|
||||
public:
|
||||
void encrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len);
|
||||
void decrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len);
|
||||
void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len);
|
||||
void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len);
|
||||
void setKey(const uint8_t* key);
|
||||
};
|
||||
|
||||
|
@ -400,10 +400,10 @@ void SoftwareAES::setKey(const uint8_t* key)
|
|||
}
|
||||
|
||||
// CBC mode decryption
|
||||
void SoftwareAES::decrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len)
|
||||
void SoftwareAES::decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len)
|
||||
{
|
||||
uint8_t block[16];
|
||||
uint8_t* ctext_ptr;
|
||||
const uint8_t* ctext_ptr;
|
||||
unsigned int blockno = 0, i;
|
||||
|
||||
//fprintf( stderr,"aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len );
|
||||
|
@ -440,9 +440,11 @@ void SoftwareAES::decrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, si
|
|||
}
|
||||
|
||||
// CBC mode encryption
|
||||
void SoftwareAES::encrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
void SoftwareAES::encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
{
|
||||
uint8_t block[16];
|
||||
uint8_t feedback[16];
|
||||
memcpy(feedback, iv, 16);
|
||||
unsigned int blockno = 0, i;
|
||||
|
||||
//printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
|
||||
|
@ -466,10 +468,10 @@ void SoftwareAES::encrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, ui
|
|||
memcpy(block, inbuf + blockno * sizeof(block), fraction);
|
||||
|
||||
for (i = 0; i < fraction; i++)
|
||||
block[i] = inbuf[blockno * sizeof(block) + i] ^ iv[i];
|
||||
block[i] = inbuf[blockno * sizeof(block) + i] ^ feedback[i];
|
||||
|
||||
_encrypt(block);
|
||||
memcpy(iv, block, sizeof(block));
|
||||
memcpy(feedback, block, sizeof(block));
|
||||
memcpy(outbuf + blockno * sizeof(block), block, sizeof(block));
|
||||
// debug_printf("Block %d output: ", blockno);
|
||||
// hexdump(outbuf + blockno*sizeof(block), 16);
|
||||
|
@ -485,7 +487,7 @@ class NiAES : public IAES
|
|||
__m128i m_ekey[11];
|
||||
__m128i m_dkey[11];
|
||||
public:
|
||||
void encrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
{
|
||||
__m128i feedback,data;
|
||||
uint64_t i,j;
|
||||
|
@ -505,7 +507,7 @@ public:
|
|||
_mm_storeu_si128(&((__m128i*)outbuf)[i], feedback);
|
||||
}
|
||||
}
|
||||
void decrypt(uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)
|
||||
{
|
||||
__m128i data,feedback,last_in;
|
||||
uint64_t i,j;
|
||||
|
|
Loading…
Reference in New Issue