Example #1
0
 def test_oids(self):
     oid_ecPublicKey = der.encode_oid(1, 2, 840, 10045, 2, 1)
     self.failUnlessEqual(hexlify(oid_ecPublicKey), "06072a8648ce3d0201")
     self.failUnlessEqual(hexlify(NIST224p.encoded_oid), "06052b81040021")
     self.failUnlessEqual(hexlify(NIST256p.encoded_oid), "06082a8648ce3d030107")
     x = oid_ecPublicKey + "more"
     x1, rest = der.remove_object(x)
     self.failUnlessEqual(x1, (1, 2, 840, 10045, 2, 1))
     self.failUnlessEqual(rest, "more")
Example #2
0
 def test_oids(self):
     oid_ecPublicKey = der.encode_oid(1, 2, 840, 10045, 2, 1)
     self.assertEqual(hexlify(oid_ecPublicKey), b("06072a8648ce3d0201"))
     self.assertEqual(hexlify(NIST224p.encoded_oid), b("06052b81040021"))
     self.assertEqual(hexlify(NIST256p.encoded_oid),
                      b("06082a8648ce3d030107"))
     x = oid_ecPublicKey + b("more")
     x1, rest = der.remove_object(x)
     self.assertEqual(x1, (1, 2, 840, 10045, 2, 1))
     self.assertEqual(rest, b("more"))
Example #3
0
 def __init__(self, name, curve, generator, oid):
     self.name = name
     self.curve = curve
     self.generator = generator
     self.order = generator.order()
     self.baselen = orderlen(self.order)
     self.verifying_key_length = 2*self.baselen
     self.signature_length = 2*self.baselen
     self.oid = oid
     self.encoded_oid = der.encode_oid(*oid)
Example #4
0
 def __init__(self, name, curve, generator, oid):
     self.name = name
     self.curve = curve
     self.generator = generator
     self.order = generator.order()
     self.baselen = orderlen(self.order)
     self.verifying_key_length = 2 * self.baselen
     self.signature_length = 2 * self.baselen
     self.oid = oid
     self.encoded_oid = der.encode_oid(*oid)
Example #5
0
scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
os.chdir(scriptPath)

#append the relative location you want to import from
sys.path.append(".")
import der
from curves import orderlen

# RFC5480:
#   The "unrestricted" algorithm identifier is:
#     id-ecPublicKey OBJECT IDENTIFIER ::= {
#       iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 }

oid_ecPublicKey = (1, 2, 840, 10045, 2, 1)
encoded_oid_ecPublicKey = der.encode_oid(*oid_ecPublicKey)


def randrange(order, entropy=None):
    """Return a random integer k such that 1 <= k < order, uniformly
    distributed across that range. For simplicity, this only behaves well if
    'order' is fairly close (but below) a power of 256. The try-try-again
    algorithm we use takes longer and longer time (on average) to complete as
    'order' falls, rising to a maximum of avg=512 loops for the worst-case
    (256**k)+1 . All of the standard curves behave well. There is a cutoff at
    10k loops (which raises RuntimeError) to prevent an infinite loop when
    something is really broken like the entropy function not working.

    Note that this function is not declared to be forwards-compatible: we may
    change the behavior in future releases. The entropy= argument (which
    should get a callable that behaves like os.urandom) can be used to
Example #6
0
import os
import math
import binascii
from hashlib import sha256
import der
from curves import orderlen

# RFC5480:
#   The "unrestricted" algorithm identifier is:
#     id-ecPublicKey OBJECT IDENTIFIER ::= {
#       iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 }

oid_ecPublicKey = (1, 2, 840, 10045, 2, 1)
encoded_oid_ecPublicKey = der.encode_oid(*oid_ecPublicKey)

def randrange(order, entropy=None):
    """Return a random integer k such that 1 <= k < order, uniformly
    distributed across that range. For simplicity, this only behaves well if
    'order' is fairly close (but below) a power of 256. The try-try-again
    algorithm we use takes longer and longer time (on average) to complete as
    'order' falls, rising to a maximum of avg=512 loops for the worst-case
    (256**k)+1 . All of the standard curves behave well. There is a cutoff at
    10k looks (which raises RuntimeError) to prevent an infinite loop when
    something is really broken like the entropy function not working.

    Note that this function is not declared to be forwards-compatible: we may
    change the behavior in future releases. The entropy= argument (which
    should get a callable that behaves like os.entropy) can be used to
    achieve stability within a given release (for repeatable unit tests), but
    should not be used as a long-term-compatible key generation algorithm.