Skip to content

Commit

Permalink
Init!
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Dec 23, 2021
0 parents commit d2fccb0
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Security Policy

Please note that I only support the last version of this module.

If you believe to have found a vulnerability in blake2-d, I strongly advise you
to draft a new security advisory under Security > Securitiy advisories.

If that's not alright with you, you can always send me an email (found on my profile).
18 changes: 18 additions & 0 deletions .github/workflows/d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: D

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dlang-community/setup-dlang@v1
- name: 'Build'
run: dub build --compiler=dmd
- name: 'Test'
run: dub test --compiler=dmd
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.dub
dub.selections.json
docs.json
__dummy.html
docs/
/blake2-d
blake2-d.so
blake2-d.dylib
blake2-d.dll
blake2-d.a
blake2-d.lib
blake2-d-test-*
*.exe
*.o
*.obj
*.lst
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# blake2-d

BLAKE2 library written in D implementing the BLAKE2b and BLAKE2s hashing
algorithms and is compatible with the Phobos Digest API (std.digest).

BLAKE2 was introduced in 2015 as IETF RFC 7693. You can visit
[the website](https://www.blake2.net/) for more information.

This module:

- [x] Supports BLAKE2b-512 and BLAKE2s-256.
- [x] Supports custom hash sizes.
- [ ] Supports HMAC. (WIP!)

Compatible and tested with DMD, GDC, and LDC.

Pull Requests accepted.

**If you would like to disclose a vulnerability, please consult [SECURITY.md](../master/.github/SECURITY.md).**

# Usage

To include it in your project, simply import the `blake2d` package.

## Digest API

If you are unfamiliar with the Digest API, here is a quick summary.

Two APIs are available: Template API and OOP API.

### Template API

The template API uses a structure template and is a good choice if your
application only plans to support one digest algorithm.

```d
// NOTE: hexString is from std.conv
BLAKE2b512 b2b512;
b2b512.put("abc");
assert(b2b512.finish() == cast(ubyte[]) hexString!(
"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
"7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"
));
b2b512.start(); // reset
b2b512.put("abcdef");
assert(b2b512.finish() == cast(ubyte[]) hexString!(
"dde410524e3569b303e494aa82a3afb3e426f9df24c1398e9ff87aafbc2f5b7b"~
"3c1a4c9400409de3b45d37a00e5eae2a93cc9c4a108b00f05217d41a424d2b8a");
```

### OOP API

The OOP API uses a class (object) implementation and is a good choice if
your application plans to support one or more digest algorithms.

```d
// NOTE: hexString is from std.conv
Digest dgst = new BLAKE2b512Digest();
dgst.put("abc");
assert(dgst.finish() == cast(ubyte[]) hexString!(
"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1"~
"7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"
));
dgst.start(); // reset
dgst.put("abcdef");
assert(dgst.finish() == cast(ubyte[]) hexString!(
"dde410524e3569b303e494aa82a3afb3e426f9df24c1398e9ff87aafbc2f5b7b"~
"3c1a4c9400409de3b45d37a00e5eae2a93cc9c4a108b00f05217d41a424d2b8a");
```

There are numerous ways to avoid GC allocation. For example when only using a
digest for a one-time use in a short scope, there's `std.typecons.scoped`.

# License

Published under the Boost License 1.0.
5 changes: 5 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name "blake2-d"
description "BLAKE2s and BLAKEb implementations."
authors "dd86k <[email protected]>"
copyright "Copyright © 2021, dd86k"
license "BSL-1.0"
Loading

0 comments on commit d2fccb0

Please sign in to comment.