Skip to content

Commit 0d0c90b

Browse files
committed
feat: sha-2 hash functions; refactoring
Breaking Changes
1 parent 2e59e17 commit 0d0c90b

File tree

158 files changed

+9075
-939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+9075
-939
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ and this project adheres to [Dart Package Versioning](https://dart.dev/tools/pub
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- file "func.dart" with the definition of the functional interfaces.
13+
- cryptographic package with hash functions sha224, sha256, sha384, sha512,
14+
along with their related Hmac function (Hash-based message authentication
15+
code)
16+
- tabular text of ordinary text and data. The data can be represented with
17+
binary, octal, decimal, or hexadecimal notation.
18+
- radix package: a set of classes for converting numeric data into its textual
19+
representation in a given radix (numeric base).
20+
- bit package: a set of classes for bit-related operations.
21+
- several benchmarks comparing Dartoos to the Dart sdk or other third-party
22+
packages like _Crypto_.
23+
24+
### Changed
25+
26+
- No class extends FutureWrap any more — **BREAKING CHANGE**.
27+
- A general reorganization of the package directory structures.
28+
29+
### Removed
30+
31+
- FutureWrap — **BREAKING CHANGE**.
32+
1033
## [0.2.0] - 2021-10-15
1134

1235
### Added

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ This project is heavily inspired by Java
3333

3434
- No external dependencies.
3535
- Object-Oriented mindset: each concept is implemented by an **immutable** class.
36-
- For easier composability and integration with the undelying Dart's sdk, most
37-
of the classes are instances of Future.
36+
- Straightforward integration with the underlying Dart sdk.
3837

3938
## Getting started
4039

example/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build output.
6+
build/

example/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

example/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dartoos Showcase
2+
3+
How to use Dartoos effectively.
4+
5+
## Getting Started
6+
7+
From the root directory of this project, enter the following commands:
8+
9+
```shell
10+
cd example/
11+
dart run radix/hex_of_bytes_benchmark.dart
12+
```
13+
14+
This launchs the benchmark of the `HexOfBytes` class, which in turn converts an
15+
array of bytes to its hexadecimal text representation. The end result is a small
16+
report that compares the performance of a typical Dart implementation of such a
17+
conversion (bytes to hexadecimal) with the performance of the conversion
18+
provided by the Dartoos package.
19+
20+
Likewise, you can issue similar commands to launch other benchmarks programs.

example/analysis_options.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include: package:lint/analysis_options_package.yaml
2+
analyzer:
3+
strong-mode:
4+
# A value of false ensures that the type inference engine never implicitly casts
5+
# from dynamic to a more specific type.
6+
implicit-casts: false
7+
# A value of false ensures that the type inference engine never chooses the
8+
# dynamic type when it can’t determine a static type.
9+
# implicit-dynamic: false
10+
implicit-dynamic: false
11+
linter:
12+
rules:
13+
# Make constructors the first thing in every class
14+
sort_constructors_first: true
15+
# Good packages document everything
16+
public_member_api_docs: true
17+
# Always await.
18+
unawaited_futures: true
19+
always_declare_return_types: true
20+
cancel_subscriptions: true
21+
close_sinks: true
22+
only_throw_errors: true
23+
package_api_docs: true

example/base64_benchmark.dart

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ignore_for_file: avoid_print
2+
3+
import 'package:crypto/crypto.dart' as crypto;
4+
import 'package:dartoos/dartoos.dart';
5+
6+
import '../../utils/perf_gain.dart';
7+
8+
/// Dartoos Hmac Sha256 vs. Dart's built-in
9+
///
10+
/// Running:
11+
/// ```dart /example/crypto/hash/hmac_sha256_benchmark.dart```
12+
///
13+
/// or
14+
///
15+
/// Compile to 'jit'.
16+
/// ```dart compile jit-snapshot example/crypto/hash/hmac_sha256_benchmark.dart```
17+
/// ```dart /example/crypto/hash/hmac_sha256_benchemark.jit```
18+
void main() {
19+
print("Dartoos HMAC-SHA256 vs. Cryptos HMAC-SHA256...");
20+
const len = 25000000;
21+
const alphabet =
22+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
23+
final data = BytesOf.text(Rand(len, alphabet)).value;
24+
final key = BytesOf.utf8('Dartoos vs Crypto').value;
25+
print('\nLength of the data to be hashed: ${data.lengthInBytes} bytes.');
26+
27+
print('\n--- Hashing elapsed times ---');
28+
final watch = Stopwatch()..start();
29+
final cryptoHmac = crypto.Hmac(crypto.sha256, key).convert(data).toString();
30+
final cryptoHashTime = watch.elapsedMicroseconds / 1000;
31+
watch.stop();
32+
print('Crypto hashing time.......: $cryptoHashTime milliseconds');
33+
print('Crypto digest value.......: $cryptoHmac');
34+
watch.reset();
35+
36+
watch.start();
37+
final dartoosHmac = HexHmac.sha256(key).value(data);
38+
final dartoosHashTime = watch.elapsedMicroseconds / 1000;
39+
watch.stop();
40+
print('Dartoos hashing time......: $dartoosHashTime milliseconds');
41+
print('Dartoos digest value......: $dartoosHmac');
42+
const perf = PerfGain();
43+
print('Performance ratio.........: ${perf(cryptoHashTime, dartoosHashTime)}');
44+
print('Are the generated digests the same? ${dartoosHmac == cryptoHmac}');
45+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ignore_for_file: avoid_print
2+
3+
import 'package:crypto/crypto.dart' as crypto;
4+
import 'package:dartoos/dartoos.dart';
5+
6+
import '../../utils/perf_gain.dart';
7+
8+
/// Dartoos sha256 vs. Dart's built-in
9+
///
10+
/// Running:
11+
/// ```dart /example/crypto/hash/sha256_benchmark.dart```
12+
///
13+
/// or
14+
///
15+
/// Compile to 'jit'.
16+
/// ```dart compile jit-snapshot example/crypto/hash/sha256_benchmark.dart```
17+
/// ```dart /example/crypto/hash/sha256_benchemark.jit```
18+
void main() {
19+
print("Dartoos sha256 vs. Cryptos sha256...");
20+
21+
const len = 25000000;
22+
const alphabet =
23+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
24+
final data = BytesOf.text(Rand(len, alphabet)).value;
25+
print('\nLength of the data to be hashed: ${data.lengthInBytes} bytes.');
26+
27+
print('\n--- Hashing elapsed times ---');
28+
final watch = Stopwatch()..start();
29+
final cryptoDigest = crypto.sha256.convert(data).toString();
30+
crypto.sha256.blockSize;
31+
final cryptoHashTime = watch.elapsedMicroseconds / 1000;
32+
watch.stop();
33+
print('Crypto hashing time.......: $cryptoHashTime milliseconds');
34+
print('Crypto digest value.......: $cryptoDigest');
35+
watch.reset();
36+
37+
watch.start();
38+
final dartoosDigest = hexSha256(data);
39+
final dartoosHashTime = watch.elapsedMicroseconds / 1000;
40+
watch.stop();
41+
print('Dartoos hashing time......: $dartoosHashTime milliseconds');
42+
print('Dartoos digest value......: $dartoosDigest');
43+
const perf = PerfGain();
44+
print('Performance ratio.........: ${perf(cryptoHashTime, dartoosHashTime)}');
45+
print('Are the generated digests the same? ${dartoosDigest == cryptoDigest}');
46+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ignore_for_file: avoid_print
2+
3+
import 'package:crypto/crypto.dart' as crypto;
4+
import 'package:dartoos/dartoos.dart';
5+
6+
import '../../utils/perf_gain.dart';
7+
8+
/// Dartoos sha512 vs. Dart's built-in
9+
///
10+
/// Running:
11+
/// ```dart /example/crypto/hash/sha512_benchmark.dart```
12+
///
13+
/// or
14+
///
15+
/// Compile to 'jit'.
16+
/// ```dart compile jit-snapshot example/crypto/hash/sha512_benchmark.dart```
17+
/// ```dart /example/crypto/hash/sha512_benchemark.jit```
18+
void main() {
19+
print("Dartoos sha512 vs. Crypto sha512...");
20+
21+
const len = 25000000;
22+
const alphabet =
23+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
24+
final data = BytesOf.text(Rand(len, alphabet)).value;
25+
print('\nLength of the data to be hashed: ${data.lengthInBytes} bytes.');
26+
27+
print('\n--- SHA-512 — Elapsed times for hasing ---');
28+
final watch = Stopwatch()..start();
29+
final cryptoDigest = crypto.sha512.convert(data).toString();
30+
final cryptoHashTime = watch.elapsedMicroseconds / 1000;
31+
watch.stop();
32+
print('Crypto hashing time.......: $cryptoHashTime milliseconds');
33+
print('Crypto digest value.......: $cryptoDigest');
34+
watch.reset();
35+
36+
watch.start();
37+
final dartoosDigest = hexSha512(data);
38+
final dartoosHashTime = watch.elapsedMicroseconds / 1000;
39+
watch.stop();
40+
print('Dartoos hashing time......: $dartoosHashTime milliseconds');
41+
print('Dartoos digest value......: $dartoosDigest');
42+
const perf = PerfGain();
43+
print('Performance ratio.........: ${perf(cryptoHashTime, dartoosHashTime)}');
44+
print('Are the generated digests the same? ${dartoosDigest == cryptoDigest}');
45+
}

0 commit comments

Comments
 (0)