Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] primality test for Big_int ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-09-01 (13:34)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] primality test for Big_int ?
> I was implementing a modular GCD algorithm for polynomial with
> big_int coefficients when I've discovered that there isn't any
> primality test in the Nums library.
> Someone can help me about this question ?

The Cryptokit library (
contains an implementation of probabilistic primality testing,
as part of RSA key generation.  

The function is called "is_pseudoprime" and it's not exported, but it
shouldn't be hard to extract it from the sources.  It operates on type
"nat", so you'll have to stick a "Big_int.nat_of_big_int" conversion
on input.

The algorithm used is that of PGP 2.6: Fermat tests against 8 small
primes.  While not as sophisticated as Miller-Rabin, this test seems
good enough for PGP, so it's good enough for me :-)

> If possible I would avoid to implement a primality test by myself because
> - I have to study the Rabin-Miller test
> - I have to implement it in C to obtain a good speed (maybe ?)

No need for C: Caml code working at the "nat" level (hand-allocated
big natural integers) is plenty fast enough.

- Xavier Leroy

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: