{"id":13491019,"url":"https://github.com/P-H-C/phc-winner-argon2","last_synced_at":"2025-03-28T07:31:39.554Z","repository":{"id":1959459,"uuid":"43629790","full_name":"P-H-C/phc-winner-argon2","owner":"P-H-C","description":"The password hash Argon2, winner of PHC ","archived":false,"fork":false,"pushed_at":"2024-08-06T13:28:45.000Z","size":5907,"stargazers_count":4933,"open_issues_count":93,"forks_count":420,"subscribers_count":119,"default_branch":"master","last_synced_at":"2025-03-25T17:17:50.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/P-H-C.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-04T08:25:27.000Z","updated_at":"2025-03-25T13:39:19.000Z","dependencies_parsed_at":"2023-07-05T19:02:56.914Z","dependency_job_id":"f0b4d1b0-a7cc-4967-a4a5-8da1ae09a1ba","html_url":"https://github.com/P-H-C/phc-winner-argon2","commit_stats":{"total_commits":492,"total_committers":82,"mean_commits":6.0,"dds":0.7134146341463414,"last_synced_commit":"f57e61e19229e23c4445b85494dbf7c07de721cb"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P-H-C%2Fphc-winner-argon2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P-H-C%2Fphc-winner-argon2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P-H-C%2Fphc-winner-argon2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P-H-C%2Fphc-winner-argon2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/P-H-C","download_url":"https://codeload.github.com/P-H-C/phc-winner-argon2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245989169,"owners_count":20705774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:00:52.870Z","updated_at":"2025-03-28T07:31:39.512Z","avatar_url":"https://github.com/P-H-C.png","language":"C","funding_links":[],"categories":["Miscellaneous","C","Packages"],"sub_categories":["Mad Science!"],"readme":"# Argon2\n\n[![Build Status](https://travis-ci.org/P-H-C/phc-winner-argon2.svg?branch=master)](https://travis-ci.org/P-H-C/phc-winner-argon2)\n[![Build status](https://ci.appveyor.com/api/projects/status/8nfwuwq55sgfkele?svg=true)](https://ci.appveyor.com/project/P-H-C/phc-winner-argon2)\n[![codecov.io](https://codecov.io/github/P-H-C/phc-winner-argon2/coverage.svg?branch=master)](https://codecov.io/github/P-H-C/phc-winner-argon2?branch=master)\n\nThis is the reference C implementation of Argon2, the password-hashing\nfunction that won the [Password Hashing Competition\n(PHC)](https://password-hashing.net).\n\nArgon2 is a password-hashing function that summarizes the state of the\nart in the design of memory-hard functions and can be used to hash\npasswords for credential storage, key derivation, or other applications.\n\nIt has a simple design aimed at the highest memory filling rate and\neffective use of multiple computing units, while still providing defense\nagainst tradeoff attacks (by exploiting the cache and memory organization\nof the recent processors).\n\nArgon2 has three variants: Argon2i, Argon2d, and Argon2id. Argon2d is faster\nand uses data-depending memory access, which makes it highly resistant\nagainst GPU cracking attacks and suitable for applications with no threats\nfrom side-channel timing attacks (eg. cryptocurrencies). Argon2i instead\nuses data-independent memory access, which is preferred for password\nhashing and password-based key derivation, but it is slower as it makes\nmore passes over the memory to protect from tradeoff attacks. Argon2id is a\nhybrid of Argon2i and Argon2d, using a combination of data-depending and\ndata-independent memory accesses, which gives some of Argon2i's resistance to\nside-channel cache timing attacks and much of Argon2d's resistance to GPU\ncracking attacks.\n\nArgon2i, Argon2d, and Argon2id are parametrized by:\n\n* A **time** cost, which defines the amount of computation realized and\n  therefore the execution time, given in number of iterations\n* A **memory** cost, which defines the memory usage, given in kibibytes\n* A **parallelism** degree, which defines the number of parallel threads\n\nThe [Argon2 document](argon2-specs.pdf) gives detailed specs and design\nrationale.\n\nPlease report bugs as issues on this repository.\n\n## Usage\n\n`make` builds the executable `argon2`, the static library `libargon2.a`,\nand the shared library `libargon2.so` (or on macOS, the dynamic library\n`libargon2.dylib` -- make sure to specify the installation prefix when\nyou compile: `make PREFIX=/usr`). Make sure to run `make test` to verify\nthat your build produces valid results. `sudo make install PREFIX=/usr`\ninstalls it to your system.\n\n### Command-line utility\n\n`argon2` is a command-line utility to test specific Argon2 instances\non your system. To show usage instructions, run\n`./argon2 -h` as\n```\nUsage:  ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)]\n        Password is read from stdin\nParameters:\n        salt            The salt to use, at least 8 characters\n        -i              Use Argon2i (this is the default)\n        -d              Use Argon2d instead of Argon2i\n        -id             Use Argon2id instead of Argon2i\n        -t N            Sets the number of iterations to N (default = 3)\n        -m N            Sets the memory usage of 2^N KiB (default 12)\n        -p N            Sets parallelism to N threads (default 1)\n        -l N            Sets hash output length to N bytes (default 32)\n        -e              Output only encoded hash\n        -r              Output only the raw bytes of the hash\n        -v (10|13)      Argon2 version (defaults to the most recent version, currently 13)\n        -h              Print argon2 usage\n```\nFor example, to hash \"password\" using \"somesalt\" as a salt and doing 2\niterations, consuming 64 MiB, using four parallel threads and an output hash\nof 24 bytes\n```\n$ echo -n \"password\" | ./argon2 somesalt -t 2 -m 16 -p 4 -l 24\nType:           Argon2i\nIterations:     2\nMemory:         65536 KiB\nParallelism:    4\nHash:           45d7ac72e76f242b20b77b9bf9bf9d5915894e669a24e6c6\nEncoded:        $argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG\n0.188 seconds\nVerification ok\n```\n\n### Library\n\n`libargon2` provides an API to both low-level and high-level functions\nfor using Argon2.\n\nThe example program below hashes the string \"password\" with Argon2i\nusing the high-level API and then using the low-level API. While the\nhigh-level API takes the three cost parameters (time, memory, and\nparallelism), the password input buffer, the salt input buffer, and the\noutput buffers, the low-level API takes in these and additional parameters\n, as defined in [`include/argon2.h`](include/argon2.h).\n\nThere are many additional parameters, but we will highlight three of them here.\n\n1. The `secret` parameter, which is used for [keyed hashing](\n   https://en.wikipedia.org/wiki/Hash-based_message_authentication_code).\n   This allows a secret key to be input at hashing time (from some external\n   location) and be folded into the value of the hash. This means that even if\n   your salts and hashes are compromised, an attacker cannot brute-force to find\n   the password without the key.\n\n2. The `ad` parameter, which is used to fold any additional data into the hash\n   value. Functionally, this behaves almost exactly like the `secret` or `salt`\n   parameters; the `ad` parameter is folding into the value of the hash.\n   However, this parameter is used for different data. The `salt` should be a\n   random string stored alongside your password. The `secret` should be a random\n   key only usable at hashing time. The `ad` is for any other data.\n\n3. The `flags` parameter, which determines which memory should be securely\n   erased. This is useful if you want to securely delete the `pwd` or `secret`\n   fields right after they are used. To do this set `flags` to either\n   `ARGON2_FLAG_CLEAR_PASSWORD` or `ARGON2_FLAG_CLEAR_SECRET`. To change how\n   internal memory is cleared, change the global flag\n   `FLAG_clear_internal_memory` (defaults to clearing internal memory).\n\nHere the time cost `t_cost` is set to 2 iterations, the\nmemory cost `m_cost` is set to 2\u003csup\u003e16\u003c/sup\u003e kibibytes (64 mebibytes),\nand parallelism is set to 1 (single-thread).\n\nCompile for example as `gcc test.c libargon2.a -Isrc -o test`, if the program\nbelow is named `test.c` and placed in the project's root directory.\n\n```c\n#include \"argon2.h\"\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cstdlib.h\u003e\n\n#define HASHLEN 32\n#define SALTLEN 16\n#define PWD \"password\"\n\nint main(void)\n{\n    uint8_t hash1[HASHLEN];\n    uint8_t hash2[HASHLEN];\n\n    uint8_t salt[SALTLEN];\n    memset( salt, 0x00, SALTLEN );\n\n    uint8_t *pwd = (uint8_t *)strdup(PWD);\n    uint32_t pwdlen = strlen((char *)pwd);\n\n    uint32_t t_cost = 2;            // 2-pass computation\n    uint32_t m_cost = (1\u003c\u003c16);      // 64 mebibytes memory usage\n    uint32_t parallelism = 1;       // number of threads and lanes\n\n    // high-level API\n    argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, hash1, HASHLEN);\n\n    // low-level API\n    argon2_context context = {\n        hash2,  /* output array, at least HASHLEN in size */\n        HASHLEN, /* digest length */\n        pwd, /* password array */\n        pwdlen, /* password length */\n        salt,  /* salt array */\n        SALTLEN, /* salt length */\n        NULL, 0, /* optional secret data */\n        NULL, 0, /* optional associated data */\n        t_cost, m_cost, parallelism, parallelism,\n        ARGON2_VERSION_13, /* algorithm version */\n        NULL, NULL, /* custom memory allocation / deallocation functions */\n        /* by default only internal memory is cleared (pwd is not wiped) */\n        ARGON2_DEFAULT_FLAGS\n    };\n\n    int rc = argon2i_ctx( \u0026context );\n    if(ARGON2_OK != rc) {\n        printf(\"Error: %s\\n\", argon2_error_message(rc));\n        exit(1);\n    }\n    free(pwd);\n\n    for( int i=0; i\u003cHASHLEN; ++i ) printf( \"%02x\", hash1[i] ); printf( \"\\n\" );\n    if (memcmp(hash1, hash2, HASHLEN)) {\n        for( int i=0; i\u003cHASHLEN; ++i ) {\n            printf( \"%02x\", hash2[i] );\n        }\n        printf(\"\\nfail\\n\");\n    }\n    else printf(\"ok\\n\");\n    return 0;\n}\n```\n\nTo use Argon2d instead of Argon2i call `argon2d_hash_raw` instead of\n`argon2i_hash_raw` using the high-level API, and `argon2d` instead of\n`argon2i` using the low-level API. Similarly for Argon2id, call `argon2id_hash_raw`\nand `argon2id`.\n\nTo produce the crypt-like encoding rather than the raw hash, call\n`argon2i_hash_encoded` for Argon2i, `argon2d_hash_encoded` for Argon2d, and\n`argon2id_hash_encoded` for Argon2id\n\nSee [`include/argon2.h`](include/argon2.h) for API details.\n\n*Note: in this example the salt is set to the all-`0x00` string for the\nsake of simplicity, but in your application you should use a random salt.*\n\n\n### Benchmarks\n\n`make bench` creates the executable `bench`, which measures the execution\ntime of various Argon2 instances:\n\n```\n$ ./bench\nArgon2d 1 iterations  1 MiB 1 threads:  5.91 cpb 5.91 Mcycles\nArgon2i 1 iterations  1 MiB 1 threads:  4.64 cpb 4.64 Mcycles\n0.0041 seconds\n\nArgon2d 1 iterations  1 MiB 2 threads:  2.76 cpb 2.76 Mcycles\nArgon2i 1 iterations  1 MiB 2 threads:  2.87 cpb 2.87 Mcycles\n0.0038 seconds\n\nArgon2d 1 iterations  1 MiB 4 threads:  3.25 cpb 3.25 Mcycles\nArgon2i 1 iterations  1 MiB 4 threads:  3.57 cpb 3.57 Mcycles\n0.0048 seconds\n\n(...)\n\nArgon2d 1 iterations  4096 MiB 2 threads:  2.15 cpb 8788.08 Mcycles\nArgon2i 1 iterations  4096 MiB 2 threads:  2.15 cpb 8821.59 Mcycles\n13.0112 seconds\n\nArgon2d 1 iterations  4096 MiB 4 threads:  1.79 cpb 7343.72 Mcycles\nArgon2i 1 iterations  4096 MiB 4 threads:  2.72 cpb 11124.86 Mcycles\n19.3974 seconds\n\n(...)\n```\n\n## Bindings\n\nBindings are available for the following languages (make sure to read\ntheir documentation):\n\n* [Android (Java/Kotlin)](https://github.com/lambdapioneer/argon2kt) by [@lambdapioneer](https://github.com/lambdapioneer)\n* [Dart](https://github.com/tmthecoder/dargon2) by [@tmthecoder](https://github.com/tmthecoder)\n* [Elixir](https://github.com/riverrun/argon2_elixir) by [@riverrun](https://github.com/riverrun)\n* [Erlang](https://github.com/ergenius/eargon2) by [@ergenius](https://github.com/ergenius)\n* [Go](https://github.com/tvdburgt/go-argon2) by [@tvdburgt](https://github.com/tvdburgt)\n* [Haskell](https://hackage.haskell.org/package/argon2) by [@hvr](https://github.com/hvr)\n* [JavaScript (native)](https://github.com/ranisalt/node-argon2), by [@ranisalt](https://github.com/ranisalt)\n* [JavaScript (native)](https://github.com/jdconley/argon2themax), by [@jdconley](https://github.com/jdconley)\n* [JavaScript (ffi)](https://github.com/cjlarose/argon2-ffi), by [@cjlarose](https://github.com/cjlarose)\n* [JavaScript (browser)](https://github.com/antelle/argon2-browser), by [@antelle](https://github.com/antelle)\n* [JVM](https://github.com/phxql/argon2-jvm) by [@phXql](https://github.com/phxql)\n* [JVM (with keyed hashing)](https://github.com/kosprov/jargon2-api) by [@kosprov](https://github.com/kosprov)\n* [Lua (native)](https://github.com/thibaultCha/lua-argon2) by [@thibaultCha](https://github.com/thibaultCha)\n* [Lua (ffi)](https://github.com/thibaultCha/lua-argon2-ffi) by [@thibaultCha](https://github.com/thibaultCha)\n* [OCaml](https://github.com/Khady/ocaml-argon2) by [@Khady](https://github.com/Khady)\n* [Python (native)](https://pypi.python.org/pypi/argon2), by [@flamewow](https://github.com/flamewow)\n* [Python (ffi)](https://pypi.python.org/pypi/argon2_cffi), by [@hynek](https://github.com/hynek)\n* [Python (ffi, with keyed hashing)](https://github.com/thusoy/porridge), by [@thusoy](https://github.com/thusoy)\n* [Python (ffi, with keyed hashing)](https://github.com/ultrahorizon/pyargon2), by [@ultrahorizon](https://github.com/ultrahorizon)\n* [R](https://cran.r-project.org/package=argon2) by [@wrathematics](https://github.com/wrathematics)\n* [Ruby](https://github.com/technion/ruby-argon2) by [@technion](https://github.com/technion)\n* [Rust](https://github.com/quininer/argon2-rs) by [@quininer](https://github.com/quininer)\n* [Rust](https://docs.rs/argonautica/) by [@bcmyers](https://github.com/bcmyers/)\n* [C#/.NET CoreCLR](https://github.com/kmaragon/Konscious.Security.Cryptography) by [@kmaragon](https://github.com/kmaragon)\n* [Perl](https://github.com/Leont/crypt-argon2) by [@leont](https://github.com/Leont)\n* [mruby](https://github.com/Asmod4n/mruby-argon2) by [@Asmod4n](https://github.com/Asmod4n)\n* [Swift](https://github.com/ImKcat/CatCrypto) by [@ImKcat](https://github.com/ImKcat)\n* [Swift](https://github.com/tmthecoder/Argon2Swift) by [@tmthecoder](https://github.com/tmthecoder)\n\n\n## Test suite\n\nThere are two sets of test suites. One is a low level test for the hash\nfunction, the other tests the higher level API. Both of these are built and\nexecuted by running:\n\n`make test`\n\n## Intellectual property\n\nExcept for the components listed below, the Argon2 code in this\nrepository is copyright (c) 2015 Daniel Dinu, Dmitry Khovratovich (main\nauthors), Jean-Philippe Aumasson and Samuel Neves, and dual licensed under the\n[CC0 License](https://creativecommons.org/about/cc0) and the\n[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For more info\nsee the LICENSE file.\n\nThe string encoding routines in [`src/encoding.c`](src/encoding.c) are\ncopyright (c) 2015 Thomas Pornin, and under\n[CC0 License](https://creativecommons.org/about/cc0).\n\nThe BLAKE2 code in [`src/blake2/`](src/blake2) is copyright (c) Samuel\nNeves, 2013-2015, and under\n[CC0 License](https://creativecommons.org/about/cc0).\n\nAll licenses are therefore GPL-compatible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FP-H-C%2Fphc-winner-argon2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FP-H-C%2Fphc-winner-argon2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FP-H-C%2Fphc-winner-argon2/lists"}