Util.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.oblivm.backend.lang.inter;
  2. import java.lang.reflect.Array;
  3. import java.util.Arrays;
  4. import com.oblivm.backend.circuits.arithmetic.IntegerLib;
  5. import com.oblivm.backend.flexsc.CompEnv;
  6. import com.oblivm.backend.oram.SecureArray;
  7. public class Util {
  8. public static <T> T[][] intToArray(T[] intInput, int bitSize, int arraySize) {
  9. @SuppressWarnings("unchecked")
  10. T[][] ret = (T[][]) Array.newInstance((Class<T>) intInput[0].getClass(), arraySize, bitSize);
  11. for (int i = 0; i < arraySize; ++i) {
  12. for (int j = 0; j < bitSize; ++j) {
  13. ret[i][j] = intInput[i * bitSize + j];
  14. }
  15. }
  16. return ret;
  17. }
  18. public static <T> SecureArray<T> intToSecArray(CompEnv<T> env, T[] intInput, int bitSize, int arraySize)
  19. throws Exception {
  20. SecureArray<T> secArray = new SecureArray<T>(env, arraySize, bitSize);
  21. IntegerLib<T> intLib = new IntegerLib<T>(env);
  22. for (int i = 0; i < arraySize; ++i) {
  23. secArray.write(intLib.toSignals(i), Arrays.copyOfRange(intInput, i * bitSize, (i + 1) * bitSize));
  24. }
  25. // for(int i=0; i<arraySize; ++i) {
  26. // System.out.println("Input["+i+"] =
  27. // "+Utils.toInt(env.outputToAlice(secArray.read(intLib.toSignals(i)))));
  28. // }
  29. return secArray;
  30. }
  31. }