00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00030 #if !defined(_TIFA_FACTORING_MACHINE_H_)
00031 
00035 #define _TIFA_FACTORING_MACHINE_H_
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 #include <stdbool.h>
00042 #include <gmp.h>
00043 
00044 #include "array.h"
00045 #include "exit_codes.h"
00046 
00053 enum factoring_mode_enum {
00057     SINGLE_RUN,
00062     FIND_SOME_FACTORS,
00068     FIND_SOME_COPRIME_FACTORS,
00078     FIND_SOME_PRIME_FACTORS,
00084     FIND_COMPLETE_FACTORIZATION
00085 };
00090 typedef enum factoring_mode_enum factoring_mode_t;
00091 
00096 static const int mode_to_outcome[5] = {
00097     SOME_FACTORS_FOUND,
00098     SOME_FACTORS_FOUND,
00099     SOME_COPRIME_FACTORS_FOUND,
00100     SOME_PRIME_FACTORS_FOUND,
00101     COMPLETE_FACTORIZATION_FOUND
00102 };
00103 
00118 struct struct_factoring_machine {
00122     mpz_t n;
00126     factoring_mode_t mode;
00132     void* context;
00138     void* params;
00145     ecode_t (*init_context_func)   (struct struct_factoring_machine* const);
00154     ecode_t (*perform_algo_func)   (struct struct_factoring_machine* const);
00164     ecode_t (*update_context_func) (struct struct_factoring_machine* const);
00172     ecode_t (*clear_context_func)  (struct struct_factoring_machine* const);
00184     ecode_t (*recurse_func) (mpz_array_t* const,
00185                              uint32_array_t* const,
00186                              const mpz_t,
00187                              factoring_mode_t);
00191     mpz_array_t* factors;
00196     uint32_array_t* multis;
00204     bool success;
00205 };
00210 typedef struct struct_factoring_machine factoring_machine_t;
00211 
00223 ecode_t run_machine(factoring_machine_t* machine);
00224 
00225 #ifdef __cplusplus
00226 }
00227 #endif
00228 
00229 #endif
00230