blob: 6767685b6cd94b4d4d8a256cca03f3596ec3199f [file] [log] [blame]
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/**
* @file fp2.h
* @author Mike Scott
* @brief FP2 Header File
*
*/
#ifndef FP2_YYY_H
#define FP2_YYY_H
#include "fp_YYY.h"
/**
@brief FP2 Structure - quadratic extension field
*/
typedef struct
{
FP_YYY a; /**< real part of FP2 */
FP_YYY b; /**< imaginary part of FP2 */
} FP2_YYY;
/* FP2 prototypes */
/** @brief Tests for FP2 equal to zero
*
@param x FP2 number to be tested
@return 1 if zero, else returns 0
*/
extern int FP2_YYY_iszilch(FP2_YYY *x);
/** @brief Conditional copy of FP2 number
*
Conditionally copies second parameter to the first (without branching)
@param x FP2 instance, set to y if s!=0
@param y another FP2 instance
@param s copy only takes place if not equal to 0
*/
extern void FP2_YYY_cmove(FP2_YYY *x,FP2_YYY *y,int s);
/** @brief Tests for FP2 equal to one
*
@param x FP2 instance to be tested
@return 1 if x=1, else returns 0
*/
extern int FP2_YYY_isunity(FP2_YYY *x);
/** @brief Tests for equality of two FP2s
*
@param x FP2 instance to be compared
@param y FP2 instance to be compared
@return 1 if x=y, else returns 0
*/
extern int FP2_YYY_equals(FP2_YYY *x,FP2_YYY *y);
/** @brief Initialise FP2 from two FP numbers
*
@param x FP2 instance to be initialised
@param a FP to form real part of FP2
@param b FP to form imaginary part of FP2
*/
extern void FP2_YYY_from_FPs(FP2_YYY *x,FP_YYY *a,FP_YYY *b);
/** @brief Initialise FP2 from two BIG integers
*
@param x FP2 instance to be initialised
@param a BIG to form real part of FP2
@param b BIG to form imaginary part of FP2
*/
extern void FP2_YYY_from_BIGs(FP2_YYY *x,BIG_XXX a,BIG_XXX b);
/** @brief Initialise FP2 from single FP
*
Imaginary part is set to zero
@param x FP2 instance to be initialised
@param a FP to form real part of FP2
*/
extern void FP2_YYY_from_FP(FP2_YYY *x,FP_YYY *a);
/** @brief Initialise FP2 from single BIG
*
Imaginary part is set to zero
@param x FP2 instance to be initialised
@param a BIG to form real part of FP2
*/
extern void FP2_YYY_from_BIG(FP2_YYY *x,BIG_XXX a);
/** @brief Copy FP2 to another FP2
*
@param x FP2 instance, on exit = y
@param y FP2 instance to be copied
*/
extern void FP2_YYY_copy(FP2_YYY *x,FP2_YYY *y);
/** @brief Set FP2 to zero
*
@param x FP2 instance to be set to zero
*/
extern void FP2_YYY_zero(FP2_YYY *x);
/** @brief Set FP2 to unity
*
@param x FP2 instance to be set to one
*/
extern void FP2_YYY_one(FP2_YYY *x);
/** @brief Negation of FP2
*
@param x FP2 instance, on exit = -y
@param y FP2 instance
*/
extern void FP2_YYY_neg(FP2_YYY *x,FP2_YYY *y);
/** @brief Conjugation of FP2
*
If y=(a,b) on exit x=(a,-b)
@param x FP2 instance, on exit = conj(y)
@param y FP2 instance
*/
extern void FP2_YYY_conj(FP2_YYY *x,FP2_YYY *y);
/** @brief addition of two FP2s
*
@param x FP2 instance, on exit = y+z
@param y FP2 instance
@param z FP2 instance
*/
extern void FP2_YYY_add(FP2_YYY *x,FP2_YYY *y,FP2_YYY *z);
/** @brief subtraction of two FP2s
*
@param x FP2 instance, on exit = y-z
@param y FP2 instance
@param z FP2 instance
*/
extern void FP2_YYY_sub(FP2_YYY *x,FP2_YYY *y,FP2_YYY *z);
/** @brief Multiplication of an FP2 by an FP
*
@param x FP2 instance, on exit = y*b
@param y FP2 instance
@param b FP residue
*/
extern void FP2_YYY_pmul(FP2_YYY *x,FP2_YYY *y,FP_YYY *b);
/** @brief Multiplication of an FP2 by a small integer
*
@param x FP2 instance, on exit = y*i
@param y FP2 instance
@param i an integer
*/
extern void FP2_YYY_imul(FP2_YYY *x,FP2_YYY *y,int i);
/** @brief Squaring an FP2
*
@param x FP2 instance, on exit = y^2
@param y FP2 instance
*/
extern void FP2_YYY_sqr(FP2_YYY *x,FP2_YYY *y);
/** @brief Multiplication of two FP2s
*
@param x FP2 instance, on exit = y*z
@param y FP2 instance
@param z FP2 instance
*/
extern void FP2_YYY_mul(FP2_YYY *x,FP2_YYY *y,FP2_YYY *z);
/** @brief Formats and outputs an FP2 to the console
*
@param x FP2 instance
*/
extern void FP2_YYY_output(FP2_YYY *x);
/** @brief Formats and outputs an FP2 to the console in raw form (for debugging)
*
@param x FP2 instance
*/
extern void FP2_YYY_rawoutput(FP2_YYY *x);
/** @brief Inverting an FP2
*
@param x FP2 instance, on exit = 1/y
@param y FP2 instance
*/
extern void FP2_YYY_inv(FP2_YYY *x,FP2_YYY *y);
/** @brief Divide an FP2 by 2
*
@param x FP2 instance, on exit = y/2
@param y FP2 instance
*/
extern void FP2_YYY_div2(FP2_YYY *x,FP2_YYY *y);
/** @brief Multiply an FP2 by (1+sqrt(-1))
*
Note that (1+sqrt(-1)) is irreducible for FP4
@param x FP2 instance, on exit = x*(1+sqrt(-1))
*/
extern void FP2_YYY_mul_ip(FP2_YYY *x);
/** @brief Divide an FP2 by (1+sqrt(-1))/2 -
*
Note that (1+sqrt(-1)) is irreducible for FP4
@param x FP2 instance, on exit = 2x/(1+sqrt(-1))
*/
extern void FP2_YYY_div_ip2(FP2_YYY *x);
/** @brief Divide an FP2 by (1+sqrt(-1))
*
Note that (1+sqrt(-1)) is irreducible for FP4
@param x FP2 instance, on exit = x/(1+sqrt(-1))
*/
extern void FP2_YYY_div_ip(FP2_YYY *x);
/** @brief Normalises the components of an FP2
*
@param x FP2 instance to be normalised
*/
extern void FP2_YYY_norm(FP2_YYY *x);
/** @brief Reduces all components of possibly unreduced FP2 mod Modulus
*
@param x FP2 instance, on exit reduced mod Modulus
*/
extern void FP2_YYY_reduce(FP2_YYY *x);
/** @brief Raises an FP2 to the power of a BIG
*
@param x FP2 instance, on exit = y^b
@param y FP2 instance
@param b BIG number
*/
extern void FP2_YYY_pow(FP2_YYY *x,FP2_YYY *y,BIG_XXX b);
/** @brief Square root of an FP2
*
@param x FP2 instance, on exit = sqrt(y)
@param y FP2 instance
*/
extern int FP2_YYY_sqrt(FP2_YYY *x,FP2_YYY *y);
/** @brief Multiply an FP2 by sqrt(-1)
*
Note that -1 is QNR
@param x FP2 instance, on exit = x*sqrt(-1)
*/
extern void FP2_YYY_times_i(FP2_YYY *x);
#endif