9(Zc@`s7dZddlmZmZmZmZddlmZdd$dYZdd%dYZ e d#d#d#Z ed d d Z e e d d dZ edd dZe edddZedd dZe edddZedd dZe edddZedd dZe ed d!d"Zd#S(&u Classes and objects to represent prime-field elliptic curves and points on them. Exports the following items: - PrimeCurve() - PrimePoint() - SECP192R1_CURVE - SECP192R1_BASE_POINT - SECP224R1_CURVE - SECP224R1_BASE_POINT - SECP256R1_CURVE - SECP256R1_BASE_POINT - SECP384R1_CURVE - SECP384R1_BASE_POINT - SECP521R1_CURVE - SECP521R1_BASE_POINT The curve constants are all PrimeCurve() objects and the base point constants are all PrimePoint() objects. Some of the following source code is derived from http://webpages.charter.net/curryfans/peter/downloads.html, but has been heavily modified to fit into this projects lint settings. The original project license is listed below: Copyright (c) 2014 Peter Pearson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. i(tunicode_literalstdivisiontabsolute_importtprint_functioni(t inverse_modt PrimeCurvecB`s eZdZdZdZRS(uc Elliptic curve over a prime field. Characteristic two field curves are not supported. cC`s||_||_||_dS(u The curve of points satisfying y^2 = x^3 + a*x + b (mod p) :param p: The prime number as an integer :param a: The component a as an integer :param b: The component b as an integer N(tptatb(tselfRRR((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt__init__<s  cC`sQ|j|j}|j|j|j}|||j|j|j|jdkS(u~ :param point: A Point object :return: Boolean if the point is on this curve i(tytxRRR(R tpointty2tx3((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pytcontainsNs (t__name__t __module__t__doc__R R(((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyR6s t PrimePointcB`sGeZdZddZdZdZdZdZdZ RS(u1 A point on a prime-field elliptic curve cC`s||_||_||_||_|jrQ|jj|sQtdqQn|jr||jtkrtdqndS(u) :param curve: A PrimeCurve object :param x: The x coordinate of the point as an integer :param y: The y coordinate of the point as an integer :param order: The order of the point, as an integer - optional uInvalid EC pointN(tcurveR R torderRt ValueErrortINFINITY(R RR R R((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyR as      cC`sB|j|jkr:|j|jkr:|j|jkr:dSdSdS(uy :param other: A PrimePoint object :return: 0 if identical, 1 otherwise iiN(RR R (R tother((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt__cmp__~s6cC`s|tkr|S|tkr |S|j|jks8t|j|jkr{|j|j|jjdkrntS|jSn|jj}|j|jt|j|j||}|||j|j|}||j||j|}t|j||S(uq :param other: A PrimePoint object :return: A PrimePoint object i( RRtAssertionErrorR R RtdoubleRR(R RRtlRty3((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt__add__s     +cC`s#d}|}|jr(||j}n|dkr8tS|tkrHtS|dksZtd|}t|j|j|j |j}||d}|}x|dkr|j}||@dkr||@dkr||}n||@dkr||@dkr||}n|d}qW|S(u :param other: An integer to multiple the Point by :return: A PrimePoint object cS`s=|dkstd}x||kr4d|}qW|dS(Niii(R(R tresult((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt leftmost_bits iiii(RRRRRR R R(R RR!tete3t negative_selftiR ((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt__mul__s*     "     cC`s||S(u :param other: An integer to multiple the Point by :return: A PrimePoint object ((R R((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt__rmul__s cC`s|jj}|jj}d|j|j|td|j||}||d|j|}||j||j|}t|j||S(uS :return: A PrimePoint object that is twice this point ii(RRRR RR R(R RRRRR((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyRs   0N( RRRtNoneR RRR&R'R(((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyR\s   + l il 9{uDjSg9g(Bl +'1t:_|v!a:@ml H<^W]dZ{cxW\Iql 1(i&^#a;l?lF eY8 w-X"PVd/%PP!-l!"X!#BXtJ9!'|%VA-l4~ f&Dv@h!fE0m9_ qlM/l=*8%(?l?@lK`Opq^cv 3,e< 1U]>{|R*ZlB11e %:f=K`wrH7gHK8hklQ~o]l+fUg+<)Z?8O?q!OlQ%x +Ohbi+}s@l~l*'#.TEbc+Z'@=D 1 "(?7N2Z_+|S/1fl dxRjoyU8T( :ss"nZL8k&"_Ul_!uR/sX0 @qaNQNB&JxS8KJEY K%lls)e`gwl X_[nlv|l#l#?VQ(zO%b95~cte1oR{V;LH w>l-rZE]"Sr&Ga9}*Fl#f=xK)H-apY$3^Q n%k{;/K!u{4-{?$Od8V1l3s: l#Pf?QE$XN!85aZU WL9YLhz f$Du13otc!% pMxjRr`l# dp"z\}[z3"nZ;PK# `7roCQN(((Rt __future__RRRRt_intRRRR(RtSECP192R1_CURVEtSECP192R1_BASE_POINTtSECP224R1_CURVEtSECP224R1_BASE_POINTtSECP256R1_CURVEtSECP256R1_BASE_POINTtSECP384R1_CURVEtSECP384R1_BASE_POINTtSECP521R1_CURVEtSECP521R1_BASE_POINT(((s>/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_elliptic_curve.pyt/sd"&