mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-23 13:57:16 +01:00
Fix typo "Chipher" -> "Cipher"
This commit is contained in:
parent
9597917183
commit
59e081f41e
|
@ -45,7 +45,7 @@ void ECBCryptoAESNI::ExpandKey (const AESKey& key)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ECBEncryptionAESNI::Encrypt (const ChipherBlock * in, ChipherBlock * out)
|
void ECBEncryptionAESNI::Encrypt (const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
|
@ -57,7 +57,7 @@ void ECBEncryptionAESNI::Encrypt (const ChipherBlock * in, ChipherBlock * out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ECBDecryptionAESNI::Decrypt (const ChipherBlock * in, ChipherBlock * out)
|
void ECBDecryptionAESNI::Decrypt (const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
|
@ -94,7 +94,7 @@ void ECBDecryptionAESNI::SetKey (const AESKey& key)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
|
void CBCEncryption::Encrypt (int numBlocks, const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
#ifdef AESNI
|
#ifdef AESNI
|
||||||
__asm__
|
__asm__
|
||||||
|
@ -131,7 +131,7 @@ void CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out)
|
||||||
// len/16
|
// len/16
|
||||||
int numBlocks = len >> 4;
|
int numBlocks = len >> 4;
|
||||||
if (numBlocks > 0)
|
if (numBlocks > 0)
|
||||||
Encrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
|
Encrypt (numBlocks, (const CipherBlock *)in, (CipherBlock *)out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
|
void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
|
||||||
|
@ -151,11 +151,11 @@ void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out)
|
||||||
: "%xmm0", "%xmm1", "memory"
|
: "%xmm0", "%xmm1", "memory"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
Encrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
|
Encrypt (1, (const CipherBlock *)in, (CipherBlock *)out);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out)
|
void CBCDecryption::Decrypt (int numBlocks, const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
#ifdef AESNI
|
#ifdef AESNI
|
||||||
__asm__
|
__asm__
|
||||||
|
@ -181,7 +181,7 @@ void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBloc
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < numBlocks; i++)
|
for (int i = 0; i < numBlocks; i++)
|
||||||
{
|
{
|
||||||
ChipherBlock tmp = in[i];
|
CipherBlock tmp = in[i];
|
||||||
m_ECBDecryption.Decrypt (in + i, out + i);
|
m_ECBDecryption.Decrypt (in + i, out + i);
|
||||||
out[i] ^= m_IV;
|
out[i] ^= m_IV;
|
||||||
m_IV = tmp;
|
m_IV = tmp;
|
||||||
|
@ -193,7 +193,7 @@ void CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out)
|
||||||
{
|
{
|
||||||
int numBlocks = len >> 4;
|
int numBlocks = len >> 4;
|
||||||
if (numBlocks > 0)
|
if (numBlocks > 0)
|
||||||
Decrypt (numBlocks, (const ChipherBlock *)in, (ChipherBlock *)out);
|
Decrypt (numBlocks, (const CipherBlock *)in, (CipherBlock *)out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
|
void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
|
||||||
|
@ -213,7 +213,7 @@ void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out)
|
||||||
: "%xmm0", "%xmm1", "memory"
|
: "%xmm0", "%xmm1", "memory"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
Decrypt (1, (const ChipherBlock *)in, (ChipherBlock *)out);
|
Decrypt (1, (const CipherBlock *)in, (CipherBlock *)out);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
crypto/aes.h
20
crypto/aes.h
|
@ -10,11 +10,11 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace crypto
|
namespace crypto
|
||||||
{
|
{
|
||||||
struct ChipherBlock
|
struct CipherBlock
|
||||||
{
|
{
|
||||||
uint8_t buf[16];
|
uint8_t buf[16];
|
||||||
|
|
||||||
void operator^=(const ChipherBlock& other) // XOR
|
void operator^=(const CipherBlock& other) // XOR
|
||||||
{
|
{
|
||||||
#if defined(__x86_64__) // for Intel x64
|
#if defined(__x86_64__) // for Intel x64
|
||||||
__asm__
|
__asm__
|
||||||
|
@ -81,7 +81,7 @@ namespace crypto
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void SetKey (const AESKey& key) { ExpandKey (key); };
|
void SetKey (const AESKey& key) { ExpandKey (key); };
|
||||||
void Encrypt (const ChipherBlock * in, ChipherBlock * out);
|
void Encrypt (const CipherBlock * in, CipherBlock * out);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ECBDecryptionAESNI: public ECBCryptoAESNI
|
class ECBDecryptionAESNI: public ECBCryptoAESNI
|
||||||
|
@ -89,7 +89,7 @@ namespace crypto
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void SetKey (const AESKey& key);
|
void SetKey (const AESKey& key);
|
||||||
void Decrypt (const ChipherBlock * in, ChipherBlock * out);
|
void Decrypt (const CipherBlock * in, CipherBlock * out);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ECBEncryptionAESNI ECBEncryption;
|
typedef ECBEncryptionAESNI ECBEncryption;
|
||||||
|
@ -105,7 +105,7 @@ namespace crypto
|
||||||
{
|
{
|
||||||
m_Encryption.SetKey (key, 32);
|
m_Encryption.SetKey (key, 32);
|
||||||
}
|
}
|
||||||
void Encrypt (const ChipherBlock * in, ChipherBlock * out)
|
void Encrypt (const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
m_Encryption.ProcessData (out->buf, in->buf, 16);
|
m_Encryption.ProcessData (out->buf, in->buf, 16);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ namespace crypto
|
||||||
{
|
{
|
||||||
m_Decryption.SetKey (key, 32);
|
m_Decryption.SetKey (key, 32);
|
||||||
}
|
}
|
||||||
void Decrypt (const ChipherBlock * in, ChipherBlock * out)
|
void Decrypt (const CipherBlock * in, CipherBlock * out)
|
||||||
{
|
{
|
||||||
m_Decryption.ProcessData (out->buf, in->buf, 16);
|
m_Decryption.ProcessData (out->buf, in->buf, 16);
|
||||||
}
|
}
|
||||||
|
@ -151,13 +151,13 @@ namespace crypto
|
||||||
void SetKey (const AESKey& key) { m_ECBEncryption.SetKey (key); }; // 32 bytes
|
void SetKey (const AESKey& key) { m_ECBEncryption.SetKey (key); }; // 32 bytes
|
||||||
void SetIV (const uint8_t * iv) { memcpy (m_LastBlock.buf, iv, 16); }; // 16 bytes
|
void SetIV (const uint8_t * iv) { memcpy (m_LastBlock.buf, iv, 16); }; // 16 bytes
|
||||||
|
|
||||||
void Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out);
|
void Encrypt (int numBlocks, const CipherBlock * in, CipherBlock * out);
|
||||||
void Encrypt (const uint8_t * in, std::size_t len, uint8_t * out);
|
void Encrypt (const uint8_t * in, std::size_t len, uint8_t * out);
|
||||||
void Encrypt (const uint8_t * in, uint8_t * out); // one block
|
void Encrypt (const uint8_t * in, uint8_t * out); // one block
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ChipherBlock m_LastBlock;
|
CipherBlock m_LastBlock;
|
||||||
|
|
||||||
ECBEncryption m_ECBEncryption;
|
ECBEncryption m_ECBEncryption;
|
||||||
};
|
};
|
||||||
|
@ -171,13 +171,13 @@ namespace crypto
|
||||||
void SetKey (const AESKey& key) { m_ECBDecryption.SetKey (key); }; // 32 bytes
|
void SetKey (const AESKey& key) { m_ECBDecryption.SetKey (key); }; // 32 bytes
|
||||||
void SetIV (const uint8_t * iv) { memcpy (m_IV.buf, iv, 16); }; // 16 bytes
|
void SetIV (const uint8_t * iv) { memcpy (m_IV.buf, iv, 16); }; // 16 bytes
|
||||||
|
|
||||||
void Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out);
|
void Decrypt (int numBlocks, const CipherBlock * in, CipherBlock * out);
|
||||||
void Decrypt (const uint8_t * in, std::size_t len, uint8_t * out);
|
void Decrypt (const uint8_t * in, std::size_t len, uint8_t * out);
|
||||||
void Decrypt (const uint8_t * in, uint8_t * out); // one block
|
void Decrypt (const uint8_t * in, uint8_t * out); // one block
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ChipherBlock m_IV;
|
CipherBlock m_IV;
|
||||||
ECBDecryption m_ECBDecryption;
|
ECBDecryption m_ECBDecryption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue