Introduction to the NTL Library By Proshanta Saha What is - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Introduction to the NTL Library By Proshanta Saha What is

Description:

Introduction to the NTL Library By Proshanta Saha What is NTL? NTL is a portable C++ library providing tools for: Arbitrary integer and floating point arithmetic ... – PowerPoint PPT presentation

Number of Views:142
Avg rating:3.0/5.0
Slides: 25
Provided by: eceGmuEdu6
Category:

less

Transcript and Presenter's Notes

Title: Introduction to the NTL Library By Proshanta Saha What is


1
Introduction to the NTL Library
  • By Proshanta Saha

2
What is NTL?
  • NTL is a portable C library providing tools
    for
  • Arbitrary integer and floating point arithmetic
  • Polynomial Arithmetic
  • Lattice basis reduction
  • Basic linear algebra
  • Allows user to implement math functions into
    their environment effortlessly.

3
Why NTL?
  • Freely available
  • Supports IEEE standards, thus accuracy can be
    measured well.
  • Has one of the fastest Polynomial Arithmetic
    capability
  • Has one of the best implementations of Lattice
    Reduction
  • Portable, and thus can be used in virtually any
    platform with minimal alterations.

4
Large Integers in NTL
  • The ZZ library is provided to perform large
    integer arithmetic.
  • Here is quick example on how to use the ZZ
    interface
  • This program reads two big integers a and b, and
    prints (a1)(b1).
  • include ltNTL/ZZ.hgt
  • int main()
  • ZZ a, b, c
  • cin gtgt a
  • cin gtgt b
  • c (a1)(b1)
  • cout ltlt c ltlt "\n"
  • return 0

5
Available Libraries
  • GF2 class GF2 integers mod 2
  • GF2X class GF2X polynomials over GF(2) (much
    more efficient than using zz_pX with p2)
    includes routines for GCDs and minimal
    polynomials
  • GF2XFactoring routines for factoring polynomials
    over GF(2) also includes routines for testing
    for and constructing irreducible polynomials
  • GF2XVec class GF2XVec fixed-length vectors of
    fixed-length GF2Xs less flexible, but more
    efficient than vec_GF2X
  • GF2E class GF2E polynomial extension field/ring
    over GF(2), implemented as GF(2)X/(P).
  • GF2EX class GF2EX class GF2EX polynomials over
    GF2E includes routines for modular polynomials
    arithmetic, modular composition, minimal and
    characteristic polynomials, and interpolation.
  • GF2EXFactoring routines for factoring polynomials
    over GF2E also includes routines for testing for
    and constructing irreducible polynomials
  • HNF routines for computing the Hermite Normal
    Form of a lattice
  • LLL routines for performing lattice basis
    reduction, including very fast and robust
    implementations of the Schnorr-Euchner LLL and
    Block Korkin Zolotarev reduction algorithm, as
    well as an integer-only reduction algorithm.
    Also, there are routines here for computing the
    kernel and image of an integer matrix, as well as
    finding integer

6
Available Libraries (cont.)
  • solutions to linear systems of equations over the
    integers.
  • RR class RR arbitrary-precision floating point
    numbers.
  • ZZ class ZZ arbitrary length integers includes
    routines for GCDs, Jacobi symbols, modular
    arithmetic, and primality testing also includes
    small prime generation routines and in-line
    routines for single-precision modular arithmetic
  • ZZVec class ZZVec fixed-length vectors of
    fixed-length ZZs less flexible, but more
    efficient than vec_ZZ
  • ZZX class ZZX polynomials over ZZ includes
    routines for GCDs, minimal and characteristic
    polynomials, norms and traces
  • ZZXFactoring routines for factoring univariate
    polynomials over ZZ
  • ZZ_p class ZZ_p integers mod p
  • ZZ_pE class ZZ_pE ring/field extension of ZZ_p
  • ZZ_pEX class ZZ_pEX polynomials over ZZ_pE
    includes routines for modular polynomials
    arithmetic, modular composition, minimal and
    characteristic polynomials, and interpolation.
  • ZZ_pEXFactoring routines for factoring
    polynomials over ZZ_pE also includes routines
    for testing for and constructing irreducible
    polynomials
  • ZZ_pX class ZZ_pX polynomials over ZZ_p
    includes routines for modular polynomials
    arithmetic, modular composition, minimal and
    characteristic polynomials, and interpolation.

7
Available Libraries (cont.)
  • ZZ_pXFactoring routines for factoring polynomials
    over ZZ_p also includes routines for testing for
    and constructing irreducible polynomials
  • lzz_p class zz_p integers mod p, where p is
    single-precision
  • lzz_pE class zz_pE ring/field extension of zz_p
  • lzz_pEX class zz_pEX polynomials over zz_pE
    provides the same functionality as class ZZ_pEX,
    but for single-precision p
  • lzz_pEXFactoring routines for factoring
    polynomials over zz_pE provides the same
    functionality as class ZZ_pEX, but for
    single-precision p
  • lzz_pX class zz_pX polynomials over zz_p
    provides the same functionality as class ZZ_pX,
    but for single-precision p
  • lzz_pXFactoring routines for factoring
    polynomials over zz_p provides the same
    functionality as class ZZ_pX, but for
    single-precision p
  • matrix template-like macros for dynamic-size
    2-dimensional arrays
  • mat_GF2 class mat_GF2 matrices over GF(2)
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_GF2E class mat_GF2E matrices over GF2E
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_RR class mat_RR matrices over RR includes
    basic matrix arithmetic operations, including
    determinant calculation, matrix inversion, and
    solving nonsingular systems of linear equations.

8
Available Libraries (cont.)
  • mat_ZZ class mat_ZZ matrices over ZZ includes
    basic matrix arithmetic operations, including
    determinant calculation, matrix inversion, and
    solving nonsingular systems of linear equations.
    See also the LLL module for additional routines.
  • mat_ZZ_p class mat_ZZ_p matrices over ZZ_p
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_ZZ_pE class mat_ZZ_pE matrices over ZZ_pE
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_lzz_p class mat_zz_p matrices over zz_p
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_lzz_pE class mat_zz_pE matrices over zz_pE
    includes basic matrix arithmetic operations,
    including determinant calculation, matrix
    inversion, solving nonsingular systems of linear
    equations, and Gaussian elimination
  • mat_poly_ZZ routine for computing the
    characteristic polynomial of a mat_ZZ
  • mat_poly_ZZ_p routine for computing the
    characteristic polynomial of a mat_ZZ_p
  • mat_poly_lzz_p routine for computing the
    characteristic polynomial of a mat_zz_p
  • pair template-like macros for pairs
  • quad_float class quad_float quadruple-precision
    floating point numbers.
  • tools some basic types and utility routines,
    including the timing function GetTime(), and
    several overloaded versions of min() and max()
  • vector template-like macros for dynamic-size
    vectors

9
Available Libraries (cont.)
  • vec_GF2 class vec_GF2 vectors over GF(2), with
    arithmetic
  • vec_GF2E class vec_GF2E vectors over GF2E, with
    arithmetic
  • vec_RR class vec_RR vectors over RR, with
    arithmetic
  • vec_ZZ class vec_ZZ vectors over ZZ, with
    arithmetic
  • vec_ZZ_p class vec_ZZ_p vectors over ZZ_p, with
    arithmetic
  • vec_ZZ_pE class vec_ZZ_pE vectors over ZZ_pE,
    with arithmetic
  • vec_lzz_p class vec_zz_p vectors over zz_p, with
    arithmetic
  • vec_lzz_pE class vec_zz_pE vectors over zz_pE,
    with arithmetic
  • version macros defining the NTL version number
  • xdouble class xdouble double-precision floating
    point numbers with extended exponent range.

10
Installing NTL
  • Because of the portability of library, it can be
    easily modified and packaged for a new platform.
  • This presentation will focus mainly on the
    windows platform
  • Windows NTL version 5.3
  • config.h file in include directory determines the
    mode of the C compiler
  • Traditional, for older C compiler
  • ISO, for newer C compilers

11
Compiling NTL
  • For the Windows Platform the configuration will
    have to be changed manually in configh.h
  • Microsoft Visual C compiler warning
  • Still does not implement namespaces consistently
  • ISO compatibility still in question
  • Traditional mode works correctly

12
Compiling under Visual C 6
  • Create a windows static library first
  • Compile all the src files into a .lib file
  • Remember to place headers in pre-compiler include
    path
  • Once you have the .lib file you are now ready to
    use the interfaces provided by NTL.
  • Remember to include the .lib file as part of the
    project

13
Result of Quick Test
  • This is NTL version 5.3
  • configuration flags
  • test is OK
  • time for 1024-bit mul 129.2us
  • time for 2048/1024-bit rem 184.75us
  • time for 1024-bit modular inverse 1732us
  • time to multiply degree 1023 polynomials
  • modulo a 1024-bit number 2.734s

14
Libraries of Interest
  • The ZZ libraries provides support for handling
    large integers
  • ZZ type allows for large integers
  • ZZX type allows for large polynomials
  • ZZ_p type allows for modulus operations
  • The GF libraries has the exact same support but
    with the efficiency for mod 2 operations

