diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
commit | 9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch) | |
tree | 63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/doc/examples/ressol.cpp | |
parent | 619d92cfef29e653bfdf852e83888e50cfc4348f (diff) | |
parent | 65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/doc/examples/ressol.cpp')
-rw-r--r-- | botan/doc/examples/ressol.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/botan/doc/examples/ressol.cpp b/botan/doc/examples/ressol.cpp new file mode 100644 index 0000000..43bb68d --- /dev/null +++ b/botan/doc/examples/ressol.cpp @@ -0,0 +1,80 @@ +#include <botan/numthry.h> +#include <botan/auto_rng.h> +#include <botan/botan.h> + +using namespace Botan; + +#include <iostream> + +void test_ressol(const BigInt& p, RandomNumberGenerator& rng) + { + std::cout << p << std::endl; + + // const BigInt p_16 = p / 16; + + int noroot = 0, false_result = 0; + + for(int j = 0; j != 1000; ++j) + { + BigInt x = BigInt::random_integer(rng, 0, p); + //if(x % p_16 == 0) + //std::cout << "p = " << p << " x = " << x << "\n"; + + BigInt sqrt_x = ressol(x, p); + + if(sqrt_x < 0) + { + ++noroot; + continue; + } + + BigInt check = square(sqrt_x) % p; + + if(check != x % p) + { + std::cout << "FAIL " + << "x = " << x << "; " + << "p = " << p << "; " + << "s = " << sqrt_x << "; " + << "s^2%p = " << check << "\n"; + ++false_result; + } + } + /* + std::cout << "nomatch=" << nomatch << " " + << "noroot=" << noroot << " " + << "false=" << false_result << "\n"; + */ + } + +int main() + { + Botan::LibraryInitializer init; + AutoSeeded_RNG rng; + +#if 0 + std::cout << ressol(8, 17) << "\n"; + std::cout << ressol_orig(8, 17) << "\n"; +#endif + +#if 1 + for(int j = 16; j != 1024; ++j) + { + std::cout << "Round " << j << "\n"; + BigInt p = random_prime(rng, j); + test_ressol(p, rng); + //printf("%d\n", j); + + + } +#endif + /* + for(u32bit j = 9; j != PRIME_TABLE_SIZE; ++j) + { + std::cout << "PRIME[" << j << "] == " << PRIMES[j] << std::endl; + //printf("%d - ", PRIMES[j]); + test_ressol(PRIMES[j], rng); + //printf("\n"); + } + */ + } |