Quadratic Sieve implementation for factorization backup, benchmark - - PowerPoint PPT Presentation

quadratic sieve implementation for factorization
SMART_READER_LITE
LIVE PREVIEW

Quadratic Sieve implementation for factorization backup, benchmark - - PowerPoint PPT Presentation

Quadratic Sieve implementation for factorization backup, benchmark and network communication Ayoub Ouarrak 26/04/2016 Universita degli studi di Parma Dipartimento di Matematica e Informatica Introduction RSA and factorization RSA is a


slide-1
SLIDE 1

Quadratic Sieve implementation for factorization

backup, benchmark and network communication

Ayoub Ouarrak 26/04/2016

Universita’ degli studi di Parma Dipartimento di Matematica e Informatica

slide-2
SLIDE 2

Introduction

slide-3
SLIDE 3

RSA and factorization

RSA is a public key cryptosystem. Each user performs the following tasks:

  • Choose p and q, large prime
  • Calculate N = pq and φ(N) = (p − 1)(q − 1)
  • Choose e ∈ Z∗

φ(N) and d ∈ Z∗ φ(N) such that ed ≡ 1 mod φ(N)

  • (N, e) is the public key
  • (φ(N), d) is the private key

To decrypt, is necessary to know e and φ(N), this means that we need to factorize N. The security of RSA relies on the difficulty of factoring N into it’s prime factors. This problem is believed to be NP.

1

slide-4
SLIDE 4

Quadratic Sieve

Integer factorization algorithm

  • Invented by C.Pomerance in 1981
  • Second fastest method known (after the general number field sieve)
  • On April 1994, the factorization of RSA-129 was completed using

QS.

2

slide-5
SLIDE 5

Quadratic Sieve algorithm

Given the number n to factorize and an upper bound B. Step 1 Create a parameter B and examine the numbers x2 - n for B-smooth values, where x runs through the integers starting at ⌊n

1 2 ⌋.

Step 2 Form the exponent vectors of B-smooth numbers, and use linear algebra to find subsequence x2

1 - n, x2 2 - n, ... , x2 t - n which has product

a square, say A2. Step 3 From the exponent vectors of the numbers x2

i - n we can produce

the prime factorization of A and find the least nonnegative residue of A mod n, say it a.

3

slide-6
SLIDE 6

Quadratic Sieve algorithm

Step 4 Find the least nonnegative residue of the product x1...xt mod n, say it b. Step 5 We have a2 ≡ b2 mod n. If a ≡ ±b mod n then compute gcd(a − b, n). Otherwise return to Step 1, find additional smooth values

  • f x2 - n, find a new linear dependency in Step 2, and repeat Step 3-4.

4

slide-7
SLIDE 7

Quadratic Sieve parallel implementation

Step 1 Master initializes the variables and the sieving range in sub intervals. Step 2 For each node, master sends the data needed to calculate the factor base and a sieving sub interval. Step 3 If a node find a solution, it sends values back to the master. Step 4 After gathering enough relations, master performs the Gaussian elimination and prints out the result and terminates nodes.

5

slide-8
SLIDE 8

Quadratic Sieve parallel implementation

What happens when this process ends in the middle of computation?

6

slide-9
SLIDE 9

Serialization

slide-10
SLIDE 10

Backup

To prevent loss of data, we need a backup system. A solution that can be used is Serialization. Serialization is the process of translating data structures or objects state into a format that can be stored (for example, in a file or memory buffer,

  • r transmitted across a network connection).

7

slide-11
SLIDE 11

Programming language support

Several object-oriented programming languages directly support objects serialization. Some of these are Ruby, Smalltalk, Python, PHP, Objective-C, Java, and the .NET family. C++ has not a direct support, we need external libraries

  • Boost
  • Cereal
  • Autoserial

8

slide-12
SLIDE 12

Kairos

slide-13
SLIDE 13

Kairos

C++ library for objects serialization

  • Simple and clean Syntax
  • Expandable library
  • Usage of Archives
  • Usage of Checkpoints to ensure serialization history

9

slide-14
SLIDE 14

Example

c l a s s F i z z : p u b l i c S e r i a l i z a b l e , p u b l i c S e r i a l i z a t i o n { p r i v a t e : f l o a t v ; i n t a ; p u b l i c : F i z z () { . . . . . r e g i s t e r O b j e c t ( t h i s , S e r i a l i z a t i o n : : TEXT) ; } void s e r i a l i z e ( Archive& a r c h i v e ) { a r c h i v e < < v < < a ; } void d e s e r i a l i z e ( Archive& a r c h i v e ) { a r c h i v e > > v > > a ; } };

10

slide-15
SLIDE 15

Steps to serialize

  • Extend Serializable and Serialization
  • Register objects, choosing serialization format between

Serialization::TEXT and Serialization::BINARY

  • Implement serialize and deserialize methods

11

slide-16
SLIDE 16

Extend Serializable and Serialization

c l a s s Object : p u b l i c S e r i a l i z a b l e , p u b l i c S e r i a l i z a t i o n

Serializable is an abstract class that offers two pure virtual methods: serialize and deserialize ”common” types. Serialization is a class thats provide methods to register objects, create checkpoints and restore objects.

12

slide-17
SLIDE 17

Objects registration

r e g i s t e r O b j e c t ( t h i s ) ; // t e x t s e r i a l i z a t i o n by d e f a u l t r e g i s t e r O b j e c t ( t h i s , S e r i a l i z a t i o n : : TEXT) ; r e g i s t e r O b j e c t ( t h i s , S e r i a l i z a t i o n : : BINARY) ;

