def test_getattr(self): curves = ECurve._CurveNames() for c in curves: cva = ECurve(c) p = cva.p n = cva.n h = cva.h G = cva.G bits = cva.bits ctype = cva.ctype if ctype == 'ShortWeierstrass': a = cva.a b = cva.b cvb = ECurve.ShortWeierstrass(p, a, b, n, h, G[0], G[1], bits) elif ctype == 'Edwards': c = cva.c d = cva.d cvb = ECurve.Edwards(p, c, d, n, h, G[0], G[1], bits) elif ctype == 'Montgomery': B = cva.B A = cva.A cvb = ECurve.Montgomery(p, B, A, n, h, G[0], G[1], bits) else: self.assertEqual(ctype, "TwistedEdwards") a = cva.a d = cva.d cvb = ECurve.TwistedEdwards(p, a, d, n, h, G[0], G[1], bits) self.assertEqual(cva, cvb)
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from ECC import FieldElement, ECurve from example_der import der_encode_privkey from example_pem import pem_wrap from argparse import ArgumentParser import base64 import sys desc = ('ecdh-gen generates a private key for elliptic curve cryptography ' 'based on a specific curve. The private key value is simply a ' 'random number ') parser = ArgumentParser(description=desc) parser.add_argument('-l', '--list_curves', action='store_true', help='list supported curves') parser.add_argument('-c', '--curve', default='secp256k1', help='choose standard curve') clargs = parser.parse_args() if clargs.list_curves: clist = ECurve._CurveNames() for c in clist: print(c) sys.exit(0) curve = ECurve(clargs.curve) privkey = int(FieldElement.urandom(curve.p)) DERkey = der_encode_privkey(privkey, curve) print(pem_wrap(DERkey, 'ECDH PRIVATE KEY'))