def main(inputSDLScheme, configName, outputFile, outputUserDefFile): config = importlib.import_module(configName) # pkg.config SDLParser.masterPubVars = config.masterPubVars SDLParser.masterSecVars = config.masterSecVars SDLParser.generators = config.generators if hasattr(config, userFuncListName): userFuncList = getattr(config, userFuncListName) else: userFuncList = [] SDLPreProcessor.SDLPreProcessor_main(inputSDLScheme, inputSDLScheme + PREPROCESSED_STRING, config) startTime = time.clock() (linesOfCodeFromKeygen, blindingFactors_NonLists, blindingFactors_Lists) = keygen(inputSDLScheme + PREPROCESSED_STRING, config) endTime = time.clock() runningTime = (endTime - startTime) * 1000 #print("running time for keygen is ", runningTime) writeLOCFromKeygenToFile(linesOfCodeFromKeygen, inputSDLScheme + PREPROCESSED_STRING, config) cleanParseLinesOfCode() startTime = time.clock() codegen_PY.codegen_PY_main(inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".py", outputUserDefFile + ".py") endTime = time.clock() runningTime = (endTime - startTime) * 1000 #print("running time for codegen python is ", runningTime) codegen_CPP.transformOutputList = transformOutputList startTime = time.clock() codegen_CPP.codegen_CPP_main(inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".cpp", userFuncList) endTime = time.clock() runningTime = (endTime - startTime) * 1000
def configAutoStrong(dest_path, sdl_file, config_file, output_file, verbose, benchmarkOpt, skip_transform): # get full path (assuming not provided) full_config_file = os.path.abspath(config_file) pkg_name = os.path.basename(full_config_file) cm = imp.load_source(pkg_name, full_config_file) # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit("configAutoStrong: need to set 'schemeType' in config.") if cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: funcOrder = [ cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName ] setattr(cm, functionOrder, funcOrder) for i in configParams: if not hasattr(cm, i): errorOut(i) if hasattr(cm, "userFuncList"): userFuncList = cm.userFuncList else: userFuncList = [] print("function order: ", cm.functionOrder) testForSUCMA = False option = {} option[skipTransform] = skip_transform option['userFuncList'] = userFuncList startTime = time.clock() strong_sdl = runAutoStrong(sdl_file, cm, option, verbose) endTime = time.clock() new_input_sdl = strong_sdl new_output_sdl = dest_path + output_file if benchmarkOpt: runningTime = (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", option['userFuncList']) if not benchmarkOpt: codegen_CPP.codegen_CPP_main(new_input_sdl, new_output_sdl + ".cpp", option['userFuncList']) codegen_PY.codegen_PY_main(new_input_sdl, new_output_sdl + ".py", new_output_sdl + "User.py") return
def buildSDLBatchVerifier(opts, sdlOutFile, sdl_data, types, verify2, batch_precompute, var_count, setting): """constructs the SDL batch verifier""" dest_path = opts['path'] if sdlOutFile == None: sdlOutFile = types['name'] + "-full-batch" codeOutfile = dest_path + types['name'] + "Batch" sdlBatch = SDLBatch(sdlOutFile, sdl_data, types, verify2, batch_precompute, var_count, setting) sdlBatch.construct(VERBOSE) # write out in current directory: TODO => add 'path' to command line options codegen_CPP.codegen_CPP_main(sdlOutFile, codeOutfile + ".cpp", []) # small exp built-in in CPP codegen_PY.codegen_PY_main(sdlOutFile, codeOutfile + ".py", codeOutfile + "User.py", {'NumSigs':True, 'SmallExp':True}) return sdlBatch.getVariableCount()
def configAutoStrong(dest_path, sdl_file, config_file, output_file, verbose, benchmarkOpt, skip_transform): # get full path (assuming not provided) full_config_file = os.path.abspath(config_file) pkg_name = os.path.basename(full_config_file) cm = imp.load_source(pkg_name, full_config_file) # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit("configAutoStrong: need to set 'schemeType' in config.") if cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: funcOrder = [cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName] setattr(cm, functionOrder, funcOrder) for i in configParams: if not hasattr(cm, i): errorOut(i) if hasattr(cm, "userFuncList"): userFuncList = cm.userFuncList else: userFuncList = [] print("function order: ", cm.functionOrder) testForSUCMA = False option = {} option[skipTransform] = skip_transform option['userFuncList'] = userFuncList startTime = time.clock() strong_sdl = runAutoStrong(sdl_file, cm, option, verbose) endTime = time.clock() new_input_sdl = strong_sdl new_output_sdl = dest_path + output_file if benchmarkOpt: runningTime = (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", option['userFuncList']) if not benchmarkOpt: codegen_CPP.codegen_CPP_main(new_input_sdl, new_output_sdl + ".cpp", option['userFuncList']) codegen_PY.codegen_PY_main(new_input_sdl, new_output_sdl + ".py", new_output_sdl + "User.py") return
def main(inputSDLScheme, configName, outputFile, outputUserDefFile): config = importlib.import_module(configName) # pkg.config SDLParser.masterPubVars = config.masterPubVars SDLParser.masterSecVars = config.masterSecVars SDLParser.generators = config.generators if hasattr(config, userFuncListName): userFuncList = getattr(config, userFuncListName) else: userFuncList = [] SDLPreProcessor.SDLPreProcessor_main(inputSDLScheme, inputSDLScheme + PREPROCESSED_STRING, config) startTime = time.clock() (linesOfCodeFromKeygen, blindingFactors_NonLists, blindingFactors_Lists) = keygen( inputSDLScheme + PREPROCESSED_STRING, config ) endTime = time.clock() runningTime = (endTime - startTime) * 1000 # print("running time for keygen is ", runningTime) writeLOCFromKeygenToFile(linesOfCodeFromKeygen, inputSDLScheme + PREPROCESSED_STRING, config) cleanParseLinesOfCode() startTime = time.clock() codegen_PY.codegen_PY_main( inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".py", outputUserDefFile + ".py" ) endTime = time.clock() runningTime = (endTime - startTime) * 1000 # print("running time for codegen python is ", runningTime) codegen_CPP.transformOutputList = transformOutputList startTime = time.clock() codegen_CPP.codegen_CPP_main( inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".cpp", userFuncList ) endTime = time.clock() runningTime = (endTime - startTime) * 1000
def compileBV(inputSDLScheme, outputFile, outputUserDefFile): # (linesOfCodeFromKeygen, blindingFactors_NonLists, blindingFactors_Lists) = keygen(inputSDLScheme) # writeLOCFromKeygenToFile(linesOfCodeFromKeygen, inputSDLScheme) codegen_PY.codegen_PY_main(inputSDLScheme, outputFile, outputUserDefFile)
def configAutoGroup(dest_path, sdl_file, config_file, output_file, verbose, benchmarkOpt, estimateOpt, shortOpt, run_auto_group): runningTime = 0 # get full path (assuming not provided) full_config_file = os.path.abspath(config_file) pkg_name = os.path.basename(full_config_file) try: cm = imp.load_source(pkg_name, full_config_file) except: sys.exit("Missing config file: %s" % full_config_file) #check if gen visual dep graph if hasattr(cm, "graphit"): graphit = cm.graphit else: graphit = False # disable splitting of pk into spk/vpk cm.enablePKprune = False if shortOpt: # overrides the one in the cm cm.short = shortOpt if cm.short not in SHORT_OPTIONS: sys.exit("You specified an invalid option.\nValid ones: " + str(SHORT_OPTIONS)) else: print("Running with short = ", cm.short) #parse assumption arguments if not hasattr(cm, "assumption") or run_auto_group: print("No assumption or specifically running the original AutoGroup") #sys.exit("configAutoGroup: need to set 'assumption' in config.") #TODO: add back in when finished and remove else # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit("configAutoGroup: need to set 'schemeType' in config.") if cm.schemeType == PKENC and getattr(cm, functionOrder, None) == None: funcOrder = [ cm.setupFuncName, cm.keygenFuncName, cm.encryptFuncName, cm.decryptFuncName ] setattr(cm, functionOrder, funcOrder) elif cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: if (hasattr(cm, "setupFuncName")): funcOrder = [ cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName ] else: funcOrder = [ cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName ] setattr(cm, functionOrder, funcOrder) print("function order: ", cm.functionOrder) if cm.schemeType == PKENC: for i in encConfigParams: if not hasattr(cm, i): errorOut(i) elif cm.schemeType == PKSIG: for i in sigConfigParams: if not hasattr(cm, i): errorOut(i) if not hasattr(cm, "secparam"): secparam = "BN256" # default pairing curve for now else: # need to check this against possible curve types secparam = cm.secparam dropFirst = None if hasattr(cm, "dropFirst"): dropFirst = cm.dropFirst options = { 'secparam': secparam, 'userFuncList': [], 'computeSize': estimateOpt, 'dropFirst': dropFirst, 'path': dest_path, 'graphit': graphit } cm.forAutoGroupPlus = False startTime = time.clock() outfile_scheme = runAutoGroupOld(sdl_file, cm, options, verbose) endTime = time.clock() if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) new_input_sdl = outfile_scheme new_output_sdl = output_file # JAA: commented out for benchmark purposes if verbose: print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", options['userFuncList']) if not benchmarkOpt: # generate the source code in the target path codegen_CPP.codegen_CPP_main(dest_path + new_input_sdl, dest_path + new_output_sdl + ".cpp", options['userFuncList']) codegen_PY.codegen_PY_main(dest_path + new_input_sdl, dest_path + new_output_sdl + ".py", new_output_sdl + "User.py") return else: #assumptionData = [] assumptionData = {} for i in cm.assumption: assumptionFile = os.path.dirname( full_config_file ) + "/" + i + ".sdl" #TODO: how to determine location of assumption SDL file?? startTime = time.clock() assumptionFileParseRun = parseAssumptionFile( cm, assumptionFile, verbose, benchmarkOpt, estimateOpt) endTime = time.clock() #assumptionData.append(assumptionFileParseRun) assumptionData[i] = assumptionFileParseRun if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") setattr(cm, functionOrder, None) #parse reduction arguments if not hasattr(cm, "reduction"): print("No reduction specified") sys.exit( "configAutoGroup: assumption set; need to set 'reduction' in config." ) #TODO: add back in when finished and remove else else: print(cm.reduction) if len(cm.reduction) == 1: cm.single_reduction = True else: cm.single_reduction = False #reductionData = [] reductionData = {} for i in cm.reduction: reductionFile = os.path.dirname( full_config_file ) + "/" + i + ".sdl" #TODO: how to determine location of reduction SDL file?? startTime = time.clock() reductionFileParseRun = parseReductionFile( cm, reductionFile, verbose, benchmarkOpt, estimateOpt) endTime = time.clock() #reductionData.append(reductionFileParseRun) reductionData[i] = reductionFileParseRun if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") setattr(cm, functionOrder, None) # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit( "configAutoGroup: need to set 'schemeType' in config.") if cm.schemeType == PKENC and getattr(cm, functionOrder, None) == None: funcOrder = [ cm.setupFuncName, cm.keygenFuncName, cm.encryptFuncName, cm.decryptFuncName ] setattr(cm, functionOrder, funcOrder) elif cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: if (hasattr(cm, "setupFuncName")): funcOrder = [ cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName ] else: funcOrder = [ cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName ] setattr(cm, functionOrder, funcOrder) if cm.schemeType == PKENC: for i in encConfigParams: if not hasattr(cm, i): errorOut(i) elif cm.schemeType == PKSIG: for i in sigConfigParams: if not hasattr(cm, i): errorOut(i) if not hasattr(cm, "secparam"): secparam = "BN256" # default pairing curve for now else: secparam = cm.secparam dropFirst = None if hasattr(cm, "dropFirst"): dropFirst = cm.dropFirst options = { 'secparam': secparam, 'userFuncList': [], 'computeSize': estimateOpt, 'dropFirst': dropFirst, 'path': dest_path, 'graphit': graphit } cm.forAutoGroupPlus = True startTime = time.clock() (outfile_scheme, outfile_assump) = runAutoGroup(sdl_file, cm, options, verbose, assumptionData, reductionData) endTime = time.clock() if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) new_input_sdl = outfile_scheme new_output_sdl = output_file # JAA: commented out for benchmark purposes if verbose: print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", options['userFuncList']) if not benchmarkOpt: codegen_CPP.codegen_CPP_main( new_input_sdl, dest_path + new_output_sdl + ".cpp", options['userFuncList']) codegen_PY.codegen_PY_main(new_input_sdl, dest_path + new_output_sdl + ".py", new_output_sdl + "User.py") return
def configAutoGroup(dest_path, sdl_file, config_file, output_file, verbose, benchmarkOpt, estimateOpt, shortOpt, run_auto_group): runningTime = 0 # get full path (assuming not provided) full_config_file = os.path.abspath(config_file) pkg_name = os.path.basename(full_config_file) try: cm = imp.load_source(pkg_name, full_config_file) except: sys.exit("Missing config file: %s" % full_config_file) #check if gen visual dep graph if hasattr(cm, "graphit"): graphit = cm.graphit else: graphit = False # disable splitting of pk into spk/vpk cm.enablePKprune = False if shortOpt: # overrides the one in the cm cm.short = shortOpt if cm.short not in SHORT_OPTIONS: sys.exit("You specified an invalid option.\nValid ones: " + str(SHORT_OPTIONS)) else: print("Running with short = ", cm.short) #parse assumption arguments if not hasattr(cm, "assumption") or run_auto_group: print("No assumption or specifically running the original AutoGroup") #sys.exit("configAutoGroup: need to set 'assumption' in config.") #TODO: add back in when finished and remove else # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit("configAutoGroup: need to set 'schemeType' in config.") if cm.schemeType == PKENC and getattr(cm, functionOrder, None) == None: funcOrder = [cm.setupFuncName, cm.keygenFuncName, cm.encryptFuncName, cm.decryptFuncName] setattr(cm, functionOrder, funcOrder) elif cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: if(hasattr(cm, "setupFuncName")): funcOrder = [cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName] else: funcOrder = [cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName] setattr(cm, functionOrder, funcOrder) print("function order: ", cm.functionOrder) if cm.schemeType == PKENC: for i in encConfigParams: if not hasattr(cm, i): errorOut(i) elif cm.schemeType == PKSIG: for i in sigConfigParams: if not hasattr(cm, i): errorOut(i) if not hasattr(cm, "secparam"): secparam = "BN256" # default pairing curve for now else: # need to check this against possible curve types secparam = cm.secparam dropFirst = None if hasattr(cm, "dropFirst"): dropFirst = cm.dropFirst options = {'secparam':secparam, 'userFuncList':[], 'computeSize':estimateOpt, 'dropFirst':dropFirst, 'path':dest_path, 'graphit':graphit} cm.forAutoGroupPlus = False startTime = time.clock() outfile_scheme = runAutoGroupOld(sdl_file, cm, options, verbose) endTime = time.clock() if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) new_input_sdl = outfile_scheme new_output_sdl = output_file # JAA: commented out for benchmark purposes if verbose: print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", options['userFuncList']) if not benchmarkOpt: # generate the source code in the target path codegen_CPP.codegen_CPP_main(dest_path + new_input_sdl, dest_path + new_output_sdl + ".cpp", options['userFuncList']) codegen_PY.codegen_PY_main(dest_path + new_input_sdl, dest_path + new_output_sdl + ".py", new_output_sdl + "User.py") return else: #assumptionData = [] assumptionData = {} for i in cm.assumption: assumptionFile = os.path.dirname(full_config_file) + "/" + i + ".sdl" #TODO: how to determine location of assumption SDL file?? startTime = time.clock() assumptionFileParseRun = parseAssumptionFile(cm, assumptionFile, verbose, benchmarkOpt, estimateOpt) endTime = time.clock() #assumptionData.append(assumptionFileParseRun) assumptionData[i] = assumptionFileParseRun if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") setattr(cm, functionOrder, None) #parse reduction arguments if not hasattr(cm, "reduction"): print("No reduction specified") sys.exit("configAutoGroup: assumption set; need to set 'reduction' in config.") #TODO: add back in when finished and remove else else: print(cm.reduction) if len(cm.reduction) == 1: cm.single_reduction = True else: cm.single_reduction = False #reductionData = [] reductionData = {} for i in cm.reduction: reductionFile = os.path.dirname(full_config_file) + "/" + i + ".sdl" #TODO: how to determine location of reduction SDL file?? startTime = time.clock() reductionFileParseRun = parseReductionFile(cm, reductionFile, verbose, benchmarkOpt, estimateOpt) endTime = time.clock() #reductionData.append(reductionFileParseRun) reductionData[i] = reductionFileParseRun if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") setattr(cm, functionOrder, None) # setup sdl parser configs sdl.masterPubVars = cm.masterPubVars sdl.masterSecVars = cm.masterSecVars if not hasattr(cm, "schemeType"): sys.exit("configAutoGroup: need to set 'schemeType' in config.") if cm.schemeType == PKENC and getattr(cm, functionOrder, None) == None: funcOrder = [cm.setupFuncName, cm.keygenFuncName, cm.encryptFuncName, cm.decryptFuncName] setattr(cm, functionOrder, funcOrder) elif cm.schemeType == PKSIG and getattr(cm, functionOrder, None) == None: if(hasattr(cm, "setupFuncName")): funcOrder = [cm.setupFuncName, cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName] else: funcOrder = [cm.keygenFuncName, cm.signFuncName, cm.verifyFuncName] setattr(cm, functionOrder, funcOrder) if cm.schemeType == PKENC: for i in encConfigParams: if not hasattr(cm, i): errorOut(i) elif cm.schemeType == PKSIG: for i in sigConfigParams: if not hasattr(cm, i): errorOut(i) if not hasattr(cm, "secparam"): secparam = "BN256" # default pairing curve for now else: secparam = cm.secparam dropFirst = None if hasattr(cm, "dropFirst"): dropFirst = cm.dropFirst options = {'secparam':secparam, 'userFuncList':[], 'computeSize':estimateOpt, 'dropFirst':dropFirst, 'path':dest_path, 'graphit':graphit} cm.forAutoGroupPlus = True startTime = time.clock() (outfile_scheme, outfile_assump) = runAutoGroup(sdl_file, cm, options, verbose, assumptionData, reductionData) endTime = time.clock() if benchmarkOpt: runningTime += (endTime - startTime) * 1000 print("running time: ", str(runningTime) + "ms") os.system("echo '%s' >> %s" % (runningTime, output_file)) new_input_sdl = outfile_scheme new_output_sdl = output_file # JAA: commented out for benchmark purposes if verbose: print("Codegen Input: ", new_input_sdl) print("Codegen Output: ", new_output_sdl) print("User defined funcs: ", options['userFuncList']) if not benchmarkOpt: codegen_CPP.codegen_CPP_main(new_input_sdl, dest_path + new_output_sdl + ".cpp", options['userFuncList']) codegen_PY.codegen_PY_main(new_input_sdl, dest_path + new_output_sdl + ".py", new_output_sdl + "User.py") return