[GH-ISSUE #919] OpenCL. -test=format-details (and other -list=format-*) VERY slow #522

Closed
opened 2026-10-14 03:11:46 +07:00 by bsakaguchi · 22 comments
Owner

Originally created by @jfoug on GitHub (Dec 20, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/919

Running things like

../run/john -list=format-tests
../run/john -list=format-details
../run/john -list=format-all-details
../run/john -list=format-methods (this one 'may' need init called??)

is very slow, once it hits opencl. where it should be almost instant, since it is only dumping static data available at compile time.

Originally created by @jfoug on GitHub (Dec 20, 2014). Original GitHub issue: https://github.com/openwall/john/issues/919 Running things like ../run/john -list=format-tests ../run/john -list=format-details ../run/john -list=format-all-details ../run/john -list=format-methods (this one 'may' need init called??) is very slow, once it hits opencl. where it should be almost instant, since it is only dumping static data available at compile time.
bsakaguchi 2026-10-14 03:11:46 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@frank-dittrich commented on GitHub (Dec 20, 2014):

For --list=format-methods, fmt_init() is only called if (format->params.flags & FMT_DYNAMIC).
And no OpenCL format sets this (alt least doesn't refer to FMT_DYNAMIC).

If even --list=format-methods is slow (it is in listconf_parse_early()), then something in john_init() in john.c called prior to listconf_parse_early() must be the culprit.

<!-- gh-comment-id:67739259 --> @frank-dittrich commented on GitHub (Dec 20, 2014): For --list=format-methods, fmt_init() is only called `if (format->params.flags & FMT_DYNAMIC)`. And no OpenCL format sets this (alt least doesn't refer to FMT_DYNAMIC). If even --list=format-methods is slow (it is in listconf_parse_early()), then something in john_init() in john.c called prior to listconf_parse_early() must be the culprit.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

The root problem is we need to call format's init() but the OpenCL formats will auto-tune then. Maybe I should try moving the auto-tune to format's reset() or some other function. Until then we could have LWS=GWS=1 or something like that.

<!-- gh-comment-id:67741116 --> @magnumripper commented on GitHub (Dec 20, 2014): The root problem is we need to call format's init() but the OpenCL formats will auto-tune then. Maybe I should try moving the auto-tune to format's reset() or some other function. Until then we could have LWS=GWS=1 or something like that.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Hm, worse than the auto-tune is we actually compile the OpenCL kernel in init(). That can take a long time if not cached already.

<!-- gh-comment-id:67742002 --> @magnumripper commented on GitHub (Dec 20, 2014): Hm, worse than the auto-tune is we actually compile the OpenCL kernel in init(). That can take a long time if not cached already.
Author
Owner

@jfoug commented on GitHub (Dec 20, 2014):

I do imagine this happened recently (since no one has complained), and likely it is due to the auto tune code being added.

Why do we need to call init() for -list=format-tests ? or format-details ? I can see so for the methods, since some formats change their methods in init. But what changes in the others?

Well for format-details, I can see this 'possibly' needing init()
Min. keys per crypt 7
Max. keys per crypt 49

But even those i think are bogus (the above was shown for zip), so init() gets us nothing.

I certainly can not see why init() would need to be called for -list=format-tests Isn't that just a dumb dump of the tests[] array ? That is static data, if I am not mistaken (except for dyna-thin)

<!-- gh-comment-id:67742030 --> @jfoug commented on GitHub (Dec 20, 2014): I do imagine this happened recently (since no one has complained), and likely it is due to the auto tune code being added. Why do we need to call init() for -list=format-tests ? or format-details ? I can see so for the methods, since some formats change their methods in init. But what changes in the others? Well for format-details, I can see this 'possibly' needing init() Min. keys per crypt 7 Max. keys per crypt 49 But even those i think are bogus (the above was shown for zip), so init() gets us nothing. I certainly can not see why init() would need to be called for -list=format-tests Isn't that just a dumb dump of the tests[] array ? That is static data, if I am not mistaken (except for dyna-thin)
Author
Owner

@jfoug commented on GitHub (Dec 20, 2014):

The reason this has become an issue is due to https://github.com/magnumripper/jtrTestSuite/issues/24 where I need to grab the tests[]. If the GPU stuff will be this slow, then I simply will do this for CPU only, unless forced to by a command line switch.

<!-- gh-comment-id:67742147 --> @jfoug commented on GitHub (Dec 20, 2014): The reason this has become an issue is due to https://github.com/magnumripper/jtrTestSuite/issues/24 where I need to grab the tests[]. If the GPU stuff will be this slow, then I simply will do this for CPU only, unless forced to by a command line switch.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

I was completely wrong about the auto-tune being the culprit. We do not auto-tune - because we do set LWS/GWS before init. The reason for the delay is we build all OpenCL kernels. If you run it again it should be much faster because they are (should be) cached.

The min/max keys per crypt will never show right unless we do a full auto-tune. But I think the specific reason we added the init() is many formats will show the wrong max password length (for --enc=utf8) without it. The NT format is one example (the CPU one, at least).

<!-- gh-comment-id:67742496 --> @magnumripper commented on GitHub (Dec 20, 2014): I was completely wrong about the auto-tune being the culprit. We do not auto-tune - because we do set LWS/GWS before init. The reason for the delay is we build _all_ OpenCL kernels. If you run it again it should be much faster because they are (should be) cached. The min/max keys per crypt will never show right unless we do a full auto-tune. But I think the specific reason we added the init() is many formats will show the wrong max password length (for --enc=utf8) without it. The NT format is one example (the CPU one, at least).
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

I think the only way to fix this canonically would be to add something like pre_init() as a format method. Anything else will be hacks. Maybe we should drop the format init for --list and live with the sometimes incorrect plaintext lengths?

<!-- gh-comment-id:67742568 --> @magnumripper commented on GitHub (Dec 20, 2014): I think the only way to fix this canonically would be to add something like pre_init() as a format method. Anything else will be hacks. Maybe we should drop the format init for --list and live with the sometimes incorrect plaintext lengths?
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Oh, one other thing that may happen in init() is we actually replace some test vectors with UTF-8 or CP ones. That is important for --list=format-tests

<!-- gh-comment-id:67742724 --> @magnumripper commented on GitHub (Dec 20, 2014): Oh, one other thing that may happen in init() is we actually replace some test vectors with UTF-8 or CP ones. That is important for --list=format-tests
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Hey hey hey, what if we only call init if we have an encoding set!? If we haven't, there's no need to call it even for CPU formats.

<!-- gh-comment-id:67742849 --> @magnumripper commented on GitHub (Dec 20, 2014): Hey hey hey, what if we only call init if we have an encoding set!? If we haven't, there's no need to call it even for CPU formats.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

That would be

        if (pers_opts.target_enc != ASCII)
                fmt_init(format);

unless I'm mistaken

<!-- gh-comment-id:67742912 --> @magnumripper commented on GitHub (Dec 20, 2014): That would be ``` C if (pers_opts.target_enc != ASCII) fmt_init(format); ``` unless I'm mistaken
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Hopefully fixed now.

<!-- gh-comment-id:67743143 --> @magnumripper commented on GitHub (Dec 20, 2014): Hopefully fixed now.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Now it will only be slow when actually testing with UTF-8 or some other encoding active. Please note though that the total test time for magnumripper/jtrTestSuite#24 will be the same no matter how we do this - at some point we need to compile the kernel. If it's done during --list it will be cached during the test.

<!-- gh-comment-id:67743249 --> @magnumripper commented on GitHub (Dec 20, 2014): Now it will only be slow when actually testing with UTF-8 or some other encoding active. Please note though that the total test time for magnumripper/jtrTestSuite#24 will be the same no matter how we do this - at some point we need to compile the kernel. If it's done during --list it will be cached during the test.
Author
Owner

@jfoug commented on GitHub (Dec 20, 2014):

Fixed for what I see.

Yes, I know the total time is the same. It is just perception. If it takes 5 minutes before any test starts, that sux (especially for me, where I get a crashed driver and everthing is dead). But if things start working right away, and then the openCL pause 10s or so before each test, that is 'expected', and it spreads the pain out well, lol.

<!-- gh-comment-id:67743512 --> @jfoug commented on GitHub (Dec 20, 2014): Fixed for what I see. Yes, I know the total time is the same. It is just perception. If it takes 5 minutes before any test starts, that sux (especially for me, where I get a crashed driver and everthing is dead). But if things start working right away, and then the openCL pause 10s or so before each test, that is 'expected', and it spreads the pain out well, lol.
Author
Owner

@jfoug commented on GitHub (Dec 20, 2014):

Thanks for the quick fix. It is much better now.

<!-- gh-comment-id:67743526 --> @jfoug commented on GitHub (Dec 20, 2014): Thanks for the quick fix. It is much better now.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

Some speedup when actually using an encoding in 648fb1a - I realized we can do this:

        if (format->params.flags & FMT_UTF8 && pers_opts.target_enc != ASCII)
                fmt_init(format);
<!-- gh-comment-id:67743649 --> @magnumripper commented on GitHub (Dec 20, 2014): Some speedup when actually using an encoding in 648fb1a - I realized we can do this: ``` C if (format->params.flags & FMT_UTF8 && pers_opts.target_enc != ASCII) fmt_init(format); ```
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

We now never execute this for most formats though:

        int omp_t = omp_get_num_threads();

        self->params.min_keys_per_crypt *= omp_t;
        omp_t *= OMP_SCALE;
        self->params.max_keys_per_crypt *= omp_t;

so min/max keys per crypt may show wrong.

<!-- gh-comment-id:67743842 --> @magnumripper commented on GitHub (Dec 20, 2014): We now never execute this for most formats though: ``` C int omp_t = omp_get_num_threads(); self->params.min_keys_per_crypt *= omp_t; omp_t *= OMP_SCALE; self->params.max_keys_per_crypt *= omp_t; ``` so min/max keys per crypt may show wrong.
Author
Owner

@magnumripper commented on GitHub (Dec 20, 2014):

The OMP problem was fixed in 61165ed without slowing things down. We now always call init() for non-GPU formats.

<!-- gh-comment-id:67744168 --> @magnumripper commented on GitHub (Dec 20, 2014): The OMP problem was fixed in 61165ed without slowing things down. We now always call init() for non-GPU formats.
Author
Owner

@frank-dittrich commented on GitHub (Dec 20, 2014):

Somewhere something got wrong.
When I compare the --list=format-tests output (without any --encoding) of a non-GPU build of commits 147da4f353 and 4f8a45fc7b, I get (in addition to te expected saph differences) some differences for mscash, krb5pa-md5, NT, nt2, Raw-MD5u.

The funny thing is, that with --encoding=utf-8 or --encoding=koi8-r, those differences disappear.

<!-- gh-comment-id:67753057 --> @frank-dittrich commented on GitHub (Dec 20, 2014): Somewhere something got wrong. When I compare the --list=format-tests output (without any --encoding) of a non-GPU build of commits 147da4f3537e77ed7aab113a5fd31745216ab9d9 and 4f8a45fc7b81c3a1ba2dcc1f8e0cdc2347c322bc, I get (in addition to te expected saph differences) some differences for mscash, krb5pa-md5, NT, nt2, Raw-MD5u. The funny thing is, that with --encoding=utf-8 or --encoding=koi8-r, those differences disappear.
Author
Owner

@frank-dittrich commented on GitHub (Dec 20, 2014):

I think the only way to fix this canonically would be to add something like pre_init() as a format method. Anything else will be hacks. Maybe we should drop the format init for --list and live with the sometimes incorrect plaintext lengths?

Seeing what max. plaintext length different implementations of the same format had was one of the reasons I added --list=format-details 2.5 years ago, so I really don't like it showing wrong information.
What does "sometimes incorrect" mean here?
Will some formats show the wrond plaintext length if you use --encoding=utf-8, or what else?

<!-- gh-comment-id:67754375 --> @frank-dittrich commented on GitHub (Dec 20, 2014): > I think the only way to fix this canonically would be to add something like pre_init() as a format method. Anything else will be hacks. Maybe we should drop the format init for --list and live with the sometimes incorrect plaintext lengths? Seeing what max. plaintext length different implementations of the same format had was one of the reasons I added --list=format-details 2.5 years ago, so I really don't like it showing wrong information. What does "sometimes incorrect" mean here? Will some formats show the wrond plaintext length if you use --encoding=utf-8, or what else?
Author
Owner

@magnumripper commented on GitHub (Dec 21, 2014):

No, that comment of mine is obsolete. Since 61165ed everything is correct (except for the bug you seem to have found - I'm looking at that now) but we only call init() when there may be a need to.

<!-- gh-comment-id:67755071 --> @magnumripper commented on GitHub (Dec 21, 2014): No, that comment of mine is obsolete. Since 61165ed everything is correct (except for the bug you seem to have found - I'm looking at that now) but we only call init() when there _may_ be a need to.
Author
Owner

@magnumripper commented on GitHub (Dec 21, 2014):

OK, this is not really a bug. It's more of a bad side-effect of how the formats define the test vectors.

Most formats have test vectors in ASCII and possibly ISO-8859-1 - and then if we use some other encoding, some test vectors are replaced in init(). But these few formats also sets ISO 8859-1 in init so some test vectors are ALWAYS replaced. I always thought this was confusing, I will fix the formats.

<!-- gh-comment-id:67755460 --> @magnumripper commented on GitHub (Dec 21, 2014): OK, this is not really a bug. It's more of a bad side-effect of how the formats define the test vectors. Most formats have test vectors in ASCII and possibly ISO-8859-1 - and then if we use some other encoding, some test vectors are replaced in init(). But these few formats also sets ISO 8859-1 in init so some test vectors are ALWAYS replaced. I always thought this was confusing, I will fix the formats.
Author
Owner

@magnumripper commented on GitHub (Dec 21, 2014):

I will fix the formats.

I opted to tweak listconf.c instead because it was easier.

<!-- gh-comment-id:67755671 --> @magnumripper commented on GitHub (Dec 21, 2014): > I will fix the formats. I opted to tweak listconf.c instead because it was easier.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#522
No description provided.