mdn.go-v.org

Hash function

A hash function is a function that takes a variable-length input and produces a fixed-length output, also called a digest (or just a "hash"). Hash functions should be quick to compute, and different inputs should as far as possible produce different outputs (this is called collision-resistance).

source: MDN Web Docslicence: CC BY-SA 2.5+ (MDN)database: /home/dbs/mdn.dbmode: tablerecords: 14753 (max_rowid)citation: https://developer.mozilla.org/

A hash function is a function that takes a variable-length input and produces a fixed-length output, also called a digest (or just a "hash"). Hash functions should be quick to compute, and different inputs should as far as possible produce different outputs (this is called collision-resistance).

Full text

A **hash function** is a function that takes a variable-length input and produces a fixed-length output, also called a _digest_ (or just a "hash"). Hash functions should be quick to compute, and different inputs should as far as possible produce different outputs (this is called _collision-resistance_).

Hash functions have both cryptographic and non-cryptographic uses. Outside cryptography, for example, hash functions can be used to generate the keys for an associative array such as a map or a dictionary.

The digest() function of the SubtleCrypto interface makes various hash functions available to web applications.

## Cryptographic hash functions

In cryptography, hash functions have many applications, including digital signatures, and message authentication codes.

Not all hash functions are appropriate for cryptography. To be used for cryptography, a hash function must be:

- quick to compute
- one-way: given the output, it should be impractical or impossible to regenerate the original input
- tamper-resistant: any change to the input leads to a different output
- collision-resistant: it should be impractical to find two different inputs that produce the same output

The hash functions most commonly used in cryptography are from the _SHA-2_ (Secure Hash Algorithm 2) family, whose names are `"SHA-"` followed by the length of the output digest in bits: for example, `"SHA-256"` and `"SHA-512"`.

SHA-2 is the successor to the SHA-1 algorithm, which is no longer considered secure and should not be used in cryptography. Note that the MD5 algorithm is also considered insecure.

## See also

- SubtleCrypto.digest()
- [Hash function](https://en.wikipedia.org/wiki/Hash_function) on Wikipedia
- [Cryptographic hash function](https://en.wikipedia.org/wiki/Cryptographic_hash_function) on Wikipedia
- Related glossary terms:
- Symmetric-key cryptography

Fields

page_typeglossary-definition
tags
source: MDN Web Docslicence: CC BY-SA 2.5+ (MDN)year: —id: Glossary/Hash_functioncitation: https://developer.mozilla.org/en-US/docs/Glossary/Hash_function

JSON · full text · full-text JSON

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.