From: Russ Cox rsc@plan9.bell-labs.com
Subject: [9fans] encryption routines for il
Date: Wed, 22 Apr 1998 14:26:51 -0400 [thread overview]
Message-ID: <19980422182651.ArfXaegEz6_WV4EcwgnlzDnBaLrGCWj_HbSdPOD-7ec@z> (raw)
Take Pace's il.tar.gz, make des.c a null file, and then
use the following encrypt.c:
(The inspiration and almost all of the code for this came from Kenji Arisawa.)
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#define DESKEYLEN 7
#define NAMELEN 22
typedef unsigned char uchar;
uchar a[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
/* get bit status at the bit position n of string s
char s[8]
int n: 0 .. 63
*/
int strbit(char *s, int n)
{ int q,m;
q = n / 8;
m = n % 8;
return (s[q] & a[m]?1:0);
}
/* uchar s[8]
uchar x[1]
*/
uchar s2b(uchar *s)
{ int i;
uchar x;
x = 0;
for(i = 0; i < 8; i++) if(s[i]) x |= a[i];
return x;
}
/* uchar s[8]
uchar x[1]
*/
void b2s(uchar x, uchar *s)
{ int i;
for(i = 0; i < 8; i++) s[i] = 0;
for(i = 0; i < 8; i++) if(x & a[i]) s[i] = 1;
}
/* uchar s[64], x[8] */
void blk2str(uchar *x, uchar *s)
{ int i;
for(i = 0; i < 8; i++) b2s(x[i],&s[8*i]);
}
/* uchar s[64], x[8] */
void str2blk(uchar *s, uchar *x)
{ int i;
for(i = 0; i < 8; i++) x[i] = s2b(&s[8*i]);
}
/* Plan9 encrypt
uchar key[7] --- deskey
uchar t[8] --- target(des cypher block)
*/
void des(uchar *key, uchar *t)
{ int i,j;
char s[64],u[64];
for(j = 0; j < 8; j++){
for(i = 0; i < 7; i++) s[8*j + i] = strbit(key, 7*j + i);
s[8*j + 7] = 0;
}
setkey(s);
blk2str(t,u);
encrypt(u,0); /* encrypt */
str2blk(u,t);
}
void
plan9_encrypt(uchar *key, uchar *t, int len)
{
des(key, t);
}
This doesn't work under Linux. Don't complain to me.
Russ
next reply other threads:[~1998-04-22 18:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-04-22 18:26 Russ [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-04-23 14:19 Paul
1998-04-23 3:58 forsyth
1998-04-22 19:56 Digby
1998-04-22 19:24 forsyth
1998-04-22 17:48 Paul
1998-04-22 17:14 Digby
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=19980422182651.ArfXaegEz6_WV4EcwgnlzDnBaLrGCWj_HbSdPOD-7ec@z \
--to=9fans@9fans.net \
/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).