26 inline static uint32_t
rol(uint32_t value, uint32_t bits) {
return (value << bits) | (value >> (32 - bits)); }
33 return block.
l[i] = (
rol(block.
l[i], 24) & 0xFF00FF00) | (
rol(block.
l[i], 8) & 0x00FF00FF);
38 inline static uint32_t
blk(
CHAR64LONG16 &block, uint32_t i) {
return block.
l[i & 15] =
rol(block.
l[(i + 13) & 15] ^ block.
l[(i + 8) & 15] ^ block.
l[(i + 2) & 15] ^ block.
l[i & 15],1); }
41 inline static void R0(
CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += ((w & (x ^ y)) ^ y) +
blk0(block, i) + 0x5A827999 +
rol(v, 5); w =
rol(w, 30); }
42 inline static void R1(
CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += ((w & (x ^ y)) ^ y) +
blk(block, i) + 0x5A827999 +
rol(v, 5); w =
rol(w, 30); }
43 inline static void R2(
CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (w ^ x ^ y) +
blk(block, i) + 0x6ED9EBA1 +
rol(v, 5); w =
rol(w, 30); }
44 inline static void R3(
CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (((w | x) & y) | (w & x)) +
blk(block, i) + 0x8F1BBCDC +
rol(v, 5); w =
rol(w, 30); }
45 inline static void R4(
CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (w ^ x ^ y) +
blk(block, i) + 0xCA62C1D6 +
rol(v, 5); w =
rol(w, 30); }
49 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0
61 uint32_t a, b, c, d, e;
64 memcpy(block.
c, buf, 64);
74 R0(block, a, b, c, d, e, 0);
R0(block, e, a, b, c, d, 1);
R0(block, d, e, a, b, c, 2);
R0(block, c, d, e, a, b, 3);
75 R0(block, b, c, d, e, a, 4);
R0(block, a, b, c, d, e, 5);
R0(block, e, a, b, c, d, 6);
R0(block, d, e, a, b, c, 7);
76 R0(block, c, d, e, a, b, 8);
R0(block, b, c, d, e, a, 9);
R0(block, a, b, c, d, e, 10);
R0(block, e, a, b, c, d, 11);
77 R0(block, d, e, a, b, c, 12);
R0(block, c, d, e, a, b, 13);
R0(block, b, c, d, e, a, 14);
R0(block, a, b, c, d, e, 15);
78 R1(block, e, a, b, c, d, 16);
R1(block, d, e, a, b, c, 17);
R1(block, c, d, e, a, b, 18);
R1(block, b, c, d, e, a, 19);
79 R2(block, a, b, c, d, e, 20);
R2(block, e, a, b, c, d, 21);
R2(block, d, e, a, b, c, 22);
R2(block, c, d, e, a, b, 23);
80 R2(block, b, c, d, e, a, 24);
R2(block, a, b, c, d, e, 25);
R2(block, e, a, b, c, d, 26);
R2(block, d, e, a, b, c, 27);
81 R2(block, c, d, e, a, b, 28);
R2(block, b, c, d, e, a, 29);
R2(block, a, b, c, d, e, 30);
R2(block, e, a, b, c, d, 31);
82 R2(block, d, e, a, b, c, 32);
R2(block, c, d, e, a, b, 33);
R2(block, b, c, d, e, a, 34);
R2(block, a, b, c, d, e, 35);
83 R2(block, e, a, b, c, d, 36);
R2(block, d, e, a, b, c, 37);
R2(block, c, d, e, a, b, 38);
R2(block, b, c, d, e, a, 39);
84 R3(block, a, b, c, d, e, 40);
R3(block, e, a, b, c, d, 41);
R3(block, d, e, a, b, c, 42);
R3(block, c, d, e, a, b, 43);
85 R3(block, b, c, d, e, a, 44);
R3(block, a, b, c, d, e, 45);
R3(block, e, a, b, c, d, 46);
R3(block, d, e, a, b, c, 47);
86 R3(block, c, d, e, a, b, 48);
R3(block, b, c, d, e, a, 49);
R3(block, a, b, c, d, e, 50);
R3(block, e, a, b, c, d, 51);
87 R3(block, d, e, a, b, c, 52);
R3(block, c, d, e, a, b, 53);
R3(block, b, c, d, e, a, 54);
R3(block, a, b, c, d, e, 55);
88 R3(block, e, a, b, c, d, 56);
R3(block, d, e, a, b, c, 57);
R3(block, c, d, e, a, b, 58);
R3(block, b, c, d, e, a, 59);
89 R4(block, a, b, c, d, e, 60);
R4(block, e, a, b, c, d, 61);
R4(block, d, e, a, b, c, 62);
R4(block, c, d, e, a, b, 63);
90 R4(block, b, c, d, e, a, 64);
R4(block, a, b, c, d, e, 65);
R4(block, e, a, b, c, d, 66);
R4(block, d, e, a, b, c, 67);
91 R4(block, c, d, e, a, b, 68);
R4(block, b, c, d, e, a, 69);
R4(block, a, b, c, d, e, 70);
R4(block, e, a, b, c, d, 71);
92 R4(block, d, e, a, b, c, 72);
R4(block, c, d, e, a, b, 73);
R4(block, b, c, d, e, a, 74);
R4(block, a, b, c, d, e, 75);
93 R4(block, e, a, b, c, d, 76);
R4(block, d, e, a, b, c, 77);
R4(block, c, d, e, a, b, 78);
R4(block, b, c, d, e, a, 79);
101 a = b = c = d = e = 0;
111 for (
int i = 0; i < 5; ++i)
112 this->state[i] = iv->first[i];
115 for (
int i = 0; i < 5; ++i)
118 this->count[0] = this->count[1] = 0;
119 memset(this->buffer, 0,
sizeof(this->buffer));
120 memset(this->digest, 0,
sizeof(this->digest));
127 j = (this->count[0] >> 3) & 63;
128 if ((this->count[0] += len << 3) < (len << 3))
130 this->count[1] += len >> 29;
133 memcpy(&this->buffer[j], data, (i = 64 - j));
135 for (; i + 63 < len; i += 64)
141 memcpy(&this->buffer[j], &data[i], len - i);
147 unsigned char finalcount[8];
149 for (i = 0; i < 8; ++i)
150 finalcount[i] = static_cast<unsigned char>((this->count[i >= 4 ? 0 : 1] >> ((3 - (i & 3)) * 8)) & 255);
151 this->
Update(reinterpret_cast<const unsigned char *>(
"\200"), 1);
152 while ((this->count[0] & 504) != 448)
153 this->
Update(reinterpret_cast<const unsigned char *>(
"\0"), 1);
154 this->
Update(finalcount, 8);
155 for (i = 0; i < 20; ++i)
156 this->digest[i] = static_cast<unsigned char>((this->state[i>>2] >> ((3 - (i & 3)) * 8)) & 255);
159 memset(this->buffer, 0,
sizeof(this->buffer));
160 memset(this->state, 0,
sizeof(this->state));
161 memset(this->count, 0,
sizeof(this->count));
162 memset(&finalcount, 0,
sizeof(finalcount));
170 hash.first = this->
digest;
171 hash.second =
sizeof(this->
digest);
190 iv.second =
sizeof(
sha1_iv) /
sizeof(uint32_t);
210 context.
Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
217 Log(
LOG_DEBUG_2) <<
"(enc_sha1) hashed password from [" << src <<
"] to [" << buf <<
"]";
233 if (!hash_method.equals_cs(
"sha1"))
237 this->
OnEncrypt(req->GetPassword(), buf);
Serialize::Reference< NickCore > nc
static NickAlias * Find(const Anope::string &nick)
bool equals_cs(const char *_str) const
void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
static uint32_t blk0(CHAR64LONG16 &block, uint32_t i)
static void R3(CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i)
static uint32_t rol(uint32_t value, uint32_t bits)
ESHA1(const Anope::string &modname, const Anope::string &creator)
void Transform(const unsigned char buf[64])
static uint32_t blk(CHAR64LONG16 &block, uint32_t i)
SHA1Provider(Module *creator)
Encryption::Context * CreateContext(Encryption::IV *iv) anope_override
void Update(const unsigned char *data, size_t len) anope_override
SHA1Provider sha1provider
static const uint32_t sha1_iv[5]
CoreExport string Hex(const string &data)
static void R0(CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i)
std::pair< const unsigned char *, size_t > Hash
SHA1Context(Encryption::IV *iv=NULL)
static const size_type npos
Encryption::IV GetDefaultIV() anope_override
Encryption::Hash GetFinalizedHash() anope_override
std::pair< const uint32_t *, size_t > IV
static void R2(CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i)
static Module * FindFirstOf(ModType type)
static void R4(CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i)
void Finalize() anope_override
static void R1(CHAR64LONG16 &block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i)
CoreExport void Encrypt(const Anope::string &src, Anope::string &dest)
size_type find(const string &_str, size_type pos=0) const
Provider(Module *creator, const Anope::string &sname)