Ejemplo n.º 1
0
    def generateAuxInfo(s, prime):
        """Generates auxilliary information for a msg integer s to satisfy the 
        quation c = bs + y where b and y are randomly generated numbers. Each 
        of c, b and y are values module prime. 

        Args:
            s: A integer message for which the auxilliary information is to be 
                generated.
            prime: A integer value specifying the prime field for modulo operations.

        Returns:
            A list consisting of values [c, b, y] that satisfies the equation 
                c = bs + y.

        Raises:
            TypeError: Error when either the s or prime is not a integer.
            ValueError: Error when prime is not greater than the given value of s.
        """

        if type(s) not in [int, long]:
            raise TypeError("invalid msg: int or long expected")
        elif type(prime) not in [int, long]:
            raise TypeError("invalid prime: int or long expected")
        elif s >= prime:
            raise ValueError("invalid prime: value larger than s expected")

        b = genRandNum(prime)
        y = genRandNum(prime)
        c = (b * s + y) % prime
        return [c, b, y]
Ejemplo n.º 2
0
    def randomPolynomial(k, prime):
        """Generates a random polynomial y = msgNum + c[0]*x + c[1]*x^2 + ... 
        + c[k-2]*x^(k-1) by generating the list of cryptographically secure 
        coefficients c[i] using prime as the order of modulo operations.

        Args:
            k: An integer value representing the number of coefficients to be 
                generated.
            prime: An integer value to be used as the order of modulo operations.

        Returns:
            A list of k-1 randomly generated coefficients for the polynomial 
            y = msgNum + c[0]*x + c[1]*x^2 + ... + c[k-2]*x^(k-1) 

        Raises:
            TypeError: Error when either k or prime is not an integer.
        """

        if type(k) not in [int, long]:
            raise TypeError("invalid k: int or long expected")
        elif type(prime) not in [int, long]:
            raise TypeError("invalid prime: int or long expected")

        coefficients = []
        for i in range(1, k):
            coefficients.append(genRandNum(prime))  
        
        return coefficients