Objects registration is necessary for the serialization process: if an object fail to register, a SerializationException is generated.

13

slide-18
SLIDE 18

serialize and deserialize methods

void s e r i a l i z e ( Archive& a r c h i v e ) { a r c h i v e < < data < < . . . ; } void d e s e r i a l i z e ( Archive& a r c h i v e ) { a r c h i v e > > data > > . . . ; }

These two methods are virtual pure functions provided by the Serializable interface, so every class thats extend this interface needs to implement the serialization methods.

14

slide-19
SLIDE 19

Create checkpoint

F i z z ∗ f i z z = new F i z z ( 2 . 3 , 5) ; t r y { S e r i a l i z a t i o n : : c r e a t e C h e c k p o i n t (& f i z z ) ; } catch ( S e r i a l i z a t i o n E x c e p t i o n ∗ exp ) { exp− >what () ; }

The method above get serialization format and calls the serialize method

  • f Fizz, passing the correct archive.

15

slide-20
SLIDE 20

Restore

t r y { auto

  • b j e c t s = S e r i a l i z a t i o n : : r e s t o r e <User >() ;
  • b j e c t 1 = o b j e c t s . at ( ” o b j e c t 1 ” )−

>get () ; } catch ( S e r i a l i z a t i o n E x c e p t i o n ∗ exp ) { exp− >what () ; }

The method above restores all objects of type User from the serialization index.

16

slide-21
SLIDE 21

Kairos Serializations

Kairos supports 4 different serializations:

  • Scalar
  • Array
  • Matrix
  • Serializable Objects

17

slide-22
SLIDE 22

Scalar

Serialization of scalar type is intuitive.

  • Write values separated by space

Deserialization works in the same way.

  • Reads values using >> operator, in this way spaces are removed

automatically. For floating point types the serialization is different, to insure a portable serialization, double and float are encapsulated into a new type using IEE745 standard: uint32 for float, and uint64 for double

18

slide-23
SLIDE 23

Array

Serialization:

  • Write array size
  • Iterate over the array and save values

Deserialization:

  • Reads array size
  • Iterate over the file and restore values

19

slide-24
SLIDE 24

Matrix

Matrix used by the Quadratic Sieve algorithm are large and quite sparse. To prevent large serialization files and to improve deserialization time, we check if the percentage of zeros is higher than a certain threshold. If the matrix is sparse, the serialization process save size of the matrix, non zero elements and their position. The deserialization process reads size of matrix, creates a zero matrix and insert the elements from the file into the matrix.

20

slide-25
SLIDE 25

Serializable Objects

c l a s s FactorBase : p u b l i c S e r i a l i z a b l e , p u b l i c S e r i a l i z a t i o n . . . . c l a s s QS : p u b l i c S e r i a l i z a b l e , p u b l i c S e r i a l i z a t i o n { FactorBase f a c t o r B a s e ; . . . . void s e r i a l i z e ( Archive& a r c h i v e ) { a r c h i v e < < f a c t o r B a s e < < . . . ; } }

21

slide-26
SLIDE 26

Serializable Objects

When we serialize QS, the serialize method of FactorBase is called first, in order to serialize all its data. After that the QS data are serialized.

22

slide-27
SLIDE 27

Benchmark

slide-28
SLIDE 28

Benchmark using cMark

We need a benchmark system to get resources usage information in order to improve the Quadratic Sieve performance. To achieve this goal a benchmark library called cMark has been developed. cMark work in two phases

  • Collect and save data into a SQLite database.
  • Read data from SQLite database and create charts.

23

slide-29
SLIDE 29

Data collection

The data collection is made by a C++ program that offers a DeviceInfo interface and a distinct implementation for each supported platform (Windows, OSX, Linux). When the program is executed, it enters a ”infinity” loop, calling OS functions to get resource information each t minutes (configurable). All data is saved in a SQLite database.

24

slide-30
SLIDE 30

Data representation

Data representation is made using web technologies

  • The layout of charts is designed using HTML/CSS
  • On the page load, a js script performs the following actions:
  • Localize the SQLite database
  • Reads all data and insert them in local vectors
  • Pass these vectors to the Chart.js library thats creates charts

cMark can be used as a normal web page or it can be packed with electron framework in order to build a native application.

25

slide-31
SLIDE 31

Chart.js memory usage example

Figure 1: Memory usage example

26

slide-32
SLIDE 32

Network communication

slide-33
SLIDE 33

MPI

The parallelism in this version of the Quadratic Sieve is achieved using the open source OpenMPI library, an implementation of the Message Passing Interface.

  • The first step is to initialize the connection between nodes and

master using MPI init that return a rank for each process of the environment.

  • Master sends all is necessary to the nodes in order to construct the

factor base.

  • For each node, Master sends a sub interval for sieving process.
  • Master remains listening for income solutions from the nodes when

it have enough data it send to the nodes the command to stop.

  • Last step is the Gaussian elimination made by the master.

27

slide-34
SLIDE 34

Conclusion

slide-35
SLIDE 35

Todo

Kairos and cMark are still in development. Several potential improvements are possible:

  • Serialization for other STL types.
  • Check endianness in binary serializations.
  • Change id generation during objects registration.
  • Other types of Archives (e.g., JSON, XML).
  • Monitoring objects state in order to make automatic checkpoints.
  • Monitor usage of other resources, in particular network

communication.

  • Load SQLite database from the network.

28

slide-36
SLIDE 36

Questions?

28