Group: fa.openbsd.tech




Subject: VIA C7 Dual RNG
From: Tobias Weingartner
Date: 1/22/2007 11:16:37 PM
On Monday, January 22, Henric Jungheim wrote: > > I put together a little diff to get the 2nd generator Hmm... > The comments around 'viac3_rnd' were also a bit > suspicious--at least compared to the docs that I have > available. Which comments would those be? > - * Note, due to some weirdness in the RNG, we need at least 7 bytes > - * extra on the end of our buffer. Also, there is an outside chance I'd have to re-read the stuff I had, but those extra 7 bytes were necessary, as the CPU could over-run the buffer given by up to 7 bytes. IE: we want to provide the CPU with extra space to do its thing. Now, it may be that not doing the "rep" version gets around this... > -#define VIAC3_RNG_BUFSIZ 16 /* 32bit words */ > struct timeout viac3_rnd_tmo; > int viac3_rnd_present; > > @@ -534,25 +531,46 @@ > viac3_rnd(void *v) > { > struct timeout *tmo = v; > - unsigned int *p, i, rv, creg0, len = VIAC3_RNG_BUFSIZ; > - static int buffer[VIAC3_RNG_BUFSIZ + 2]; /* XXX why + 2? */ The "+2" was those extra 7 bytes. (4 bytes * 2 == 8, which is more than enough...) :) > + * We avoid the "rep" variant and divisors to keep things sane. > + * This also gives the hardware a chance to replenish its buffers > + * while add_true_randomness() does its thing. > */ > - __asm __volatile("rep xstore-rng" > - : "=a" (rv) : "d" (3), "D" (buffer), "c" (len*sizeof(int)) > - : "memory", "cc"); > > - lcr0(creg0); > + for (i = 0; i < 16; ++i) > + { > + int* p = buffer; > + > + __asm __volatile("xstore-rng" > + : "=a" (rv), "+D" (p) > + : "d" (0) > + : "memory" ); > + > + if (0 == (rv & 0xf)) > + break; > > - for (i = 0, p = buffer; i < VIAC3_RNG_BUFSIZ; i++, p++) > - add_true_randomness(*p); > + add_true_randomness(buffer[0]); > + add_true_randomness(buffer[1]); > + } > + > + lcr0(creg0); I'm not sure this is better or worse. Could you point me at the documentation you have so I can have a read please? --Toby.

Subject: VIA C7 Dual RNG
From: Tobias Weingartner
Date: 1/24/2007 6:18:42 AM
On Monday, January 22, Henric Jungheim wrote: > > Errr... configure the divider for 8 bytes (EDX = 0) and ask > for one byte of output, then call "rep xstore-rng". It will > write 8 bytes when only one was asked for, so it could > overwrite the output buffer by 7 bytes. There's the > mysterious "7". (Now I just need to do something about this > palm-print; I must remember to not slap my forehead like > that... A Homer-esque, "Doh!" should be an effective > alternative.) Does the palm-print mean your original diff needs to be modified? :) --Toby.