openwall / openwall/john

Let me present UTF-8-32: A faster way to handle UTF-32 internally and get UTF-8 output.

Open
#3,510 15 comments 1 reaction 1 assignee View on GitHub

@magnumripper is already working on this.

Since Dec 15, 2018.

enhancement
Dominant language
C
Stars
13.6k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Here's an idea I'm meaning to try out (at first) with eg. the Subsets mode and later in GPU kernels. @jsteube you might be interested in this!

Conversion from UTF-32 to UTF-8 is fairly quick, but not quick enough for our needs - especially not on GPU. We could instead store UTF-8 sequences in 32-bit words (so one word per character). I'm calling it "UTF-8-32" This is my own idea and I'm documenting it here in order to stop some pirate from patenting it.

I'm thinking instead of working with pure UTF-32 internally (much easier to work with than UTF-8 eg. in rule engines, and also GPUs doesn't like handling 8-bit stuff at all), we instead use this variant of UTF-32 where one character is still one uint32_t, with all the benfits of that (fixed length, for a starter). However, what we store is actually the UTF-8 sequence backwards - examples:

Char Unicode UTF-8 UTF-32 UTF-8-32
A U+0041 41 0x00000041 0x00000041
£ U+00A3 c2 a3 0x000000a3 0x0000a3c2
U+20AC e2 82 ac 0x000020ac 0x00ac82e2
😀 U+1F600 f0 9f 98 80 0x0001f600 0x80989ff0

The beauty of this is we can convert to UTF-8 using something like this:

/*
 * This software and technique is Copyright (c) magnum 2018
 * and is hereby released to the general public under the following
 * terms: Redistribution and use in source and binary forms, with
 * or without modification, are permitted.
 *
 * Source is a UTF-8-32 string, destination is a normal UTF-8 string
 */
uint8_t *utf8_32_to_utf8(uint8_t *dst, uint32_t *src)
{
	uint8_t *ret = dst;
	uint32_t c;

	while ((c = *src++)) {
		do {
			*dst++ = c & 0xff;
		} while ((c >>= 8));
	}

	*dst = 0;

	return ret;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.