@@ -28,9 +28,10 @@ fn test_nacl_vector() {
28
28
0xd9 ,
29
29
] ;
30
30
31
- assert_eq ! ( & Poly1305 :: new( & key) . chain( & msg) . result( ) , & expected[ ..] ) ;
31
+ let result1 = Poly1305 :: new ( & key) . chain ( & msg) . result ( ) ;
32
+ assert_eq ! ( & expected[ ..] , result1. code( ) . as_slice( ) ) ;
32
33
33
- let result = Poly1305 :: new ( & key)
34
+ let result2 = Poly1305 :: new ( & key)
34
35
. chain ( & msg[ 0 ..32 ] )
35
36
. chain ( & msg[ 32 ..96 ] )
36
37
. chain ( & msg[ 96 ..112 ] )
@@ -44,7 +45,7 @@ fn test_nacl_vector() {
44
45
. chain ( & msg[ 130 ..131 ] )
45
46
. result ( ) ;
46
47
47
- assert_eq ! ( & result , & expected[ ..] ) ;
48
+ assert_eq ! ( & expected[ ..] , result2 . code ( ) . as_slice ( ) ) ;
48
49
}
49
50
50
51
#[ test]
@@ -65,10 +66,9 @@ fn donna_self_test() {
65
66
0x00 ,
66
67
] ;
67
68
68
- assert_eq ! (
69
- & Poly1305 :: new( & wrap_key) . chain( & wrap_msg) . result( ) ,
70
- & wrap_mac[ ..]
71
- ) ;
69
+ let result = Poly1305 :: new ( & wrap_key) . chain ( & wrap_msg) . result ( ) ;
70
+
71
+ assert_eq ! ( & wrap_mac[ ..] , result. code( ) . as_slice( ) ) ;
72
72
73
73
let total_key = [
74
74
0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0xff , 0xfe , 0xfd , 0xfc , 0xfb , 0xfa , 0xf9 , 0xff ,
@@ -88,29 +88,56 @@ fn donna_self_test() {
88
88
key. copy_from_slice ( & repeat ( i as u8 ) . take ( KEY_SIZE ) . collect :: < Vec < _ > > ( ) ) ;
89
89
90
90
let msg: Vec < u8 > = repeat ( i as u8 ) . take ( 256 ) . collect ( ) ;
91
- tpoly. input ( & Poly1305 :: new ( & key) . chain ( & msg[ ..i] ) . result ( ) ) ;
91
+ let tag = Poly1305 :: new ( & key) . chain ( & msg[ ..i] ) . result ( ) ;
92
+ tpoly. input ( tag. code ( ) . as_slice ( ) ) ;
92
93
}
93
94
94
- assert_eq ! ( & tpoly. result( ) , & total_mac [ .. ] ) ;
95
+ assert_eq ! ( & total_mac [ .. ] , tpoly. result( ) . code ( ) . as_slice ( ) ) ;
95
96
}
96
97
97
98
#[ test]
98
99
fn test_tls_vectors ( ) {
99
100
// from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04
100
101
let key = b"this is 32-byte key for Poly1305" ;
101
- let msg = [ 0u8 ; 32 ] ;
102
- let expected = [
102
+
103
+ let msg1 = [ 0u8 ; 32 ] ;
104
+ let expected1 = [
103
105
0x49 , 0xec , 0x78 , 0x09 , 0x0e , 0x48 , 0x1e , 0xc6 , 0xc2 , 0x6b , 0x33 , 0xb9 , 0x1c , 0xcc , 0x03 ,
104
106
0x07 ,
105
107
] ;
106
108
107
- assert_eq ! ( & Poly1305 :: new( & key) . chain( & msg) . result( ) , & expected[ ..] ) ;
109
+ let result1 = Poly1305 :: new ( & key) . chain ( & msg1) . result ( ) ;
110
+ assert_eq ! ( & expected1[ ..] , result1. code( ) . as_slice( ) ) ;
108
111
109
- let msg = b"Hello world!" ;
110
- let expected = [
112
+ let msg2 = b"Hello world!" ;
113
+ let expected2 = [
111
114
0xa6 , 0xf7 , 0x45 , 0x00 , 0x8f , 0x81 , 0xc9 , 0x16 , 0xa2 , 0x0d , 0xcc , 0x74 , 0xee , 0xf2 , 0xb2 ,
112
115
0xf0 ,
113
116
] ;
114
117
115
- assert_eq ! ( & Poly1305 :: new( & key) . chain( & msg[ ..] ) . result( ) , & expected[ ..] ) ;
118
+ let result2 = Poly1305 :: new ( & key) . chain ( & msg2[ ..] ) . result ( ) ;
119
+ assert_eq ! ( & expected2[ ..] , result2. code( ) . as_slice( ) ) ;
120
+ }
121
+
122
+ #[ test]
123
+ fn padded_input ( ) {
124
+ // poly1305 key and AAD from <https://tools.ietf.org/html/rfc8439#section-2.8.2>
125
+ let key = [
126
+ 0x7b , 0xac , 0x2b , 0x25 , 0x2d , 0xb4 , 0x47 , 0xaf , 0x09 , 0xb6 , 0x7a , 0x55 , 0xa4 , 0xe9 , 0x55 ,
127
+ 0x84 , 0x0a , 0xe1 , 0xd6 , 0x73 , 0x10 , 0x75 , 0xd9 , 0xeb , 0x2a , 0x93 , 0x75 , 0x78 , 0x3e , 0xd5 ,
128
+ 0x53 , 0xff ,
129
+ ] ;
130
+
131
+ let msg = [
132
+ 0x50 , 0x51 , 0x52 , 0x53 , 0xc0 , 0xc1 , 0xc2 , 0xc3 , 0xc4 , 0xc5 , 0xc6 , 0xc7 ,
133
+ ] ;
134
+
135
+ let expected = [
136
+ 0xad , 0xa5 , 0x6c , 0xaa , 0x48 , 0xf , 0xe6 , 0xf5 , 0x6 , 0x70 , 0x39 , 0x24 , 0x4a , 0x3d , 0x76 ,
137
+ 0xba ,
138
+ ] ;
139
+
140
+ let mut poly = Poly1305 :: new ( & key) ;
141
+ poly. input_padded ( & msg) ;
142
+ assert_eq ! ( & expected[ ..] , poly. result( ) . code( ) . as_slice( ) ) ;
116
143
}
0 commit comments