"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stress-crypt.c" between
stress-ng-0.13.04.tar.xz and stress-ng-0.13.05.tar.xz

About: stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.

stress-crypt.c  (stress-ng-0.13.04.tar.xz):stress-crypt.c  (stress-ng-0.13.05.tar.xz)
skipping to change at line 36 skipping to change at line 36
static const stress_help_t help[] = { static const stress_help_t help[] = {
{ NULL, "crypt N", "start N workers performing password encryption" }, { NULL, "crypt N", "start N workers performing password encryption" },
{ NULL, "crypt-ops N", "stop after N bogo crypt operations" }, { NULL, "crypt-ops N", "stop after N bogo crypt operations" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };
#if defined(HAVE_LIB_CRYPT) && \ #if defined(HAVE_LIB_CRYPT) && \
defined(HAVE_CRYPT_H) defined(HAVE_CRYPT_H)
typedef struct {
const char id;
const char *method;
} crypt_method_t;
static const crypt_method_t crypt_methods[] = {
{ '1', "MD5" },
{ '5', "SHA-256" },
{ '6', "SHA-512" },
{ '7', "scrypt" },
{ '3', "NT" },
{ 'y', "yescrypt" },
};
/* /*
* stress_crypt_id() * stress_crypt_id()
* crypt a password with given seed and id * crypt a password with given seed and id
*/ */
static int stress_crypt_id( static int stress_crypt_id(
const stress_args_t *args, const stress_args_t *args,
const char id, const char id,
const char *method, const char *method,
const char *passwd, const char *passwd,
char *salt) char *salt)
{ {
salt[1] = id; salt[1] = id;
char *encrypted; char *encrypted;
#if defined (HAVE_CRYPT_R) #if defined (HAVE_CRYPT_R)
static struct crypt_data data; static struct crypt_data data;
(void)memset(&data, 0, sizeof(data)); (void)memset(&data, 0, sizeof(data));
errno = 0;
encrypted = crypt_r(passwd, salt, &data); encrypted = crypt_r(passwd, salt, &data);
#else #else
encrypted = crypt(passwd, salt); encrypted = crypt(passwd, salt);
#endif #endif
if (!encrypted) { if (!encrypted) {
pr_fail("%s: cannot encrypt with %s\n", args->name, method); switch (errno) {
return -1; case 0:
break;
case EINVAL:
break;
#if defined(ENOSYS)
case ENOSYS:
break;
#endif
#if defined(EOPNOTSUPP)
case EOPNOTSUPP:
#endif
break;
default:
pr_fail("%s: cannot encrypt with %s, errno=%d (%s)\n",
args->name, method, errno, strerror(errno));
return -1;
}
} }
return 0; return 0;
} }
/* /*
* stress_crypt() * stress_crypt()
* stress libc crypt * stress libc crypt
*/ */
static int stress_crypt(const stress_args_t *args) static int stress_crypt(const stress_args_t *args)
{ {
stress_set_proc_state(args->name, STRESS_STATE_RUN); stress_set_proc_state(args->name, STRESS_STATE_RUN);
do { do {
static const char seedchars[] = static const char seedchars[] =
"./0123456789ABCDEFGHIJKLMNOPQRST" "./0123456789ABCDEFGHIJKLMNOPQRST"
"UVWXYZabcdefghijklmnopqrstuvwxyz"; "UVWXYZabcdefghijklmnopqrstuvwxyz";
char passwd[16]; char passwd[16];
char salt[] = "$x$........"; char salt[] = "$x$........";
uint64_t seed[2]; uint64_t seed[2];
size_t i; size_t i, failed = 0;
seed[0] = stress_mwc64(); seed[0] = stress_mwc64();
seed[1] = stress_mwc64(); seed[1] = stress_mwc64();
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
salt[i + 3] = seedchars[(seed[i / 5] >> (i % 5) * 6) & 0x 3f]; salt[i + 3] = seedchars[(seed[i / 5] >> (i % 5) * 6) & 0x 3f];
for (i = 0; i < sizeof(passwd) - 1; i++) for (i = 0; i < sizeof(passwd) - 1; i++)
passwd[i] = seedchars[stress_mwc32() % sizeof(seedchars)] ; passwd[i] = seedchars[stress_mwc32() % sizeof(seedchars)] ;
passwd[i] = '\0'; passwd[i] = '\0';
if (stress_crypt_id(args, '1', "MD5", passwd, salt) < 0) for (i = 0; i < SIZEOF_ARRAY(crypt_methods); i++) {
break; int ret;
#if NEED_GLIBC(2,7,0)
if (stress_crypt_id(args, '5', "SHA-256", passwd, salt) < 0) ret = stress_crypt_id(args,
break; crypt_methods[i].id,
if (stress_crypt_id(args, '6', "SHA-512", passwd, salt) < 0) crypt_methods[i].method,
passwd, salt);
if (ret < 0)
failed++;
}
if (failed)
break; break;
#endif
inc_counter(args); inc_counter(args);
} while (keep_stressing(args)); } while (keep_stressing(args));
stress_set_proc_state(args->name, STRESS_STATE_DEINIT); stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
stressor_info_t stress_crypt_info = { stressor_info_t stress_crypt_info = {
.stressor = stress_crypt, .stressor = stress_crypt,
 End of changes. 6 change blocks. 
10 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)