/** * Generates random bits (as authenticated elements). * * @param numBits number of bits to generate * @return random bits */ public List<AuthenticatedElement> getRandomBits(int numBits) { return bitConverter.convertToBits(getRandomElements(numBits)); } }
@Override public SpdzTriple getNextTriple() { ensureInitialized(); if (triples.isEmpty()) { logger.trace("Getting another triple batch"); triples.addAll(mascot.getTriples(batchSize)); logger.trace("Got another triple batch"); } MultiplicationTriple triple = triples.pop(); return MascotFormatConverter.toSpdzTriple(triple); }
@Override public SpdzInputMask getNextInputMask(int towardsPlayerId) { ensureInitialized(); ArrayDeque<InputMask> inputMasks = masks.get(towardsPlayerId); if (inputMasks.isEmpty()) { logger.trace("Getting another mask batch"); inputMasks.addAll(mascot.getInputMasks(towardsPlayerId, batchSize)); logger.trace("Got another mask batch"); } return MascotFormatConverter.toSpdzInputMask(inputMasks.pop()); }
@Test public void testFirstTriples() throws Exception { List<Map<Integer, RotList>> seedOts = setupOts(); Map<Integer, FieldElement> perPartyMacKeyShares = setupMacKeyShares(); List<Callable<List<MultiplicationTriple>>> mascotCreators = new ArrayList<>(); for (int i = 0; i < iterations; i++) { @SuppressWarnings("resource") NetManager normalManager = new NetManager(ports); for (int myId = 1; myId <= noOfParties; myId++) { int finalMyId = myId; int finalInstanceId = i; FieldElement randomSsk = perPartyMacKeyShares.get(finalMyId); Map<Integer, RotList> seedOt = seedOts.get(finalMyId - 1); mascotCreators.add(() -> { Mascot mascot = new Mascot( new MascotResourcePoolImpl(finalMyId, noOfParties, finalInstanceId, getDrbg(), seedOt, mascotSecurityParameters, definition), normalManager.createExtraNetwork(finalMyId), randomSsk); return mascot.getTriples(16); }); } } invoke(mascotCreators); }
private void ensureInitialized() { if (mascot != null) { return; } int numCandidatesPerTriple = 3; mascot = new Mascot( new MascotResourcePoolImpl(myId, numberOfPlayers, instanceId, drbg, seedOts, new MascotSecurityParameters(modBitLength, prgSeedLength, numCandidatesPerTriple), this.fieldDefinition), tripleNetwork.get(), ssk); } }
@Override public SpdzSInt getNextBit() { ensureInitialized(); if (randomBits.isEmpty()) { logger.trace("Getting another bit batch"); randomBits.addAll(mascot.getRandomBits(batchSize)); logger.trace("Got another bit batch"); } return MascotFormatConverter.toSpdzSInt(randomBits.pop()); }
/** * Generates random input masks. * * @param maskerId the party that knows the plain mask * @param numMasks number of masks to generate * @return input masks */ public List<InputMask> getInputMasks(Integer maskerId, int numMasks) { if (maskerId.equals(resourcePool.getMyId())) { List<FieldElement> randomMasks = resourcePool.getLocalSampler().getNext(numMasks); List<AuthenticatedElement> authenticated = input(randomMasks); return IntStream.range(0, numMasks) .mapToObj(idx -> new InputMask(randomMasks.get(idx), authenticated.get(idx))) .collect(Collectors.toList()); } else { return input(maskerId, numMasks).stream().map(InputMask::new) .collect(Collectors.toList()); } }
private void constructMascot() throws Exception { List<Map<Integer, RotList>> seedOts = setupOts(); Map<Integer, FieldElement> perPartyMacKeyShares = setupMacKeyShares(); List<Callable<Mascot>> mascotCreators = new ArrayList<>(); for (int i = 0; i < iterations; i++) { @SuppressWarnings("resource") NetManager normalManager = new NetManager(ports); for (int myId = 1; myId <= noOfParties; myId++) { FieldElement randomSsk = perPartyMacKeyShares.get(myId); int finalMyId = myId; int finalInstanceId = i; Map<Integer, RotList> seedOt = seedOts.get(finalMyId - 1); mascotCreators.add(() -> new Mascot( new MascotResourcePoolImpl(finalMyId, noOfParties, finalInstanceId, getDrbg(), seedOt, mascotSecurityParameters, definition), normalManager.createExtraNetwork(finalMyId), randomSsk)); } } invoke(mascotCreators); }
@Override public SpdzSInt getNextRandomFieldElement() { ensureInitialized(); if (randomElements.isEmpty()) { logger.trace("Getting another random element batch"); randomElements.addAll(mascot.getRandomElements(batchSize)); logger.trace("Got another random element batch"); } return MascotFormatConverter.toSpdzSInt(randomElements.pop()); }