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