예제 #1
0
def sign(message):
    pp = PublicParams.get_default()
    params = LocalParams.get_default()
    G = pp.ec_group
    digest = pp.hash_func(message).digest()
    kinv_rp = do_ecdsa_setup(G, params.sig.sk)
    sig = do_ecdsa_sign(G, params.sig.sk, digest, kinv_rp=kinv_rp)
    return sig
예제 #2
0
파일: __init__.py 프로젝트: blighli/rscoin
 def __init__(self, key_bytes, public=True):
     """ Make a key given a public or private key in bytes """
     self.G = _globalECG
     if public:
         self.sec = None
         self.pub = EcPt.from_binary(key_bytes, self.G)
         self.optim = None
     else:
         self.sec = Bn.from_binary(sha256(key_bytes).digest())
         self.pub = self.sec * self.G.generator()
         self.optim = do_ecdsa_setup(self.G, self.sec)
예제 #3
0
 def __init__(self, key_bytes, public=True):
     """ Make a key given a public or private key in bytes """
     self.G = _globalECG
     if public:
         self.sec = None
         self.pub = EcPt.from_binary(key_bytes, self.G)
         self.optim = None
     else:
         self.sec = Bn.from_binary(sha256(key_bytes).digest())
         self.pub = self.sec * self.G.generator()
         self.optim = do_ecdsa_setup(self.G, self.sec)
예제 #4
0
def ecdsa_sign(G, priv_sign, message):
    """ Sign the SHA256 digest of the message using ECDSA and return a signature """
    plaintext = message.encode("utf8")

    ## YOUR CODE HERE
    G = EcGroup()
    ver_key = priv_sign * G.generator()
    digest = sha256(plaintext).digest()
    kinv_rp = do_ecdsa_setup(G, priv_sign)
    sig = do_ecdsa_sign(G, priv_sign, digest, kinv_rp=kinv_rp)

    return sig
예제 #5
0
def sign(message):
    """Sign a message.

    :param bytes message: Message
    :return: Tuple of bignums (``petlib.bn.Bn``)
    """
    pp = PublicParams.get_default()
    params = LocalParams.get_default()
    G = pp.ec_group
    digest = pp.hash_func(message).digest()
    kinv_rp = do_ecdsa_setup(G, params.sig.sk)
    sig = do_ecdsa_sign(G, params.sig.sk, digest, kinv_rp=kinv_rp)
    return sig
예제 #6
0
from collections import defaultdict, Counter
import binascii
import json
import uuid
import random
import qrcode

G = EcGroup(934)
order = G.order()
h = G.generator()
sleeve = "nothing_up_my_sleeve"
g = G.hash_to_point(sleeve.encode('utf-8'))

#secret!!!
sig_key = order.random()
kinv_rp = do_ecdsa_setup(G, sig_key)
#not secret
ver_key = sig_key * h


def commit(a, r):
    return a * h + r * g


def genRealCommitments(vote, k, R):
    real_commitment = commit(vote, R)
    rb = [order.random() for i in range(k)]
    masks = [commit(vote, R + rb[i]) for i in range(k)]
    return real_commitment, masks, rb

예제 #7
0
    failed = 0
    result = True
    for a, b in zip(hashes, sigs):
        res = do_ecdsa_verify(Gx, pub_verifyx, b, a)
        if (res == False):
            result = False
    return result


# ---------------------- Signing Phase --------------------------------- #

G = EcGroup(714)
print("G is: ", G)
priv_sign = G.order().random()
print("priv_sign: ", priv_sign)
kinv_rp = do_ecdsa_setup(G, priv_sign)
pub_verify = priv_sign * G.generator()
print("pub_verify: ", pub_verify)

VariantsArr = OpenVCFfileAsArray(VCFfilePath)
SegmentedVariantsArr = SegmentArr(VariantsArr, Segments)
SegmentedVariantsArrEncoded = EncodeArr(SegmentedVariantsArr)

signatures = []


def signit(Gx, priv_signx, pub_verifyx, SigsFile, segs, VCFfilePath, HType,
           ArrFName):
    global signatures
    global SegmentedVariantsArrEncoded
    hashesToBeSigned = CreateHashListOfVariants(SegmentedVariantsArrEncoded,
예제 #8
0
See also http://andrea.corbellini.name/2015/05/30/elliptic-curve-cryptography-ecdh-and-ecdsa/

The first thing we are going to do is sign a peice of text. Signing is an important foundational part of our contract design.

Before signing we create a digest of the text as it might be very long.
"""

digest = sha1(b"Something I wish to sign").digest()

print hexlify(digest)
"""Next we can sign it. We need the elliptic curve parameter `G` which we can get from the params we created in the setup. We pass it the public key we generated earlier"""

(G, _, _, _) = params

kinv_rp = do_ecdsa_setup(G, private_key)
"""Now we can sign our digest"""

sig = do_ecdsa_sign(G, private_key, digest, kinv_rp=kinv_rp)

print pack(sig)
"""Finally we can verify it using the public key from our keypair"""

do_ecdsa_verify(G, public_key, sig, digest)
"""Here is a bunch of crypto functions for [homomorphic encryption](https://en.wikipedia.org/wiki/Homomorphic_encryption)

See [here](https://crypto.stackexchange.com/questions/45040/can-elliptic-curve-cryptography-encrypt-with-public-key-and-decrypt-with-private) for an answer about doing encryption with elliptic curve cryptography.

In order to do [asymetric encryption](https://en.wikipedia.org/wiki/Public-key_cryptography)  using ECC you first have to turn your message into a point on the curve,you can then encrypt using a public key which can be decrypted with the private key. 

There is a scheme for more general encrpytion, the https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme which allows two parties to generate a symetric key that they can use to encrypt a message between them