diff --git a/YSI_Extra/y_bcrypt/y_bcrypt_entry.inc b/YSI_Extra/y_bcrypt/y_bcrypt_entry.inc index 9ed1a133..8d0da518 100644 --- a/YSI_Extra/y_bcrypt/y_bcrypt_entry.inc +++ b/YSI_Extra/y_bcrypt/y_bcrypt_entry.inc @@ -134,6 +134,7 @@ public _YSI_BCryptHashDone(hashid, arg2, arg3) // V1. new prop[16]; + // Secret internal hash ID. _YSI_gLastHash = arg2, format(prop, sizeof (prop), YSI_gscProp1, hashid), extra = GetSVarInt(prop), @@ -207,59 +208,53 @@ stock bool:BCrypt_Check(extra, const callback[], const password[], const hash[]) } } -stock _BCrypt_Hash(extra, ptr, const password[], cost) +stock BCrypt_Hash(extra, const callback[], const password[], cost = 12) { ++_YSI_gHashID; - switch (BCrypt_GetPlugin()) - { - case BCRYPT_PLUGIN_VERSION_LASSIR: - { - return _YSI_BCryptHashA(password, cost, YSI_gscBCryptHashDone, YSI_gcIII, _YSI_gHashID, ptr, extra) ? _YSI_gHashID : 0; - } - case BCRYPT_PLUGIN_VERSION_SREYAS_1: + new ptr; + if (AMX_GetPublicPointer(0, ptr, callback, true)) { - if (_YSI_BCryptHashB(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost)) + switch (BCrypt_GetPlugin()) { - new - prop[16]; - format(prop, sizeof (prop), YSI_gscProp1, _YSI_gHashID), - SetSVarInt(prop, extra), - format(prop, sizeof (prop), YSI_gscProp2, _YSI_gHashID), - SetSVarInt(prop, ptr); - return _YSI_gHashID; + case BCRYPT_PLUGIN_VERSION_LASSIR: + { + return _YSI_BCryptHashA(password, cost, YSI_gscBCryptHashDone, YSI_gcIII, _YSI_gHashID, ptr, extra) ? _YSI_gHashID : 0; } - } - case BCRYPT_PLUGIN_VERSION_SREYAS_2: - { - if (_YSI_BCryptHashE(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost, YSI_gcII, ptr, extra)) + case BCRYPT_PLUGIN_VERSION_SREYAS_1: { - new - prop[16]; - format(prop, sizeof (prop), YSI_gscProp1, _YSI_gHashID), - SetSVarInt(prop, extra), - format(prop, sizeof (prop), YSI_gscProp2, _YSI_gHashID), - SetSVarInt(prop, ptr); - return _YSI_gHashID; + if (_YSI_BCryptHashB(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost)) + { + new + prop[16]; + format(prop, sizeof (prop), YSI_gscProp1, _YSI_gHashID), + SetSVarInt(prop, extra), + format(prop, sizeof (prop), YSI_gscProp2, _YSI_gHashID), + SetSVarInt(prop, ptr); + return _YSI_gHashID; + } + } + case BCRYPT_PLUGIN_VERSION_SREYAS_2: + { + if (_YSI_BCryptHashE(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost, YSI_gcII, ptr, extra)) + { + new + prop[16]; + format(prop, sizeof (prop), YSI_gscProp1, _YSI_gHashID), + SetSVarInt(prop, extra), + format(prop, sizeof (prop), YSI_gscProp2, _YSI_gHashID), + SetSVarInt(prop, ptr); + return _YSI_gHashID; + } + } + case BCRYPT_PLUGIN_VERSION_SREYAS_3, BCRYPT_PLUGIN_VERSION_SREYAS_4: + { + // May have extra data. + return _YSI_BCryptHashE(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost, YSI_gcII, ptr, extra) ? _YSI_gHashID : 0; + } + default: + { + } } - } - case BCRYPT_PLUGIN_VERSION_SREYAS_3, BCRYPT_PLUGIN_VERSION_SREYAS_4: - { - // May have extra data. - return _YSI_BCryptHashE(_YSI_gHashID, YSI_gscBCryptHashDone, password, cost, YSI_gcII, ptr, extra) ? _YSI_gHashID : 0; - } - default: - { - } - } - return 0; -} - -stock BCrypt_Hash(extra, const callback[], const password[], cost = 12) -{ - new ptr; - if (AMX_GetPublicPointer(0, ptr, callback, true)) - { - return _BCrypt_Hash(extra, ptr, password, cost); } return 0; } diff --git a/YSI_Extra/y_inline_bcrypt/y_inline_bcrypt_entry.inc b/YSI_Extra/y_inline_bcrypt/y_inline_bcrypt_entry.inc index a1ac278d..d6363502 100644 --- a/YSI_Extra/y_inline_bcrypt/y_inline_bcrypt_entry.inc +++ b/YSI_Extra/y_inline_bcrypt/y_inline_bcrypt_entry.inc @@ -78,12 +78,14 @@ Optional plugins: #include "..\..\YSI_Core\y_utils" #include "..\..\YSI_Server\y_thirdpartyinclude\y3_indirection" -#include "..\y_bcrypt\y_bcrypt_entry" +#include "..\y_bcrypt\y_bcrypt_natives" static stock const - YSI_gsc_Inline_BCryptCheckDone[] = "_Inline_BCryptCheckDone"; + YSI_gsc_Inline_BCryptCheckDone[] = "_Inline_BCryptCheckDone", + YSI_gsc_Inline_BCryptHashDone[] = "_Inline_BCryptHashDone"; forward _Inline_BCryptCheckDone(Func:cb, success); +forward _Inline_BCryptHashDone(Func:cb, arg2); public _Inline_BCryptCheckDone(Func:cb, success) { @@ -91,17 +93,28 @@ public _Inline_BCryptCheckDone(Func:cb, success) { success = _YSI_BCryptIsEqualA(); } - success = @.cb(success); + @.cb(success); Indirect_Release(cb); - return success; } -static stock _Inline_BCryptHashDone(Func:cb, hashid) +public _Inline_BCryptHashDone(Func:cb, arg2) { - new hash[61]; - // If the plugin is anything other than `1` or `2` this can't be called - // so there's no need for extra checks. - BCrypt_GetHash(hash); + new + hash[61], + hashid = Indirect_GetMeta(cb); + if (numargs() == 2) + { + // Secret internal hash ID. + _YSI_BCryptGetHashB(arg2, hash, sizeof (hash)); + } + else if (BCrypt_GetPlugin() == BCRYPT_PLUGIN_VERSION_LASSIR) + { + _YSI_BCryptGetHashA(hash); + } + else + { + _YSI_BCryptGetHashE(hash, sizeof (hash)); + } if (Indirect_GetTag(cb) == _:tagof (F@_@si:)) { Indirect_Call(_:cb, tagof (F@_@si:), hash, hashid); @@ -111,11 +124,8 @@ static stock _Inline_BCryptHashDone(Func:cb, hashid) Indirect_Call(_:cb, tagof (F@_@s:), hash); } Indirect_Release(cb); - return hashid; } -#define CALL@_Inline_BCryptHashDone%8() _Inline_BCryptHashDone%8(Func:0, 0) - stock bool:BCrypt_CheckInline(const password[], const hash[], Func:cb) { switch (BCrypt_GetPlugin()) @@ -132,13 +142,23 @@ stock bool:BCrypt_CheckInline(const password[], const hash[], Func:cb) stock BCrypt_HashInline(const password[], cost = 12, {F@_@s, F@_@si}:cb, tag = tagof (cb)) { - cost = _BCrypt_Hash(_:cb, _:__addressof(_Inline_BCryptHashDone), password, cost); - if (cost) + ++_YSI_gHashID; + Indirect_SetTag(cb, tag); + Indirect_SetMeta(cb, _YSI_gHashID); + switch (BCrypt_GetPlugin()) { - Indirect_SetTag(cb, tag); - Indirect_Claim(cb); + case BCRYPT_PLUGIN_VERSION_LASSIR: + { + return _YSI_BCryptHashA(password, cost, YSI_gsc_Inline_BCryptHashDone, YSI_gcI, _:cb) ? _YSI_gHashID : 0; + } + case BCRYPT_PLUGIN_VERSION_SREYAS_1, BCRYPT_PLUGIN_VERSION_SREYAS_2, BCRYPT_PLUGIN_VERSION_SREYAS_3, BCRYPT_PLUGIN_VERSION_SREYAS_4: + { + return _YSI_BCryptHashB(_:cb, YSI_gsc_Inline_BCryptHashDone, password, cost) ? _YSI_gHashID : 0; + } + default: + { + return 0; + } } - // Return the hashid. - return cost; }