software.common
Class MarkPermutations

java.lang.Object
  extended by software.common.MarkPermutations

public class MarkPermutations
extends java.lang.Object

Computes the mark permutations using the following algorithm
For P:
Let M be a byte array of length 16 (see below how M is constructed for P1,P2,D2) Compute a secret key SK = Dmk1(C xor Emk2(C xor Emk1(M))) AES128 ECB NoPadding Let MM be a byte array of length 2, MM[0]=question number, MM[1]=answer number Using the secret key SK, encrypt MM using AES128 ECB PKCS#5Padding sort the cryptograms to generate the permutation
For P1:
M=serial+"top"
For P2:
M=serial+"bottom"
For D2:
M=DInstanceNumber+serial+"d2"
D4 is computed from P1,P2,P4
The format of the permutatio is:
each permutation is represented as an array of possitive bytes (thus max 127). The questions takes n possitions in the array (n is the number of answers) , each possition having one element of the permutation. For example, if question 6 starts at possition 19 and has 4 answers, ans possitions 19,20,21 and 22 have 2,3,1,0 the permutation is 0->2,1->3,2->1,3->0

Author:
Stefan

Constructor Summary
MarkPermutations(byte[] c, org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification es, java.util.Vector<java.util.Vector<java.lang.Integer>> partitions)
           
MarkPermutations(javax.crypto.spec.SecretKeySpec mk1, javax.crypto.spec.SecretKeySpec mk2, byte[] c, org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification es, java.util.Vector<java.util.Vector<java.lang.Integer>> partitions)
           
 
Method Summary
 byte[] compose(byte[] p1, byte[] p2)
          Composes two layers.
 byte[] compose(byte[] p1, byte[] p2, byte partitionId)
          Composes two layers.
 byte[] computeD3(byte[] p3, byte[] d2, byte partitionId)
           
 byte[] computeR(byte[] d3, byte[] d4, byte partitionId)
           
 byte[] getCanonical()
           
 byte[] getD2(byte[] did, byte dInstance, int partitionId)
          this permutation is pseudo-randomly generated
 byte[] getD4(byte[] top, byte[] bottom, byte[] d2, byte partitionId)
          permutation is deterministically generated.
 byte[] getInverseAllPartition(byte[] d2)
           
 byte[] getInversePartition(byte[] d2, int partitionId)
           
 int getMaxNoAnswersInPartition(int partitionId)
           
 int getMaxNoAnswersInQuestion(int q)
           
 int getNoAnswersInPartition(int partitionId)
           
 byte[] getP1(byte[] serial)
          this permutation is pseudo-randomly generated
 byte[] getP1(byte[] serial, byte partitionId)
          this permutation is pseudo-randomly generated
 byte[] getP2(byte[] serial)
          this permutation is pseudo-randomly generated
 byte[] getP2(byte[] serial, byte partitionId)
          this permutation is pseudo-randomly generated
 int getSize()
           
 int getTotalMaxNoAnswers()
           
 int getTotalNoAnswers()
           
 byte[] project(byte[] p, int partitionId)
          Projects a byte array on a given partition I.E extracts only the possitions that corespond to the given partition from the byte array and concatenates them together
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkPermutations

public MarkPermutations(byte[] c,
                        org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification es,
                        java.util.Vector<java.util.Vector<java.lang.Integer>> partitions)
Parameters:
c - - the public constant
es - - the Election Specification
partitions - - what questions are in each partition

MarkPermutations

public MarkPermutations(javax.crypto.spec.SecretKeySpec mk1,
                        javax.crypto.spec.SecretKeySpec mk2,
                        byte[] c,
                        org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification es,
                        java.util.Vector<java.util.Vector<java.lang.Integer>> partitions)
Parameters:
mk1 - - master key 1
mk2 - - master key 2
c - - public constant
es - - Election Specification
partitions - - what questions are in each partition (ex {{0,1}{2}{3,4,5}} means that there are 3 partitions, in the first one there are questions 0 and 1, in the second one question 2 and in the third patition questions 3,4,5)
Method Detail

getCanonical

public byte[] getCanonical()
Returns:
a copy of the canonical form of the ballot (all the permutations are the identity permutatuion)
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getP1

public byte[] getP1(byte[] serial)
             throws java.lang.Exception
this permutation is pseudo-randomly generated

Parameters:
serial - the serial number of the ballot
Returns:
top permutation (for all partitions)
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getP2

public byte[] getP2(byte[] serial)
             throws java.lang.Exception
this permutation is pseudo-randomly generated

Parameters:
serial - the serial number of the ballot
Returns:
the bottom permutation (for all partitions)
Throws:
java.lang.Exception

