From 6ee959115f3ba5d888cb68f26422b5385d34bb56 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 6 Aug 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-08-06 --- pc/trap.c | 21 +++++++------ port/devssl.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++--- port/portdat.h | 3 +- port/proc.c | 1 + port/qlock.c | 46 +++------------------------ 5 files changed, 99 insertions(+), 57 deletions(-) diff --git a/pc/trap.c b/pc/trap.c index 317aa8987ec48725b65a61c4cd3de28a046ea286..5273a89ae949155eaccb791773cc80adce61a240 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -18,21 +18,24 @@ static Irqctl *irqctl[256]; void intrenable(int v, void (*f)(Ureg*, void*), void* a, int tbdf) { - Irq * irq; + Irq *irq; Irqctl *ctl; lock(&irqctllock); - if(irqctl[v] == 0){ - ctl = xalloc(sizeof(Irqctl)); - if(v >= VectorINTR && arch->intrenable(v, tbdf, ctl) == -1){ - unlock(&irqctllock); - //print("intrenable: didn't find v %d, tbdf 0x%uX\n", v, tbdf); + if(irqctl[v] == 0) + irqctl[v] = xalloc(sizeof(Irqctl)); + ctl = irqctl[v]; + + if(v >= VectorINTR && arch->intrenable(v, tbdf, ctl) == -1){ + if(ctl->irq == nil){ + irqctl[v] = nil; xfree(ctl); - return; } - irqctl[v] = ctl; + unlock(&irqctllock); + print("intrenable: didn't find v %d, tbdf 0x%uX\n", v, tbdf); + return; } - ctl = irqctl[v]; + irq = xalloc(sizeof(Irq)); irq->f = f; irq->a = a; diff --git a/port/devssl.c b/port/devssl.c index e5cc8dbf531e794deb2273f88704e604a23a19bc..7e24dca49d526024a729f97f17a379dd526f01d6 100644 --- a/port/devssl.c +++ b/port/devssl.c @@ -10,6 +10,8 @@ #include +#define NOSPOOKS 1 + typedef struct OneWay OneWay; struct OneWay { @@ -728,6 +730,40 @@ initDESkey(OneWay *w) error("secret too short"); } +/* + * 40 bit DES is the same as 56 bit DES. However, + * 16 bits of the key are masked to zero. + */ +static void +initDESkey_40(OneWay *w) +{ + if(w->state){ + free(w->state); + w->state = 0; + } + + if(w->slen >= 16) { + w->secret[8] &= 0x0f; + w->secret[10] &= 0x0f; + w->secret[12] &= 0x0f; + w->secret[14] &= 0x0f; + } + if(w->slen >= 8) { + w->secret[0] &= 0x0f; + w->secret[2] &= 0x0f; + w->secret[4] &= 0x0f; + w->secret[6] &= 0x0f; + } + + w->state = malloc(sizeof(DESstate)); + if(w->slen >= 16) + setupDESstate(w->state, w->secret, w->secret+8); + else if(w->slen >= 8) + setupDESstate(w->state, w->secret, 0); + else + error("secret too short"); +} + static void initRC4key(OneWay *w) { @@ -740,12 +776,34 @@ initRC4key(OneWay *w) setupRC4state(w->state, w->secret, w->slen); } +/* + * 40 bit RC4 is the same as n-bit RC4. However, + * we ignore all but the first 40 bits of the key. + */ +static void +initRC4key_40(OneWay *w) +{ + if(w->state){ + free(w->state); + w->state = 0; + } + + if(w->slen > 5) + w->slen = 5; + + w->state = malloc(sizeof(RC4state)); + setupRC4state(w->state, w->secret, w->slen); +} + +typedef struct Hashalg Hashalg; struct Hashalg { char *name; int diglen; DigestState *(*hf)(uchar*, ulong, uchar*, DigestState*); -} hashtab[] = +}; + +Hashalg hashtab[] = { { "md4", MD4dlen, md4, }, { "md5", MD5dlen, md5, }, @@ -756,7 +814,7 @@ struct Hashalg static int parsehashalg(char *p, Dstate *s) { - struct Hashalg *ha; + Hashalg *ha; for(ha = hashtab; ha->name; ha++){ if(strcmp(p, ha->name) == 0){ @@ -770,24 +828,43 @@ parsehashalg(char *p, Dstate *s) return -1; } +typedef struct Encalg Encalg; struct Encalg { char *name; int blocklen; int alg; void (*keyinit)(OneWay*); -} encrypttab[] = +}; + +#ifdef NOSPOOKS +Encalg encrypttab[] = { { "descbc", 8, DESCBC, initDESkey, }, { "desebc", 8, DESECB, initDESkey, }, + { "descbc_40", 8, DESCBC, initDESkey_40, }, + { "desebc_40", 8, DESECB, initDESkey_40, }, { "rc4", 1, RC4, initRC4key, }, + { "rc4_40", 1, RC4, initRC4key_40, }, + { 0 } +}; +#else +Encalg encrypttab[] = +{ + { "descbc", 8, DESCBC, initDESkey_40, }, + { "desebc", 8, DESECB, initDESkey_40, }, + { "descbc_40", 8, DESCBC, initDESkey_40, }, + { "desebc_40", 8, DESECB, initDESkey_40, }, + { "rc4", 1, RC4, initRC4key_40, }, + { "rc4_40", 1, RC4, initRC4key_40, }, { 0 } }; +#endif NOSPOOKS static int parseencryptalg(char *p, Dstate *s) { - struct Encalg *ea; + Encalg *ea; for(ea = encrypttab; ea->name; ea++){ if(strcmp(p, ea->name) == 0){ diff --git a/port/portdat.h b/port/portdat.h index 4af3bfe6621cc057d6c7cc652e18427eb604a64b..0bbc723dc66c72155b70713be1ed7f672daeb9b1 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -68,8 +68,6 @@ struct RWlock Proc *tail; int readers; /* number of readers */ int writer; /* number of writers */ -// int pidw; -// int pidr[10]; }; struct Talarm @@ -498,6 +496,7 @@ enum Scheding, Running, Queueing, + QueueingR, QueueingW, Wakeme, Broken, diff --git a/port/proc.c b/port/proc.c index 2053a8c306850f6b2387e0b670ec0cb589941700..f60a7151bb1543b1d2c932aa31707cbc47816a76 100644 --- a/port/proc.c +++ b/port/proc.c @@ -41,6 +41,7 @@ char *statename[] = "Scheding", "Running", "Queueing", + "QueueingR", "QueueingW", "Wakeme", "Broken", diff --git a/port/qlock.c b/port/qlock.c index 7e238334ab67abbf3c196e7183319f994199be04..89503f8292df5f419114932f4afd47d7ef5622c5 100644 --- a/port/qlock.c +++ b/port/qlock.c @@ -78,20 +78,9 @@ rlock(RWlock *q) Proc *p, *mp; lock(&q->use); -//{int i; -//for(i=0; ipidr); i++) -//if(q->pidr[i]==up->pid) -//print("***already %d\n", up->pid); -//} rwstats.rlock++; if(q->writer == 0 && q->head == nil){ /* no writer, go for it */ -//{int i; -//for(i=0; ipidr); i++) -//if(q->pidr[i]==0) { -//q->pidr[i]=up->pid; -//break; -//}} q->readers++; unlock(&q->use); return; @@ -106,8 +95,7 @@ rwstats.rlockq++; p->qnext = mp; q->tail = mp; mp->qnext = 0; - mp->state = Queueing; -//print("%d rl for w%d\n", up->pid, q->pidw); + mp->state = QueueingR; unlock(&q->use); sched(); } @@ -118,12 +106,6 @@ runlock(RWlock *q) Proc *p; lock(&q->use); -//{int i; -//for(i=0; ipidr); i++) -//if(q->pidr[i]==up->pid) { -//q->pidr[i] = 0; -//break; -//}} p = q->head; if(--(q->readers) > 0 || p == nil){ unlock(&q->use); @@ -137,7 +119,6 @@ runlock(RWlock *q) if(q->head == 0) q->tail = 0; q->writer = 1; -//q->pidw = p->pid; unlock(&q->use); ready(p); } @@ -151,14 +132,13 @@ wlock(RWlock *q) rwstats.wlock++; if(q->readers == 0 && q->writer == 0){ /* noone waiting, go for it */ -//q->pidw = up->pid; q->writer = 1; unlock(&q->use); return; } /* wait */ -//rwstats.wlockq++; +rwstats.wlockq++; p = q->tail; mp = up; if(p == nil) @@ -168,14 +148,6 @@ rwstats.wlock++; q->tail = mp; mp->qnext = 0; mp->state = QueueingW; -//print("%d wl for %d%d", up->pid, q->readers, q->writer); -//if(q->pidw) print(" w%d", q->pidw); -//{int i; -//for(i=0; ipidr); i++) -//if(q->pidr[i]) -//print(" %d", q->pidr[i]); -//print("\n"); -//} unlock(&q->use); sched(); } @@ -186,9 +158,6 @@ wunlock(RWlock *q) Proc *p; lock(&q->use); -//if(q->pidw!=up->pid) -//print("not qw\n"); -//q->pidw = 0; p = q->head; if(p == nil){ q->writer = 0; @@ -196,7 +165,6 @@ wunlock(RWlock *q) return; } if(p->state == QueueingW){ -//q->pidw = p->pid; /* start waiting writer */ q->head = p->qnext; if(q->head == nil) @@ -206,17 +174,11 @@ wunlock(RWlock *q) return; } - if(p->state != Queueing) + if(p->state != QueueingR) panic("wunlock"); /* waken waiting readers */ - while(q->head != nil && q->head->state == Queueing){ -//{int i; -//for(i=0;ipidr); i++) -//if(q->pidr[i]==0) { -//q->pidr[i] = p->pid; -//break; -//}} + while(q->head != nil && q->head->state == QueueingR){ p = q->head; q->head = p->qnext; q->readers++;