MCPcopy Create free account
hub / github.com/conflow-dev/ConFlow / EnCryptOp

Class EnCryptOp

en_ops/encrypt.cc:76–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 .Output("output: float");
75
76class EnCryptOp : public OpKernel
77{
78public:
79 explicit EnCryptOp(OpKernelConstruction *context) : OpKernel(context)
80 {
81 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
82 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
83 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
84 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
85 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
86 }
87 void Compute(OpKernelContext *context) override
88 {
89
90 const Tensor &input = context->input(0);
91 auto input_flat = input.flat<float>();
92 // check shapes of input
93 const TensorShape &input_shape = input.shape();
94 TensorShape output_shape;
95 if (input_shape.dims() == 2)
96 {
97 output_shape.AddDim(times_ * input_shape.dim_size(0));
98 output_shape.AddDim(input_shape.dim_size(1));
99 }
100 else if (input_shape.dims() == 3)
101 {
102 output_shape.AddDim(times_ * input_shape.dim_size(0));
103 output_shape.AddDim(input_shape.dim_size(1));
104 output_shape.AddDim(input_shape.dim_size(2));
105 }
106 else
107 {
108 output_shape.AddDim(times_ * input_shape.dim_size(0));
109 output_shape.AddDim(input_shape.dim_size(1));
110 output_shape.AddDim(input_shape.dim_size(2));
111 output_shape.AddDim(input_shape.dim_size(3));
112 }
113 // create output tensor
114 Tensor *output = NULL;
115 OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output));
116 auto output_flat = output->flat<float>();
117 int N = input_flat.size();
118
119 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
120 typedef void (*function)(unsigned long int eid, float *x, int N, float *y);
121 dlerror();
122 function encrypt_kernel = (function)dlsym(lib, "encrypt1");
123 const char *dlsym_error = dlerror();
124
125 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of encrypt1 failed: ", dlsym_error));
126 encrypt_kernel(eid_, (float *)input_flat.data(), N, (float *)output_flat.data());
127 };
128
129private:
130 void *lib;
131 int64 eid_low_;
132 int64 eid_high_;
133 int64 times_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected