Skip to content

Commit e9940da

Browse files
committed
Modifies interface for Poly1305
1 parent c7f974c commit e9940da

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.20.2
2+
3+
- Modifies interface for `Poly1305`
4+
15
# 1.20.1
26

37
- Modifies `MACHash` and `MACHashBase` interfaces for accessibility.

lib/src/poly1305.dart

+40-24
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,13 @@ import 'package:hashlib/src/core/mac_base.dart';
1010

1111
export 'algorithms/poly1305/poly1305_sink.dart' show Poly1305Sink;
1212

13-
/// The Poly1305 MAC (message authentication code) generator for an input
14-
/// message using either 16 or 32-byte long authentication key.
15-
const poly1305 = Poly1305();
16-
17-
class _Poly1305 extends HashBase<Poly1305Sink> with MACHashBase<Poly1305Sink> {
18-
final Uint8List key;
19-
20-
const _Poly1305(this.key);
21-
22-
@override
23-
final String name = 'Poly1305';
24-
25-
@override
26-
Poly1305Sink createSink() => Poly1305Sink(key);
27-
}
28-
29-
class Poly1305 extends MACHash<Poly1305Sink> {
30-
const Poly1305();
13+
class _Poly1305 extends MACHash<Poly1305Sink> {
14+
const _Poly1305();
3115

3216
@override
3317
final String name = 'Poly1305';
3418

35-
/// Create a new instance of [Poly1305] with a 16 or 32-byte long keypair.
19+
/// Create a new instance of [_Poly1305] with a 16 or 32-byte long keypair.
3620
/// The first 16-bytes will be used as a secret key to encode the message,
3721
/// and the last 16-bytes will be used as the authentication key to sign it.
3822
///
@@ -47,12 +31,12 @@ class Poly1305 extends MACHash<Poly1305Sink> {
4731
/// allow for forgeries.
4832
///
4933
/// See also:
50-
/// - [Poly1305.pair] to input key(`r`) and secret(`s`) pair separately.
34+
/// - [_Poly1305.pair] to input key(`r`) and secret(`s`) pair separately.
5135
@override
5236
MACHashBase<Poly1305Sink> by(List<int> keypair) =>
53-
_Poly1305(keypair is Uint8List ? keypair : Uint8List.fromList(keypair));
37+
Poly1305(keypair is Uint8List ? keypair : Uint8List.fromList(keypair));
5438

55-
/// Creates a new instance of [Poly1305].
39+
/// Creates a new instance of [_Poly1305].
5640
///
5741
/// Parameters:
5842
/// - [key] is required and must contain exactly 16 bytes.
@@ -68,7 +52,7 @@ class Poly1305 extends MACHash<Poly1305Sink> {
6852
/// allow for forgeries.
6953
///
7054
/// See also:
71-
/// - [Poly1305.by] to input key(`r`) and secret(`s`) pair together.
55+
/// - [_Poly1305.by] to input key(`r`) and secret(`s`) pair together.
7256
MACHashBase<Poly1305Sink> pair(List<int> key, [List<int>? secret]) {
7357
if (secret == null) {
7458
return by(key);
@@ -82,10 +66,42 @@ class Poly1305 extends MACHash<Poly1305Sink> {
8266
var pair = Uint8List(32);
8367
pair.setAll(0, key);
8468
pair.setAll(16, secret);
85-
return _Poly1305(pair);
69+
return Poly1305(pair);
8670
}
8771
}
8872

73+
/// The Poly1305 MAC (message authentication code) generator for an input
74+
/// message using either 16 or 32-byte long authentication key.
75+
const poly1305 = _Poly1305();
76+
77+
class Poly1305 extends HashBase<Poly1305Sink> with MACHashBase<Poly1305Sink> {
78+
final Uint8List keypair;
79+
80+
@override
81+
final String name = 'Poly1305';
82+
83+
/// Create a new instance of [_Poly1305] with a 16 or 32-byte long keypair.
84+
/// The first 16-bytes will be used as a secret key to encode the message,
85+
/// and the last 16-bytes will be used as the authentication key to sign it.
86+
///
87+
/// Parameters:
88+
/// - [keypair] is required and must contain exactly 16 or 32 bytes.
89+
///
90+
/// If [keypair] length is 16 bytes, the final digest will not be signed.
91+
///
92+
/// **Warning**:
93+
/// The algorithm is designed to ensure unforgeability of a message with a
94+
/// random key. Authenticating multiple messages using the same key could
95+
/// allow for forgeries.
96+
///
97+
/// See also:
98+
/// - [_Poly1305.pair] to input key(`r`) and secret(`s`) pair separately.
99+
const Poly1305(this.keypair);
100+
101+
@override
102+
Poly1305Sink createSink() => Poly1305Sink(keypair);
103+
}
104+
89105
/// Computes the Poly1305 MAC (message authentication code) of the given
90106
/// [message] using the given the 16 or 32-byte long [keypair] for authentication.
91107
///

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: hashlib
22
description: Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.
33
homepage: https://github.com/bitanon/hashlib
4-
version: 1.20.1
4+
version: 1.20.2
55

66
environment:
77
sdk: '>=2.14.0 <4.0.0'

test/poly1305_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void main() {
197197
0x28, 0x99, 0x57, 0x94, 0x41, 0x27, 0xd7, 0x5e,
198198
];
199199

200-
var sink = Poly1305().by(key).createSink();
200+
var sink = poly1305.by(key).createSink();
201201
for (int i = 0; i < 256; i++) {
202202
var mac = poly1305
203203
.pair(

0 commit comments

Comments
 (0)