15
Functions of Interest (cont.)
  • All the libraries implements
  • add, sub, negage, mul, sqr, div, rem, DivRem,
    LeftShift, RightShift, bit_and, bit_or, bit_xor
  • In addition to overloading the C operators.

16
Examples
  • To perform large integer arithmetic
  • Include ltNTL\ZZ.hgt
  • Accepted input is a long string of decimals, hex
    does not seem to be supported.
  • Example code
  • coutltlt"Please enter large integer\n"
  • ZZ a
  • cingtgta
  • coutltlt"a has the value "ltlta ltltendl
  • Output
  • Please enter large integer
  • 99999999999999999999999999999023332112312312312312
    3123
  • a has the value 9999999999999999999999999999902333
    21123123123123123123

17
Examples (cont.)
  • Example
  • coutltlt"This program will compute ab\n"
  • coutltlt"Please enter large integer a\n"
  • ZZ a
  • cingtgta
  • coutltlt"Please enter large integer b\n"
  • ZZ b
  • cingtgtb
  • coutltlt"The result is "ltlt ab ltltendl
  • Output
  • This program will compute ab
  • Please enter large integer a
  • 99999999999999999999999999999900000000000001
  • Please enter large integer b
  • 11111111111111111111111111111133333333333333
  • The result is 111111111111111111111111111111033333
    333333334

18
Examples (cont.)
  • Example
  • coutltlt"This program will compute ab\n"
  • coutltlt"Please enter large integer a\n"
  • ZZ a
  • cingtgta
  • coutltlt"Please enter large integer b\n"
  • ZZ b
  • cingtgtb
  • add(a, a, b)
  • coutltlt"The result is "ltlt a ltltendl
  • Output
  • This program will compute ab
  • Please enter large integer a
  • 1111111111111111111111111111111111000002
  • Please enter large integer b
  • 3333333333333333333333333333333333000030
  • The result is 444444444444444444444444444444444400
    0032

19
Examples (cont.)
  • Modular arithmetic
  • use for xa mod b use either or mod(x, a, b)
  • Basic arithmetic
  • for xab use either or add(ZZ x, const ZZ a,
    const ZZ b)
  • for xa-b use either or sub(ZZ x, const ZZ a,
    const ZZ b)
  • for xa/b use either / or div(ZZ x, const ZZ a,
    const ZZ b)
  • for x (ab)n use AddMod(ZZ x, const ZZ a,
    const ZZ b, const ZZ n)

20
Examples (cont.)
  • Basic arithmetic (cont.)
  • for x (a-b)n use SubMod(ZZ x, const ZZ a,
    const ZZ b, const ZZ n)
  • for x (ab)n use MulMod(ZZ x, const ZZ a,
    const ZZ b, const ZZ n)
  • for x a2 n use SqrMod(ZZ x, const ZZ a,
    const ZZ n)
  • for a-1 mod n use InvMod(ZZ x, const ZZ a,
    const ZZ n)
  • for a-1 mod n use InvMod(ZZ x, const ZZ a,
    const ZZ n)

21
Examples (cont.)
  • NTL also has libraries that have been optimized
    for performing For GF2 (mod 2 operations).
  • These libraries are similar in function to the ZZ
    library (i.e. ZZ_p where p2) but are optimized
    for mod 2 operations.
  • The libraries available are GF2 for large integer
    calculations, GF2X for large polynomial
    calculations, and GF2EX for extensions to the
    field ie GF(2m) operations

22
Examples (cont.)
  • Performing GF(2m) based arithmetic, is very
    similar in interface to the ZZ functions take for
    example
  • for x a b, use add(GF2EX x, const GF2EX a,
    const GF2EX b)
  • for x a - b, use sub(GF2EX x, const GF2EX a,
    const GF2EX b)
  • In short, the same functions available for the ZZ
    libraries, are also implemented for the GF
    libraries

23
Examples (cont.)
  • Example
  • BuildIrred(p, 512)
  • GF2Einit(p)
  • GF2EX A, B, C, C1
  • random(A, 512)
  • random(B, 512)
  • double t
  • t GetTime()
  • PlainMul(C, A, B)
  • t GetTime() - t
  • cerr ltlt "time for plain mul of degree 511 over
    GF(2512) " ltlt t ltlt "s\n"
  • Output
  • time for plain mul of degree 511 over GF(2512)
    11.446s

24
References
  • A complete reference to the NTL library and how
    to install it in several different platforms as
    well as some examples on how to use the various
    library components can be found at
    http//www.shoup.net/ntl/
Write a Comment
User Comments (0)
About PowerShow.com