alpine 3.9
crypto weakness #15


Weakness Breakdown


This weakness involves creating non-standard or non-tested algorithms, using weak algorithms or applying cryptographic algorithms incorrectly. Algorithms that were once considered safe are commonly later found to be unsafe, as the algorithms were broken.

Warning code(s):

The crypt functions use a poor one-way hashing algorithm; since they only accept passwords of 8 characters or fewer and only a two-byte salt, they are excessively vulnerable to dictionary attacks given today's faster computing equipment.

File Name:



The highlighted line of code below is the trigger point of this particular Alpine 3.9 crypto weakness.

 static char * _hash_shmd5(char const * password, char const * salt)
	const char prefix[] = "$ 1$ ";
	const char characters[] = "!\"%&'()*+,-./ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	char * ret;
	char * p = NULL;
	size_t len;
	char * s;

	if(salt == NULL)
		if((p = _makepasswd_password(characters, 8, 8)) == NULL)
			return NULL;
		salt = p;
	len = sizeof(prefix) + strlen(salt);
	if((s = malloc(len)) == NULL)
		_error("malloc", 1);
		return NULL;
	snprintf(s, len, "%s%s", prefix, salt);
	ret = crypt(password, s);
	if(ret == NULL)
		_error("crypt", 1);
	else if((ret = strdup(ret)) == NULL)
		_error("malloc", 1);
	return ret;

/* makepasswd_password */
static char * _makepasswd_password(char const * characters, size_t min,
		size_t max)
	char * ret;
	size_t len = min;
	size_t clen;
	size_t i;

	if(characters == NULL)
		return NULL;
	if((clen = strlen(characters)) == 0)
		errno = EINVAL;
		_error("password", 1); 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.