Example #1
0
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from Crypto.Random import random

from binascii import hexlify, unhexlify
import time
import json

from ecpy.curves import curve_secp256k1
from ecpy.point import Point, Generator
from ecpy.ecdsa import ECDSA

_def_curve = curve_secp256k1
Point.set_curve(_def_curve)
ECDSA.set_curve(_def_curve)
ECDSA.set_generator(Generator.init(_def_curve['G'][0], _def_curve['G'][1]))

class NAK(object):
    n = _def_curve['n']
    G = Generator.init(_def_curve['G'][0], _def_curve['G'][1])
    ecdsa = ECDSA()
    
    def __init__(self, expire=None, pubkey=None, signature=None, privkey=None):
        self.expire = expire
        self.pubkey = pubkey
        self.signature = signature
        self.privkey = privkey
        if privkey is not None and pubkey is None:
            self.pubkey = NAK.G * privkey
        if self.pubkey is not None:
from ecpy.ecdsa import ECDSA

# version = 1.00 in fixed point
_msg_api_ver_v1 = b'M0100'
_msg_api_ver_v2 = b'M\x02\x00\x00'

_C = curve_secp256k1
# _C = curve_secp384r1
# _C = curve_secp112r1
# _C = curve_bauer9

_masksize = min(32, _C['bits'])
_maskbits = (int((_masksize / 3) + 0))

_G = Generator.init(_C['G'][0], _C['G'][1])
ECDSA.set_curve(_C)
ECDSA.set_generator(_G)
_ecdsa = ECDSA()

# convert integer to hex string
_pfmt = '%%0%dx' % (((_C['bits'] + 7) >> 3) << 1)
_mfmt = '%%0%dx' % (((_masksize + 7) >> 3) << 1)

# 256 bit message seed
_s_bytes = 32 
# 64 bit plaintext length field
_l_bytes = 8

_lfmt = '%016x'

_header_size_v1 = (5+1+8+1+8+1+66+1+66+1+66)
Example #3
0
import ecpy.curves as curves
from ecpy.ecdsa import ECDSA
from Crypto.Random import random
from Crypto.Cipher import AES
from Crypto.Util import Counter
import hashlib
import binascii
import base64

#_curve = curves.curve_secp112r1
_curve = curves.curve_secp256k1
#_curve = curves.curve_secp384r1

Point.set_curve(_curve)
_G = Generator.init(_curve['G'][0], _curve['G'][1])
ECDSA.set_curve(_curve)
ECDSA.set_generator(_G)

ecdsa = ECDSA()
recdsa = ECDSA()

friends = ['Alice', 'Bob', 'Carl', 'Donna', 'Eve']

data = []
for f in friends:
    datum = {}
    datum['name'] = f
    p = random.randint(1,_curve['n']-1)
    P = p * _G
    datum['privkey'] = p
    datum['pubkey'] = P