示例#1
0
    def __init__(self, realnumber, realpath, dummypath, leavesnumber,
                 evictionrate, circuitlength, blocksize, prerandompointsnum):
        #--------------------------------------------------------------------------
        """ Initiation of a BtITPIRORAM for our construction-1 """

        self.debug = 0  #flag for debugging
        self.positionmap = {}  # dataid --> tag, level, number
        self.peermap = {}  # available peers: o-ram id --> peerid
        self.peermapreverse = {}  # reverse peermap: peerid --> o-ram id
        self.peerdata = {
        }  # {peertag:{count:0, rvalid:[], dvalid:[], dataid:[dataid1, dataid2]},...}
        #self.stashrealdata = {} #Real data: dataid --> datacontent
        self.stashmap = {}  #dataid: --> datatag (new assigned tag)}
        self.stashpeermap = []  #dataid stored on stashpeer in sequence
        self.tagmap = {}  #datatag --> number (maximum is Z)
        self.secretmap = {
        }  #dataid --> ecc random point: we use randomnum represent it, which can be calculated by usedcurve.G * randomnum
        self.usedcurve = getcurvebyname("NIST P-256")  #The ecc curve we use
        #self.usedcurve = getcurvebyname("brainpoolP160t1")#brainpoolP160t1
        self.pointsnum = int(blocksize / 512 *
                             8)  #The number of points for one block
        self.stashpeer = ""  #the peertag chosen to store stashdata
        self.Z = realnumber
        self.C = circuitlength  #circuit length
        #self.S = dummynumber
        self.A = evictionrate
        self.N = leavesnumber  #2**N is number of leaves
        #self.key = generateKey(16) #Generate a random key for btringoram
        self.blocksize = blocksize
        self.dummypath = dummypath
        self.realpath = realpath
        self.neutralpoint = self.usedcurve.G * 0

        #initiation
        self.__init_peermap(self.N)
        self.__init_tagmap(self.N)
        #self.btaes = AESCipher(self.key)
        self.G = 0  #global counter for evictionpath
        self.Acount = 0  #global counter for eviction
        self.evictionpaths = self.__initevictionpaths(
        )  #eviction paths following reverse lexi order

        self.prerandompointsnum = prerandompointsnum
        #self.prerandompointsnum = 2**self.N
        self.randompoints = self.__init_randompoints(
            self.prerandompointsnum)  #pre generate random points
示例#2
0
    def __init__( self, realnumber, realpath, dummypath, leavesnumber, evictionrate, circuitlength, blocksize, prerandompointsnum ):
    #--------------------------------------------------------------------------
        """ Initiation of a BtITPIRORAM for our construction-1 """

        self.debug = 0 #flag for debugging
        self.positionmap = {} # dataid --> tag, level, number
        self.peermap = {} # available peers: o-ram id --> peerid
        self.peermapreverse = {} # reverse peermap: peerid --> o-ram id
        self.peerdata = {} # {peertag:{count:0, rvalid:[], dvalid:[], dataid:[dataid1, dataid2]},...}
        #self.stashrealdata = {} #Real data: dataid --> datacontent
        self.stashmap = {} #dataid: --> datatag (new assigned tag)}
        self.stashpeermap = [] #dataid stored on stashpeer in sequence
        self.tagmap = {} #datatag --> number (maximum is Z)
        self.secretmap = {} #dataid --> ecc random point: we use randomnum represent it, which can be calculated by usedcurve.G * randomnum
        self.usedcurve = getcurvebyname("NIST P-256") #The ecc curve we use
        #self.usedcurve = getcurvebyname("brainpoolP160t1")#brainpoolP160t1
        self.pointsnum = int(blocksize / 512 * 8)  #The number of points for one block
        self.stashpeer = "" #the peertag chosen to store stashdata
        self.Z = realnumber
        self.C = circuitlength #circuit length
        #self.S = dummynumber
        self.A = evictionrate
        self.N = leavesnumber #2**N is number of leaves
        #self.key = generateKey(16) #Generate a random key for btringoram
        self.blocksize = blocksize
        self.dummypath = dummypath
        self.realpath = realpath
        self.neutralpoint = self.usedcurve.G * 0

        #initiation
        self.__init_peermap(self.N)
        self.__init_tagmap(self.N)
        #self.btaes = AESCipher(self.key)
        self.G = 0 #global counter for evictionpath
        self.Acount = 0 #global counter for eviction
        self.evictionpaths = self.__initevictionpaths() #eviction paths following reverse lexi order

        self.prerandompointsnum = prerandompointsnum
        #self.prerandompointsnum = 2**self.N
        self.randompoints = self.__init_randompoints(self.prerandompointsnum) #pre generate random points
示例#3
0
文件: ecctest.py 项目: mdxs/joeecc
#	along with joeecc; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	Johannes Bauer <*****@*****.**>
#

import sys

from ecc import AffineCurvePoint, ShortWeierstrassCurve, getcurvebyname
from ecc import ECPrivateKey

def separator():
	print("-" * 150)


