Beispiel #1
0
int main()
{
    printf("Hello World\n");
    _crypt_extended_init(); 
    #ifdef TESTERINO
    struct php_crypt_extended_data buffer; 
    memset(&buffer, 0, sizeof(buffer));
    salterino(pw1, salt1);
    salterino(pw2, salt2);
    salterino(pw3, salt3);
    char *hash1 = _crypt_extended_r(pw1, salt1, &buffer);
    shifterino(hash1);
    printf(hash1);
    printf("\n");
    memset(&buffer, 0, sizeof(buffer));
    char *hash2 = _crypt_extended_r(pw2, salt2, &buffer);
    shifterino(hash2);
    printf(hash2);
    printf("\n");
    memset(&buffer, 0, sizeof(buffer));
    char *hash3 = _crypt_extended_r(pw3, salt3, &buffer);
    shifterino(hash3);
    printf(hash2);
    printf("\n");
    generate_pw(&seed, pw4);
    printf(pw4);
    printf("\n");
    #endif

    #ifdef TESTERINO2
    search(pat, 0); 
    #endif 
    return 0; 
}
Beispiel #2
0
PHPAPI int php_crypt(const char *password, const int pass_len, const char *salt, int salt_len, char **result)
{
	char *crypt_res;
/* Windows (win32/crypt) has a stripped down version of libxcrypt and 
	a CryptoApi md5_crypt implementation */
#if PHP_USE_PHP_CRYPT_R
	{
		struct php_crypt_extended_data buffer;

		if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$') {
			char output[MD5_HASH_MAX_LEN], *out;

			out = php_md5_crypt_r(password, salt, output);
			if (out) {
				*result = estrdup(out);
				return SUCCESS;
			}
			return FAILURE;
		} else if (salt[0]=='$' && salt[1]=='6' && salt[2]=='$') {
			char *output;
			output = emalloc(PHP_MAX_SALT_LEN);

			crypt_res = php_sha512_crypt_r(password, salt, output, PHP_MAX_SALT_LEN);
			if (!crypt_res) {
				memset(output, 0, PHP_MAX_SALT_LEN);
				efree(output);
				return FAILURE;
			} else {
				*result = estrdup(output);
				memset(output, 0, PHP_MAX_SALT_LEN);
				efree(output);
				return SUCCESS;
			}
		} else if (salt[0]=='$' && salt[1]=='5' && salt[2]=='$') {
			char *output;
			output = emalloc(PHP_MAX_SALT_LEN);

			crypt_res = php_sha256_crypt_r(password, salt, output, PHP_MAX_SALT_LEN);
			if (!crypt_res) {
				memset(output, 0, PHP_MAX_SALT_LEN);
				efree(output);
				return FAILURE;
			} else {
				*result = estrdup(output);
				memset(output, 0, PHP_MAX_SALT_LEN);
				efree(output);
				return SUCCESS;
			}
		} else if (
				salt[0] == '$' &&
				salt[1] == '2' &&
				salt[2] >= 'a' && salt[2] <= 'z' &&
				salt[3] == '$' &&
				salt[4] >= '0' && salt[4] <= '3' &&
				salt[5] >= '0' && salt[5] <= '9' &&
				salt[6] == '$') {
			char output[PHP_MAX_SALT_LEN + 1];

			memset(output, 0, PHP_MAX_SALT_LEN + 1);

			crypt_res = php_crypt_blowfish_rn(password, salt, output, sizeof(output));
			if (!crypt_res) {
				memset(output, 0, PHP_MAX_SALT_LEN + 1);
				return FAILURE;
			} else {
				*result = estrdup(output);
				memset(output, 0, PHP_MAX_SALT_LEN + 1);
				return SUCCESS;
			}
		} else {
			memset(&buffer, 0, sizeof(buffer));
			_crypt_extended_init_r();

			crypt_res = _crypt_extended_r(password, salt, &buffer);
			if (!crypt_res) {
				return FAILURE;
			} else {
				*result = estrdup(crypt_res);
				return SUCCESS;
			}
		}
	}
#else

# if defined(HAVE_CRYPT_R) && (defined(_REENTRANT) || defined(_THREAD_SAFE))
	{
#  if defined(CRYPT_R_STRUCT_CRYPT_DATA)
		struct crypt_data buffer;
		memset(&buffer, 0, sizeof(buffer));
#  elif defined(CRYPT_R_CRYPTD)
		CRYPTD buffer;
#  else
#    error Data struct used by crypt_r() is unknown. Please report.
#  endif
		crypt_res = crypt_r(password, salt, &buffer);
		if (!crypt_res) {
			return FAILURE;
		} else {
			*result = estrdup(crypt_res);
			return SUCCESS;
		}
	}
# endif
#endif
}