Re: When is it safe to cheat?

2000-05-09 Thread Fergus Henderson

On 10-May-2000, Sverker Nilsson <[EMAIL PROTECTED]> wrote:
> 
> Relevance for Haskell would be that you wouldnt be able to fork a
> program written in C into a protected environment (functional
> sandbox?) and know that its result would depend only on its input
> arguments. So you couldnt safely do this thru an ordinary Haskell
> function call that could be cached for example.

Well, you don't have that guarantee anyway.
C has many areas of undefined and/or unspecified behaviour.
There is no guarantee that C code will be deterministic.
So do operating system ABIs.  Even hardware architectures often have
areas of undefined and/or unspecified behaviour.

To give you a practical example: on SPARCs, the contents of
uninitialized stack slots are unspecified, and in practice they are
nondeterministic.  This happens because the SPARC's register windows
get flushed to the stack when a context switch occurs, and the timing
of context switches is in general nondeterministic.  If you write a C
program that examines uninitialized stack slots -- for example one
using a conservative garbage collector -- then the program's exact
behaviour can be nondeterministic.  (This has bitten me in the past.)

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW:   |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]| -- the last words of T. S. Garp.




Re: When is it safe to cheat?

2000-05-09 Thread Sverker Nilsson

Michael Hobbs wrote:
> I believe that the P3 chips come with a noisy diode built-in,
> specifically for the purpose of generating random numbers. You might try
> to find a way to access that little gizmo. (Assuming that you're running
> on a P3.)

Interesting! Do you have any reference for this? 

I hope this diode is only accessible from supervisor mode, because
otherwise we won't have as many provably deterministic user mode
programs as before.

Relevance for Haskell would be that you wouldnt be able to fork a
program written in C into a protected environment (functional
sandbox?) and know that its result would depend only on its input
arguments. So you couldnt safely do this thru an ordinary Haskell
function call that could be cached for example.

To get at this diode, or any other such device, one should have
to go thru a device driver or I/O instruction that could be disabled.
I hope they did it like this...

Sverker Nilsson


> 
> - Michael Hobbs




Re: When is it safe to cheat?

2000-05-09 Thread Michael Hobbs

Jan Skibinski wrote:
> Any good idea? First prize: a bottle of something good. :-)

In C, I've sometimes added in the memory location of an arbitrary
variable, just for good measure. But that's not quite as secure in an
open source environment. (Maybe not even that secure in a closed source
environment.) Probably not as good as the entropy daemon, anyway.

I believe that the P3 chips come with a noisy diode built-in,
specifically for the purpose of generating random numbers. You might try
to find a way to access that little gizmo. (Assuming that you're running
on a P3.)

- Michael Hobbs




Re: Converting float to double.

2000-05-09 Thread Marcin 'Qrczak' Kowalczyk

Mon, 8 May 2000 20:42:10 -0700 (PDT), Ronald J. Legere <[EMAIL PROTECTED]> pisze:

>  I have a very simple question. What is the best way to 
> convert a float to a double?
>  I use fromRational.toRational, and the notes in the prelude
> seem to imply that this is optimized into something sensible..

The Prelude contains:

realToFrac:: (Real a, Fractional b) => a -> b
realToFrac = fromRational . toRational

Unfortunately GHC currently does not optimize this into anything
smarter than going through Rational. Fortunately it contains enough
machinery so you can let it optimize it yourself :-)  Just add:

import NumExts (floatToDouble, doubleToFloat)

