Commit 24361c65 authored by Gerard Ryan's avatar Gerard Ryan
Browse files

flogging be6 into submissionaround interface.h

parent 9c75e46c
......@@ -32,10 +32,6 @@ Description:
#include "../../utils/serializable.h"
#include "../../utils/debug.h"
#if defined(_MSC_VER)
#pragma intrinsic(_BitScanReverse64)
#endif
namespace cpu_int {
//MOST REQUIRED STATIC CONSTANTS INITIALIZATION
......@@ -125,16 +121,19 @@ BigInteger<uint_type,BITLENGTH>::BigInteger(const BigInteger& bigInteger){
}
}
template<typename uint_type,usint BITLENGTH>
BigInteger<uint_type,BITLENGTH>::BigInteger(BigInteger&& bigInteger){
m_MSB = std::move(bigInteger.m_MSB);
for (size_t i=0; i < m_nSize; ++i) {
m_value[i] = std::move(bigInteger.m_value[i]);
}
}
template<typename uint_type,usint BITLENGTH>
unique_ptr<BigInteger<uint_type,BITLENGTH>> BigInteger<uint_type,BITLENGTH>::Allocator() {
return lbcrypto::make_unique<cpu_int::BigInteger<uint_type,BITLENGTH>>();
};
template<typename uint_type,usint BITLENGTH>
BigInteger<uint_type,BITLENGTH>::~BigInteger()
{
}
/*
*Converts the BigInteger to unsigned integer or returns the first 32 bits of the BigInteger.
*Splits the BigInteger into bit length of uint data type and then uses shift and add to form the 32 bit unsigned integer.
......@@ -180,6 +179,18 @@ const BigInteger<uint_type,BITLENGTH>& BigInteger<uint_type,BITLENGTH>::operato
return *this;
}
template<typename uint_type,usint BITLENGTH>
const BigInteger<uint_type,BITLENGTH>& BigInteger<uint_type,BITLENGTH>::operator=(BigInteger &&rhs){
if(this!=&rhs){
this->m_MSB = std::move(rhs.m_MSB);
for( size_t i=0; i < m_nSize; i++ )
this->m_value[i] = std::move(rhs.m_value[i]);
}
return *this;
}
/*
* Left Shift is done by splitting the number of shifts into
*1. Multiple of the bit length of uint data type.
......
......@@ -240,16 +240,20 @@ namespace cpu_int{
*/
BigInteger(const BigInteger& bigInteger);
/**
* Move constructor for copying a big binary integer
*
* @param bigInteger is the big binary integer to be copied.
*/
BigInteger(BigInteger&& bigInteger);
/**
* Construct a BigInteger from a NativeInteger
* @param native
*/
BigInteger(const NativeInteger& native) : BigInteger( native.ConvertToInt() ) {}
/**
* Destructor.
*/
~BigInteger();
~BigInteger() {}
/**
* Assignment operator
......@@ -259,23 +263,39 @@ namespace cpu_int{
*/
const BigInteger& operator=(const BigInteger &rhs);
/**
* Move Assignment operator
*
* @param &rhs is the big binary integer to be assigned from.
* @return assigned BigInteger ref.
*/
const BigInteger& operator=(BigInteger &&rhs);
/**
* Assignment operator from unsigned integer
*
* @param val is the unsigned integer value that is assigned.
* @return the assigned BigInteger ref.
*/
//TODO: should this be uint_64_t?
inline const BigInteger& operator=(usint val) {
*this = intToBigInteger(val);
const BigInteger& operator=(uint64_t val) {
*this = BigInteger(val);
return *this;
}
inline const BigInteger& operator=(std::string strval) {
/**
* Assignment from string
* @param strval
* @return the assigned BigInteger ref.
*/
const BigInteger& operator=(const std::string strval) {
*this = BigInteger(strval);
return *this;
}
const BigInteger& operator=(const NativeInteger& val) {
*this = BigInteger(val);
return *this;
}
//Auxillary Functions
......
......@@ -65,7 +65,6 @@ BigVectorImpl<IntegerType>::BigVectorImpl(usint length, const IntegerType& modul
m_data[i] = 0;
}
}
}
template<class IntegerType>
......@@ -92,7 +91,6 @@ BigVectorImpl<IntegerType>::BigVectorImpl(const BigVectorImpl &bigVector){
for(usint i=0;i<m_length;i++){
m_data[i] = bigVector.m_data[i];
}
}
template<class IntegerType>
......@@ -101,6 +99,8 @@ BigVectorImpl<IntegerType>::BigVectorImpl(BigVectorImpl &&bigVector){
m_length = bigVector.m_length;
m_modulus = bigVector.m_modulus;
bigVector.m_data = NULL;
bigVector.m_length = 0;
bigVector.m_modulus = 0;
}
//ASSIGNMENT OPERATOR
......@@ -108,7 +108,7 @@ template<class IntegerType>
const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(const BigVectorImpl &rhs){
if(this!=&rhs){
if(this->m_length==rhs.m_length){
for (usint i = 0; i < m_length; i++){
for (size_t i = 0; i < m_length; i++){
this->m_data[i] = rhs.m_data[i];
}
}
......@@ -118,7 +118,7 @@ const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(const Bi
m_length = rhs.m_length;
m_modulus = rhs.m_modulus;
m_data = new IntegerType[m_length];
for (usint i = 0; i < m_length; i++){
for (size_t i = 0; i < m_length; i++){
m_data[i] = rhs.m_data[i];
}
}
......@@ -128,10 +128,24 @@ const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(const Bi
return *this;
}
template<class IntegerType>
const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(BigVectorImpl &&rhs){
if(this!=&rhs){
delete [] m_data;
m_data = rhs.m_data;
m_length = rhs.m_length;
m_modulus = rhs.m_modulus;
rhs.m_data = NULL;
}
return *this;
}
template<class IntegerType>
const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(std::initializer_list<uint64_t> rhs){
usint len = rhs.size();
for(usint i=0;i<m_length;i++){ // this loops over each tower
size_t len = rhs.size();
for(size_t i=0;i<m_length;i++){
if(i<len) {
if (m_modulus!=0)
m_data[i] = IntegerType(*(rhs.begin()+i))%m_modulus;
......@@ -146,10 +160,10 @@ const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(std::ini
}
template<class IntegerType>
const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(std::initializer_list<std::string> rhs){
const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(std::initializer_list<std::string> rhs) {
bool dbg_flag = false;
usint len = rhs.size();
for(usint i=0;i<m_length;i++){ // this loops over each tower
size_t len = rhs.size();
for(size_t i=0;i<m_length;i++){
if(i<len) {
if (m_modulus!=0)
m_data[i] = IntegerType(*(rhs.begin()+i))%m_modulus;
......@@ -164,22 +178,6 @@ const BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(std::ini
return *this;
}
template<class IntegerType>
BigVectorImpl<IntegerType>& BigVectorImpl<IntegerType>::operator=(BigVectorImpl &&rhs){
if(this!=&rhs){
delete [] m_data;
m_data = rhs.m_data;
m_length = rhs.m_length;
m_modulus = rhs.m_modulus;
rhs.m_data = NULL;
}
return *this;
}
template<class IntegerType>
BigVectorImpl<IntegerType>::~BigVectorImpl(){
delete [] m_data;
......
......@@ -51,7 +51,7 @@ namespace cpu_int {
*/
template <class IntegerType>
class BigVectorImpl : public lbcrypto::BigVectorInterface<BigVectorImpl<IntegerType>,IntegerType>, lbcrypto::Serializable
class BigVectorImpl : public lbcrypto::BigVectorInterface<BigVectorImpl<IntegerType>,IntegerType>, public lbcrypto::Serializable
{
public:
/**
......@@ -123,7 +123,7 @@ public:
* @param &&rhs is the big binary vector to be moved.
* @return moved BigVectorImpl object
*/
BigVectorImpl& operator=(BigVectorImpl &&rhs);
const BigVectorImpl& operator=(BigVectorImpl &&rhs);
/**
* Initializer list for BigVectorImpl.
......@@ -147,8 +147,10 @@ public:
* @param val is the value to be assigned at the first entry.
* @return Assigned BigVectorImpl.
*/
inline const BigVectorImpl& operator=(uint64_t val) {
const BigVectorImpl& operator=(uint64_t val) {
this->m_data[0] = val;
if( this->m_modulus != 0 )
this->m_data[0] %= this->m_modulus;
for (size_t i = 1; i < GetLength(); ++i) {
this->m_data[i] = 0;
}
......
......@@ -341,7 +341,6 @@ namespace exp_int{
* @return the assigned ubint ref.
*/
const ubint& operator=(const uint64_t val) {
// *this = intTobint(val);
*this = ubint(val);
return *this;
}
......
......@@ -50,13 +50,6 @@ namespace NTL {
// constant log2 of limb bitlength
const usint myZZ::m_log2LimbBitLength = Log2<NTL_ZZ_NBITS>::value;
const myZZ myZZ::ZERO=myZZ(0L);
const myZZ myZZ::ONE=myZZ(1);
const myZZ myZZ::TWO=myZZ(2);
const myZZ myZZ::THREE=myZZ(3);
const myZZ myZZ::FOUR=myZZ(4);
const myZZ myZZ::FIVE=myZZ(5);
myZZ::myZZ():ZZ() {SetMSB();}
myZZ::myZZ(uint64_t d): ZZ(0) {
......@@ -333,7 +326,6 @@ namespace NTL {
const std::string myZZ::ToString() const
{
//todo Not sure if this string is safe, it may be ephemeral if not returned by value.
std::stringstream result("");
result << *this;
return result.str();
......@@ -355,7 +347,7 @@ namespace NTL {
//check for garbage initialization and 0 condition
//check for garbage initialization and 0 condition
if(q==ZERO)
if(q==myZZ(0))
throw std::logic_error("DivideAndRound() Divisor is zero");
myZZ halfQ(q>>1);
......@@ -363,9 +355,9 @@ namespace NTL {
if (*this < q) {
if (*this <= halfQ)
return myZZ(ZERO);
return myZZ(0);
else
return myZZ(ONE);
return myZZ(1);
}
//=============
myZZ ans(0);
......@@ -394,19 +386,13 @@ namespace NTL {
//==============
//Rounding operation from running remainder
if (!(rv <= halfQ)) {
ans += ONE;
ans += myZZ(1);
DEBUG("added1 ans "<<ans.ToString());
}
return ans;
}
//various operators on mixed operands
myZZ& myZZ::operator*=(const myZZ &a) {
*this = *this*a;
return *this;
}
// helper functions convert a ubint in and out of a string of
// characters the encoding is Base64-like: the first 11 6-bit
// groupings are Base64 encoded
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -41,7 +41,7 @@ namespace lbcrypto {
// Constructors must be implemented in the derived classes
// There are no base class constructors that need to be called
// The derived classes should implement constructors from integers and strings
// The derived classes should implement constructors from uint64_t, NativeInteger, and strings
// There should be copy and move constructors, as well as copy and move assignment
// ACCESSORS
......
......@@ -494,10 +494,10 @@ namespace lbcrypto {
{
bool dbg_flag = false;
DEBUG("in NTL MRPT");
if (p < NTL::myZZ::TWO || ((p != NTL::myZZ::TWO) &&
(p.Mod(NTL::myZZ::TWO) == NTL::myZZ::ZERO)))
if (p < NTL::myZZ(2) || ((p != NTL::myZZ(2)) &&
(p.Mod(NTL::myZZ(2)) == NTL::myZZ(0))))
return false;
if (p == NTL::myZZ::TWO || p == NTL::myZZ::THREE || p == NTL::myZZ::FIVE)
if (p == NTL::myZZ(2) || p == NTL::myZZ(3) || p == NTL::myZZ(5))
return true;
return (bool)ProbPrime(p, niter); //TODO: check to see if niter >maxint
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment