Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
323 views
import sys #Elliptic Curve Equation S = 0x3CC520E9434349DF680A8F4BCADDA648D693B2907B216EE55CB4853DB68F9165 B = 0xBADA55ECFD9CA54C0738B8A6FB8CF4CCF84E916D83D6DA1B78B622351E11AB4E # not verified in this script: B is keccakc512 hash of S p = 2^224 - 2^96 + 1 k = GF(p) E = EllipticCurve([-3,k(B)]) POINT=E([24294131642903404145362439328552232420913806199043249784369083939543,17606117047404906940971205441144757367619393122854115924698840695678]) ### %timeit ## Device Parameter Kp_Device =E([6327408393275691764421702233721194182741567030907130764481789421023,5941226427717805249171622352202515769251645036961947533587467922945]); Ks_Device =345689234715694576280443562782396541287; R1_Value =201789304238901928399129302030029883; Rc_Value =E([26958216024458566358533683726881768019865155258594696047350119889787,7569845708834249284265954409598807805624127804150706075593937436989]); ## User Parameter R2_Value = 83896900857616190668356691213866118443; ##R3_Value =E([23745121403197030605972291629059229726107511912505077029333609870661,13411095009376414804175132633303063079189679844552032853429137224474]); R3_Value=R2_Value * Rc_Value #Public Server Kps_Device =E([6327408393275691764421702233721194182741567030907130764481789421023,5941226427717805249171622352202515769251645036961947533587467922945]); AVC=R1_Value + (R2_Value*Ks_Device); Rc2=(AVC * POINT)-(R2_Value * Kps_Device); R=R2_Value*(R1_Value*POINT) #First Authentication Process if (Kps_Device == Kp_Device): print 'Public Key Device valid'; else: print 'Public Key Device is Not Valid'; #Second Authentication Process if Rc2==Rc_Value: print 'Legitimate Device'; else: print 'Unlegitimate Device'; if R==R3_Value: print 'Legitimate user'; else: print 'Unlegitimate User';
25 loops, best of 3: 34.6 ms per loop