{-# RULES
"realToFrac/Float->Double" realToFrac = floatToDouble
"realToFrac/Double->Float" realToFrac = doubleToFloat #-}

and compile with  -syslib lang -O  and use realToFrac.

To GHC developers: please add it to the GHC's library.

-- 
 __("$ P+++ L++>$ E-
  ^^  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK  5? X- R tv-- b+>++ DI D- G+ e> h! r--%>++ y-





RE: Showing tuples

2000-05-09 Thread Mike Jones



Sven,

That explains it. My tuples are of size 20.

Thanks,

Mike


Deriving works, but GHC currently only contains instance declarations
for tuples up to 5 elements, so you have to write you own boring
instances for larger ones.  *yawn*

Cheers,
   Sven
-- 
Sven PanneTel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen  Oettingenstr. 67
mailto:[EMAIL PROTECTED]D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne





RE: Showing tuples

2000-05-09 Thread grust




Do you derive Show for MyData?

> -Original Message-
> From: Mike Jones [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2000 05:58
> To: [EMAIL PROTECTED]
> Subject: Showing tuples
>
>
> Hi,
>
> I am having trouble with Show and tuples.
>
> I have a data structure, say:
>
> data MyData = ...
>
> And a value, say:
>
> value = (MyData..., MyData..., MyData)
>
> Then try to:
>
> show value
>
> I get a compiler message from ghc 4.05 that says:
>
> No instance for `Show (MyData, MyData, MyData)...
>
> What is the best way to deal with this problem?
>
> Thanks,
>
> Mike
>
>






Showing tuples

2000-05-09 Thread grust




Hi,

I am having trouble with Show and tuples.

I have a data structure, say:

data MyData = ...

And a value, say:

value = (MyData..., MyData..., MyData)

Then try to:

show value

I get a compiler message from ghc 4.05 that says:

No instance for `Show (MyData, MyData, MyData)...

What is the best way to deal with this problem?

Thanks,

Mike







RE: Showing tuples

2000-05-09 Thread Chris Angus

Mike ... try this ...extend it to however long tuples you have


data MyData = Foo | Bar deriving Show

main = print (Foo,Foo,Foo,Foo,Foo,Foo)

instance (Show tv1, Show tv2, Show tv3, Show tv4, Show tv5 , Show tv6) =>
Show (tv1,tv2,tv3,tv4,
tv5,tv6) where
showsPrec p (v1,v2,v3,v4,v5,v6) = showChar '(' . shows v1 . showChar
',' .
 shows v2 . showChar
',' .
 shows v3 . showChar
',' .
 shows v4 . showChar
',' .
 shows v5 . showChar
',' .
 shows v6 . showChar
')'

instance (Read tv1, Read tv2, Read tv3, Read tv4, Read tv5 , Read tv6) =>
Read (tv1,tv2,tv3,tv4,
tv5,tv6) where
readsPrec p = readParen False
(\s0 -> [((v1,v2,v3,v4,v5,v6),s6A) | ("(",s1) <- lex
s0,
   (v1,s1A) <- reads
s1,
   (",",s2) <- lex
s1A,
   (v2,s2A) <- reads
s2,
   (",",s3) <- lex
s2A,
   (v3,s3A) <- reads
s3,
   (",",s4) <- lex
s3A,
   (v4,s4A) <- reads
s4,
   (",",s5) <- lex
s4A,
   (v5,s5A) <- reads
s5,
   (",",s6) <- lex
s5A,
   (v6,s6A) <- reads
s6,
   (")",s3) <- lex
s2A ])



> -Original Message-
> From: Mike Jones [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2000 14:54
> To: 'Chris Angus'
> Cc: [EMAIL PROTECTED]
> Subject: RE: Showing tuples
> 
> 
> Chris,
> 
> Yes, I do derive Show for MyData. I was surprised it did not work.
> 
> Mike
> 
> -Original Message-
> From: Chris Angus [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 09, 2000 12:57 AM
> To: 'Mike Jones'; [EMAIL PROTECTED]
> Subject: RE: Showing tuples
> 
> 
> Do you derive Show for MyData?
> 
> > -Original Message-
> > From: Mike Jones [mailto:[EMAIL PROTECTED]]
> > Sent: 09 May 2000 05:58
> > To: [EMAIL PROTECTED]
> > Subject: Showing tuples
> > 
> > 
> > Hi,
> > 
> > I am having trouble with Show and tuples.
> > 
> > I have a data structure, say:
> > 
> > data MyData = ...
> > 
> > And a value, say:
> > 
> > value = (MyData..., MyData..., MyData)
> > 
> > Then try to:
> > 
> > show value
> > 
> > I get a compiler message from ghc 4.05 that says:
> > 
> > No instance for `Show (MyData, MyData, MyData)...
> > 
> > What is the best way to deal with this problem?
> > 
> > Thanks,
> > 
> > Mike
> > 
> > 
> 
> 
> 




Re: Showing tuples

2000-05-09 Thread Sven Panne

Mike Jones wrote:
> Yes, I do derive Show for MyData. I was surprised it did not work.

Deriving works, but GHC currently only contains instance declarations
for tuples up to 5 elements, so you have to write you own boring
instances for larger ones.  *yawn*

Cheers,
   Sven
-- 
Sven PanneTel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen  Oettingenstr. 67
mailto:[EMAIL PROTECTED]D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne




RE: Showing tuples

2000-05-09 Thread Mike Jones

Chris,

Yes, I do derive Show for MyData. I was surprised it did not work.

Mike

-Original Message-
From: Chris Angus [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 09, 2000 12:57 AM
To: 'Mike Jones'; [EMAIL PROTECTED]
Subject: RE: Showing tuples


Do you derive Show for MyData?

> -Original Message-
> From: Mike Jones [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2000 05:58
> To: [EMAIL PROTECTED]
> Subject: Showing tuples
> 
> 
> Hi,
> 
> I am having trouble with Show and tuples.
> 
> I have a data structure, say:
> 
> data MyData = ...
> 
> And a value, say:
> 
> value = (MyData..., MyData..., MyData)
> 
> Then try to:
> 
> show value
> 
> I get a compiler message from ghc 4.05 that says:
> 
> No instance for `Show (MyData, MyData, MyData)...
> 
> What is the best way to deal with this problem?
> 
> Thanks,
> 
> Mike
> 
> 






Re: When is it safe to cheat?

2000-05-09 Thread Jan Skibinski



On Tue, 9 May 2000, Frank Atanassow wrote:

> Jan Skibinski writes:
>  >Any good idea? First prize: a bottle of something good. :-)
> 
> There is a thing known as an Entropy Gathering Demon (EGD). 
> 
> >From http://www.lothar.com/tech/crypto/ :

You have been nominated for the first prize, 
thank you. That's all make sense to me. Now
that I know I should blame myself for not
noticing this little daemon running all the time
on our machines. But to give others a chance
I will postpone the final announcement :-)
Jan

P.S. 
I do not have a clue as yet why my mailer mishandled
my question about sources of randomness. I thought
it was sent few days ago. Sorry if you received it twice. 
I had few hardware problems recently, the servers
were down few times. Add to it yesterday's terrifying
storm - I could not belive my eyes when I saw sparks
coming out the receptacles. What a week!



 
 






Re: When is it safe to cheat?

2000-05-09 Thread Ketil Malde

Jan Skibinski <[EMAIL PROTECTED]> writes:

> Any good idea? First prize: a bottle of something good. :-)

The easiest ought to simply have enough granularity in the
gettimeofday() or equivalent.  Sure you can guess the approximate time 
in hours or seconds, but can you guess it in micro- or nanoseconds?

(Is there a clock cycle counter on modern CPUs?  That would give you
ns resolution, on modern hardware).  Modern motherboards also have
temperature and voltage sensors - although I don't know if the
granularity is good enough.

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants




Re: When is it safe to cheat?

2000-05-09 Thread Frank Atanassow

Jan Skibinski writes:
 >  Good point. Short of reading some truly random device
 >  (perhaps ambient temperature fluctuation) this can be always
 >  theoretically defeated. I can only make life more difficult
 >  to the attacker by trying to outsmart him algoritmically
 >  (Or to confuse him. My clock is always several hours too late
 >   or too early. Just kidding)
 >   
 >  Any good idea? First prize: a bottle of something good. :-)

There is a thing known as an Entropy Gathering Demon (EGD). 

>From http://www.lothar.com/tech/crypto/ :

One of the nice features of the Linux kernel is the /dev/random
device. This is a little character device that gives you random
numbers when you read it. In a variety of places scattered
throughout the kernel, certain interrupts (network packets arriving,
keyboard hits, mouse movement) cause a timestamp and some event
information to be hashed into an "entropy pool". The pool, perhaps
4k in size, always contains very random data, but as bits are
"stirred" in, a counter is incremented to reflect the fact that the
poll is now even more random than before. When you read from
/dev/random, you get a hashed portion of the pool, and the counter
is decremented. This gives you high quality cryptographically strong
random data.

...

EGD is an Entropy Gathering Daemon meant to be used on systems that
can run GPG* but which don't have this convenient source of random
bits. It is a regular user-space program that sits around, running
programs like 'w' and 'last' and 'vmstat', collecting the randomness
(or at least the unpredictability) inherent in the output of these
system statistics programs when used on a reasonably busy system. It
slowly stirs the output of these gathering programs into a pool of
entropy, much like the linux kernel device, and allows other programs
to read out random bits from this pool.

* GPG = GNU Privacy Guard

-- 
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791





Re: When is it safe to cheat?

2000-05-09 Thread Jan Skibinski



On Tue, 2 May 2000, Keith Wansbrough wrote:

> Off-topic, I know, but even if this worked as I think you intend, 
> it would hardly be random and would certainly be unsuitable for use as a
> nonce.  Applying `mkStdGen' to the current time doesn't make it any more
> random!  You might as well use
> 
> nonce size = take size (cycle (map chr (chop_into_smaller_bits timeFrom1970)))
> 
> where chop_into_smaller_bits expresses timeFrom1970 in base 36 or something.
> 
> An attacker can certainly guess within a few seconds (= a few trials) when your 
>connection was negotiated.
> 

Good point. Short of reading some truly random device
(perhaps ambient temperature fluctuation) this can be always
theoretically defeated. I can only make life more difficult
to the attacker by trying to outsmart him algoritmically
(Or to confuse him. My clock is always several hours too late
 or too early. Just kidding)
 
Any good idea? First prize: a bottle of something good. :-)

Jan
 








RE: Showing tuples

2000-05-09 Thread Chris Angus

Do you derive Show for MyData?

> -Original Message-
> From: Mike Jones [mailto:[EMAIL PROTECTED]]
> Sent: 09 May 2000 05:58
> To: [EMAIL PROTECTED]
> Subject: Showing tuples
> 
> 
> Hi,
> 
> I am having trouble with Show and tuples.
> 
> I have a data structure, say:
> 
> data MyData = ...
> 
> And a value, say:
> 
> value = (MyData..., MyData..., MyData)
> 
> Then try to:
> 
> show value
> 
> I get a compiler message from ghc 4.05 that says:
> 
> No instance for `Show (MyData, MyData, MyData)...
> 
> What is the best way to deal with this problem?
> 
> Thanks,
> 
> Mike
> 
>