Compare commits

...

5 Commits

Author SHA1 Message Date
Yaniv Kaul
ff18b1ca00 Apply suggested fix to utils/crypt_sha512.cc from Copilot Autofix
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2025-12-15 10:39:46 +02:00
Yaniv Kaul
55a9de8a45 Apply suggested fix to utils/crypt_sha512.cc from Copilot Autofix
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2025-12-15 10:39:45 +02:00
Yaniv Kaul
b98d2fd85e Apply suggested fix to utils/crypt_sha512.cc from Copilot Autofix
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2025-12-15 10:39:45 +02:00
Yaniv Kaul
882cb4a620 Apply suggested fix to utils/crypt_sha512.cc from Copilot Autofix
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2025-12-15 10:39:45 +02:00
Yaniv Kaul
9c2aa70aed Apply suggested fix to utils/crypt_sha512.cc from Copilot Autofix
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2025-12-15 10:39:44 +02:00

View File

@@ -31,7 +31,10 @@ struct sha512 {
uint8_t buf[128]; /* message block buffer */
};
static uint64_t ror(uint64_t n, int k) { return (n >> k) | (n << (64-k)); }
static uint64_t ror(uint64_t n, int k) {
int s = k & 63;
return (n >> s) | (n << ((64 - s) & 63));
}
#define Ch(x,y,z) (z ^ (x & (y ^ z)))
#define Maj(x,y,z) ((x & y) | (z & (x | y)))
#define S0(x) (ror(x,28) ^ ror(x,34) ^ ror(x,39))
@@ -224,7 +227,9 @@ static seastar::future<char *> sha512crypt(const char *key, const char *setting,
char *p;
/* reject large keys */
for (i = 0; i <= KEY_MAX && key[i]; i++);
for (i = 0; i <= KEY_MAX && key[i]; i++) {
/* iterate to find key length */
}
if (i > KEY_MAX)
co_return nullptr;
klen = i;
@@ -327,7 +332,6 @@ static seastar::future<char *> sha512crypt(const char *key, const char *setting,
/* output is $6$rounds=n$salt$hash */
p = output;
p += sprintf(p, "$6$%s%.*s$", rounds, slen, salt);
#if 1
static const unsigned char perm[][3] = {
{0,21,42},{22,43,1},{44,2,23},{3,24,45},{25,46,4},
{47,5,26},{6,27,48},{28,49,7},{50,8,29},{9,30,51},
@@ -336,35 +340,12 @@ static seastar::future<char *> sha512crypt(const char *key, const char *setting,
{62,20,41} };
for (i=0; i<21; i++) p = to64(p,
(md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4);
#else
p = to64(p, (md[0]<<16)|(md[21]<<8)|md[42], 4);
p = to64(p, (md[22]<<16)|(md[43]<<8)|md[1], 4);
p = to64(p, (md[44]<<16)|(md[2]<<8)|md[23], 4);
p = to64(p, (md[3]<<16)|(md[24]<<8)|md[45], 4);
p = to64(p, (md[25]<<16)|(md[46]<<8)|md[4], 4);
p = to64(p, (md[47]<<16)|(md[5]<<8)|md[26], 4);
p = to64(p, (md[6]<<16)|(md[27]<<8)|md[48], 4);
p = to64(p, (md[28]<<16)|(md[49]<<8)|md[7], 4);
p = to64(p, (md[50]<<16)|(md[8]<<8)|md[29], 4);
p = to64(p, (md[9]<<16)|(md[30]<<8)|md[51], 4);
p = to64(p, (md[31]<<16)|(md[52]<<8)|md[10], 4);
p = to64(p, (md[53]<<16)|(md[11]<<8)|md[32], 4);
p = to64(p, (md[12]<<16)|(md[33]<<8)|md[54], 4);
p = to64(p, (md[34]<<16)|(md[55]<<8)|md[13], 4);
p = to64(p, (md[56]<<16)|(md[14]<<8)|md[35], 4);
p = to64(p, (md[15]<<16)|(md[36]<<8)|md[57], 4);
p = to64(p, (md[37]<<16)|(md[58]<<8)|md[16], 4);
p = to64(p, (md[59]<<16)|(md[17]<<8)|md[38], 4);
p = to64(p, (md[18]<<16)|(md[39]<<8)|md[60], 4);
p = to64(p, (md[40]<<16)|(md[61]<<8)|md[19], 4);
p = to64(p, (md[62]<<16)|(md[20]<<8)|md[41], 4);
#endif
p = to64(p, md[63], 2);
*p = 0;
co_return output;
}
seastar::future<const char *> __crypt_sha512(const char *key, const char *setting, char *output)
seastar::future<const char *> crypt_sha512(const char *key, const char *setting, char *output)
{
static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !";
static const char testsetting[] = "$6$rounds=1234$abc0123456789$";
@@ -375,7 +356,7 @@ seastar::future<const char *> __crypt_sha512(const char *key, const char *settin
p = co_await sha512crypt(key, setting, output);
/* self test and stack cleanup */
q = co_await sha512crypt(testkey, testsetting, testbuf);
if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash))
if (!p || q != testbuf || memcmp(testbuf, testhash, strlen(testhash)))
co_return "*";
co_return p;
}