usedcurve = getcurvebyname("secp112r1")
#usedcurve = getcurvebyname("brainpoolP160r1")
#usedcurve = getcurvebyname("secp192k1")
print("Selected curve parameters:")
print(str(usedcurve))
separator()

privatekey = ECPrivateKey(0x12345, usedcurve)
print("Generated privatekey")
print(str(privatekey))
separator()


########################### Encryption example ###########################
e = privatekey.pubkey.ecies_encrypt()
print("Encryption")
示例#4
0
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with joeecc; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	Johannes Bauer <*****@*****.**>
#

import time
import sys
from ecc import getcurvebyname, ECPrivateKey
from StopWatch import StopWatch

curve = getcurvebyname("ed25519")

if len(sys.argv) < 2:
	keypair = ECPrivateKey.eddsa_generate(curve)
	print("Generating keypair on the fly")
else:
	keypair = ECPrivateKey.loadkeypair(bytes.fromhex(sys.argv[1]))
print("Keypair:", keypair)

msg = b"Foobar!"
print("Message:", msg)

signature = keypair.eddsa_sign(msg)
print("Signature:", signature)

print("Verify correct message: %s (should be True)" % (keypair.pubkey.eddsa_verify(msg, signature)))
示例#5
0
#
#	joeecc is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with joeecc; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	Johannes Bauer <*****@*****.**>
#

from ecc import getcurvebyname, ECPrivateKey

curve = getcurvebyname("secp521r1")


def msg_to_point(curve, msg, msg_width_bits):
    int_message = int.from_bytes(msg, byteorder="little")
    for i in range(100):
        try_message = int_message | (i << msg_width_bits)
        point = curve.getpointwithx(try_message)
        if point:
            point = point[0]
            break
    return point


def elgamal_encrypt(recipient_pubkey, msg, msg_width_bits):
    k = ECPrivateKey.generate(curve)
示例#6
0
#	along with joeecc; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	Johannes Bauer <*****@*****.**>
#

import sys

from ecc import AffineCurvePoint, ShortWeierstrassCurve, getcurvebyname
from ecc import ECPrivateKey

def separator():
	print("-" * 150)


usedcurve = getcurvebyname("secp112r1")
#usedcurve = getcurvebyname("brainpoolP160r1")
#usedcurve = getcurvebyname("secp192k1")
print("Selected curve parameters:")
print(str(usedcurve))
separator()

privatekey = ECPrivateKey(0x12345, usedcurve)
print("Generated privatekey")
print(str(privatekey))
separator()


########################### Encryption example ###########################
e = privatekey.pubkey.ecies_encrypt()
print("Encryption")
示例#7
0
for i in range(16):
    hash[8 + i] = hash[8 + i] ^ lic[16 + i]

hash[31] = (hash[31] & 0x7F) | 0x40
hash[0] = hash[0] & 0xF8

print("-- Modified license hash")
printBytes(hash)
print()

sig = lic[32:64]
print("-- License signature (from License)")
printBytes(sig)
print()

curve = getcurvebyname("curve25519")

pub = "8E1067E4305FCDC0CFBF95C10F96E5DFE8C49AEF486BD1A4E2E96C27F01E3E32"

pub = binascii.b2a_hex(binascii.a2b_hex(pub)[::-1])
pub = int(pub, 16)

hash = int.from_bytes(hash, 'little')
sig = int.from_bytes(sig, 'little')

# Py of public key to Px
pub = AffineCurvePoint(
    pub,
    int(FieldElement(pub**3 + int(curve.a) * pub**2 + pub, curve.p).sqrt()[0]),
    curve)
示例#8
0
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with joeecc; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#	Johannes Bauer <*****@*****.**>
#

import time
import sys
from ecc import getcurvebyname, ECPrivateKey
from StopWatch import StopWatch

curve = getcurvebyname("ed25519")

if len(sys.argv) < 2:
    keypair = ECPrivateKey.eddsa_generate(curve)
    print("Generating keypair on the fly")
else:
    keypair = ECPrivateKey.loadkeypair(bytes.fromhex(sys.argv[1]))
print("Keypair:", keypair)

msg = b"Foobar!"
print("Message:", msg)

signature = keypair.eddsa_sign(msg)
print("Signature:", signature)

print("Verify correct message: %s (should be True)" %
示例#9
0
文件: ecccc.py 项目: ncme/ecccc
def vvprint(*args, **kwargs):
    if arg.verbose >= 2:
        print(args, kwargs)


def vvvprint(*args, **kwargs):
    if arg.verbose >= 3:
        print(args, kwargs)


vvvprint(parser.parse_args())

################################ Curve Specifications ################################

usedcurve = getcurvebyname("secp256r1")

# General Domain Parameters
p = 57896044618658097711785492504343953926634992332820282019728792003956564819949
n = 7237005577332262213973186563042994240857116359379907606001950938285454250989
h = 8

# Montgommery Domain Parameters
A = 486662

# Edwards Domain Parameters
d = 37095705934669439343138083508754565189542113879843219016388785533085940283555

wei = ShortWeierstrassCurve(
    19298681539552699237261830834781317975544997444273427339909597334573241639236,  # a
    55751746669818908907645289078257140818241103727901012315294400837956729358436,  # b