9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "boyd, rounin" <boyd@insultant.net>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] crypto question
Date: Wed, 13 Apr 2005 01:10:44 +0200	[thread overview]
Message-ID: <030f01c53fb4$db070260$9efb7d50@kilgore> (raw)
In-Reply-To: <Pine.BSI.4.61.0504121245410.5044@malasada.lava.net>

>   I noticed that the libc function encrypt() uses some non-standard form 
> of cipher chaining.  In the normal case one byte from the previous block 

yeah that sounds right.

from:

    http://www.insultant.net/repo/des.msg

sed 's/.//' >9des.c <<'//GO.SYSIN DD 9des.c'
-/*
- *	Plan 9 DES encryption.
- */
-
-#include "des.h"
-
-int
-encrypt(void *key, void *data, int len)
-{
-	int	n;
-	int	r;
-	int	i;
-	char	*b;
-
-	if (len < DESBLOCKLEN)
-		return 0;
-
-	deskey(key);
-
-	len -= DESBLOCKLEN;
-	n = len / 7 + 1;
-	r = len % 7;
-
-	b = data;
-
-	for (i = 0; i < n; i++)
-	{
-		des(b, 0);
-		b += 7;
-	}
-
-	if (r)
-	{
-		b = data;
-		des(&b[len], 0);
-	}
-
-	return 1;
-}
-
-/*
- *	Plan 9 DES decryption.
- */
-int
-decrypt(void *key, void *data, int len)
-{
-	int	n;
-	int	r;
-	int	i;
-	char	*b;
-
-	if (len < DESBLOCKLEN)
-		return 0;
-
-	deskey(key);
-
-	len -= DESBLOCKLEN;
-	n = len / 7 + 1;
-	r = len % 7;
-
-	b = data;
-
-	if (r)
-		des(&b[len], 1);
-
-	b = &b[len - r];
-
-	for (i = 0; i < n; i++)
-	{
-		des(b, 1);
-		b -= 7;
-	}
-
-	return 1;
-}
-
-/*
- *	Convert a Plan 9 key to a DES key.
- */
-uchar	*
-des9key(uchar *key)
-{
-	int		i;
-	int		m1[]	= { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F };
-	int		m2[]	= { 0x00, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 };
-	static uchar	nkey[DESKEYPLEN];
-
-	nkey[0] = key[0] & 0xFE;
-
-	for (i = 1; i < 7; i++)
-		nkey[i] = (key[i - 1] & m1[i]) << 8 - i | (key[i] & m2[i]) >> i;
-
-	nkey[7] = (key[6] & 0x7F) << 1;
-
-
-	return nkey;
-}
-
-/*
- *	Securenet challenge encryption.
- */
-int
-netcrypt(void *key, void *data)
-{
-	uchar	b[DESBLOCKLEN];
-
-	strncpy((char *)b, (char *)data, DESBLOCKLEN);
-
-	if (!encrypt(des9key(key), b, DESBLOCKLEN))
-		return 0;
-
-	sprint((char *)data, "%.2ux%.2ux%.2ux%.2ux", b[0], b[1], b[2], b[3]);
-	return 1;
-}
-
-/*
- *	Map a hexadecimal string to Securenet decimal string.
- */
-void
-sechex(char *buf)
-{
-	char	*p;
-
-	for (p = buf; *p != '\0'; p++)
-	{
-		switch (*p)
-		{
-		case 'A':
-		case 'B':
-		case 'C':
-		case 'a':
-		case 'b':
-		case 'c':
-			*p = '2';
-			break;
-
-		case 'D':
-		case 'E':
-		case 'F':
-		case 'd':
-		case 'e':
-		case 'f':
-			*p = '3';
-			break;
-		}
-	}
-}
//GO.SYSIN DD 9des.c

--
MGRS 31U DQ 52572 12604




  reply	other threads:[~2005-04-12 23:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-12 22:54 Tim Newsham
2005-04-12 23:10 ` boyd, rounin [this message]
2005-04-13  0:18 ` Martin Harriss
2005-04-13  3:36   ` Tim Newsham
2005-04-13  3:44     ` boyd, rounin
2005-04-13 15:52       ` Bruce Ellis
2005-04-13 18:45         ` Tim Newsham
2005-04-13 19:23 ` Devon H. O'Dell 
2005-04-13 22:01   ` Karl Magdsick
2005-04-13 22:05     ` Devon H. O'Dell 
2005-04-13 22:16       ` Bruce Ellis

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='030f01c53fb4$db070260$9efb7d50@kilgore' \
    --to=boyd@insultant.net \
    --cc=9fans@cse.psu.edu \
    /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;
as well as URLs for NNTP newsgroup(s).