You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
7.2 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>hmac - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package hmac</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "crypto/hmac"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as
  68. defined in U.S. Federal Information Processing Standards Publication 198.
  69. An HMAC is a cryptographic hash that uses a key to sign a message.
  70. The receiver verifies the hash by recomputing it using the same key.
  71. </p>
  72. <p>
  73. Receivers should be careful to use Equal to compare MACs in order to avoid
  74. timing side-channels:
  75. </p>
  76. <pre>// CheckMAC reports whether messageMAC is a valid HMAC tag for message.
  77. func CheckMAC(message, messageMAC, key []byte) bool {
  78. mac := hmac.New(sha256.New, key)
  79. mac.Write(message)
  80. expectedMAC := mac.Sum(nil)
  81. return hmac.Equal(messageMAC, expectedMAC)
  82. }
  83. </pre>
  84. </div>
  85. </div>
  86. <div id="pkg-index" class="toggleVisible">
  87. <div class="collapsed">
  88. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  89. </div>
  90. <div class="expanded">
  91. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  92. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  93. <div id="manual-nav">
  94. <dl>
  95. <dd><a href="index.html#Equal">func Equal(mac1, mac2 []byte) bool</a></dd>
  96. <dd><a href="index.html#New">func New(h func() hash.Hash, key []byte) hash.Hash</a></dd>
  97. </dl>
  98. </div><!-- #manual-nav -->
  99. <h4>Package files</h4>
  100. <p>
  101. <span style="font-size:90%">
  102. <a href="http://localhost:6060/src/crypto/hmac/hmac.go">hmac.go</a>
  103. </span>
  104. </p>
  105. </div><!-- .expanded -->
  106. </div><!-- #pkg-index -->
  107. <div id="pkg-callgraph" class="toggle" style="display: none">
  108. <div class="collapsed">
  109. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  110. </div> <!-- .expanded -->
  111. <div class="expanded">
  112. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  113. <p>
  114. In the call graph viewer below, each node
  115. is a function belonging to this package
  116. and its children are the functions it
  117. calls&mdash;perhaps dynamically.
  118. </p>
  119. <p>
  120. The root nodes are the entry points of the
  121. package: functions that may be called from
  122. outside the package.
  123. There may be non-exported or anonymous
  124. functions among them if they are called
  125. dynamically from another package.
  126. </p>
  127. <p>
  128. Click a node to visit that function's source code.
  129. From there you can visit its callers by
  130. clicking its declaring <code>func</code>
  131. token.
  132. </p>
  133. <p>
  134. Functions may be omitted if they were
  135. determined to be unreachable in the
  136. particular programs or tests that were
  137. analyzed.
  138. </p>
  139. <!-- Zero means show all package entry points. -->
  140. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  141. </div>
  142. </div> <!-- #pkg-callgraph -->
  143. <h2 id="Equal">func <a href="http://localhost:6060/src/crypto/hmac/hmac.go?s=2448:2482#L87">Equal</a></h2>
  144. <pre>func Equal(mac1, mac2 []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../builtin/index.html#bool">bool</a></pre>
  145. <p>
  146. Equal compares two MACs for equality without leaking timing information.
  147. </p>
  148. <h2 id="New">func <a href="http://localhost:6060/src/crypto/hmac/hmac.go?s=1969:2019#L68">New</a></h2>
  149. <pre>func New(h func() <a href="../../hash/index.html">hash</a>.<a href="../../hash/index.html#Hash">Hash</a>, key []<a href="../../builtin/index.html#byte">byte</a>) <a href="../../hash/index.html">hash</a>.<a href="../../hash/index.html#Hash">Hash</a></pre>
  150. <p>
  151. New returns a new HMAC hash using the given hash.Hash type and key.
  152. </p>
  153. <div id="footer">
  154. Build version go1.6.<br>
  155. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  156. the content of this page is licensed under the
  157. Creative Commons Attribution 3.0 License,
  158. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  159. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  160. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  161. </div>
  162. </div><!-- .container -->
  163. </div><!-- #page -->
  164. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  165. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  166. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  167. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  168. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  169. </body>
  170. </html>