"hmac" — メッセージ認証のための鍵付きハッシュ化
***********************************************

バージョン 2.2 で追加.

**ソースコード:** Lib/hmac.py

======================================================================

このモジュールでは **RFC 2104** で記述されている HMAC アルゴリズムを実
装しています。

hmac.new(key[, msg[, digestmod]])

   Return a new hmac object.  If *msg* is present, the method call
   "update(msg)" is made. *digestmod* is the digest constructor or
   module for the HMAC object to use. It defaults to  the
   "hashlib.md5" constructor.

HMAC オブジェクトは以下のメソッドを持っています:

HMAC.update(msg)

   Update the hmac object with the string *msg*.  Repeated calls are
   equivalent to a single call with the concatenation of all the
   arguments: "m.update(a); m.update(b)" is equivalent to "m.update(a
   + b)".

HMAC.digest()

   Return the digest of the strings passed to the "update()" method so
   far. This string will be the same length as the *digest_size* of
   the digest given to the constructor.  It may contain non-ASCII
   characters, including NUL bytes.

   警告: "digest()" の出力結果と外部から供給されたダイジェストを検証
     ルーチ ン内で比較しようとするのであれば、タイミング攻撃への脆弱性
     を減ら すために、 "==" 演算子ではなく "compare_digest()" を使うこ
     とをお 奨めします。

HMAC.hexdigest()

   "digest()" と似ていますが、返される文字列は倍の長さとなり、16進形式
   となります。これは、電子メールなどの非バイナリ環境で値を交換する場
   合に便利です。

   警告: "hexdigest()" の出力結果と外部から供給されたダイジェストを
     検証ル ーチン内で比較しようとするのであれば、タイミング攻撃への脆
     弱性を 減らすために、 "==" 演算子ではなく "compare_digest()" を使
     うこと をお奨めします。

HMAC.copy()

   hmac オブジェクトのコピー (「クローン」) を返します。このコピーは最
   初の部分文字列が共通になっている文字列のダイジェスト値を効率よく計
   算するために使うことができます。

このモジュールは以下のヘルパ関数も提供しています:

hmac.compare_digest(a, b)

   Return "a == b".  This function uses an approach designed to
   prevent timing analysis by avoiding content-based short circuiting
   behaviour, making it appropriate for cryptography.  *a* and *b*
   must both be of the same type: either "unicode" or a *bytes-like
   object*.

   注釈: *a* と *b* が異なる長さであったりエラーが発生すれ場合には、
     タイミ ング攻撃で理論上 *a* と *b* の型と長さについての情報が暴露
     されま すが、その値は明らかになりません。

   バージョン 2.7.7 で追加.

参考:

  "hashlib" モジュール
     セキュアハッシュ関数を提供する Python モジュールです。
