mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #849] Comprehensive base-x conversion function #457
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#457
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jfoug on GitHub (Nov 9, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/849
I am working on some new code. I will list what it does here. I am about 75% done on a POC level.
The code has 1 function (2 actually, 1 returns int, the other returns char *)
The char * version simply returns the *to value. The int version returns the number of bytes written into *to (minus the null byte). raw does not get \0, but all other string types do get null termination. Right now, the base-64 types do not output padding. I may make that an option (it;s trivial)
The b64_convert_type enum is:
There is also a command line tool (../run/base64conv). It's usage() output is:
This 'issue' is simply a heads up, and if people want to comment, FEEL FREE.
@jfoug commented on GitHub (Nov 9, 2014):
Here is an example circular run
$ ../run/base64conv -i raw -o hex 123456789abcdefgHHHu
123456789abcdefgHHHu --> 3132333435363738396162636465666748484875
$ ../run/base64conv -i hex -o mime 3132333435363738396162636465666748484875
3132333435363738396162636465666748484875 --> MTIzNDU2Nzg5YWJjZGVmZ0hISHU
$ ../run/base64conv -i mime -o crypt MTIzNDU2Nzg5YWJjZGVmZ0hISHU
MTIzNDU2Nzg5YWJjZGVmZ0hISHU --> AH6nB1IqBnUtMK7XN4JaNoV6G5I
$ ../run/base64conv -i crypt -o raw AH6nB1IqBnUtMK7XN4JaNoV6G5I
AH6nB1IqBnUtMK7XN4JaNoV6G5I --> 123456789abcdefgHHHu
$ ../run/base64conv -i raw -o mime 123456789abcdefgHHHu
123456789abcdefgHHHu --> MTIzNDU2Nzg5YWJjZGVmZ0hISHU
But here I see I still have some bugs in code! (it should be AH6nB....)
$ ../run/base64conv -i raw -o crypt 123456789abcdefgHHHu
123456789abcdefgHHHu --> l6nAoIXBrUHCV7qMYJaNbV2G6J5
@magnumripper commented on GitHub (Nov 9, 2014):
BTW I think you have a bug in current base64.c:82
It should end in
+/, not./, yes?@jfoug commented on GitHub (Nov 9, 2014):
You are probably correct. I was going by the abase64_decode() function, which swaps + and . I do think the core should use +
This might be something to add as a modification flag, To be able to handle + or . Also to add or trim the = or trailing . values. Those type things should be in a flag (probably output case of hex also).
The new code strips out many of the latest changes (to base64, scrypt/pbkdf2-hmac-sha256, etc), and unifies them into base64_convert.c
The only conversion function that will not be in base64_convert (at the start), is the base64_decode contained in base64.h
I have a little more testing to do, but am about ready to plug it in and go.
@jfoug commented on GitHub (Nov 9, 2014):
After changing . to + for mime, I had to change prepare to 'undo that' for pbkdf2_hmac_sha256 (for the cisco9 stuff)
But I think you are right, the + is the right thing to do.
@magnumripper commented on GitHub (Nov 9, 2014):
Actually I think we should pass the wanted Base64 alphabet(s) as a whole, as one parameter. The normal ones would be defined as macros.
Then we could do things like
or
@jfoug commented on GitHub (Nov 9, 2014):
It is not just alphabet. It is also bit selection order.
@jfoug commented on GitHub (Nov 9, 2014):
Anyhow, I will be checking in a version shortly.
@jfoug commented on GitHub (Nov 9, 2014):
This is a first version:
38218feHere is a real simple test script, that ran it through its paces. I will need to also add some 'known' correct conversions, to make sure that things are correct.
$ cat tst
@jfoug commented on GitHub (Nov 10, 2014):
I have a much more in depth test case, and have added overwrite detection logic into the base64conv program. I have it where I know every 'extra' byte.
The current code has zero overwrite for many of the conversions. BUT for some, there is 1 and for some length 2 bytes that get overwritten (past the 1 extra \0 byte). I have run test of all base64 to other base64 tests. The overwrites come from having to convert into raw, then into the final base-64 type. This conversion is only needed for endianty different base-64s. If they are the same byte order, I can simply do direct conversions from 1 to the other, replacing chars of the alphabets from the same offset.
This is mostly a query to @magnumripper. Is having to have +3 bytes longer than a flat string (with no null), to big of a thing to ask. Now that I have the base64conv program working, it may be that I can find better ways to convert from 1 encoding to another, than doing a full decode/encode pair. It may be that I can work my way through the buffer 4 characters at a time, and deal with the last 1,2,3 byte bundle by itself. But at this time, I am not there yet.
@magnumripper commented on GitHub (Nov 10, 2014):
As long as we know it, it's not much of an issue. The real problem is when we are simply not aware that we need to alloc one or a few extra bytes, like a week ago before
804754ca4andc4574d02.@jfoug commented on GitHub (Nov 11, 2014):
Added update that reworks some buffer size stuff for conversions and also adds -e to check for overflow errors (1 and 2 byte are ignored, as was discussed)
7926b5cI have used this to add ScryptKDF format to scrypt. Again, I simply did a conversion into original escryp\crypto_scrypt format. the ScryptKDF has salt in mime format (I had to convert to raw), and hash in mime format, I had to convert to cryptBS. But other than that, it was pretty trivial, and I will get it checked in, and issue #368 closed.
@jfoug commented on GitHub (Nov 12, 2014):
65c0417Big improvements. Have a better test suite now, and almost all passes. What does not pass (2 items in one run of the mixer), I have not tracked down, but it should be trivial, I hope). I still have to add code to USE most of the flags, and add more flags.New code uses no allocs for base64-base64 converts. All base64 converts now take 4 chars, convert them into 3 memory bytes, then take those 3 memory bytes and convert into the other base64 format. Very trivial until you get to the last limb (which will be 2, 3 or 4 valid base-64 characters). The code also handles input with padding properly (= or . padding). For the . padding it is harder. Sometimes, the first . character IS required. Currently, we ONLY output in non-padded format. If that extra '.' is supposed to be there, it will be. BUT padding out to even 4, has not been done yet. It is a flag, and I will get code to handle it, I have just not got it done yet.
@magnumripper commented on GitHub (Nov 12, 2014):
I can't even build it...
Neither can the bots: https://travis-ci.org/magnumripper/JohnTheRipper/builds/40827333
@jfoug commented on GitHub (Nov 12, 2014):
Try now, sorry.
@magnumripper commented on GitHub (Nov 12, 2014):
Using
ab93c6f8@magnumripper commented on GitHub (Nov 12, 2014):
I fixed OpenCL for you some day ago. You need to have them in mind even if you don't build them yourself. As soon as you change a function jtr_foo(), try
git grep -l jtr_fooand you'll see a list of all files affected.@jfoug commented on GitHub (Nov 12, 2014):
I am building now.
@magnumripper commented on GitHub (Nov 12, 2014):
Actually it seems to be this easy this time:
But I'll let you commit it so we don't clash mid air.
@jfoug commented on GitHub (Nov 12, 2014):
already fixed, no need for an unsure patch.
@magnumripper commented on GitHub (Nov 12, 2014):
All fine now, including --test=0
@jfoug commented on GitHub (Nov 12, 2014):
I got a Travis all - OK for build 1841, even though openCL had errors. I see Travis does not build opencl. I will have to keep that in mind also. Build 1842 is correct for CPU and GPU
@jfoug commented on GitHub (Nov 13, 2014):
3211c44This patch passes my entire test suite (include here). Also there are no memory allocations required any more. All conversions are done in place, with minimal temp memory used.Now, I need to handle the flags, AND get this tied into other areas were we do base-64 stuff in john (and possibly hex stuff also), and remove TONS of custom code. The only issue would be if there are speed differences. If so, then all I need to do is optimize this 'common' code some.
Here is my test script
@jfoug commented on GitHub (Nov 13, 2014):
I am going to make a post on john_users listing this change. The base64conv tool in of itself if useful enough for a post.
@jfoug commented on GitHub (Nov 13, 2014):
I am adding this function (and also thinking about possible rename of these functions)
int base64_valid_length(const char *from, b64_convert_type from_t, unsigned flags);
This would return the number of bytes that were valid for this from_t type. NOTE, e_b64_raw type would not be a valid type to get length, it would have to be one of the encodings. But there are MANY MANY formats that have this as custom code in their valid formats. Simple common functions like this could save a lot of coding.
This would return the length of valid characters passed in
@jfoug commented on GitHub (Nov 18, 2014):
8029a11Starts getting other flags working. I did see a bug and will have to work on it. (mime2crypt where mime has trailing == chars)@jfoug commented on GitHub (Nov 20, 2014):
e52d74cmime2hex length bugs, and added a new mime alphabet (ends with -_ vs +/)@frank-dittrich commented on GitHub (Dec 15, 2014):
When no data is given, base64conv should just read from stdin.
@jfoug commented on GitHub (Dec 15, 2014):
529fcf4