mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: linux@horizon.com
To: linux-kernel@vger.kernel.org
Cc: jmorris@redhat.com, Valdis.Kletnieks@vt.edu
Subject: Re: [PATCH 2.6.1 -- take two] Add CRC32C chksums to crypto and lib
Date: 4 Feb 2004 03:48:10 -0000	[thread overview]
Message-ID: <20040204034810.29593.qmail@science.horizon.com> (raw)

> I could have *sworn* that abandoning something to the public
> domain prohibited any disclaimer-of-liability clauses - the original
> reason for the MIT X copyright was because they couldn't disclaim
> liability if they let it into the public domain.  It's the same basic
> "by copying, you agree to our terms" copyright that essentially all
> open-source depends on.
>
> And if it's in the public domain, they don't have to agree to your terms,
> and thus you can't enforce that liability disclaimer..

> Placing the code in the public domain then adding additional rights seems 
> to be inherently conflicted.
>
> People will pay for distribution of the code, so these additional rights 
> would not be acceptable anyway.

If there's a problem, then change it - like delete the disclaimer.
The code is too trivial to worry about.

I'll rewrite it AGAIN if anybody needs a legally-clean version; it takes
about 5 minutes, and a few more for testing.

/*
 * poly is the polynomial, with bit n corresponding to the x^(31-n)
 * coefficient and the x^32 coefficient implicitly 1.
 */
void __attribute__((nonnull))
make_crc32_table_le(u32 table[256], u32 poly)
{
	unsigned i, j;
	u32 crc = 1;

	table[0] = 0;
	for (i = 1; i < 256; i *= 2) {
		crc = (crc >> 1) ^ (crc & 1 ? poly : 0);
		for (j = 0; j < i; j++)
			table[i+j] = crc ^ table[j];
	}
}


/* Append the given (data, len) to the computed CRC.
 * For most protocols, initialize crc to -(u32)1 and invert it
 * before appending to the data.  The final CRC can be checked
 * by repeating the generation computation, or by computing the CRC again
 * over the entire stream (including the first CRC) and comparing to
 * a known value.  If the final CRC is not inverted, the result should
 * be zero.  If the final CRC is inverted, the result should be a fixed
 * non-zero value.
 */
u32 __attribute__((nonnull(1)))
calc_crc32_le(u32 const table[256], u8 data, unsigned len, u32 crc)
{
	while (len--)
		crc = (crc >> 8) ^ table[(u8)(crc ^ *data++)];
	return crc;
}

/*
 * poly is the polynomial, with bit n corresponding to the x^n
 * coefficient and the x^32 coefficient implicitly 1.
 */
void __attribute__((nonnull))
make_crc32_table_be(u32 table[256], u32 poly)
{
	unsigned i, j;
	u32 crc = 0x80000000;

	table[0] = 0;
	for (i = 128; i; i /= 2) {
		crc = (crc << 1) ^ (crc & 0x80000000 ? poly : 0);
		for (j = 0; j < 256; j += 2*i)
			table[i+j] = crc ^ table[j];
	}
}


u32 __attribute__((nonnull))
calc_crc32_be(u32 const table[256], u8 data, unsigned len, u32 crc)
{
	while (len--)
		crc = (crc << 8) ^ table[(u8)((crc >> 24) ^ *data++)];
	return crc;
}


Okay, that took 10 minutes and 5 seconds.  And it's not tested.
But it's pretty straightforweard.

                 reply	other threads:[~2004-02-04  3:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040204034810.29593.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®