9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] netkey on unix
@ 1997-10-22  8:16 Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: Boyd @ 1997-10-22  8:16 UTC (permalink / raw)


here's some posix code for mangling tty echo (for those who feel
that way inclined):

/*
 * Horrible system dependent tty routines.
 */

#include	<termios.h>

/*
 * Is echo on?
 */
int
ttyechoing(int fd)
{
	struct termios	t;

	if (tcgetattr(fd, &t) == -1)
		return -1;

	return (t.c_lflag & ECHO) != 0;
}

/*
 * Turn echo off/on?
 */
int
ttyecho(int fd, int on)
{
	struct termios	t;

	if (tcgetattr(fd, &t) == -1)
		return -1;

	if (on)
		t.c_lflag |= ECHO;
	else
		t.c_lflag &= ~ECHO;

	return tcsetattr(fd, TCSADRAIN, &t);
}




^ permalink raw reply	[flat|nested] 2+ messages in thread

* [9fans] netkey on unix
@ 1997-10-22  5:04 Kenji
  0 siblings, 0 replies; 2+ messages in thread
From: Kenji @ 1997-10-22  5:04 UTC (permalink / raw)


Hello 9fans!

Here is a netkey program that runs on unix.
DES source code is not required for this program.

Kenji arisawa
E-mail: arisawa@aichi-u.ac.jp

/*
*   netkey on unix
*   coded by
*       Kenji Arisawa
*       E-mail: arisawa@aichi-u.ac.jp
*
*   usage: netkey
*/

#include <stdio.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);
}

/* imported from plan9 /sys/src/libauth/passtokey.c - slitely modified -
   uchar p[NAMELEN]    --- password
   uchar key[DESKEYLEN] --- DESKEY
*/
int
pass2key(uchar *p, uchar *key)
{
        uchar buf[NAMELEN], *t;
        int i, n;

        n = strlen(p);
        if(n >= NAMELEN)
                n = NAMELEN-1;
        memset(buf, ' ', 8);
        t = buf;
        strncpy((char*)t, p, n);
        t[n] = 0;
        memset(key, 0, DESKEYLEN);
        for(;;){
                for(i = 0; i < DESKEYLEN; i++)
                        key[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1)));
                if(n <= 8)
                        return 1;
                n -= 8;
                t += 8;
                if(n < 8){
                        t -= 8 - n;
                        n = 8;
                }
                des(key, t); /* originally encrypt(key,t,8) */
        }
        return 1;       /* not reached */
}



main()
{   uchar buf[80];
    uchar key[DESKEYLEN];
    int i;

     /* system() is applied for portability */
    system("stty -echo");
    fprintf(stderr,"password: ");
    gets(buf);
    pass2key(buf,key);
    system("stty echo;echo");

    for(;;){
        memset(buf,0,8);
        fprintf(stderr,"challenge: ");
        gets(buf);
        if(strlen(buf) == 0) break;
        buf[7] = 0;
        des(key,buf);
        printf("response: ");
        for(i = 0; i < 4; i++) printf("%02x",buf[i]);
        puts("");
    }
}




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-10-22  8:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-22  8:16 [9fans] netkey on unix Boyd
  -- strict thread matches above, loose matches on Subject: below --
1997-10-22  5:04 Kenji

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).