getP1

public byte[] getP1(byte[] serial,
                    byte partitionId)
             throws java.lang.Exception
this permutation is pseudo-randomly generated

Parameters:
serial - the serial number of the ballot
partitionId -
Returns:
the top permutation for the questions in the given partitions
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getP2

public byte[] getP2(byte[] serial,
                    byte partitionId)
             throws java.lang.Exception
this permutation is pseudo-randomly generated

Parameters:
serial - the serial number of the ballot
partitionId -
Returns:
bottom permutation for the questions in the given partitions
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getD2

public byte[] getD2(byte[] did,
                    byte dInstance,
                    int partitionId)
             throws java.lang.Exception
this permutation is pseudo-randomly generated

Parameters:
dInstance - the instance number of D
did - the serial number of the ballot
Returns:
the first permutation in D
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getInverseAllPartition

public byte[] getInverseAllPartition(byte[] d2)
                              throws java.lang.Exception
Parameters:
d2 - all the permutations for all partitions
Returns:
for each question, computes the inverse permutation. Returns a concatenation of them
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

getInversePartition

public byte[] getInversePartition(byte[] d2,
                                  int partitionId)
                           throws java.lang.Exception
Parameters:
d2 - the permutations in a given partition
partitionId - - the partition id
Returns:
computes the inverse of each permutattion in the given partition
Throws:
java.lang.Exception - - if the length of d2 is different then the length of the questions in the given partition, an Exception si thrown

getD4

public byte[] getD4(byte[] top,
                    byte[] bottom,
                    byte[] d2,
                    byte partitionId)
             throws java.lang.Exception
permutation is deterministically generated.

Parameters:
top - the top permutation
bottom - the bottom permutation
d2 - the first permutation in D
Returns:
the second permutation in D = flip1-1 o bottom o top-1
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown

project

public byte[] project(byte[] p,
                      int partitionId)
Projects a byte array on a given partition I.E extracts only the possitions that corespond to the given partition from the byte array and concatenates them together

Parameters:
p - - the permutation for all the questions
partitionId -
Returns:
- the permutatuions for the given partition

getSize

public int getSize()
Returns:
the total number of answers (in all the questions)

getNoAnswersInPartition

public int getNoAnswersInPartition(int partitionId)
Parameters:
partitionId -
Returns:
the total number of answers for questions in the given partition

getMaxNoAnswersInQuestion

public int getMaxNoAnswersInQuestion(int q)
Parameters:
q - - question numbers
Returns:
- the maximum number of answers that a voter can select for a particular question

getMaxNoAnswersInPartition

public int getMaxNoAnswersInPartition(int partitionId)
Parameters:
partitionId -
Returns:
- the maximum number of answers that a voter can select for the question in a given partition (their sum)

compose

public byte[] compose(byte[] p1,
                      byte[] p2)
Composes two layers. For each question, composes the permutations.

Parameters:
p1 - - the permutation that is appleid second
p2 - - the permutation that is applied first
Returns:
p1[p2]

compose

public byte[] compose(byte[] p1,
                      byte[] p2,
                      byte partitionId)
Composes two layers. For each question in the given partition, composes the permutations.

Parameters:
p1 - - the permutation that is appleid second
p2 - - the permutation that is applied first
partitionId -
Returns:
p1[p2]

getTotalMaxNoAnswers

public int getTotalMaxNoAnswers()
Returns:
the total number of answers that the voter can select (for the entire ballot)

getTotalNoAnswers

public int getTotalNoAnswers()
Returns:
the total number of answers on the ballot

computeD3

public byte[] computeD3(byte[] p3,
                        byte[] d2,
                        byte partitionId)
                 throws java.lang.Exception
Parameters:
p3 - - the selection made by the voter (the entire selection, not just for the given partition)
d2 - - the transformation
partitionId -
Returns:
- extracts the selection made by the voter for the given partition and applies the d2 transformation to the selection in each question
Throws:
java.lang.Exception - if p3.length!=total number of answers that the voter can select on the entire ballot (non votes are represented by -1) or if d2.length!=the number of answers in the given partition (the sum for all the questions)

computeR

public byte[] computeR(byte[] d3,
                       byte[] d4,
                       byte partitionId)
                throws java.lang.Exception
Parameters:
d3 - - the partial decripted balot in the D table
d4 - - the second transformation in the D table
partitionId -
Returns:
- applies the d4 transformation to d3
Throws:
java.lang.Exception - if d3.length!=the maximum number of answers the voter can select for the questions in the given partition (their sum) or if d4.length!=the total number of answers in the given partition (the sum for all the questions)