@@ -10,29 +10,13 @@ import 'package:hashlib/src/core/mac_base.dart';
10
10
11
11
export 'algorithms/poly1305/poly1305_sink.dart' show Poly1305Sink;
12
12
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 ();
31
15
32
16
@override
33
17
final String name = 'Poly1305' ;
34
18
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.
36
20
/// The first 16-bytes will be used as a secret key to encode the message,
37
21
/// and the last 16-bytes will be used as the authentication key to sign it.
38
22
///
@@ -47,12 +31,12 @@ class Poly1305 extends MACHash<Poly1305Sink> {
47
31
/// allow for forgeries.
48
32
///
49
33
/// 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.
51
35
@override
52
36
MACHashBase <Poly1305Sink > by (List <int > keypair) =>
53
- _Poly1305 (keypair is Uint8List ? keypair : Uint8List .fromList (keypair));
37
+ Poly1305 (keypair is Uint8List ? keypair : Uint8List .fromList (keypair));
54
38
55
- /// Creates a new instance of [Poly1305 ] .
39
+ /// Creates a new instance of [_Poly1305 ] .
56
40
///
57
41
/// Parameters:
58
42
/// - [key] is required and must contain exactly 16 bytes.
@@ -68,7 +52,7 @@ class Poly1305 extends MACHash<Poly1305Sink> {
68
52
/// allow for forgeries.
69
53
///
70
54
/// 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.
72
56
MACHashBase <Poly1305Sink > pair (List <int > key, [List <int >? secret]) {
73
57
if (secret == null ) {
74
58
return by (key);
@@ -82,10 +66,42 @@ class Poly1305 extends MACHash<Poly1305Sink> {
82
66
var pair = Uint8List (32 );
83
67
pair.setAll (0 , key);
84
68
pair.setAll (16 , secret);
85
- return _Poly1305 (pair);
69
+ return Poly1305 (pair);
86
70
}
87
71
}
88
72
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
+
89
105
/// Computes the Poly1305 MAC (message authentication code) of the given
90
106
/// [message] using the given the 16 or 32-byte long [keypair] for authentication.
91
107
///
0 commit comments