chacha20 1.0.2

Introduction #

A pure Dart implementation of Chacha20, a popular stream encryption algorithm. Tests utilize examples from RFC 7539, an implementation guide by the the Internet Research Task Force.

Performance on a recent Intel CPU + Dart VM is:

  • About 100MB/s when message size is 1 MB.
  • About 50MB/s when message size is 100 bytes.

Licensed under the Apache License 2.0.

A simple example #

import 'dart:typed_data';

void main() {
    // ----------
    // Parameters
    // ----------
    // 256-bit (secret) key
    var key = Chacha20.randomKey();
    // 96-bit (non-secret) nonce
    var nonce = new Uint8List(12);
    // -------------
    // Convert bytes
    // -------------
    // Initialize
    final chacha20 = new Chacha20();
    chacha20.initialize(key: key, nonce: nonce);
    // convert message [1,2,3]
    // ---------------------------------------
    // Convert more messages with the same key
    // ---------------------------------------
    // It's important that we don't re-use the same (key, nonce) combination.
    // So let's increment the nonce for the next message.
    nonce = Chacha20.incrementNonceBytes(nonce);
    // ------------------
    // Converting streams
    // ------------------
    // Let's say we have the following stream
    final stream = new Stream<List<int>>.fromIterable([[1,2,3], [5], [7,11]]);
    // Initialize
    chacha20.initialize(key: key, nonce: nonce);
    // Convert chunk-by-chunk.
    // 'keyStreamIndex' is incremented when you advance in the stream.
    final convertedStream = {
      return chacha20.convert(chunk);

1.0.1 #

  • Removed non-inlined version.

1.0.0 #

  • Initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  chacha20: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:chacha20/chacha20.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:chacha20/chacha20.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and chacha20.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
meta ^1.0.0 1.1.7
Dev dependencies
benchmark_harness ^1.0.5
pedantic ^1.0.0
test ^1.4.0