# chacha

> ChaCha20 Poly1305 auth cipher with a node api with pure js and native bindings

Latest version **2.1.0** (published 2015-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install chacha
pnpm add chacha
yarn add chacha
bun add chacha
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2015-09-10 |
| First published | 2014-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Maintainers | cwmma |
| Keywords | chacha20, chacha, poly1305, cipher, hmac, crypto |

## Links

- npm: https://www.npmjs.com/package/chacha
- Repository: https://github.com/calvinmetcalf/chacha20poly1305
- Issues: https://github.com/calvinmetcalf/chacha20poly1305/issues
- npm.io page: https://npm.io/package/chacha

## Dependencies (3)

- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [chacha-native](https://npm.io/package/chacha-native.md) ^2.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^1.0.33

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2015-09-10
- 2.0.0 — 2015-03-17
- 1.1.2 — 2015-03-16
- 1.1.1 — 2015-01-21
- 1.1.0 — 2014-11-21
- 1.0.5 — 2014-11-19
- 1.0.4 — 2014-11-19
- 1.0.3 — 2014-11-18
- 1.0.2 — 2014-11-18
- 1.0.1 — 2014-11-18
- 1.0.0 — 2014-11-18

## README

ChaCha [![Build Status](https://travis-ci.org/calvinmetcalf/chacha20poly1305.svg?branch=master)](https://travis-ci.org/calvinmetcalf/chacha20poly1305)
====


ChaCha20 Poly1305 implementation based on this [repo](https://github.com/devi/chacha20poly1305), test vectors are from this [ietf draft](https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-03) and boringssl.  Note there are 2 versions of the chacha20/poly1305 aead, an [earlier draft](https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04) and a modified version with a longer nonce, shorter counter and different tag generation.  This is the more recent version, boringssl implemented the older version which is also included.

By default in node it attempts to use [native bindings](https://github.com/calvinmetcalf/chacha-native) and falls back to using the pure js implimentation. In the browser it defaults to the pure js one.  To use the pure js one in node `require('/chacha/browser');`.

API
===

```js
var chacha = require('chacha');
```

# ChaCha20 Poly1305

```js
var cipher =  chacha.createCipher(key, nonce);
var decipher =  chacha.createDecipher(key, nonce);
```

Create a cipher object by passing it a 256 bit key and 96 bit nonce, API is identical to crypto.createCipheriv()/createDecipheriv in node >= 11 with a gcm mode, in other words, e.g.

```js
cipher.setAAD(nonencrypteddata);// must be called before data
var tag = cipher.getAuthTag();// must be called after finish or end

decipher.setAAD(nonencrypteddata);// must be called before data
decipher.setAuthTag(tag);// must be called before data
```

decipher with throw if you don't set a tag or the tag doesn't match. See the [node docs](https://github.com/joyent/node/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/doc/api/crypto.markdown#cryptocreatecipherivalgorithm-key-iv) for more info (the iv length for gcm is also 96 bit fyi).

# ChaCha20


```js
var cipher =  chacha.chacha(key, nonce);
```

The API is identical to a cipher/decipher object in node >= 10. Encryption and decryption are the same.

# Poly1305

```js
var hmac =  chacha.createHmac(key);
```

API is identical to an hmac in node, so it's a stream with update and digest methods.

# Legacy Aead

A variant version of the aead that is compatible with boringssl.

```js
var cipher =  new chacha.AeadLegacy(key, nonce);
var decipher =  new chacha.AeadLegacy(key, nonce, true);
```

The third parameter is whether it should decipher, otherwise identical to createCipher/createDecipher. Doesn't implement variable length tags.

---
_Source: https://npm.io/package/chacha · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
