aboutsummaryrefslogtreecommitdiffstats
path: root/docs/development/custom-vectors/secp256k1
Commit message (Expand)AuthorAgeFilesLines
* use the non-deprecated name for this functionAlex Gaynor2015-12-191-2/+2
* Verification scriptAlex Stapleton2015-05-031-0/+59
* Script for generating SECP256K1 vectorsAlex Stapleton2015-05-031-0/+89
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
.. hazmat::

Two-factor authentication
=========================

.. currentmodule:: cryptography.hazmat.primitives.twofactor

This module contains algorithms related to two-factor authentication.

Currently, it contains an algorithm for generating and verifying
one time password values based on Hash-based message authentication
codes (HMAC).

.. class:: InvalidToken

    This is raised when the verify method of a one time password function's
    computed token does not match the expected token.

.. currentmodule:: cryptography.hazmat.primitives.twofactor.hotp

.. class:: HOTP(key, length, algorithm, backend, enforce_key_length=True)

    .. versionadded:: 0.3

    HOTP objects take a ``key``, ``length`` and ``algorithm`` parameter. The
    ``key`` should be :doc:`randomly generated bytes </random-numbers>` and is
    recommended to be 160 :term:`bits` in length. The ``length`` parameter
    controls the length of the generated one time password and must be >= 6
    and <= 8.

    This is an implementation of :rfc:`4226`.

    .. doctest::

        >>> import os
        >>> from cryptography.hazmat.backends import default_backend
        >>> from cryptography.hazmat.primitives.twofactor.hotp import HOTP
        >>> from cryptography.hazmat.primitives.hashes import SHA1
        >>> key = os.urandom(20)
        >>> hotp = HOTP(key, 6, SHA1(), backend=default_backend())
        >>> hotp_value = hotp.generate(0)
        >>> hotp.verify(hotp_value, 0)

    :param bytes key: Per-user secret key. This value must be kept secret
                      and be at least 128 :term:`bits`. It is recommended that
                      the key be 160 bits.
    :param int length: Length of generated one time password as ``int``.
    :param cryptography.hazmat.primitives.hashes.HashAlgorithm algorithm: A
        :class:`~cryptography.hazmat.primitives.hashes`