def test_all(args, obfuscate): success = True if not os.path.isdir(args.test_all): print("%s '%s' is not a valid directory" % (errorstr, args.test_all)) sys.exit(1) ext = '.circ' for circuit in os.listdir(args.test_all): path = os.path.join(args.test_all, circuit) if os.path.isfile(path) and path.endswith(ext): success &= test_file(path, obfuscate, args) if os.path.isfile(path) and path.endswith('.json'): success &= test_file(path, obfuscate, args, formula=False) return success
def obf(args): if args.mmap not in ('CLT', 'GGH', 'DUMMY'): print('--mmap must be either CLT, GGH, or DUMMY') sys.exit(1) success = True try: if args.test: formula = is_formula(args.test, args) success = test_file(args.test, True, args, formula=formula) elif args.test_all: success = test_all(args, True) else: directory = None if args.load_obf: directory = args.load_obf elif args.load: formula = is_formula(args.load, args) start = time.time() obf = SZObfuscator(args.mmap, base=args.base, verbose=args.verbose, nthreads=args.nthreads, ncores=args.ncores) directory = args.save if args.save \ else '%s.obf.%d' % (args.load, args.secparam) obf.obfuscate(args.load, args.secparam, directory, kappa=args.kappa, formula=formula, randomization=(not args.no_randomization), seed=args.seed) end = time.time() print('Obfuscation took: %f seconds' % (end - start)) else: print('%s One of --load-obf, --load, or ' '--test must be used' % errorstr) sys.exit(1) if args.eval: assert directory obf = SZObfuscator(args.mmap, base=args.base, verbose=args.verbose, nthreads=args.nthreads, ncores=args.ncores) r = obf.evaluate(directory, args.eval) print('Output = %d' % r) except ParseException as e: print('%s %s' % (errorstr, e)) sys.exit(1) return success
def bp(args): success = True try: if args.test: success = test_file(args.test, False, args) elif args.test_all: success = test_all(args, False) elif args.load: formula = is_formula(args.load, args) bp = SZBranchingProgram(args.load, base=args.base, verbose=args.verbose, formula=formula) if args.print: print(bp) if args.eval: r = bp.evaluate(args.eval) print('Output = %d' % r) except ParseException as e: print('%s %s' % (errorstr, e)) sys.exit(1) return success