Skip to content

Commit

Permalink
full modify the pailler to paillier
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin committed Aug 4, 2017
1 parent 21fcab6 commit d838a60
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ add_subdirectory(libcontract)
add_subdirectory(libsinglepoint)
add_subdirectory(libpbftseal)
add_subdirectory(libraftseal)
add_subdirectory(libpailler)
add_subdirectory(libpaillier)
add_subdirectory(libethcore)
add_subdirectory(libethereum)
add_subdirectory(libevm)
Expand Down
2 changes: 1 addition & 1 deletion libevm/VMExtends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <arpa/inet.h>
#include "VMExtends.h"
#include <boost/algorithm/string.hpp>
#include "pailler.h"
#include "paillier.h"

using namespace std;
using namespace dev;
Expand Down
100 changes: 50 additions & 50 deletions libpaillier/pailler.c → libpaillier/paillier.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
#include "pailler.h"

void PAI_HomAdd(U8 *pbBN_Result, U8 *pbBN_c1, U8 *pbBN_c2, U8 *pbBN_n, S32 iBNWordLen)
{
/****************************/
U32 BN_N2[BNMAXWordLen];
U32 BN_N[BNMAXWordLen];
U32 BN_R[BNMAXWordLen];
U32 BN_R2[BNMAXWordLen];
U32 BN_C1[BNMAXWordLen];
U32 BN_C2[BNMAXWordLen];
U32 BN_C3[BNMAXWordLen];
U32 BN_One[BNMAXWordLen];
U32 wModuleConst = 0;

U8 bBN_T[8*BNMAXWordLen] = {0};
S32 i = 0;
S32 len = 0;
/****************************/

BN_Reset(BN_N2, BNMAXWordLen);
BN_Reset(BN_N, BNMAXWordLen);
BN_Reset(BN_R, BNMAXWordLen);
BN_Reset(BN_R2, BNMAXWordLen);
BN_Reset(BN_C1, BNMAXWordLen);
BN_Reset(BN_C2, BNMAXWordLen);
BN_Reset(BN_C3, BNMAXWordLen);
BN_Reset(BN_One, BNMAXWordLen);
BN_One[0] = LSBOfWord;

ByteToBN(pbBN_n, 4*iBNWordLen, BN_N, iBNWordLen);
ByteToBN(pbBN_c1, 8*iBNWordLen, BN_C1, 2*iBNWordLen);
ByteToBN(pbBN_c2, 8*iBNWordLen, BN_C2, 2*iBNWordLen);

//n^2
BN_Mul(BN_N2, BN_N, BN_N, iBNWordLen);

wModuleConst = BN_GetMontConst(BN_N2[0], 32);
BN_GetR(BN_R, BN_N2, 2*iBNWordLen);

BN_GetR2(BN_R2, BN_R, BN_N2, wModuleConst, 2*iBNWordLen, LogPaiBN2BitLen);
BN_GetLastRes(BN_R2, BN_N2, 2*iBNWordLen);

BN_ModMul_Mont(BN_C1, BN_C1, BN_R2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C2, BN_C2, BN_R2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C3, BN_C1, BN_C2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C3, BN_C3, BN_One, BN_N2, wModuleConst, 2*iBNWordLen);
BN_GetLastRes(BN_C3, BN_N2, 2*iBNWordLen);

BNToByte(BN_C3, 2*iBNWordLen, pbBN_Result, &len);
#include "pailler.h"

void PAI_HomAdd(U8 *pbBN_Result, U8 *pbBN_c1, U8 *pbBN_c2, U8 *pbBN_n, S32 iBNWordLen)
{
/****************************/
U32 BN_N2[BNMAXWordLen];
U32 BN_N[BNMAXWordLen];
U32 BN_R[BNMAXWordLen];
U32 BN_R2[BNMAXWordLen];
U32 BN_C1[BNMAXWordLen];
U32 BN_C2[BNMAXWordLen];
U32 BN_C3[BNMAXWordLen];
U32 BN_One[BNMAXWordLen];
U32 wModuleConst = 0;

U8 bBN_T[8*BNMAXWordLen] = {0};
S32 i = 0;
S32 len = 0;
/****************************/

BN_Reset(BN_N2, BNMAXWordLen);
BN_Reset(BN_N, BNMAXWordLen);
BN_Reset(BN_R, BNMAXWordLen);
BN_Reset(BN_R2, BNMAXWordLen);
BN_Reset(BN_C1, BNMAXWordLen);
BN_Reset(BN_C2, BNMAXWordLen);
BN_Reset(BN_C3, BNMAXWordLen);
BN_Reset(BN_One, BNMAXWordLen);
BN_One[0] = LSBOfWord;

ByteToBN(pbBN_n, 4*iBNWordLen, BN_N, iBNWordLen);
ByteToBN(pbBN_c1, 8*iBNWordLen, BN_C1, 2*iBNWordLen);
ByteToBN(pbBN_c2, 8*iBNWordLen, BN_C2, 2*iBNWordLen);

//n^2
BN_Mul(BN_N2, BN_N, BN_N, iBNWordLen);

wModuleConst = BN_GetMontConst(BN_N2[0], 32);
BN_GetR(BN_R, BN_N2, 2*iBNWordLen);

BN_GetR2(BN_R2, BN_R, BN_N2, wModuleConst, 2*iBNWordLen, LogPaiBN2BitLen);
BN_GetLastRes(BN_R2, BN_N2, 2*iBNWordLen);

BN_ModMul_Mont(BN_C1, BN_C1, BN_R2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C2, BN_C2, BN_R2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C3, BN_C1, BN_C2, BN_N2, wModuleConst, 2*iBNWordLen);
BN_ModMul_Mont(BN_C3, BN_C3, BN_One, BN_N2, wModuleConst, 2*iBNWordLen);
BN_GetLastRes(BN_C3, BN_N2, 2*iBNWordLen);

BNToByte(BN_C3, 2*iBNWordLen, pbBN_Result, &len);
}
40 changes: 20 additions & 20 deletions libpaillier/pailler.h → libpaillier/paillier.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef __HEADER_PAILLER_H__
#define __HEADER_PAILLER_H__

#include "bn.h"
#include "common.h"
#include "macro.h"

#ifdef __cplusplus
extern "C" {
#endif

void PAI_HomAdd(U8 *pbBN_Result, U8 *pbBN_c1, U8 *pbBN_c2, U8 *pbBN_n, S32 iBNWordLen);

#ifdef __cplusplus
}
#endif


#endif

#ifndef __HEADER_PAILLER_H__
#define __HEADER_PAILLER_H__

#include "bn.h"
#include "common.h"
#include "macro.h"

#ifdef __cplusplus
extern "C" {
#endif

void PAI_HomAdd(U8 *pbBN_Result, U8 *pbBN_c1, U8 *pbBN_c2, U8 *pbBN_n, S32 iBNWordLen);

#ifdef __cplusplus
}
#endif


#endif

0 comments on commit d838a60

Please sign in to comment.