This file is indexed.

/usr/share/doc/python-cryptography-doc/html/hazmat/primitives/asymmetric/ec.html is in python-cryptography-doc 2.1.4-1ubuntu1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Elliptic curve cryptography &#8212; Cryptography 2.1.4 documentation</title>
    <link rel="stylesheet" href="../../../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '2.1.4',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="RSA" href="rsa.html" />
    <link rel="prev" title="DSA" href="dsa.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="rsa.html" title="RSA"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="dsa.html" title="DSA"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">Cryptography 2.1.4 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Primitives</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Asymmetric algorithms</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="admonition danger">
<p class="first admonition-title">Danger</p>
<p class="last">
This is a &quot;Hazardous Materials&quot; module. You should <strong>ONLY</strong> use it if you're
100% absolutely sure that you know what you're doing because this module is
full of land mines, dragons, and dinosaurs with laser guns.</p>
</div>
<div class="section" id="module-cryptography.hazmat.primitives.asymmetric.ec">
<span id="elliptic-curve-cryptography"></span><h1>Elliptic curve cryptography<a class="headerlink" href="#module-cryptography.hazmat.primitives.asymmetric.ec" title="Permalink to this headline"></a></h1>
<dl class="function">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.generate_private_key">
<code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">generate_private_key</code><span class="sig-paren">(</span><em>curve</em>, <em>backend</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.generate_private_key" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>Generate a new private key on <code class="docutils literal"><span class="pre">curve</span></code> for use with <code class="docutils literal"><span class="pre">backend</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>curve</strong> -- An instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a>.</li>
<li><strong>backend</strong> -- An instance of
<a class="reference internal" href="../../backends/interfaces.html#cryptography.hazmat.backends.interfaces.EllipticCurveBackend" title="cryptography.hazmat.backends.interfaces.EllipticCurveBackend"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveBackend</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A new instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateKey</span></code></a>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.derive_private_key">
<code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">derive_private_key</code><span class="sig-paren">(</span><em>private_value</em>, <em>curve</em>, <em>backend</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.derive_private_key" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.6.</span></p>
</div>
<p>Derive a private key from <code class="docutils literal"><span class="pre">private_value</span></code> on <code class="docutils literal"><span class="pre">curve</span></code> for use with
<code class="docutils literal"><span class="pre">backend</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>private_value</strong> (<em>int</em>) -- The secret scalar value.</li>
<li><strong>curve</strong> -- An instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a>.</li>
<li><strong>backend</strong> -- An instance of
<a class="reference internal" href="../../backends/interfaces.html#cryptography.hazmat.backends.interfaces.EllipticCurveBackend" title="cryptography.hazmat.backends.interfaces.EllipticCurveBackend"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveBackend</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A new instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateKey</span></code></a>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<div class="section" id="elliptic-curve-signature-algorithms">
<h2>Elliptic Curve Signature Algorithms<a class="headerlink" href="#elliptic-curve-signature-algorithms" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.ECDSA">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">ECDSA</code><span class="sig-paren">(</span><em>algorithm</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.ECDSA" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>The ECDSA signature algorithm first standardized in NIST publication
<a class="reference external" href="https://csrc.nist.gov/csrc/media/publications/fips/186/3/archive/2009-06-25/documents/fips_186-3.pdf">FIPS 186-3</a>, and later in <a class="reference external" href="https://csrc.nist.gov/publications/detail/fips/186/4/final">FIPS 186-4</a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>algorithm</strong> -- An instance of
<a class="reference internal" href="../cryptographic-hashes.html#cryptography.hazmat.primitives.hashes.HashAlgorithm" title="cryptography.hazmat.primitives.hashes.HashAlgorithm"><code class="xref py py-class docutils literal"><span class="pre">HashAlgorithm</span></code></a>.</td>
</tr>
</tbody>
</table>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.backends</span> <span class="k">import</span> <span class="n">default_backend</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives</span> <span class="k">import</span> <span class="n">hashes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives.asymmetric</span> <span class="k">import</span> <span class="n">ec</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">private_key</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot;this is some data I&#39;d like to sign&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">signature</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">data</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">ECDSA</span><span class="p">(</span><span class="n">hashes</span><span class="o">.</span><span class="n">SHA256</span><span class="p">())</span>
<span class="gp">... </span><span class="p">)</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">signature</span></code> is a <code class="docutils literal"><span class="pre">bytes</span></code> object, whose contents is DER encoded as
described in <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc3279.html"><strong>RFC 3279</strong></a>. This can be decoded using
<a class="reference internal" href="utils.html#cryptography.hazmat.primitives.asymmetric.utils.decode_dss_signature" title="cryptography.hazmat.primitives.asymmetric.utils.decode_dss_signature"><code class="xref py py-func docutils literal"><span class="pre">decode_dss_signature()</span></code></a>.</p>
<p>If your data is too large to be passed in a single call, you can hash it
separately and pass that value using
<a class="reference internal" href="utils.html#cryptography.hazmat.primitives.asymmetric.utils.Prehashed" title="cryptography.hazmat.primitives.asymmetric.utils.Prehashed"><code class="xref py py-class docutils literal"><span class="pre">Prehashed</span></code></a>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives.asymmetric</span> <span class="k">import</span> <span class="n">utils</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">chosen_hash</span> <span class="o">=</span> <span class="n">hashes</span><span class="o">.</span><span class="n">SHA256</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span> <span class="o">=</span> <span class="n">hashes</span><span class="o">.</span><span class="n">Hash</span><span class="p">(</span><span class="n">chosen_hash</span><span class="p">,</span> <span class="n">default_backend</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;data &amp; &quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;more data&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">digest</span> <span class="o">=</span> <span class="n">hasher</span><span class="o">.</span><span class="n">finalize</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sig</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">digest</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">ECDSA</span><span class="p">(</span><span class="n">utils</span><span class="o">.</span><span class="n">Prehashed</span><span class="p">(</span><span class="n">chosen_hash</span><span class="p">))</span>
<span class="gp">... </span><span class="p">)</span>
</pre></div>
</div>
<p>Verification requires the public key, the signature itself, the signed
data, and knowledge of the hashing algorithm that was used when producing
the signature:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">public_key</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">public_key</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">public_key</span><span class="o">.</span><span class="n">verify</span><span class="p">(</span><span class="n">signature</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">ec</span><span class="o">.</span><span class="n">ECDSA</span><span class="p">(</span><span class="n">hashes</span><span class="o">.</span><span class="n">SHA256</span><span class="p">()))</span>
</pre></div>
</div>
<p>If the signature is not valid, an
<a class="reference internal" href="../../../exceptions.html#cryptography.exceptions.InvalidSignature" title="cryptography.exceptions.InvalidSignature"><code class="xref py py-class docutils literal"><span class="pre">InvalidSignature</span></code></a> exception will be raised.</p>
<p>If your data is too large to be passed in a single call, you can hash it
separately and pass that value using
<a class="reference internal" href="utils.html#cryptography.hazmat.primitives.asymmetric.utils.Prehashed" title="cryptography.hazmat.primitives.asymmetric.utils.Prehashed"><code class="xref py py-class docutils literal"><span class="pre">Prehashed</span></code></a>.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">chosen_hash</span> <span class="o">=</span> <span class="n">hashes</span><span class="o">.</span><span class="n">SHA256</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span> <span class="o">=</span> <span class="n">hashes</span><span class="o">.</span><span class="n">Hash</span><span class="p">(</span><span class="n">chosen_hash</span><span class="p">,</span> <span class="n">default_backend</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;data &amp; &quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hasher</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;more data&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">digest</span> <span class="o">=</span> <span class="n">hasher</span><span class="o">.</span><span class="n">finalize</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">public_key</span><span class="o">.</span><span class="n">verify</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">sig</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">digest</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">ECDSA</span><span class="p">(</span><span class="n">utils</span><span class="o">.</span><span class="n">Prehashed</span><span class="p">(</span><span class="n">chosen_hash</span><span class="p">))</span>
<span class="gp">... </span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Although in this case the public key was derived from the private one,
in a typical setting you will not possess the private key. The
<a class="reference internal" href="#key-loading">Key loading</a> section explains how to load the public key from other
sources.</p>
</div>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePrivateNumbers</code><span class="sig-paren">(</span><em>private_value</em>, <em>public_numbers</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>The collection of integers that make up an EC private key.</p>
<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.public_numbers">
<code class="descname">public_numbers</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.public_numbers" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body"><a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a></td>
</tr>
</tbody>
</table>
<p>The <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a> which makes up the EC public
key associated with this EC private key.</p>
</dd></dl>

<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.private_value">
<code class="descname">private_value</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.private_value" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>The private value.</p>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.private_key">
<code class="descname">private_key</code><span class="sig-paren">(</span><em>backend</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.private_key" title="Permalink to this definition"></a></dt>
<dd><p>Convert a collection of numbers into a private key suitable for doing
actual cryptographic operations.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>backend</strong> -- An instance of
<a class="reference internal" href="../../backends/interfaces.html#cryptography.hazmat.backends.interfaces.EllipticCurveBackend" title="cryptography.hazmat.backends.interfaces.EllipticCurveBackend"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveBackend</span></code></a>.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A new instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateKey</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePublicNumbers</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>curve</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>The collection of integers that make up an EC public key.</p>
<blockquote>
<div><dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.curve">
<code class="descname">curve</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.curve" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body"><a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a></td>
</tr>
</tbody>
</table>
<p>The elliptic curve for this key.</p>
</dd></dl>

</div></blockquote>
<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.x">
<code class="descname">x</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.x" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>The affine x component of the public point used for verifying.</p>
</dd></dl>

<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.y">
<code class="descname">y</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.y" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>The affine y component of the public point used for verifying.</p>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.public_key">
<code class="descname">public_key</code><span class="sig-paren">(</span><em>backend</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.public_key" title="Permalink to this definition"></a></dt>
<dd><p>Convert a collection of numbers into a public key suitable for doing
actual cryptographic operations.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>backend</strong> -- An instance of
<a class="reference internal" href="../../backends/interfaces.html#cryptography.hazmat.backends.interfaces.EllipticCurveBackend" title="cryptography.hazmat.backends.interfaces.EllipticCurveBackend"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveBackend</span></code></a>.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A new instance of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicKey</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.encode_point">
<code class="descname">encode_point</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.encode_point" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<p>Encodes an elliptic curve point to a byte string as described in
<a class="reference external" href="http://www.secg.org/sec1-v2.pdf">SEC 1 v2.0</a> section 2.3.3. This method only supports uncompressed
points.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Return bytes:</th><td class="field-body">The encoded point.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="classmethod">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.from_encoded_point">
<em class="property">classmethod </em><code class="descname">from_encoded_point</code><span class="sig-paren">(</span><em>curve</em>, <em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers.from_encoded_point" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<p>Decodes a byte string as described in <a class="reference external" href="http://www.secg.org/sec1-v2.pdf">SEC 1 v2.0</a> section 2.3.3 and
returns an <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a>. This method only
supports uncompressed points.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>curve</strong> -- An
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a>
instance.</li>
<li><strong>data</strong> (<em>bytes</em>) -- The serialized point byte string.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a> instance.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><ul class="first last simple">
<li><strong>ValueError</strong> -- Raised on invalid point type or data length.</li>
<li><strong>TypeError</strong> -- Raised when curve is not an
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="elliptic-curve-key-exchange-algorithm">
<h2>Elliptic Curve Key Exchange algorithm<a class="headerlink" href="#elliptic-curve-key-exchange-algorithm" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.ECDH">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">ECDH</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.ECDH" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<p>The Elliptic Curve Diffie-Hellman Key Exchange algorithm first standardized
in NIST publication <a class="reference external" href="https://csrc.nist.gov/publications/detail/sp/800-56a/revised/archive/2007-03-14">800-56A</a>, and later in <a class="reference external" href="https://csrc.nist.gov/publications/detail/sp/800-56a/rev-2/final">800-56Ar2</a>.</p>
<p>For most applications the <code class="docutils literal"><span class="pre">shared_key</span></code> should be passed to a key
derivation function.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.backends</span> <span class="k">import</span> <span class="n">default_backend</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives.asymmetric</span> <span class="k">import</span> <span class="n">ec</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Generate a private key for use in the exchange.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">private_key</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># In a real handshake the peer_public_key will be received from the</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># other party. For this example we&#39;ll generate another private key</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># and get a public key from that.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">peer_public_key</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span><span class="o">.</span><span class="n">public_key</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">shared_key</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">exchange</span><span class="p">(</span><span class="n">ec</span><span class="o">.</span><span class="n">ECDH</span><span class="p">(),</span> <span class="n">peer_public_key</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># For the next handshake we MUST generate another private key.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">private_key_2</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">peer_public_key_2</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span><span class="o">.</span><span class="n">public_key</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">shared_key_2</span> <span class="o">=</span> <span class="n">private_key_2</span><span class="o">.</span><span class="n">exchange</span><span class="p">(</span><span class="n">ec</span><span class="o">.</span><span class="n">ECDH</span><span class="p">(),</span> <span class="n">peer_public_key_2</span><span class="p">)</span>
</pre></div>
</div>
<p>ECDHE (or EECDH), the ephemeral form of this exchange, is <strong>strongly
preferred</strong> over simple ECDH and provides <a class="reference external" href="https://en.wikipedia.org/wiki/Forward_secrecy">forward secrecy</a> when used.
You must generate a new private key using <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.generate_private_key" title="cryptography.hazmat.primitives.asymmetric.ec.generate_private_key"><code class="xref py py-func docutils literal"><span class="pre">generate_private_key()</span></code></a> for
each <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.exchange" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.exchange"><code class="xref py py-meth docutils literal"><span class="pre">exchange()</span></code></a> when performing an ECDHE key
exchange.</p>
</dd></dl>

</div>
<div class="section" id="elliptic-curves">
<h2>Elliptic Curves<a class="headerlink" href="#elliptic-curves" title="Permalink to this headline"></a></h2>
<p>Elliptic curves provide equivalent security at much smaller key sizes than
other asymmetric cryptography systems such as RSA or DSA. For many operations
elliptic curves are also significantly faster; <a class="reference external" href="http://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1100&amp;context=cseconfwork">elliptic curve diffie-hellman
is faster than diffie-hellman</a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Curves with a size of <a class="reference external" href="http://www.ecrypt.eu.org/ecrypt2/documents/D.SPA.20.pdf">less than 224 bits</a> should not be used. You should
strongly consider using curves of at least 224 <a class="reference internal" href="../../../glossary.html#term-bits"><span class="xref std std-term">bits</span></a>.</p>
</div>
<p>Generally the NIST prime field (&quot;P&quot;) curves are significantly faster than the
other types suggested by NIST at both signing and verifying with ECDSA.</p>
<p>Prime fields also <a class="reference external" href="https://cr.yp.to/ecdh/curve25519-20060209.pdf">minimize the number of security concerns for elliptic-curve
cryptography</a>. However, there is <a class="reference external" href="https://crypto.stackexchange.com/questions/10263/should-we-trust-the-nist-recommended-ecc-parameters">some concern</a> that both the prime field and
binary field (&quot;B&quot;) NIST curves may have been weakened during their generation.</p>
<p>Currently <cite>cryptography</cite> only supports NIST curves, none of which are
considered &quot;safe&quot; by the <a class="reference external" href="https://safecurves.cr.yp.to/">SafeCurves</a> project run by Daniel J. Bernstein and
Tanja Lange.</p>
<p>All named curves are instances of <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a>.</p>
<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT571K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT571K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT571K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect571k1</span></code>. Also called NIST K-571.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT409K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT409K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT409K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect409k1</span></code>. Also called NIST K-409.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT283K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT283K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT283K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect283k1</span></code>. Also called NIST K-283.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT233K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT233K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT233K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect233k1</span></code>. Also called NIST K-233.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT163K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT163K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT163K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect163k1</span></code>. Also called NIST K-163.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT571R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT571R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT571R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect571r1</span></code>. Also called NIST B-571.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT409R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT409R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT409R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect409r1</span></code>. Also called NIST B-409.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT283R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT283R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT283R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect283r1</span></code>. Also called NIST B-283.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT233R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT233R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT233R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect233r1</span></code>. Also called NIST B-233.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECT163R2">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECT163R2</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECT163R2" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">sect163r2</span></code>. Also called NIST B-163.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP521R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP521R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP521R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp521r1</span></code>. Also called NIST P-521.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP384R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP384R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP384R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp384r1</span></code>. Also called NIST P-384.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP256R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP256R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP256R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp256r1</span></code>. Also called NIST P-256.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP224R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP224R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP224R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp224r1</span></code>. Also called NIST P-224.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP192R1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP192R1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP192R1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp192r1</span></code>. Also called NIST P-192.</p>
</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.SECP256K1">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">SECP256K1</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.SECP256K1" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.9.</span></p>
</div>
<p>SECG curve <code class="docutils literal"><span class="pre">secp256k1</span></code>.</p>
</dd></dl>

<div class="section" id="key-interfaces">
<h3>Key Interfaces<a class="headerlink" href="#key-interfaces" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurve</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>A named elliptic curve.</p>
<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve.name">
<code class="descname">name</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve.name" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">string</td>
</tr>
</tbody>
</table>
<p>The name of the curve. Usually the name used for the ASN.1 OID such as
<code class="docutils literal"><span class="pre">secp256k1</span></code>.</p>
</dd></dl>

<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve.key_size">
<code class="descname">key_size</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve.key_size" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>Size (in <a class="reference internal" href="../../../glossary.html#term-bits"><span class="xref std std-term">bits</span></a>) of a secret scalar for the curve (as generated
by <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.generate_private_key" title="cryptography.hazmat.primitives.asymmetric.ec.generate_private_key"><code class="xref py py-func docutils literal"><span class="pre">generate_private_key()</span></code></a>).</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurveSignatureAlgorithm</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.6: </span><a class="reference internal" href="utils.html#cryptography.hazmat.primitives.asymmetric.utils.Prehashed" title="cryptography.hazmat.primitives.asymmetric.utils.Prehashed"><code class="xref py py-class docutils literal"><span class="pre">Prehashed</span></code></a>
can now be used as an <code class="docutils literal"><span class="pre">algorithm</span></code>.</p>
</div>
<p>A signature algorithm for use with elliptic curve keys.</p>
<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm.algorithm">
<code class="descname">algorithm</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm.algorithm" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body"><a class="reference internal" href="../cryptographic-hashes.html#cryptography.hazmat.primitives.hashes.HashAlgorithm" title="cryptography.hazmat.primitives.hashes.HashAlgorithm"><code class="xref py py-class docutils literal"><span class="pre">HashAlgorithm</span></code></a> or
<a class="reference internal" href="utils.html#cryptography.hazmat.primitives.asymmetric.utils.Prehashed" title="cryptography.hazmat.primitives.asymmetric.utils.Prehashed"><code class="xref py py-class docutils literal"><span class="pre">Prehashed</span></code></a></td>
</tr>
</tbody>
</table>
<p>The digest algorithm to be used with the signature scheme.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePrivateKey</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>An elliptic curve private key for use with an algorithm such as <a class="reference external" href="https://en.wikipedia.org/wiki/ECDSA">ECDSA</a> or
<a class="reference external" href="https://en.wikipedia.org/wiki/EdDSA">EdDSA</a>. An elliptic curve private key that is not an
<a class="reference internal" href="../../../glossary.html#term-opaque-key"><span class="xref std std-term">opaque key</span></a> also implements
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateKeyWithSerialization</span></code></a> to provide serialization
methods.</p>
<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.exchange">
<code class="descname">exchange</code><span class="sig-paren">(</span><em>algorithm</em>, <em>peer_public_key</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.exchange" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<p>Performs a key exchange operation using the provided algorithm with
the peer's public key.</p>
<p>For most applications the result should be passed to a key derivation
function.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>algorithm</strong> -- The key exchange algorithm, currently only
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.ECDH" title="cryptography.hazmat.primitives.asymmetric.ec.ECDH"><code class="xref py py-class docutils literal"><span class="pre">ECDH</span></code></a> is
supported.</li>
<li><strong>peer_public_key</strong> (<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey"><em>EllipticCurvePublicKey</em></a>) -- The public key for the
peer.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns bytes:</th><td class="field-body"><p class="first last">A shared key.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.public_key">
<code class="descname">public_key</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.public_key" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicKey</span></code></a></td>
</tr>
</tbody>
</table>
<p>The EllipticCurvePublicKey object for this private key.</p>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.sign">
<code class="descname">sign</code><span class="sig-paren">(</span><em>data</em>, <em>signature_algorithm</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.sign" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
<p>Sign one block of data which can be verified later by others using the
public key.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> (<em>bytes</em>) -- The message string to sign.</li>
<li><strong>signature_algorithm</strong> -- An instance of
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveSignatureAlgorithm</span></code></a>, such as <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.ECDSA" title="cryptography.hazmat.primitives.asymmetric.ec.ECDSA"><code class="xref py py-class docutils literal"><span class="pre">ECDSA</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return bytes:</th><td class="field-body"><p class="first last">Signature.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.key_size">
<code class="descname">key_size</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey.key_size" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.9.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>Size (in <a class="reference internal" href="../../../glossary.html#term-bits"><span class="xref std std-term">bits</span></a>) of a secret scalar for the curve (as generated
by <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.generate_private_key" title="cryptography.hazmat.primitives.asymmetric.ec.generate_private_key"><code class="xref py py-func docutils literal"><span class="pre">generate_private_key()</span></code></a>).</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePrivateKeyWithSerialization</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.8.</span></p>
</div>
<p>This interface contains additional methods relating to serialization.
Any object with this interface also has all the methods from
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateKey</span></code></a>.</p>
<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization.private_numbers">
<code class="descname">private_numbers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization.private_numbers" title="Permalink to this definition"></a></dt>
<dd><p>Create a <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateNumbers</span></code></a> object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePrivateNumbers</span></code></a> instance.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization.private_bytes">
<code class="descname">private_bytes</code><span class="sig-paren">(</span><em>encoding</em>, <em>format</em>, <em>encryption_algorithm</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization.private_bytes" title="Permalink to this definition"></a></dt>
<dd><p>Allows serialization of the key to bytes. Encoding (
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding.PEM" title="cryptography.hazmat.primitives.serialization.Encoding.PEM"><code class="xref py py-attr docutils literal"><span class="pre">PEM</span></code></a> or
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding.DER" title="cryptography.hazmat.primitives.serialization.Encoding.DER"><code class="xref py py-attr docutils literal"><span class="pre">DER</span></code></a>),
format (
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.PrivateFormat.TraditionalOpenSSL" title="cryptography.hazmat.primitives.serialization.PrivateFormat.TraditionalOpenSSL"><code class="xref py py-attr docutils literal"><span class="pre">TraditionalOpenSSL</span></code></a>
or
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8" title="cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8"><code class="xref py py-attr docutils literal"><span class="pre">PKCS8</span></code></a>)
and encryption algorithm (such as
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.BestAvailableEncryption" title="cryptography.hazmat.primitives.serialization.BestAvailableEncryption"><code class="xref py py-class docutils literal"><span class="pre">BestAvailableEncryption</span></code></a>
or <a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.NoEncryption" title="cryptography.hazmat.primitives.serialization.NoEncryption"><code class="xref py py-class docutils literal"><span class="pre">NoEncryption</span></code></a>)
are chosen to define the exact serialization.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>encoding</strong> -- A value from the
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding" title="cryptography.hazmat.primitives.serialization.Encoding"><code class="xref py py-class docutils literal"><span class="pre">Encoding</span></code></a> enum.</li>
<li><strong>format</strong> -- A value from the
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.PrivateFormat" title="cryptography.hazmat.primitives.serialization.PrivateFormat"><code class="xref py py-class docutils literal"><span class="pre">PrivateFormat</span></code></a> enum.</li>
<li><strong>encryption_algorithm</strong> -- An instance of an object conforming to the
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.KeySerializationEncryption" title="cryptography.hazmat.primitives.serialization.KeySerializationEncryption"><code class="xref py py-class docutils literal"><span class="pre">KeySerializationEncryption</span></code></a>
interface.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return bytes:</th><td class="field-body"><p class="first last">Serialized key.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePublicKey</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</div>
<p>An elliptic curve public key.</p>
<blockquote>
<div><dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.curve">
<code class="descname">curve</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.curve" title="Permalink to this definition"></a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body"><a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurve</span></code></a></td>
</tr>
</tbody>
</table>
<p>The elliptic curve for this key.</p>
</dd></dl>

</div></blockquote>
<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_numbers">
<code class="descname">public_numbers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_numbers" title="Permalink to this definition"></a></dt>
<dd><p>Create a <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a> object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicNumbers</span></code></a> instance.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_bytes">
<code class="descname">public_bytes</code><span class="sig-paren">(</span><em>encoding</em>, <em>format</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_bytes" title="Permalink to this definition"></a></dt>
<dd><p>Allows serialization of the key to bytes. Encoding (
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding.PEM" title="cryptography.hazmat.primitives.serialization.Encoding.PEM"><code class="xref py py-attr docutils literal"><span class="pre">PEM</span></code></a> or
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding.DER" title="cryptography.hazmat.primitives.serialization.Encoding.DER"><code class="xref py py-attr docutils literal"><span class="pre">DER</span></code></a>) and
format (
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo" title="cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo"><code class="xref py py-attr docutils literal"><span class="pre">SubjectPublicKeyInfo</span></code></a>)
are chosen to define the exact serialization.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>encoding</strong> -- A value from the
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.Encoding" title="cryptography.hazmat.primitives.serialization.Encoding"><code class="xref py py-class docutils literal"><span class="pre">Encoding</span></code></a> enum.</li>
<li><strong>format</strong> -- A value from the
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.PublicFormat" title="cryptography.hazmat.primitives.serialization.PublicFormat"><code class="xref py py-class docutils literal"><span class="pre">PublicFormat</span></code></a> enum.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return bytes:</th><td class="field-body"><p class="first last">Serialized key.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.verify">
<code class="descname">verify</code><span class="sig-paren">(</span><em>signature</em>, <em>data</em>, <em>signature_algorithm</em><span class="sig-paren">)</span><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.verify" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
<p>Verify one block of data was signed by the private key associated
with this public key.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>signature</strong> (<em>bytes</em>) -- The signature to verify.</li>
<li><strong>data</strong> (<em>bytes</em>) -- The message string that was signed.</li>
<li><strong>signature_algorithm</strong> -- An instance of
<a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurveSignatureAlgorithm</span></code></a>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><a class="reference internal" href="../../../exceptions.html#cryptography.exceptions.InvalidSignature" title="cryptography.exceptions.InvalidSignature"><strong>cryptography.exceptions.InvalidSignature</strong></a> -- If the signature does
not validate.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.key_size">
<code class="descname">key_size</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.key_size" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 1.9.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type:</th><td class="field-body">int</td>
</tr>
</tbody>
</table>
<p>Size (in <a class="reference internal" href="../../../glossary.html#term-bits"><span class="xref std std-term">bits</span></a>) of a secret scalar for the curve (as generated
by <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.generate_private_key" title="cryptography.hazmat.primitives.asymmetric.ec.generate_private_key"><code class="xref py py-func docutils literal"><span class="pre">generate_private_key()</span></code></a>).</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKeyWithSerialization">
<em class="property">class </em><code class="descclassname">cryptography.hazmat.primitives.asymmetric.ec.</code><code class="descname">EllipticCurvePublicKeyWithSerialization</code><a class="headerlink" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKeyWithSerialization" title="Permalink to this definition"></a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified">New in version 0.6.</span></p>
</div>
<p>Alias for <a class="reference internal" href="#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey" title="cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey"><code class="xref py py-class docutils literal"><span class="pre">EllipticCurvePublicKey</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="serialization">
<h3>Serialization<a class="headerlink" href="#serialization" title="Permalink to this headline"></a></h3>
<p>This sample demonstrates how to generate a private key and serialize it.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.backends</span> <span class="k">import</span> <span class="n">default_backend</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives</span> <span class="k">import</span> <span class="n">hashes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives.asymmetric</span> <span class="k">import</span> <span class="n">ec</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives</span> <span class="k">import</span> <span class="n">serialization</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">private_key</span> <span class="o">=</span> <span class="n">ec</span><span class="o">.</span><span class="n">generate_private_key</span><span class="p">(</span><span class="n">ec</span><span class="o">.</span><span class="n">SECP384R1</span><span class="p">(),</span> <span class="n">default_backend</span><span class="p">())</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">serialized_private</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">private_bytes</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">encoding</span><span class="o">=</span><span class="n">serialization</span><span class="o">.</span><span class="n">Encoding</span><span class="o">.</span><span class="n">PEM</span><span class="p">,</span>
<span class="gp">... </span>    <span class="nb">format</span><span class="o">=</span><span class="n">serialization</span><span class="o">.</span><span class="n">PrivateFormat</span><span class="o">.</span><span class="n">PKCS8</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">encryption_algorithm</span><span class="o">=</span><span class="n">serialization</span><span class="o">.</span><span class="n">BestAvailableEncryption</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;testpassword&#39;</span><span class="p">)</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">serialized_private</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">&#39;-----BEGIN ENCRYPTED PRIVATE KEY-----&#39;</span>
</pre></div>
</div>
<p>You can also serialize the key without a password, by relying on
<a class="reference internal" href="serialization.html#cryptography.hazmat.primitives.serialization.NoEncryption" title="cryptography.hazmat.primitives.serialization.NoEncryption"><code class="xref py py-class docutils literal"><span class="pre">NoEncryption</span></code></a>.</p>
<p>The public key is serialized as follows:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">public_key</span> <span class="o">=</span> <span class="n">private_key</span><span class="o">.</span><span class="n">public_key</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">serialized_public</span> <span class="o">=</span> <span class="n">public_key</span><span class="o">.</span><span class="n">public_bytes</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">encoding</span><span class="o">=</span><span class="n">serialization</span><span class="o">.</span><span class="n">Encoding</span><span class="o">.</span><span class="n">PEM</span><span class="p">,</span>
<span class="gp">... </span>    <span class="nb">format</span><span class="o">=</span><span class="n">serialization</span><span class="o">.</span><span class="n">PublicFormat</span><span class="o">.</span><span class="n">SubjectPublicKeyInfo</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">serialized_public</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">&#39;-----BEGIN PUBLIC KEY-----&#39;</span>
</pre></div>
</div>
<p>This is the part that you would normally share with the rest of the world.</p>
</div>
<div class="section" id="key-loading">
<h3>Key loading<a class="headerlink" href="#key-loading" title="Permalink to this headline"></a></h3>
<p>This extends the sample in the previous section, assuming that the variables
<code class="docutils literal"><span class="pre">serialized_private</span></code> and <code class="docutils literal"><span class="pre">serialized_public</span></code> contain the respective keys
in PEM format.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">loaded_public_key</span> <span class="o">=</span> <span class="n">serialization</span><span class="o">.</span><span class="n">load_pem_public_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">serialized_public</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">backend</span><span class="o">=</span><span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">loaded_private_key</span> <span class="o">=</span> <span class="n">serialization</span><span class="o">.</span><span class="n">load_pem_private_key</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">serialized_private</span><span class="p">,</span>
<span class="gp">... </span>    <span class="c1"># or password=None, if in plain text</span>
<span class="gp">... </span>    <span class="n">password</span><span class="o">=</span><span class="sa">b</span><span class="s1">&#39;testpassword&#39;</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">backend</span><span class="o">=</span><span class="n">default_backend</span><span class="p">()</span>
<span class="gp">... </span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Elliptic curve cryptography</a><ul>
<li><a class="reference internal" href="#elliptic-curve-signature-algorithms">Elliptic Curve Signature Algorithms</a></li>
<li><a class="reference internal" href="#elliptic-curve-key-exchange-algorithm">Elliptic Curve Key Exchange algorithm</a></li>
<li><a class="reference internal" href="#elliptic-curves">Elliptic Curves</a><ul>
<li><a class="reference internal" href="#key-interfaces">Key Interfaces</a></li>
<li><a class="reference internal" href="#serialization">Serialization</a></li>
<li><a class="reference internal" href="#key-loading">Key loading</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="dsa.html"
                        title="previous chapter">DSA</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="rsa.html"
                        title="next chapter">RSA</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/hazmat/primitives/asymmetric/ec.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="rsa.html" title="RSA"
             >next</a> |</li>
        <li class="right" >
          <a href="dsa.html" title="DSA"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">Cryptography 2.1.4 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Primitives</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Asymmetric algorithms</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2013-2018, Individual Contributors.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
    </div>
  </body>
</html>