00001 #ifndef RSA_CONTEXT_MP_HH
00002 #define RSA_CONTEXT_MP_HH
00003
00004 #include "rsa_context.hh"
00005 #include "mp_modexp.h"
00006 #include "device_context.hh"
00007
00008 #include <cuda_runtime.h>
00009 #include <cutil_inline.h>
00010
00017 class rsa_context_mp : public rsa_context
00018 {
00019 public:
00026 rsa_context_mp(int keylen);
00027
00036 rsa_context_mp(const std::string &filename, const std::string &passwd);
00037
00046 rsa_context_mp(const char *filename, const char *passwd);
00047
00048 virtual ~rsa_context_mp();
00049
00050 virtual void dump();
00051
00061 virtual void priv_decrypt(unsigned char *out, int *out_len,
00062 const unsigned char *in, int in_len);
00063
00074 virtual void priv_decrypt_batch(unsigned char **out, int *out_len,
00075 const unsigned char **in, const int *in_len,
00076 int n);
00077
00090 void priv_decrypt_stream(unsigned char **out, int *out_len,
00091 const unsigned char **in, const int *in_len,
00092 int n, unsigned int stream_id);
00093
00107 bool sync(unsigned int stream_id, bool block = true, bool copy_result = true);
00108
00109 static const unsigned int max_stream = MAX_STREAMS;
00110
00117 void set_device_context(device_context *dev_ctx) {dev_ctx_ = dev_ctx;};
00118
00119 protected:
00120
00121 private:
00122 void gpu_setup();
00123
00124
00125 cudaEvent_t begin_evt;
00126 cudaEvent_t end_evt;
00127 device_context *dev_ctx_;
00128
00129 struct {
00130 bool post_launched;
00131
00132 unsigned char **out;
00133 int *out_len;
00134 int n;
00135
00136 WORD *a;
00137 WORD *ret;
00138 WORD *dbg;
00139
00140 WORD *a_d;
00141 WORD *ret_d;
00142 WORD *dbg_d;
00143 } streams[max_stream + 1];
00144
00145 struct mp_sw *sw_d;
00146 WORD *n_d;
00147 WORD *np_d;
00148 WORD *r_sqr_d;
00149 WORD *iqmp_d;
00150
00151 WORD mp_e[2][MAX_S];
00152 WORD mp_n[2][MAX_S];
00153 WORD mp_np[2][MAX_S];
00154 WORD mp_r_sqr[2][MAX_S];
00155 WORD mp_iqmp[MAX_S];
00156
00157 BIGNUM *r;
00158 BIGNUM *r_inv[2];
00159
00160 BIGNUM *in_bn_p;
00161 BIGNUM *in_bn_q;
00162 BIGNUM *out_bn_p;
00163 BIGNUM *out_bn_q;
00164 };
00165
00166 #endif