def checkSignature(self, data, signature, pubKey): dgst = gost34112012256.new(data.encode()).digest() return verify(self.curve, pub_unmarshal(hexdec(pubKey), mode=2012), dgst, hexdec(signature), mode=2012)
def test_2(self): """Test vector from 34.10-2012 standard itself """ curve = GOST3410Curve( p= 3623986102229003635907788753683874306021320925534678605086546150450856166624002482588482022271496854025090823603058735163734263822371964987228582907372403, q= 3623986102229003635907788753683874306021320925534678605086546150450856166623969164898305032863068499961404079437936585455865192212970734808812618120619743, a=7, b= 1518655069210828534508950034714043154928747527740206436194018823352809982443793732829756914785974674866041605397883677596626326413990136959047435811826396, x= 1928356944067022849399309401243137598997786635459507974357075491307766592685835441065557681003184874819658004903212332884252335830250729527632383493573274, y= 2288728693371972859970012155529478416353562327329506180314497425931102860301572814141997072271708807066593850650334152381857347798885864807605098724013854, ) prv = bytes2long( hexdec( "0BA6048AADAE241BA40936D47756D7C93091A0E8514669700EE7508E508B102072E8123B2200A0563322DAD2827E2714A2636B7BFD18AADFC62967821FA18DD4" )) digest = hexdec( "3754F3CFACC9E0615C4F4A7C4D8DAB531B09B6F9C170C533A71D147035B0C5917184EE536593F4414339976C647C5D5A407ADEDB1D560C4FC6777D2972075B8C" ) rand = hexdec( "0359E7F4B1410FEACC570456C6801496946312120B39D019D455986E364F365886748ED7A44B3E794434006011842286212273A6D14CF70EA3AF71BB1AE679F1" ) signature = sign(curve, prv, digest, rand, mode=2012) r = "2f86fa60a081091a23dd795e1e3c689ee512a3c82ee0dcc2643c78eea8fcacd35492558486b20f1c9ec197c90699850260c93bcbcd9c5c3317e19344e173ae36" s = "1081b394696ffe8e6585e7a9362d26b6325f56778aadbc081c0bfbe933d52ff5823ce288e8c4f362526080df7f70ce406a6eeb1f56919cb92a9853bde73e5b4a" self.assertSequenceEqual(hexenc(signature), s + r)
def test_cryptomanager(self): """ Test vector from http://cryptomanager.com/tv.html """ sbox = "id-GostR3411-94-TestParamSet" key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B") self.assertSequenceEqual( ecb_encrypt(key, hexdec(b"1122334455667788"), sbox=sbox), hexdec(b"03251E14F9D28ACB"), )
def test_cryptomanager(self): """ Test vector from http://cryptomanager.com/tv.html """ sbox = "GostR3411_94_TestParamSet" key = hexdec(b'75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B') self.assertEqual( ecb_encrypt(key, hexdec(b'1122334455667788'), sbox=sbox), hexdec(b'03251E14F9D28ACB'), )
def test_m2(self): m = hexdec("fbe2e5f0eee3c820fbeafaebef20fffbf0e1e0f0f520e0ed20e8ece0ebe5f0f2f120fff0eeec20f120faf2fee5e2202ce8f6f3ede220e8e6eee1e8f0f2d1202ce8f0f2e5e220e5d1")[::-1] self.assertEqual( GOST341112(m).digest(), hexdec("28fbc9bada033b1460642bdcddb90c3fb3e56c497ccd0f62b8a2ad4935e85f037613966de4ee00531ae60f3b5a47f8dae06915d5f2f194996fcabf2622e6881e")[::-1] ) self.assertEqual( GOST341112(m, digest_size=256).digest(), hexdec("508f7e553c06501d749a66fc28c6cac0b005746d97537fa85d9e40904efed29d")[::-1] )
def test_m1(self): m = hexdec("323130393837363534333231303938373635343332313039383736353433323130393837363534333231303938373635343332313039383736353433323130")[::-1] self.assertEqual( GOST341112(m).digest(), hexdec("486f64c1917879417fef082b3381a4e211c324f074654c38823a7b76f830ad00fa1fbae42b1285c0352f227524bc9ab16254288dd6863dccd5b9f54a1ad0541b")[::-1] ) self.assertEqual( GOST341112(m, digest_size=256).digest(), hexdec("00557be5e584fd52a449b16b0251d05d27f94ab76cbaa6da890b59d8ef1e159d")[::-1] )
def test_vector(self): curve = GOST3410Curve(*CURVE_PARAMS["GostR3410_2001_TestParamSet"]) ukm = ukm_unmarshal(hexdec("5172be25f852a233")) prv1 = prv_unmarshal(hexdec("1df129e43dab345b68f6a852f4162dc69f36b2f84717d08755cc5c44150bf928")) prv2 = prv_unmarshal(hexdec("5b9356c6474f913f1e83885ea0edd5df1a43fd9d799d219093241157ac9ed473")) kek = hexdec("ee4618a0dbb10cb31777b4b86a53d9e7ef6cb3e400101410f0c0f2af46c494a6") pub1 = public_key(curve, prv1) pub2 = public_key(curve, prv2) self.assertEqual(kek_34102001(curve, prv1, pub2, ukm), kek) self.assertEqual(kek_34102001(curve, prv2, pub1, ukm), kek)
class KuznechikTest(TestCase): key = hexdec( "8899aabbccddeeff0011223344556677fedcba98765432100123456789abcdef") plaintext = hexdec("1122334455667700ffeeddccbbaa9988") ciphertext = hexdec("7f679d90bebc24305a468d42b9d4edcd") def test_c(self): self.assertSequenceEqual(C[0], hexdec("6ea276726c487ab85d27bd10dd849401")) self.assertSequenceEqual(C[1], hexdec("dc87ece4d890f4b3ba4eb92079cbeb02")) self.assertSequenceEqual(C[2], hexdec("b2259a96b4d88e0be7690430a44f7f03")) self.assertSequenceEqual(C[3], hexdec("7bcd1b0b73e32ba5b79cb140f2551504")) self.assertSequenceEqual(C[4], hexdec("156f6d791fab511deabb0c502fd18105")) self.assertSequenceEqual(C[5], hexdec("a74af7efab73df160dd208608b9efe06")) self.assertSequenceEqual(C[6], hexdec("c9e8819dc73ba5ae50f5b570561a6a07")) self.assertSequenceEqual(C[7], hexdec("f6593616e6055689adfba18027aa2a08")) def test_roundkeys(self): ciph = GOST3412Kuznechik(self.key) self.assertSequenceEqual(ciph.ks[0], hexdec("8899aabbccddeeff0011223344556677")) self.assertSequenceEqual(ciph.ks[1], hexdec("fedcba98765432100123456789abcdef")) self.assertSequenceEqual(ciph.ks[2], hexdec("db31485315694343228d6aef8cc78c44")) self.assertSequenceEqual(ciph.ks[3], hexdec("3d4553d8e9cfec6815ebadc40a9ffd04")) self.assertSequenceEqual(ciph.ks[4], hexdec("57646468c44a5e28d3e59246f429f1ac")) self.assertSequenceEqual(ciph.ks[5], hexdec("bd079435165c6432b532e82834da581b")) self.assertSequenceEqual(ciph.ks[6], hexdec("51e640757e8745de705727265a0098b1")) self.assertSequenceEqual(ciph.ks[7], hexdec("5a7925017b9fdd3ed72a91a22286f984")) self.assertSequenceEqual(ciph.ks[8], hexdec("bb44e25378c73123a5f32f73cdb6e517")) self.assertSequenceEqual(ciph.ks[9], hexdec("72e9dd7416bcf45b755dbaa88e4a4043")) def test_encrypt(self): ciph = GOST3412Kuznechik(self.key) self.assertSequenceEqual(ciph.encrypt(self.plaintext), self.ciphertext) def test_decrypt(self): ciph = GOST3412Kuznechik(self.key) self.assertSequenceEqual(ciph.decrypt(self.ciphertext), self.plaintext)
def test_roundkeys(self): ciph = GOST3412Kuz(self.key) self.assertEqual(ciph.ks[0], hexdec("8899aabbccddeeff0011223344556677")) self.assertEqual(ciph.ks[1], hexdec("fedcba98765432100123456789abcdef")) self.assertEqual(ciph.ks[2], hexdec("db31485315694343228d6aef8cc78c44")) self.assertEqual(ciph.ks[3], hexdec("3d4553d8e9cfec6815ebadc40a9ffd04")) self.assertEqual(ciph.ks[4], hexdec("57646468c44a5e28d3e59246f429f1ac")) self.assertEqual(ciph.ks[5], hexdec("bd079435165c6432b532e82834da581b")) self.assertEqual(ciph.ks[6], hexdec("51e640757e8745de705727265a0098b1")) self.assertEqual(ciph.ks[7], hexdec("5a7925017b9fdd3ed72a91a22286f984")) self.assertEqual(ciph.ks[8], hexdec("bb44e25378c73123a5f32f73cdb6e517")) self.assertEqual(ciph.ks[9], hexdec("72e9dd7416bcf45b755dbaa88e4a4043"))
def test_512(self): for digestmod in (GOST34112012512, gost34112012512): self.assertEqual( hmac.new( key=hexdec( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ), msg=hexdec("0126bdb87800af214341456563780100"), digestmod=digestmod, ).hexdigest(), "a59bab22ecae19c65fbde6e5f4e9f5d8549d31f037f9df9b905500e171923a773d5f1530f2ed7e964cb2eedc29e9ad2f3afe93b2814f79f5000ffc0366c251e6", )
def test_256(self): for digestmod in (GOST34112012256, gost34112012256): self.assertEqual( hmac.new( key=hexdec( "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ), msg=hexdec("0126bdb87800af214341456563780100"), digestmod=digestmod, ).hexdigest(), "a1aa5f7de402d7b3d323f2991c8d4534013137010a83754fd0af6d7cd4922ed9", )
class MagmaTest(TestCase): key = hexdec( "ffeeddccbbaa99887766554433221100f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff") plaintext = hexdec("fedcba9876543210") ciphertext = hexdec("4ee901e5c2d8ca3d") def test_encrypt(self): ciph = GOST3412Magma(self.key) self.assertSequenceEqual(ciph.encrypt(self.plaintext), self.ciphertext) def test_decrypt(self): ciph = GOST3412Magma(self.key) self.assertSequenceEqual(ciph.decrypt(self.ciphertext), self.plaintext)
def test_m2(self): m = hexdec( "fbe2e5f0eee3c820fbeafaebef20fffbf0e1e0f0f520e0ed20e8ece0ebe5f0f2f120fff0eeec20f120faf2fee5e2202ce8f6f3ede220e8e6eee1e8f0f2d1202ce8f0f2e5e220e5d1" )[::-1] self.assertEqual( GOST341112(m).digest(), hexdec( "28fbc9bada033b1460642bdcddb90c3fb3e56c497ccd0f62b8a2ad4935e85f037613966de4ee00531ae60f3b5a47f8dae06915d5f2f194996fcabf2622e6881e" )[::-1]) self.assertEqual( GOST341112(m, digest_size=256).digest(), hexdec( "508f7e553c06501d749a66fc28c6cac0b005746d97537fa85d9e40904efed29d" )[::-1])
def test_m1(self): m = hexdec( "323130393837363534333231303938373635343332313039383736353433323130393837363534333231303938373635343332313039383736353433323130" )[::-1] self.assertEqual( GOST341112(m).digest(), hexdec( "486f64c1917879417fef082b3381a4e211c324f074654c38823a7b76f830ad00fa1fbae42b1285c0352f227524bc9ab16254288dd6863dccd5b9f54a1ad0541b" )[::-1]) self.assertEqual( GOST341112(m, digest_size=256).digest(), hexdec( "00557be5e584fd52a449b16b0251d05d27f94ab76cbaa6da890b59d8ef1e159d" )[::-1])
def test_ecb_vectors(self): ciphtext = "" ciphtext += "7f679d90bebc24305a468d42b9d4edcd" ciphtext += "b429912c6e0032f9285452d76718d08b" ciphtext += "f0ca33549d247ceef3f5a5313bd4b157" ciphtext += "d0b09ccde830b9eb3a02c4c5aa8ada98" self.assertSequenceEqual( hexenc(ecb_encrypt(self.ciph.encrypt, 16, hexdec(self.plaintext))), ciphtext, ) self.assertSequenceEqual( hexenc(ecb_decrypt(self.ciph.decrypt, 16, hexdec(ciphtext))), self.plaintext, )
def test_ecb_vectors(self): ciphtext = "" ciphtext += "2b073f0494f372a0" ciphtext += "de70e715d3556e48" ciphtext += "11d8d9e9eacfbc1e" ciphtext += "7c68260996c67efb" self.assertSequenceEqual( hexenc(ecb_encrypt(self.ciph.encrypt, 8, hexdec(self.plaintext))), ciphtext, ) self.assertSequenceEqual( hexenc(ecb_decrypt(self.ciph.decrypt, 8, hexdec(ciphtext))), self.plaintext, )
def test_ctr_vectors(self): ciphtext = "" ciphtext += "f195d8bec10ed1dbd57b5fa240bda1b8" ciphtext += "85eee733f6a13e5df33ce4b33c45dee4" ciphtext += "a5eae88be6356ed3d5e877f13564a3a5" ciphtext += "cb91fab1f20cbab6d1c6d15820bdba73" iv = self.iv[:8] self.assertSequenceEqual( hexenc(ctr(self.ciph.encrypt, 16, hexdec(self.plaintext), iv)), ciphtext, ) self.assertSequenceEqual( hexenc(ctr(self.ciph.encrypt, 16, hexdec(ciphtext), iv)), self.plaintext, )
def test_ofb_vectors(self): ciphtext = "" ciphtext += "81800a59b1842b24ff1f795e897abd95" ciphtext += "ed5b47a7048cfab48fb521369d9326bf" ciphtext += "66a257ac3ca0b8b1c80fe7fc10288a13" ciphtext += "203ebbc066138660a0292243f6903150" self.assertSequenceEqual( hexenc(ofb(self.ciph.encrypt, 16, hexdec(self.plaintext), self.iv)), ciphtext, ) self.assertSequenceEqual( hexenc(ofb(self.ciph.encrypt, 16, hexdec(ciphtext), self.iv)), self.plaintext, )
def test_ofb_vectors(self): iv = self.iv[:16] ciphtext = "" ciphtext += "db37e0e266903c83" ciphtext += "0d46644c1f9a089c" ciphtext += "a0f83062430e327e" ciphtext += "c824efb8bd4fdb05" self.assertSequenceEqual( hexenc(ofb(self.ciph.encrypt, 8, hexdec(self.plaintext), iv)), ciphtext, ) self.assertSequenceEqual( hexenc(ofb(self.ciph.encrypt, 8, hexdec(ciphtext), iv)), self.plaintext, )
def test_ctr_vectors(self): ciphtext = "" ciphtext += "4e98110c97b7b93c" ciphtext += "3e250d93d6e85d69" ciphtext += "136d868807b2dbef" ciphtext += "568eb680ab52a12d" iv = self.iv[:4] self.assertSequenceEqual( hexenc(ctr(self.ciph.encrypt, 8, hexdec(self.plaintext), iv)), ciphtext, ) self.assertSequenceEqual( hexenc(ctr(self.ciph.encrypt, 8, hexdec(ciphtext), iv)), self.plaintext, )
def test_curve1(self): c = CURVES["id-GostR3410-2001-CryptoPro-A-ParamSet"] q_ind = ( 0xA69D51CAF1A309FA9E9B66187759B0174C274E080356F23CFCBFE84D396AD7BB, 0x5D26F29ECC2E9AC0404DCF7986FA55FE94986362170F54B9616426A659786DAC, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F18127067" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x59495655D1E7C7424C622485F575CCF121F3122D274101E8AB734CC9C9A9B45E, 0x48D1C311D33C9B701F3B03618562A4A07A044E3AF31E3999E67B487778B53C62, )) self.assertEqual( c.exp( 0x1F2538097D5A031FA68BBB43C84D12B3DE47B7061C0D5E24993E0C873CDBA6B3 ), ( 0xBBC77CF42DC1E62D06227935379B4AA4D14FEA4F565DDF4CB4FA4D31579F9676, 0x8E16604A4AFDF28246684D4996274781F6CB80ABBBA1414C1513EC988509DABF, )) self.assertEqual( c.exp( 0xDC497D9EF6324912FD367840EE509A2032AEDB1C0A890D133B45F596FCCBD45D ), ( 0x6097341C1BE388E83E7CA2DF47FAB86E2271FD942E5B7B2EB2409E49F742BC29, 0xC81AA48BDB4CA6FA0EF18B9788AE25FE30857AA681B3942217F9FED151BAB7D0, ), )
def test_256(self): cert_raw = b64decode(""" MIICYjCCAg+gAwIBAgIBATAKBggqhQMHAQEDAjBWMSkwJwYJKoZIhvcNAQkBFhpH b3N0UjM0MTAtMjAxMkBleGFtcGxlLmNvbTEpMCcGA1UEAxMgR29zdFIzNDEwLTIw MTIgKDI1NiBiaXQpIGV4YW1wbGUwHhcNMTMxMTA1MTQwMjM3WhcNMzAxMTAxMTQw MjM3WjBWMSkwJwYJKoZIhvcNAQkBFhpHb3N0UjM0MTAtMjAxMkBleGFtcGxlLmNv bTEpMCcGA1UEAxMgR29zdFIzNDEwLTIwMTIgKDI1NiBiaXQpIGV4YW1wbGUwZjAf BggqhQMHAQEBATATBgcqhQMCAiQABggqhQMHAQECAgNDAARAut/Qw1MUq9KPqkdH C2xAF3K7TugHfo9n525D2s5mFZdD5pwf90/i4vF0mFmr9nfRwMYP4o0Pg1mOn5Rl aXNYraOBwDCBvTAdBgNVHQ4EFgQU1fIeN1HaPbw+XWUzbkJ+kHJUT0AwCwYDVR0P BAQDAgHGMA8GA1UdEwQIMAYBAf8CAQEwfgYDVR0BBHcwdYAU1fIeN1HaPbw+XWUz bkJ+kHJUT0ChWqRYMFYxKTAnBgkqhkiG9w0BCQEWGkdvc3RSMzQxMC0yMDEyQGV4 YW1wbGUuY29tMSkwJwYDVQQDEyBHb3N0UjM0MTAtMjAxMiAoMjU2IGJpdCkgZXhh bXBsZYIBATAKBggqhQMHAQEDAgNBAF5bm4BbARR6hJLEoWJkOsYV3Hd7kXQQjz3C dqQfmHrz6TI6Xojdh/t8ckODv/587NS5/6KsM77vc6Wh90NAT2s= """) prv_key_raw = hexdec( "BFCF1D623E5CDD3032A7C6EABB4A923C46E43D640FFEAAF2C3ED39A8FA399924" )[::-1] self.process_cert( "id-GostR3410-2001-CryptoPro-XchA-ParamSet", 2001, GOST34112012256, prv_key_raw, cert_raw, )
def test_curve7(self): c = CURVES["id-tc26-gost-3410-2012-512-paramSetC"] q_ind = ( 0x489C91784E02E98F19A803ABCA319917F37689E5A18965251CE2FF4E8D8B298F5BA7470F9E0E713487F96F4A8397B3D09A270C9D367EB5E0E6561ADEEB51581D, 0x684EA885ACA64EAF1B3FEE36C0852A3BE3BD8011B0EF18E203FF87028D6EB5DB2C144A0DCC71276542BFD72CA2A43FA4F4939DA66D9A60793C704A8C94E16F18, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F181270671C6213E3930EFDDA26451792C6208122EE60D200520D695DFD9F5F0FD5ABA702" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x0185AE6271A81BB7F236A955F7CAA26FB63849813C0287D96C83A15AE6B6A86467AB13B6D88CE8CD7DC2E5B97FF5F28FAC2C108F2A3CF3DB5515C9E6D7D210E8, 0xED0220F92EF771A71C64ECC77986DB7C03D37B3E2AB3E83F32CE5E074A762EC08253C9E2102B87532661275C4B1D16D2789CDABC58ACFDF7318DE70AB64F09B8, )) self.assertEqual( c.exp( 0x332F930421D14CFE260042159F18E49FD5A54167E94108AD80B1DE60B13DE7999A34D611E63F3F870E5110247DF8EC7466E648ACF385E52CCB889ABF491EDFF0 ), ( 0x561655966D52952E805574F4281F1ED3A2D498932B00CBA9DECB42837F09835BFFBFE2D84D6B6B242FE7B57F92E1A6F2413E12DDD6383E4437E13D72693469AD, 0xF6B18328B2715BD7F4178615273A36135BC0BF62F7D8BB9F080164AD36470AD03660F51806C64C6691BADEF30F793720F8E3FEAED631D6A54A4C372DCBF80E82, )) self.assertEqual( c.exp( 0x38481771E7D054F96212686B613881880BD8A6C89DDBC656178F014D2C093432A033EE10415F13A160D44C2AD61E6E2E05A7F7EC286BCEA3EA4D4D53F8634FA2 ), ( 0xB7C5818687083433BC1AFF61CB5CA79E38232025E0C1F123B8651E62173CE6873F3E6FFE7281C2E45F4F524F66B0C263616ED08FD210AC4355CA3292B51D71C3, 0x497F14205DBDC89BDDAF50520ED3B1429AD30777310186BE5E68070F016A44E0C766DB08E8AC23FBDFDE6D675AA4DF591EB18BA0D348DF7AA40973A2F1DCFA55, ), )
def test_1(self): """Test vector from 34.10-2012 standard itself """ curve = CURVES["id-GostR3410-2001-TestParamSet"] prv = bytes2long( hexdec( "7A929ADE789BB9BE10ED359DD39A72C11B60961F49397EEE1D19CE9891EC3B28" )) digest = hexdec( "2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5") rand = hexdec( "77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3") signature = sign(curve, prv, digest, rand) r = "41aa28d2f1ab148280cd9ed56feda41974053554a42767b83ad043fd39dc0493" s = "01456c64ba4642a1653c235a98a60249bcd6d3f746b631df928014f6c5bf9c40" self.assertSequenceEqual(hexenc(signature), s + r)
def test_curve5(self): c = CURVES["id-tc26-gost-3410-12-512-paramSetB"] q_ind = ( 0x7E1FAE8285E035BEC244BEF2D0E5EBF436633CF50E55231DEA9C9CF21D4C8C33DF85D4305DE92971F0A4B4C07E00D87BDBC720EB66E49079285AAF12E0171149, 0x2CC89998B875D4463805BA0D858A196592DB20AB161558FF2F4EF7A85725D20953967AE621AFDEAE89BB77C83A2528EF6FCE02F68BDA4679D7F2704947DBC408, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F181270671C6213E3930EFDDA26451792C6208122EE60D200520D695DFD9F5F0FD5ABA702" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x7D03E65B8050D1E12CBB601A17B9273B0E728F5021CD47C8A4DD822E4627BA5F9C696286A2CDDA9A065509866B4DEDEDC4A118409604AD549F87A60AFA621161, 0x16037DAD45421EC50B00D50BDC6AC3B85348BC1D3A2F85DB27C3373580FEF87C2C743B7ED30F22BE22958044E716F93A61CA3213A361A2797A16A3AE62957377, )) self.assertEqual( c.exp( 0x715E893FA639BF341296E0623E6D29DADF26B163C278767A7982A989462A3863FE12AEF8BD403D59C4DC4720570D4163DB0805C7C10C4E818F9CB785B04B9997 ), ( 0x10C479EA1C04D3C2C02B0576A9C42D96226FF033C1191436777F66916030D87D02FB93738ED7669D07619FFCE7C1F3C4DB5E5DF49E2186D6FA1E2EB5767602B9, 0x039F6044191404E707F26D59D979136A831CCE43E1C5F0600D1DDF8F39D0CA3D52FBD943BF04DDCED1AA2CE8F5EBD7487ACDEF239C07D015084D796784F35436, )) self.assertEqual( c.exp( 0x30FA8C2B4146C2DBBE82BED04D7378877E8C06753BD0A0FF71EBF2BEFE8DA8F3DC0836468E2CE7C5C961281B6505140F8407413F03C2CB1D201EA1286CE30E6D ), ( 0x34C0149E7BB91AE377B02573FCC48AF7BFB7B16DEB8F9CE870F384688E3241A3A868588CC0EF4364CCA67D17E3260CD82485C202ADC76F895D5DF673B1788E67, 0x608E944929BD643569ED5189DB871453F13333A1EAF82B2FE1BE8100E775F13DD9925BD317B63BFAF05024D4A738852332B64501195C1B2EF789E34F23DDAFC5, ), )
def test_curve3(self): c = CURVES["id-GostR3410-2001-CryptoPro-C-ParamSet"] q_ind = ( 0x1E36383E43BB6CFA2917167D71B7B5DD3D6D462B43D7C64282AE67DFBEC2559D, 0x137478A9F721C73932EA06B45CF72E37EB78A63F29A542E563C614650C8B6399, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F18127067" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x945821DAF91E158B839939630655A3B21FF3E146D27041E86C05650EB3B46B59, 0x3A0C2816AC97421FA0E879605F17F0C9C3EB734CFF196937F6284438D70BDC48, )) self.assertEqual( c.exp( 0x3A54AC3F19AD9D0B1EAC8ACDCEA70E581F1DAC33D13FEAFD81E762378639C1A8 ), ( 0x96B7F09C94D297C257A7DA48364C0076E59E48D221CBA604AE111CA3933B446A, 0x54E4953D86B77ECCEB578500931E822300F7E091F79592CA202A020D762C34A6, )) self.assertEqual( c.exp( 0x448781782BF7C0E52A1DD9E6758FD3482D90D3CFCCF42232CF357E59A4D49FD4 ), ( 0x4B9C0AB55A938121F282F48A2CC4396EB16E7E0068B495B0C1DD4667786A3EB7, 0x223460AA8E09383E9DF9844C5A0F2766484738E5B30128A171B69A77D9509B96, ), )
def test_curve2(self): c = CURVES["id-GostR3410-2001-CryptoPro-B-ParamSet"] q_ind = ( 0x3D715A874A4B17CB3B517893A9794A2B36C89D2FFC693F01EE4CC27E7F49E399, 0x1C5A641FCF7CE7E87CDF8CEA38F3DB3096EACE2FAD158384B53953365F4FE7FE, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F18127067" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x6DC2AE26BC691FCA5A73D9C452790D15E34BA5404D92955B914C8D2662ABB985, 0x3B02AAA9DD65AE30C335CED12F3154BBAC059F66B088306747453EDF6E5DB077, )) self.assertEqual( c.exp( 0x499D72B90299CAB0DA1F8BE19D9122F622A13B32B730C46BD0664044F2144FAD ), ( 0x61D6F916DB717222D74877F179F7EBEF7CD4D24D8C1F523C048E34A1DF30F8DD, 0x3EC48863049CFCFE662904082E78503F4973A4E105E2F1B18C69A5E7FB209000, )) self.assertEqual( c.exp( 0x0F69FF614957EF83668EDC2D7ED614BE76F7B253DB23C5CC9C52BF7DF8F4669D ), ( 0x33BC6F7E9C0BA10CFB2B72546C327171295508EA97F8C8BA9F890F2478AB4D6C, 0x75D57B396C396F492F057E9222CCC686437A2AAD464E452EF426FC8EEED1A4A6, ), )
def test_gcl2(self): """ Test vectors 2 from libgcl3 """ sbox = "id-Gost28147-89-TestParamSet" key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a") plaintext = bytes(bytearray(( 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, ))) ciphertext = bytes(bytearray(( 0xd0, 0xbe, 0x60, 0x1a, 0x2c, 0xf1, 0x90, 0x26, 0x9b, 0x7b, 0x23, 0xb4, 0xd2, 0xcc, 0xe1, 0x15, 0xf6, 0x05, 0x57, 0x28, 0x88, 0x75, 0xeb, 0x1e, 0xd3, 0x62, 0xdc, 0xda, 0x9b, 0x62, 0xee, 0x9a, 0x57, 0x87, 0x8a, 0xf1, 0x82, 0x37, 0x9c, 0x7f, 0x13, 0xcc, 0x55, 0x38, 0xb5, 0x63, 0x32, 0xc5, 0x23, 0xa4, 0xcb, 0x7d, 0x51, ))) iv = 8 * b"\x00" encrypted = cnt(key, plaintext, iv=iv, sbox=sbox) self.assertSequenceEqual(encrypted, ciphertext) decrypted = cnt(key, encrypted, iv=iv, sbox=sbox) self.assertSequenceEqual(decrypted, plaintext)
def test_256(self): content_info_raw = b64decode(""" MIIBhgYJKoZIhvcNAQcDoIIBdzCCAXMCAQIxggEwoYIBLAIBA6BooWYwHwYIKoUD BwEBAQEwEwYHKoUDAgIkAAYIKoUDBwEBAgIDQwAEQPAdWM4pO38iZ49UjaXQpq+a jhTa4KwY4B9TFMK7AiYmbFKE0eX/wvu69kFMQ2o3OJTnMOlr1WHiPYOmNO6C5hOh CgQIX+vNomZakEIwIgYIKoUDBwEBAQEwFgYHKoUDAgINADALBgkqhQMHAQIFAQEw gYwwgYkwWzBWMSkwJwYJKoZIhvcNAQkBFhpHb3N0UjM0MTAtMjAxMkBleGFtcGxl LmNvbTEpMCcGA1UEAxMgR29zdFIzNDEwLTIwMTIgMjU2IGJpdHMgZXhjaGFuZ2UC AQEEKjAoBCCNhrZOr7x2fsjjQAeDMv/tSoNRQSSQzzxgqdnYxJ3fIAQEgYLqVDA6 BgkqhkiG9w0BBwEwHwYGKoUDAgIVMBUECHVmR/S+hlYiBgkqhQMHAQIFAQGADEI9 UNjyuY+54uVcHw== """) prv_key_our = hexdec( "BFCF1D623E5CDD3032A7C6EABB4A923C46E43D640FFEAAF2C3ED39A8FA399924" )[::-1] def keker(curve, prv, pub, ukm): return kek_34102012256( curve, prv_unmarshal(prv), pub_unmarshal(pub), ukm_unmarshal(ukm), mode=2001, ) self.process_cms( content_info_raw, prv_key_our, "id-GostR3410-2001-CryptoPro-XchA-ParamSet", keker, b"Test message", )
def test_curve6(self): c = CURVES["id-tc26-gost-3410-2012-256-paramSetA"] q_ind = ( 0xB51ADF93A40AB15792164FAD3352F95B66369EB2A4EF5EFAE32829320363350E, 0x74A358CC08593612F5955D249C96AFB7E8B0BB6D8BD2BBE491046650D822BE18, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F18127067" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0xDBF99827078956812FA48C6E695DF589DEF1D18A2D4D35A96D75BF6854237629, 0x9FDDD48BFBC57BEE1DA0CFF282884F284D471B388893C48F5ECB02FC18D67589, )) self.assertEqual( c.exp( 0x147B72F6684FB8FD1B418A899F7DBECAF5FCE60B13685BAA95328654A7F0707F ), ( 0x33FBAC14EAE538275A769417829C431BD9FA622B6F02427EF55BD60EE6BC2888, 0x22F2EBCF960A82E6CDB4042D3DDDA511B2FBA925383C2273D952EA2D406EAE46, )) self.assertEqual( c.exp( 0x30D5CFADAA0E31B405E6734C03EC4C5DF0F02F4BA25C9A3B320EE6453567B4CB ), ( 0x2B2D89FAB735433970564F2F28CFA1B57D640CB902BC6334A538F44155022CB2, 0x10EF6A82EEF1E70F942AA81D6B4CE5DEC0DDB9447512962874870E6F2849A96F, ), )
def test_512(self): content_info_raw = b64decode(""" MIIBzAYJKoZIhvcNAQcDoIIBvTCCAbkCAQIxggF2oYIBcgIBA6CBraGBqjAhBggq hQMHAQEBAjAVBgkqhQMHAQIBAgIGCCqFAwcBAQIDA4GEAASBgCB0nQy/Ljva/mRj w6o+eDKIvnxwYIQB5XCHhZhCpHNZiWcFxFpYXZLWRPKifOxV7NStvqGE1+fkfhBe btkQu0tdC1XL3LO2Cp/jX16XhW/IP5rKV84qWr1Owy/6tnSsNRb+ez6IttwVvaVV pA6ONFy9p9gawoC8nitvAVJkWW0PoQoECDVfxzxgMTAHMCIGCCqFAwcBAQECMBYG ByqFAwICDQAwCwYJKoUDBwECBQEBMIGMMIGJMFswVjEpMCcGCSqGSIb3DQEJARYa R29zdFIzNDEwLTIwMTJAZXhhbXBsZS5jb20xKTAnBgNVBAMTIEdvc3RSMzQxMC0y MDEyIDUxMiBiaXRzIGV4Y2hhbmdlAgEBBCowKAQg8C/OcxRR0Uq8nDjHrQlayFb3 WFUZEnEuAKcuG6dTOawEBLhi9hIwOgYJKoZIhvcNAQcBMB8GBiqFAwICFTAVBAiD 1wH+CX6CwgYJKoUDBwECBQEBgAzUvQI4H2zRfgNgdlY= """) prv_key_our = hexdec( "3FC01CDCD4EC5F972EB482774C41E66DB7F380528DFE9E67992BA05AEE462435757530E641077CE587B976C8EEB48C48FD33FD175F0C7DE6A44E014E6BCB074B" )[::-1] def keker(curve, prv, pub, ukm): return kek_34102012256( curve, prv_unmarshal(prv), pub_unmarshal(pub, mode=2012), ukm_unmarshal(ukm), ) self.process_cms( content_info_raw, prv_key_our, "id-tc26-gost-3410-12-512-paramSetB", keker, b"Test message", )
def test_curve4(self): c = CURVES["id-tc26-gost-3410-12-512-paramSetA"] q_ind = ( 0x2A17F8833A32795327478871B5C5E88AEFB91126C64B4B8327289BEA62559425D18198F133F400874328B220C74497CD240586CB249E158532CB8090776CD61C, 0x728F0C4A73B48DA41CE928358FAD26B47A6E094E9362BAE82559F83CDDC4EC3A4676BD3707EDEAF4CD85E99695C64C241EDC622BE87DC0CF87F51F4367F723C5, ) self.assertEqual( c.exp(bytes2long( hexdec( "BD04673F7149B18E98155BD1E2724E71D0099AA25174F792D3326C6F181270671C6213E3930EFDDA26451792C6208122EE60D200520D695DFD9F5F0FD5ABA702" )[::-1]), x=q_ind[0], y=q_ind[1]), ( 0x0C0AB53D0E0A9C607CAD758F558915A0A7DC5DC87B45E9A58FDDF30EC3385960283E030CD322D9E46B070637785FD49D2CD711F46807A24C40AF9A42C8E2D740, 0xDF93A8012B86D3A3D4F8A4D487DA15FC739EB31B20B3B0E8C8C032AAF8072C6337CF7D5B404719E5B4407C41D9A3216A08CA69C271484E9ED72B8AAA52E28B8B, )) self.assertEqual( c.exp( 0x3CE54325DB52FE798824AEAD11BB16FA766857D04A4AF7D468672F16D90E7396046A46F815693E85B1CE5464DA9270181F82333B0715057BBE8D61D400505F0E ), ( 0xB93093EB0FCC463239B7DF276E09E592FCFC9B635504EA4531655D76A0A3078E2B4E51CFE2FA400CC5DE9FBE369DB204B3E8ED7EDD85EE5CCA654C1AED70E396, 0x809770B8D910EA30BD2FA89736E91DC31815D2D9B31128077EEDC371E9F69466F497DC64DD5B1FADC587F860EE256109138C4A9CD96B628E65A8F590520FC882, )) self.assertEqual( c.exp( 0xB5C286A79AA8E97EC0E19BC1959A1D15F12F8C97870BA9D68CC12811A56A3BB11440610825796A49D468CDC9C2D02D76598A27973D5960C5F50BCE28D8D345F4 ), ( 0x238B38644E440452A99FA6B93D9FD7DA0CB83C32D3C1E3CFE5DF5C3EB0F9DB91E588DAEDC849EA2FB867AE855A21B4077353C0794716A6480995113D8C20C7AF, 0xB2273D5734C1897F8D15A7008B862938C8C74CA7E877423D95243EB7EBD02FD2C456CF9FC956F078A59AA86F19DD1075E5167E4ED35208718EA93161C530ED14, ), )
def test_512(self): cert_raw = b64decode(""" MIIC6DCCAlSgAwIBAgIBATAKBggqhQMHAQEDAzBWMSkwJwYJKoZIhvcNAQkBFhpH b3N0UjM0MTAtMjAxMkBleGFtcGxlLmNvbTEpMCcGA1UEAxMgR29zdFIzNDEwLTIw MTIgKDUxMiBiaXQpIGV4YW1wbGUwHhcNMTMxMDA0MDczNjA0WhcNMzAxMDAxMDcz NjA0WjBWMSkwJwYJKoZIhvcNAQkBFhpHb3N0UjM0MTAtMjAxMkBleGFtcGxlLmNv bTEpMCcGA1UEAxMgR29zdFIzNDEwLTIwMTIgKDUxMiBiaXQpIGV4YW1wbGUwgaow IQYIKoUDBwEBAQIwFQYJKoUDBwECAQICBggqhQMHAQECAwOBhAAEgYATGQ9VCiM5 FRGCQ8MEz2F1dANqhaEuywa8CbxOnTvaGJpFQVXQwkwvLFAKh7hk542vOEtxpKtT CXfGf84nRhMH/Q9bZeAc2eO/yhxrsQhTBufa1Fuou2oe/jUOaG6RAtUUvRzhNTpp RGGl1+EIY2vzzUua9j9Ol/gAoy/LNKQIfqOBwDCBvTAdBgNVHQ4EFgQUPcbTRXJZ nHtjj+eBP7b5lcTMekIwCwYDVR0PBAQDAgHGMA8GA1UdEwQIMAYBAf8CAQEwfgYD VR0BBHcwdYAUPcbTRXJZnHtjj+eBP7b5lcTMekKhWqRYMFYxKTAnBgkqhkiG9w0B CQEWGkdvc3RSMzQxMC0yMDEyQGV4YW1wbGUuY29tMSkwJwYDVQQDEyBHb3N0UjM0 MTAtMjAxMiAoNTEyIGJpdCkgZXhhbXBsZYIBATAKBggqhQMHAQEDAwOBgQBObS7o ppPTXzHyVR1DtPa8b57nudJzI4czhsfeX5HDntOq45t9B/qSs8dC6eGxbhHZ9zCO SFtxWYdmg0au8XI9Xb8vTC1qdwWID7FFjMWDNQZb6lYh/J+8F2xKylvB5nIlRZqO o3eUNFkNyHJwQCk2WoOlO16zwGk2tdKH4KmD5w== """) prv_key_raw = hexdec( "3FC01CDCD4EC5F972EB482774C41E66DB7F380528DFE9E67992BA05AEE462435757530E641077CE587B976C8EEB48C48FD33FD175F0C7DE6A44E014E6BCB074B" )[::-1] self.process_cert( "id-tc26-gost-3410-12-512-paramSetB", 2012, GOST34112012512, prv_key_raw, cert_raw, )
def test_c(self): self.assertEqual(C[0], hexdec("6ea276726c487ab85d27bd10dd849401")) self.assertEqual(C[1], hexdec("dc87ece4d890f4b3ba4eb92079cbeb02")) self.assertEqual(C[2], hexdec("b2259a96b4d88e0be7690430a44f7f03")) self.assertEqual(C[3], hexdec("7bcd1b0b73e32ba5b79cb140f2551504")) self.assertEqual(C[4], hexdec("156f6d791fab511deabb0c502fd18105")) self.assertEqual(C[5], hexdec("a74af7efab73df160dd208608b9efe06")) self.assertEqual(C[6], hexdec("c9e8819dc73ba5ae50f5b570561a6a07")) self.assertEqual(C[7], hexdec("f6593616e6055689adfba18027aa2a08"))
def digest(self): """ Get hash of the provided data """ l = 0 checksum = 0 h = 32 * b'\x00' m = self.data for i in xrange(0, len(m), BLOCKSIZE): part = m[i:i + BLOCKSIZE][::-1] l += len(part) * 8 checksum = addmod(checksum, int(hexenc(part), 16), 2 ** 256) if len(part) < BLOCKSIZE: part = b'\x00' * (BLOCKSIZE - len(part)) + part h = _step(h, part, self.sbox) h = _step(h, 24 * b'\x00' + pack(">Q", l), self.sbox) checksum = hex(checksum)[2:].rstrip("L") if len(checksum) % 2 != 0: checksum = "0" + checksum checksum = hexdec(checksum) checksum = b'\x00' * (BLOCKSIZE - len(checksum)) + checksum h = _step(h, checksum, self.sbox) return h
from pygost.gost28147 import addmod from pygost.gost28147 import block2ns from pygost.gost28147 import encrypt from pygost.gost28147 import ns2block from pygost.gost28147 import validate_sbox from pygost.utils import hexdec from pygost.utils import hexenc from pygost.utils import strxor from pygost.utils import xrange DEFAULT_SBOX = "GostR3411_94_TestParamSet" BLOCKSIZE = 32 C2 = 32 * b'\x00' C3 = hexdec(b'ff00ffff000000ffff0000ff00ffff0000ff00ff00ff00ffff00ff00ff00ff00') C4 = 32 * b'\x00' def A(x): x4, x3, x2, x1 = x[0:8], x[8:16], x[16:24], x[24:32] return b''.join((strxor(x1, x2), x4, x3, x2)) def P(x): return bytearray(( x[0], x[8], x[16], x[24], x[1], x[9], x[17], x[25], x[2], x[10], x[18], x[26], x[3], x[11], x[19], x[27], x[4], x[12], x[20], x[28], x[5], x[13], x[21], x[29], x[6], x[14], x[22], x[30], x[7], x[15], x[23], x[31], ))
84, 198, 128, 195, 189, 13, 87, 223, 245, 36, 169, 62, 168, 67, 201, 215, 121, 214, 246, 124, 34, 185, 3, 224, 15, 236, 222, 122, 148, 176, 188, 220, 232, 40, 80, 78, 51, 10, 74, 167, 151, 96, 115, 30, 0, 98, 68, 26, 184, 56, 130, 100, 159, 38, 65, 173, 69, 70, 146, 39, 94, 85, 47, 140, 163, 165, 125, 105, 213, 149, 59, 7, 88, 179, 64, 134, 172, 29, 247, 48, 55, 107, 228, 136, 217, 231, 137, 225, 27, 131, 73, 76, 63, 248, 254, 141, 83, 170, 144, 202, 216, 133, 97, 32, 113, 103, 164, 45, 43, 9, 91, 203, 155, 37, 208, 190, 229, 108, 82, 89, 166, 116, 210, 230, 244, 180, 192, 209, 102, 175, 194, 57, 75, 99, 182, )) A = [unpack(">Q", hexdec(s))[0] for s in ( "8e20faa72ba0b470", "47107ddd9b505a38", "ad08b0e0c3282d1c", "d8045870ef14980e", "6c022c38f90a4c07", "3601161cf205268d", "1b8e0b0e798c13c8", "83478b07b2468764", "a011d380818e8f40", "5086e740ce47c920", "2843fd2067adea10", "14aff010bdd87508", "0ad97808d06cb404", "05e23c0468365a02", "8c711e02341b2d01", "46b60f011a83988e", "90dab52a387ae76f", "486dd4151c3dfdb9", "24b86a840e90f0d2", "125c354207487869", "092e94218d243cba", "8a174a9ec8121e5d", "4585254f64090fa0", "accc9ca9328a8950", "9d4df05d5f661451", "c0a878a0a1330aa6", "60543c50de970553", "302a1e286fc58ca7", "18150f14b9ec46dd", "0c84890ad27623e0", "0642ca05693b9f70", "0321658cba93c138", "86275df09ce8aaa8", "439da0784e745554", "afc0503c273aa42a", "d960281e9d1d5215", "e230140fc0802984", "71180a8960409a42", "b60c05ca30204d21", "5b068c651810a89e", "456c34887a3805b9", "ac361a443d1c8cd2", "561b0d22900e4669", "2b838811480723ba", "9bcf4486248d9f5d", "c3e9224312c8c1a0", "effa11af0964ee50", "f97d86d98a327728", "e4fa2054a80b329c", "727d102a548b194e", "39b008152acb8227", "9258048415eb419d", "492c024284fbaec0", "aa16012142f35760", "550b8e9e21f7a530", "a48b474f9ef5dc18", "70a6a56e2440598e", "3853dc371220a247", "1ca76e95091051ad", "0edd37c48a08a6d8",
def test_vec2(self): blk = bytearray(hexdec("d456584dd0e3e84cc3166e4b7fa2890d")) self.assertEqual(L(blk), hexdec("79d26221b87b584cd42fbc4ffea5de9a"))
validate_key(key) validate_iv(iv) validate_sbox(sbox) if not data: raise ValueError("No data supplied") n2, n1 = encrypt(sbox, key, block2ns(iv)) size, data = _pad(data) gamma = [] for _ in xrange(0, len(data), BLOCKSIZE): n1 = addmod(n1, C2, 2 ** 32) n2 = addmod(n2, C1, 2 ** 32 - 1) gamma.append(ns2block(encrypt(sbox, key, (n1, n2)))) return strxor(b''.join(gamma), data[:size]) MESH_CONST = hexdec("6900722264C904238D3ADB9646E92AC418FEAC9400ED0712C086DCC2EF4CA92B") MESH_MAX_DATA = 1024 def meshing(key, iv, sbox=DEFAULT_SBOX): """:rfc:`4357` key meshing """ key = ecb_decrypt(key, MESH_CONST, sbox=sbox) iv = ecb_encrypt(key, iv, sbox=sbox) return key, iv def cfb_encrypt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX, mesh=False): """ CFB encryption mode of operation :param bytes key: encryption key
def test_vec4(self): blk = bytearray(hexdec("0e93691a0cfc60408b7b68f66b513c13")) self.assertEqual(L(blk), hexdec("e6a8094fee0aa204fd97bcb0b44b8580"))
def test_vec3(self): blk = bytearray(hexdec("79d26221b87b584cd42fbc4ffea5de9a")) self.assertEqual(L(blk), hexdec("0e93691a0cfc60408b7b68f66b513c13"))
def test_vec1(self): blk = bytearray(hexdec("ffeeddccbbaa99881122334455667700")) self.assertEqual(S(blk), hexdec("b66cd8887d38e8d77765aeea0c9a7efc"))
def test_vec1(self): blk = bytearray(hexdec("64a59400000000000000000000000000")) self.assertEqual(L(blk), hexdec("d456584dd0e3e84cc3166e4b7fa2890d"))
def test_vec4(self): blk = bytearray(hexdec("0c3322fed531e4630d80ef5c5a81c50b")) self.assertEqual(S(blk), hexdec("23ae65633f842d29c5df529c13f5acda"))
def test_vec2(self): blk = bytearray(hexdec("b66cd8887d38e8d77765aeea0c9a7efc")) self.assertEqual(S(blk), hexdec("559d8dd7bd06cbfe7e7b262523280d39"))
def test_vec2(self): blk = bytearray(hexdec("94000000000000000000000000000001")) self.assertEqual(R(blk), hexdec("a5940000000000000000000000000000"))
def test_vec3(self): blk = bytearray(hexdec("559d8dd7bd06cbfe7e7b262523280d39")) self.assertEqual(S(blk), hexdec("0c3322fed531e4630d80ef5c5a81c50b"))
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD94", "00000000000000000000000000000000000000000000000000000000000000a6", "0000000000000000000000000000000000000000000000000000000000000001", "8D91E471E0989CDA27DF505A453F2B7635294F2DDF23E3B122ACC99C9E9F1E14", ), "GostR3410_2001_CryptoPro_XchB_ParamSet": ( "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D759B", "9B9F605F5A858107AB1EC85E6B41C8AA582CA3511EDDFB74F02F3A6598980BB9", "9B9F605F5A858107AB1EC85E6B41C8AACF846E86789051D37998F7B9022D7598", "000000000000000000000000000000000000000000000000000000000000805a", "0000000000000000000000000000000000000000000000000000000000000000", "41ECE55743711A8C3CBF3783CD08C0EE4D4DC440D4641A8F366E550DFDB3BB67", ), } for c, params in CURVE_PARAMS.items(): CURVE_PARAMS[c] = [hexdec(s) for s in params] class GOST3410Curve(object): """ GOST 34.10 validated curve >>> p, q, a, b, x, y = CURVE_PARAMS["GostR3410_2001_TestParamSet"] >>> curve = GOST3410Curve(p, q, a, b, x, y) >>> priv = bytes2long(urandom(32)) >>> signature = sign(curve, priv, GOST341194(data).digest()) >>> pubX, pubY = public_key(curve, priv) >>> verify(curve, pubX, pubY, GOST341194(data).digest(), signature) True """ def __init__(self, p, q, a, b, x, y): self.p = bytes2long(p)
def test_vec4(self): blk = bytearray(hexdec("64a59400000000000000000000000000")) self.assertEqual(R(blk), hexdec("0d64a594000000000000000000000000"))